ruby-lokalise-api 3.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -91,7 +91,7 @@ module Lokalise
91
91
  # Collection example: `{ "content": {"comments": [ ... ]} }`
92
92
  def produce_collection_for(response)
93
93
  model_class = self.class.name.base_class_name
94
- data_key_plural = data_key_for model_class, true, true
94
+ data_key_plural = data_key_for model_class: model_class, plural: true, collection: true
95
95
 
96
96
  # Fetch collection data and instantiate an individual resource for each object
97
97
  # We also preserve the `client` to be able to chain API methods later
@@ -162,6 +162,7 @@
162
162
  "languages",
163
163
  "auto_close_languages",
164
164
  "auto_close_task",
165
+ "auto_close_items",
165
166
  "completed_at",
166
167
  "completed_at_timestamp",
167
168
  "completed_by",
@@ -95,7 +95,7 @@ module Lokalise
95
95
  # Instantiates a new resource or collection based on the given response
96
96
  def object_from(response, params)
97
97
  model_class = name.base_class_name
98
- data_key_plural = data_key_for model_class, true
98
+ data_key_plural = data_key_for model_class: model_class, plural: true
99
99
  # Preserve the initial path to allow chaining
100
100
  response['path'] = params.delete(:_initial_path) if params.key?(:_initial_path)
101
101
 
@@ -107,7 +107,7 @@ module Lokalise
107
107
  end
108
108
 
109
109
  def produce_resource(model_class, response)
110
- data_key_singular = data_key_for model_class
110
+ data_key_singular = data_key_for model_class: model_class
111
111
  if response['content'].key? data_key_singular
112
112
  data = response['content'].delete data_key_singular
113
113
  response['content'].merge! data
@@ -124,7 +124,7 @@ module Lokalise
124
124
  # Generates path for the individual resource based on the path for the collection
125
125
  def infer_path_from(response, endpoint_generator = nil)
126
126
  id_key = id_key_for self.class.name.base_class_name
127
- data_key = data_key_for self.class.name.base_class_name
127
+ data_key = data_key_for model_class: self.class.name.base_class_name
128
128
 
129
129
  path_with_id response, id_key, data_key, endpoint_generator
130
130
  end
@@ -164,7 +164,7 @@ module Lokalise
164
164
  # Store all resources attributes under the corresponding instance variables.
165
165
  # `ATTRIBUTES` is defined inside resource-specific classes
166
166
  def populate_attributes_for(content)
167
- data_key = data_key_for self.class.name.base_class_name
167
+ data_key = data_key_for model_class: self.class.name.base_class_name
168
168
 
169
169
  self.class.const_get(:ATTRIBUTES).each do |attr|
170
170
  value = if content.key?(data_key) && content[data_key].is_a?(Hash)
@@ -6,7 +6,7 @@ module Lokalise
6
6
  supports :update, :destroy, [:reload_data, '', :find]
7
7
 
8
8
  def empty
9
- self.class.empty @client, @path + '/empty'
9
+ self.class.empty @client, "#{@path}/empty"
10
10
  end
11
11
 
12
12
  class << self
@@ -6,7 +6,7 @@ module Lokalise
6
6
  supports :update, :destroy, [:reload_data, '', :find]
7
7
 
8
8
  def regenerate_secret
9
- self.class.regenerate_secret @client, @path + '/secret/regenerate'
9
+ self.class.regenerate_secret @client, "#{@path}/secret/regenerate"
10
10
  end
11
11
 
12
12
  class << self
@@ -16,16 +16,21 @@ module Lokalise
16
16
  # @return [String]
17
17
  # @param model_class [String]
18
18
  # @param plural [Boolean] Should the returned value be pluralized?
19
- def data_key_for(model_class, plural = false, collection = false)
20
- data_key_plural = get_key('DATA_KEY_PLURAL', model_class, true, true)
19
+ def data_key_for(model_class:, plural: false, collection: false)
20
+ data_key_plural = get_key(
21
+ name: 'DATA_KEY_PLURAL',
22
+ model_class: model_class,
23
+ collection: true,
24
+ strict: true
25
+ )
21
26
 
22
27
  return data_key_plural if collection && data_key_plural
23
28
 
24
- data_key = get_key 'DATA_KEY', model_class, collection
29
+ data_key = get_key name: 'DATA_KEY', model_class: model_class, collection: collection
25
30
 
26
31
  return data_key unless plural
27
32
 
28
- data_key + 's'
33
+ "#{data_key}s"
29
34
  end
30
35
 
31
36
  # Returns key used to determine resource id (for example `user_id` or `project_id`).
@@ -35,7 +40,7 @@ module Lokalise
35
40
  # @return [String]
36
41
  # @param model_class [String]
37
42
  def id_key_for(model_class)
38
- get_key('ID_KEY', model_class) + '_id'
43
+ "#{get_key(name: 'ID_KEY', model_class: model_class)}_id"
39
44
  end
40
45
 
41
46
  # Loads attributes for the given resource based on its name
@@ -52,7 +57,7 @@ module Lokalise
52
57
 
53
58
  private
54
59
 
55
- def get_key(name, model_class, collection = false, strict = false)
60
+ def get_key(name:, model_class:, collection: false, strict: false)
56
61
  key = if collection && Module.const_defined?("Lokalise::Collections::#{model_class}::#{name}")
57
62
  Module.const_get "Lokalise::Collections::#{model_class}::#{name}"
58
63
  elsif Module.const_defined? "Lokalise::Resources::#{model_class}::#{name}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lokalise
4
- VERSION = '3.1.0'
4
+ VERSION = '4.0.0'
5
5
  end
@@ -10,8 +10,9 @@ Gem::Specification.new do |spec|
10
10
  spec.summary = 'Ruby interface to the Lokalise API'
11
11
  spec.description = 'Opinionated Ruby client for the Lokalise platform API allowing to work with translations, projects, users and other resources as with Ruby objects.'
12
12
  spec.homepage = 'https://github.com/lokalise/ruby-lokalise-api'
13
- spec.license = 'MIT'
13
+ spec.license = 'BSD-3-Clause'
14
14
  spec.platform = Gem::Platform::RUBY
15
+ spec.required_ruby_version = '>= 2.5.0'
15
16
 
16
17
  spec.files = Dir['README.md', 'LICENSE',
17
18
  'CHANGELOG.md', 'lib/**/*.rb', 'lib/ruby-lokalise-api/data/attributes.json',
@@ -30,9 +31,9 @@ Gem::Specification.new do |spec|
30
31
  spec.add_development_dependency 'oj', '~> 3.10'
31
32
  spec.add_development_dependency 'rake', '~> 13.0'
32
33
  spec.add_development_dependency 'rspec', '~> 3.6'
33
- spec.add_development_dependency 'rubocop', '~> 0.60'
34
+ spec.add_development_dependency 'rubocop', '~> 1.6'
34
35
  spec.add_development_dependency 'rubocop-performance', '~> 1.5'
35
- spec.add_development_dependency 'rubocop-rspec', '~> 1.37'
36
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.0'
36
37
  spec.add_development_dependency 'simplecov', '~> 0.16'
37
38
  spec.add_development_dependency 'vcr', '~> 6.0'
38
39
  end
@@ -27,7 +27,7 @@ RSpec.describe Lokalise::JsonHandler do
27
27
  '{":name":"rspec proj",":description":"demo project for rspec"}'
28
28
  end
29
29
 
30
- # rubocop:disable RSpec/LeakyConstantDeclaration
30
+ # rubocop:disable RSpec/LeakyConstantDeclaration, Lint/ConstantDefinitionInBlock
31
31
  before do
32
32
  module Lokalise
33
33
  module JsonHandler
@@ -55,10 +55,10 @@ RSpec.describe Lokalise::JsonHandler do
55
55
  end
56
56
  end
57
57
  end
58
- # rubocop:enable RSpec/LeakyConstantDeclaration
58
+ # rubocop:enable RSpec/LeakyConstantDeclaration, Lint/ConstantDefinitionInBlock
59
59
 
60
60
  it 'allows to customize #load' do
61
- expect(Oj).to receive(:load).and_return(loaded_json)
61
+ allow(Oj).to receive(:load).and_return(loaded_json)
62
62
  expect(JSON).not_to receive(:parse)
63
63
  projects = VCR.use_cassette('all_projects_pagination') do
64
64
  test_client.projects limit: 1, page: 2
@@ -70,7 +70,7 @@ RSpec.describe Lokalise::JsonHandler do
70
70
  end
71
71
 
72
72
  it 'allows to customize #dump' do
73
- expect(Oj).to receive(:dump).and_return(dumped_json)
73
+ allow(Oj).to receive(:dump).and_return(dumped_json)
74
74
  expect(JSON).not_to receive(:dump)
75
75
  project = VCR.use_cassette('new_project') do
76
76
  test_client.create_project name: 'rspec proj', description: 'demo project for rspec'
@@ -36,9 +36,9 @@ RSpec.describe Lokalise::Client do
36
36
  specify '#create_payment_card' do
37
37
  card = VCR.use_cassette('new_payment_card') do
38
38
  test_client.create_payment_card number: '4242424242424242',
39
- "cvc": '123',
40
- "exp_month": 1,
41
- "exp_year": 2030
39
+ cvc: '123',
40
+ exp_month: 1,
41
+ exp_year: 2030
42
42
  end
43
43
 
44
44
  expect(card.card_id).to eq(card_id)
@@ -35,8 +35,8 @@ RSpec.describe Lokalise::Client do
35
35
  expect(task.task_id).to eq(11_925)
36
36
  expect(task.title).to eq('node updated')
37
37
  expect(task.description).to eq('')
38
- expect(task.status).to eq('in progress')
39
- expect(task.progress).to eq(1)
38
+ expect(task.status).to eq('completed')
39
+ expect(task.progress).to eq(0)
40
40
  expect(task.due_date).to eq(nil)
41
41
  expect(task.due_date_timestamp).to eq(nil)
42
42
  expect(task.keys_count).to eq(16)
@@ -45,17 +45,18 @@ RSpec.describe Lokalise::Client do
45
45
  expect(task.created_at_timestamp).to eq(1_557_764_126)
46
46
  expect(task.created_by).to eq(20_181)
47
47
  expect(task.created_by_email).to eq('bodrovis@protonmail.com')
48
- expect(task.can_be_parent).to eq(true)
48
+ expect(task.can_be_parent).to eq(false)
49
49
  expect(task.task_type).to eq('review')
50
50
  expect(task.parent_task_id).to eq(nil)
51
51
  expect(task.closing_tags).to eq([])
52
52
  expect(task.languages.first['language_iso']).to eq('sq')
53
53
  expect(task.auto_close_languages).to eq(true)
54
54
  expect(task.auto_close_task).to eq(true)
55
- expect(task.completed_by).to eq(nil)
56
- expect(task.completed_by_email).to eq(nil)
57
- expect(task.completed_at).to eq(nil)
58
- expect(task.completed_at_timestamp).to eq(nil)
55
+ expect(task.auto_close_items).to eq(true)
56
+ expect(task.completed_by).to eq(20_181)
57
+ expect(task.completed_by_email).to eq('bodrovis@protonmail.com')
58
+ expect(task.completed_at).to eq('2019-10-01 11:09:12 (Etc/UTC)')
59
+ expect(task.completed_at_timestamp).to eq(1_569_928_152)
59
60
  expect(task.do_lock_translations).to eq(false)
60
61
  expect(task.custom_translation_status_ids).to eq([])
61
62
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lokalise-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Bodrov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-08 00:00:00.000000000 Z
11
+ date: 2021-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0.60'
131
+ version: '1.6'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0.60'
138
+ version: '1.6'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rubocop-performance
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '1.37'
159
+ version: '2.0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '1.37'
166
+ version: '2.0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: simplecov
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -317,9 +317,9 @@ files:
317
317
  - spec/support/vcr.rb
318
318
  homepage: https://github.com/lokalise/ruby-lokalise-api
319
319
  licenses:
320
- - MIT
320
+ - BSD-3-Clause
321
321
  metadata: {}
322
- post_install_message:
322
+ post_install_message:
323
323
  rdoc_options: []
324
324
  require_paths:
325
325
  - lib
@@ -327,15 +327,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
327
327
  requirements:
328
328
  - - ">="
329
329
  - !ruby/object:Gem::Version
330
- version: '0'
330
+ version: 2.5.0
331
331
  required_rubygems_version: !ruby/object:Gem::Requirement
332
332
  requirements:
333
333
  - - ">="
334
334
  - !ruby/object:Gem::Version
335
335
  version: '0'
336
336
  requirements: []
337
- rubygems_version: 3.1.4
338
- signing_key:
337
+ rubygems_version: 3.2.7
338
+ signing_key:
339
339
  specification_version: 4
340
340
  summary: Ruby interface to the Lokalise API
341
341
  test_files: