Skip to content

Commit

Permalink
Merge pull request #5 from papo2608/master
Browse files Browse the repository at this point in the history
Add optional 'filters' argument
  • Loading branch information
devxoul authored Jan 8, 2019
2 parents c9dd2e8 + 412a00b commit 146b14f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/poeditor/commands/pull_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def get_configuration(argv)
project_id: get_or_raise(yaml, "project_id"),
type: get_or_raise(yaml, "type"),
tags: yaml["tags"],
filters: yaml["filters"],
languages: get_or_raise(yaml, "languages"),
language_alias: yaml["language_alias"],
path: get_or_raise(yaml, "path"),
Expand Down
7 changes: 6 additions & 1 deletion lib/poeditor/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class Configuration

# @return [Array<String>] Tag filters (optional)
attr_accessor :tags

# @return [Array<String>] Filters by 'translated', 'untranslated', 'fuzzy', 'not_fuzzy', 'automatic', 'not_automatic', 'proofread', 'not_proofread' (optional)
attr_accessor :filters

# @return [Array<String>] The languages codes
attr_accessor :languages
Expand All @@ -26,12 +29,13 @@ class Configuration
attr_accessor :path_replace

def initialize(api_key:, project_id:, type:, tags:nil,
languages:, language_alias:nil,
filters:nil, languages:, language_alias:nil,
path:, path_replace:nil)
@api_key = from_env(api_key)
@project_id = from_env(project_id.to_s)
@type = type
@tags = tags || []
@filters = filters || []

@languages = languages
@language_alias = language_alias || {}
Expand All @@ -53,6 +57,7 @@ def to_s
values = {
"type" => self.type,
"tags" => self.tags,
"filters" => self.filters,
"languages" => self.languages,
"language_alias" => self.language_alias,
"path" => self.path,
Expand Down
7 changes: 5 additions & 2 deletions lib/poeditor/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def pull()
:project_id => @configuration.project_id,
:language => language,
:type => @configuration.type,
:tags => @configuration.tags)
:tags => @configuration.tags,
:filters => @configuration.filters)
write(language, content)

for alias_to, alias_from in @configuration.language_alias
Expand All @@ -57,14 +58,16 @@ def pull()
# @param language [String]
# @param type [String]
# @param tags [Array<String>]
# @param filters [Array<String>]
#
# @return Downloaded translation content
def export(api_key:, project_id:, language:, type:, tags:nil)
def export(api_key:, project_id:, language:, type:, tags:nil, filters:nil)
options = {
"id" => project_id,
"language" => convert_to_poeditor_language(language),
"type" => type,
"tags" => (tags || []).join(","),
"filters" => (filters || []).join(","),
}
response = self.api("projects/export", api_key, options)
data = JSON(response.body)
Expand Down
1 change: 1 addition & 0 deletions test/test_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def get_client(type:,
:project_id => 12345,
:type => type,
:tags => nil,
:filters => nil,
:languages => languages,
:language_alias => language_alias,
:path_replace => path_replace,
Expand Down

0 comments on commit 146b14f

Please sign in to comment.