ruby-lokalise-api 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +28 -3
- data/lib/ruby-lokalise-api.rb +1 -1
- data/lib/ruby-lokalise-api/json_handler.rb +15 -0
- data/lib/ruby-lokalise-api/request.rb +5 -4
- data/lib/ruby-lokalise-api/version.rb +1 -1
- data/ruby-lokalise-api.gemspec +1 -1
- data/spec/lib/ruby-lokalise-api/custom_json_parser_spec.rb +77 -0
- metadata +12 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caa20ece7cfd9bbf173ddd4213d6e30b67bec03a78a28188f473414eea7ae42a
|
4
|
+
data.tar.gz: 99069ccfa82ca5cebd820de4da81d9215d24341899862ad8c2b21c52500d5fa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb97f63d412ac981efa9f2b3302b740dbc7ae25a93f6a4637a4e6706f8b5150bfd249915bd80b6279249f4e9298da61d29d53855228b73bdce19206adbef3cef
|
7
|
+
data.tar.gz: 5ee66d9e5bd269c7c0cfefa8e73e34601ff18cf487cf623373240ee4b49344a88991cb4cee91f1250944ec14a0c63491e68cf7aa2f893d462c28fb6213b3ea8d
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 2.
|
3
|
+
## 2.4.0 (31-Jul-19)
|
4
|
+
|
5
|
+
* Remove MultiJson dependency and allow to use a custom JSON parser
|
6
|
+
|
7
|
+
## 2.3.0 (17-Jul-19)
|
4
8
|
|
5
9
|
* Incorporated latest API changes
|
6
10
|
* Added support for [`TranslationStatus` endpoint](https://lokalise.co/api2docs/ruby/#resource-translation-statuses)
|
data/README.md
CHANGED
@@ -31,6 +31,7 @@ Official opinionated Ruby interface for the [Lokalise API](https://lokalise.co/a
|
|
31
31
|
+ [Translation Providers](#translation-providers)
|
32
32
|
+ [Translation Statuses](#translation-statuses)
|
33
33
|
* [Additional Info](#additional-info)
|
34
|
+
+ [Customizing JSON parser](#customizing-json-parser)
|
34
35
|
+ [Error handling](#error-handling)
|
35
36
|
+ [API Rate Limits](#api-rate-limits)
|
36
37
|
* [Running Tests](#running-tests)
|
@@ -1462,13 +1463,37 @@ As long as Lokalise supports only very limited array of color hexadecimal codes
|
|
1462
1463
|
|
1463
1464
|
```ruby
|
1464
1465
|
@client.translation_status_colors(project_id) # Input:
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1466
|
+
## project_id (string, required)
|
1467
|
+
# Output:
|
1468
|
+
## Array of color codes in HEX format
|
1468
1469
|
```
|
1469
1470
|
|
1470
1471
|
## Additional Info
|
1471
1472
|
|
1473
|
+
### Customizing JSON parser
|
1474
|
+
|
1475
|
+
This gem used to rely on [MultiJson](https://github.com/intridea/multi_json) but it is not maintained anymore. By default we are using a [built-in JSON module](https://ruby-doc.org/stdlib-2.0.0/libdoc/json/rdoc/JSON.html) but you may utilize any other parser by overriding `#custom_dump` and `#custom_load` methods inside `Lokalise::JsonHandler` module.
|
1476
|
+
|
1477
|
+
For example, to use [Oj](https://github.com/ohler55/oj) you would do the following:
|
1478
|
+
|
1479
|
+
```ruby
|
1480
|
+
require 'oj'
|
1481
|
+
|
1482
|
+
module Lokalise
|
1483
|
+
module JsonHandler
|
1484
|
+
# This method accepts a Ruby object and must return a JSON string
|
1485
|
+
def custom_dump(obj)
|
1486
|
+
Oj.dump obj
|
1487
|
+
end
|
1488
|
+
|
1489
|
+
# This method accepts JSON and must return Ruby object
|
1490
|
+
def custom_load(obj)
|
1491
|
+
Oj.load obj
|
1492
|
+
end
|
1493
|
+
end
|
1494
|
+
end
|
1495
|
+
```
|
1496
|
+
|
1472
1497
|
### Error handling
|
1473
1498
|
|
1474
1499
|
[Error codes](https://lokalise.co/api2docs/curl/#resource-errors)
|
data/lib/ruby-lokalise-api.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'faraday'
|
2
|
-
require 'multi_json'
|
3
2
|
require 'yaml'
|
4
3
|
require 'addressable'
|
5
4
|
|
6
5
|
require 'ruby-lokalise-api/version'
|
6
|
+
require 'ruby-lokalise-api/json_handler'
|
7
7
|
require 'ruby-lokalise-api/connection'
|
8
8
|
require 'ruby-lokalise-api/request'
|
9
9
|
require 'ruby-lokalise-api/error'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Lokalise
|
2
|
+
module JsonHandler
|
3
|
+
# JSON custom parser. Uses built-in JSON by default but can be overridden to any other parser
|
4
|
+
|
5
|
+
# Converts Ruby object to JSON
|
6
|
+
def custom_dump(obj)
|
7
|
+
JSON.dump obj
|
8
|
+
end
|
9
|
+
|
10
|
+
# Converts JSON to Ruby object
|
11
|
+
def custom_load(obj)
|
12
|
+
JSON.parse obj
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Lokalise
|
2
2
|
module Request
|
3
3
|
include Lokalise::Connection
|
4
|
+
include Lokalise::JsonHandler
|
4
5
|
|
5
6
|
PAGINATION_HEADERS = %w[x-pagination-total-count x-pagination-page-count x-pagination-limit x-pagination-page].freeze
|
6
7
|
|
@@ -13,14 +14,14 @@ module Lokalise
|
|
13
14
|
|
14
15
|
def post(path, client, params = {})
|
15
16
|
respond_with(
|
16
|
-
connection(client.token).post(prepare(path),
|
17
|
+
connection(client.token).post(prepare(path), custom_dump(params)),
|
17
18
|
client
|
18
19
|
)
|
19
20
|
end
|
20
21
|
|
21
22
|
def put(path, client, params = {})
|
22
23
|
respond_with(
|
23
|
-
connection(client.token).put(prepare(path),
|
24
|
+
connection(client.token).put(prepare(path), custom_dump(params)),
|
24
25
|
client
|
25
26
|
)
|
26
27
|
end
|
@@ -31,7 +32,7 @@ module Lokalise
|
|
31
32
|
# rubocop:disable Style/CollectionMethods
|
32
33
|
connection(client.token).delete(prepare(path)) do |req|
|
33
34
|
# rubocop:enable Style/CollectionMethods
|
34
|
-
req.body =
|
35
|
+
req.body = custom_dump params
|
35
36
|
end,
|
36
37
|
client
|
37
38
|
)
|
@@ -45,7 +46,7 @@ module Lokalise
|
|
45
46
|
end
|
46
47
|
|
47
48
|
def respond_with(response, client)
|
48
|
-
body =
|
49
|
+
body = custom_load response.body
|
49
50
|
uri = Addressable::URI.parse response.env.url
|
50
51
|
respond_with_error(response.status, body) if body.respond_to?(:has_key?) && body.key?('error')
|
51
52
|
extract_headers_from(response).
|
data/ruby-lokalise-api.gemspec
CHANGED
@@ -22,9 +22,9 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_dependency 'addressable', '~> 2.5'
|
24
24
|
spec.add_dependency 'faraday', '~> 0.13'
|
25
|
-
spec.add_dependency 'multi_json', '~> 1.12'
|
26
25
|
|
27
26
|
spec.add_development_dependency 'dotenv', '~> 2.5'
|
27
|
+
spec.add_development_dependency 'oj', '~> 3.8'
|
28
28
|
spec.add_development_dependency 'rake', '~> 12.1'
|
29
29
|
spec.add_development_dependency 'rspec', '~> 3.6'
|
30
30
|
spec.add_development_dependency 'rubocop', '~> 0.60'
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'oj'
|
2
|
+
|
3
|
+
RSpec.describe 'Custom JSON parser' do
|
4
|
+
let(:loaded_json) do
|
5
|
+
{'projects' => [{'project_id' => '547879415c01a0e6e0b855.29978928',
|
6
|
+
'name' => 'demo phoenix copy',
|
7
|
+
'description' => '',
|
8
|
+
'created_at' => '2018-11-30 20:43:18 (Etc/UTC)',
|
9
|
+
'created_by' => 20_181,
|
10
|
+
'created_by_email' => 'bodrovis@protonmail.com',
|
11
|
+
'team_id' => 176_692,
|
12
|
+
'statistics' =>
|
13
|
+
{'progress' => 0,
|
14
|
+
'keys' => 1,
|
15
|
+
'team' => 1,
|
16
|
+
'base_words' => 0,
|
17
|
+
'qa_issues' => 1,
|
18
|
+
'languages' =>
|
19
|
+
[{'language_id' => 640, 'language_iso' => 'en', 'progress' => 0, 'words_to_do' => 0},
|
20
|
+
{'language_id' => 597, 'language_iso' => 'ru', 'progress' => 0, 'words_to_do' => 0},
|
21
|
+
{'language_id' => 673, 'language_iso' => 'f_over', 'progress' => 0, 'words_to_do' => 0}]}}]}
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:dumped_json) do
|
25
|
+
'{":name":"rspec proj",":description":"demo project for rspec"}'
|
26
|
+
end
|
27
|
+
|
28
|
+
before :all do
|
29
|
+
module Lokalise
|
30
|
+
module JsonHandler
|
31
|
+
def custom_dump(obj)
|
32
|
+
Oj.dump obj
|
33
|
+
end
|
34
|
+
|
35
|
+
def custom_load(obj)
|
36
|
+
Oj.load obj
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
after :all do
|
43
|
+
module Lokalise
|
44
|
+
module JsonHandler
|
45
|
+
def custom_dump(obj)
|
46
|
+
JSON.dump obj
|
47
|
+
end
|
48
|
+
|
49
|
+
def custom_load(obj)
|
50
|
+
JSON.parse obj
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should allow to customize #load' do
|
57
|
+
expect(Oj).to receive(:load).and_return(loaded_json)
|
58
|
+
expect(JSON).not_to receive(:parse)
|
59
|
+
projects = VCR.use_cassette('all_projects_pagination') do
|
60
|
+
test_client.projects limit: 1, page: 2
|
61
|
+
end
|
62
|
+
|
63
|
+
expect(projects.collection.count).to eq(1)
|
64
|
+
expect(projects.total_results).to eq(5)
|
65
|
+
expect(projects.collection.first.name).to eq('demo phoenix copy')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should allow to customize #dump' do
|
69
|
+
expect(Oj).to receive(:dump).and_return(dumped_json)
|
70
|
+
expect(JSON).not_to receive(:dump)
|
71
|
+
project = VCR.use_cassette('new_project') do
|
72
|
+
test_client.create_project name: 'rspec proj', description: 'demo project for rspec'
|
73
|
+
end
|
74
|
+
|
75
|
+
expect(project.name).to eq('rspec proj')
|
76
|
+
end
|
77
|
+
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: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Bodrov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -39,33 +39,33 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.13'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: dotenv
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
-
type: :
|
47
|
+
version: '2.5'
|
48
|
+
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2.5'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: oj
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '3.8'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '3.8'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,6 +192,7 @@ files:
|
|
192
192
|
- lib/ruby-lokalise-api/connection.rb
|
193
193
|
- lib/ruby-lokalise-api/data/attributes.json
|
194
194
|
- lib/ruby-lokalise-api/error.rb
|
195
|
+
- lib/ruby-lokalise-api/json_handler.rb
|
195
196
|
- lib/ruby-lokalise-api/request.rb
|
196
197
|
- lib/ruby-lokalise-api/resources/base.rb
|
197
198
|
- lib/ruby-lokalise-api/resources/contributor.rb
|
@@ -235,6 +236,7 @@ files:
|
|
235
236
|
- lib/ruby-lokalise-api/utils/string_utils.rb
|
236
237
|
- lib/ruby-lokalise-api/version.rb
|
237
238
|
- ruby-lokalise-api.gemspec
|
239
|
+
- spec/lib/ruby-lokalise-api/custom_json_parser_spec.rb
|
238
240
|
- spec/lib/ruby-lokalise-api/error_spec.rb
|
239
241
|
- spec/lib/ruby-lokalise-api/rest/comments_spec.rb
|
240
242
|
- spec/lib/ruby-lokalise-api/rest/contributors_spec.rb
|
@@ -282,6 +284,7 @@ signing_key:
|
|
282
284
|
specification_version: 4
|
283
285
|
summary: Ruby interface to the Lokalise API
|
284
286
|
test_files:
|
287
|
+
- spec/lib/ruby-lokalise-api/custom_json_parser_spec.rb
|
285
288
|
- spec/lib/ruby-lokalise-api/error_spec.rb
|
286
289
|
- spec/lib/ruby-lokalise-api/rest/comments_spec.rb
|
287
290
|
- spec/lib/ruby-lokalise-api/rest/contributors_spec.rb
|