ruby-lokalise-api 9.0.0 → 9.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_lokalise_api/collections/base.rb +33 -8
- data/lib/ruby_lokalise_api/endpoints/base_endpoint.rb +1 -1
- data/lib/ruby_lokalise_api/endpoints/main_endpoint.rb +1 -1
- data/lib/ruby_lokalise_api/endpoints/oauth2/oauth2_endpoint.rb +1 -1
- data/lib/ruby_lokalise_api/error.rb +6 -1
- data/lib/ruby_lokalise_api/generics.rb +1 -1
- data/lib/ruby_lokalise_api/request.rb +5 -1
- data/lib/ruby_lokalise_api/resources/base.rb +2 -2
- data/lib/ruby_lokalise_api/response.rb +2 -3
- data/lib/ruby_lokalise_api/version.rb +1 -1
- data/ruby-lokalise-api.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f104ba9751dfab41967f0a7c766d4cb631a9219ae6a7d6f791b48dd3f68b171
|
4
|
+
data.tar.gz: 25416c89c5b24ca8439050a7adec02568eb5a6ed1379b6703957706dd33b4431
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9787b6d1bd962049fa0c1963a348dffa370dc03c23dfc1799688999128d5552f7bad9cc149cd204020ae04e5ff1301ca7a87208eb9cbd40f7fa78dbf2131e32e
|
7
|
+
data.tar.gz: 26e9576d4b8f554954f7d1486c8abad86bab2c1cdde67aa7d57c8f8aa71b6eef3a3477e467e081d6b12c618d6239ea9c585e19e16a7d8f5633a91d3e7c7fc60c
|
@@ -18,7 +18,7 @@ module RubyLokaliseApi
|
|
18
18
|
def_delegators :collection, :[], :last, :each
|
19
19
|
|
20
20
|
attr_reader :total_pages, :total_results, :results_per_page, :current_page,
|
21
|
-
:collection
|
21
|
+
:collection, :next_cursor
|
22
22
|
|
23
23
|
def initialize(response)
|
24
24
|
@self_endpoint = response.endpoint
|
@@ -32,9 +32,25 @@ module RubyLokaliseApi
|
|
32
32
|
def next_page
|
33
33
|
return nil if last_page?
|
34
34
|
|
35
|
+
override_params = { page: current_page + 1 }
|
36
|
+
|
35
37
|
self.class.new(
|
36
38
|
reinit_endpoint(
|
37
|
-
override_req_params:
|
39
|
+
override_req_params: override_params
|
40
|
+
).do_get
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Tries to fetch the next cursor for paginated collection
|
45
|
+
# Returns a new collection or nil if the next cursor is not available
|
46
|
+
def load_next_cursor
|
47
|
+
return nil unless next_cursor?
|
48
|
+
|
49
|
+
override_params = { cursor: next_cursor }
|
50
|
+
|
51
|
+
self.class.new(
|
52
|
+
reinit_endpoint(
|
53
|
+
override_req_params: override_params
|
38
54
|
).do_get
|
39
55
|
)
|
40
56
|
end
|
@@ -75,6 +91,12 @@ module RubyLokaliseApi
|
|
75
91
|
!prev_page?
|
76
92
|
end
|
77
93
|
|
94
|
+
# Checks whether the next cursor is available
|
95
|
+
# @return [Boolean]
|
96
|
+
def next_cursor?
|
97
|
+
!next_cursor.nil? && next_cursor != ''
|
98
|
+
end
|
99
|
+
|
78
100
|
private
|
79
101
|
|
80
102
|
# This method is utilized to recreate an endpoint for the current collection
|
@@ -86,17 +108,20 @@ module RubyLokaliseApi
|
|
86
108
|
|
87
109
|
def populate_common_attrs_from(response)
|
88
110
|
supported_attrs.each do |attrib|
|
89
|
-
instance_variable_set "@#{attrib}", response.content[attrib]
|
111
|
+
instance_variable_set :"@#{attrib}", response.content[attrib]
|
90
112
|
end
|
91
113
|
|
92
|
-
|
114
|
+
extract_common_from_headers(response.headers)
|
115
|
+
end
|
93
116
|
|
117
|
+
def extract_common_from_headers(headers)
|
94
118
|
return unless headers.any?
|
95
119
|
|
96
|
-
@total_results = headers[:'x-pagination-total-count']
|
97
|
-
@total_pages = headers[:'x-pagination-page-count']
|
98
|
-
@results_per_page = headers[:'x-pagination-limit']
|
99
|
-
@current_page = headers[:'x-pagination-page']
|
120
|
+
@total_results = headers[:'x-pagination-total-count'].to_i
|
121
|
+
@total_pages = headers[:'x-pagination-page-count'].to_i
|
122
|
+
@results_per_page = headers[:'x-pagination-limit'].to_i
|
123
|
+
@current_page = headers[:'x-pagination-page'].to_i
|
124
|
+
@next_cursor = headers[:'x-pagination-next-cursor']
|
100
125
|
end
|
101
126
|
|
102
127
|
def produce_collection_from(response)
|
@@ -38,7 +38,7 @@ module RubyLokaliseApi
|
|
38
38
|
# Creates methods like `do_post`, `do_get` that proxy calls to the
|
39
39
|
# corresponding methods in the `Request` module
|
40
40
|
HTTP_METHODS.each do |method_postfix|
|
41
|
-
define_method "do_#{method_postfix}" do
|
41
|
+
define_method :"do_#{method_postfix}" do
|
42
42
|
send method_postfix, self
|
43
43
|
end
|
44
44
|
end
|
@@ -40,7 +40,12 @@ module RubyLokaliseApi
|
|
40
40
|
class << self
|
41
41
|
# Create a new error from an HTTP response
|
42
42
|
def from_response(body)
|
43
|
-
msg = body.
|
43
|
+
msg = if body.respond_to?(:key)
|
44
|
+
body.key?('error') ? body['error']['message'] : body['message']
|
45
|
+
else
|
46
|
+
body
|
47
|
+
end
|
48
|
+
|
44
49
|
new msg.to_s
|
45
50
|
end
|
46
51
|
end
|
@@ -63,7 +63,11 @@ module RubyLokaliseApi
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def respond_with(response, endpoint)
|
66
|
-
|
66
|
+
begin
|
67
|
+
body = custom_load response.body
|
68
|
+
rescue JSON::ParserError
|
69
|
+
respond_with_error(response.status, response.body)
|
70
|
+
end
|
67
71
|
|
68
72
|
raise_on_error! response, body
|
69
73
|
|
@@ -49,7 +49,7 @@ module RubyLokaliseApi
|
|
49
49
|
|
50
50
|
def read_main_params
|
51
51
|
self.class.const_get(:MAIN_PARAMS).to_array.map do |param|
|
52
|
-
instance_variable_get "@#{param}"
|
52
|
+
instance_variable_get :"@#{param}"
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -69,7 +69,7 @@ module RubyLokaliseApi
|
|
69
69
|
content[attrib]
|
70
70
|
end
|
71
71
|
|
72
|
-
instance_variable_set "@#{attrib}", value
|
72
|
+
instance_variable_set :"@#{attrib}", value
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
@@ -5,7 +5,7 @@ module RubyLokaliseApi
|
|
5
5
|
class Response
|
6
6
|
# Lokalise returns pagination info in special headers
|
7
7
|
PAGINATION_HEADERS = %w[x-pagination-total-count x-pagination-page-count x-pagination-limit
|
8
|
-
x-pagination-page].freeze
|
8
|
+
x-pagination-page x-pagination-next-cursor].freeze
|
9
9
|
|
10
10
|
attr_reader :content, :endpoint, :headers
|
11
11
|
|
@@ -43,8 +43,7 @@ module RubyLokaliseApi
|
|
43
43
|
raw_headers.
|
44
44
|
to_h.
|
45
45
|
keep_if { |header, _value| pagination_headers.include?(header) }.
|
46
|
-
transform_keys(&:to_sym)
|
47
|
-
transform_values(&:to_i)
|
46
|
+
transform_keys(&:to_sym)
|
48
47
|
end
|
49
48
|
end
|
50
49
|
end
|
data/ruby-lokalise-api.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_dependency 'json', '~> 2'
|
28
28
|
spec.add_dependency 'zeitwerk', '~> 2.4'
|
29
29
|
|
30
|
-
spec.add_development_dependency 'dotenv', '~>
|
30
|
+
spec.add_development_dependency 'dotenv', '~> 3.0'
|
31
31
|
spec.add_development_dependency 'oj', '~> 3.10'
|
32
32
|
spec.add_development_dependency 'rake', '~> 13.0'
|
33
33
|
spec.add_development_dependency 'rspec', '~> 3.6'
|
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: 9.
|
4
|
+
version: 9.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Krukowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '3.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '3.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: oj
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -397,7 +397,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
397
397
|
- !ruby/object:Gem::Version
|
398
398
|
version: '0'
|
399
399
|
requirements: []
|
400
|
-
rubygems_version: 3.
|
400
|
+
rubygems_version: 3.5.10
|
401
401
|
signing_key:
|
402
402
|
specification_version: 4
|
403
403
|
summary: Ruby interface to the Lokalise API
|