openpix-ruby_sdk 1.1.0 → 1.2.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 +14 -0
- data/README.md +1 -1
- data/lib/openpix/ruby_sdk/api_response.rb +24 -5
- data/lib/openpix/ruby_sdk/http_client.rb +2 -2
- data/lib/openpix/ruby_sdk/resources/resource.rb +57 -41
- data/lib/openpix/ruby_sdk/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 568304637b2105328d5baccbea435111c0df6f9fba29398e5a228feb738df2da
|
4
|
+
data.tar.gz: 3be1e2e0f40aff2293260907aa40cf83a2483b0cdbcb9ee99e9798192c392c7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afaa3a60b4cc720c3e600e5c3bbc7ea27dea597cbb9be47a6d31ceb1700ee597f2b447991f2b3562b4e4c7e5499018e4d473ed11d63d4b264ebb54ff6269fc0d
|
7
|
+
data.tar.gz: ff6414815c729bfe36d012f9ce65ef163fe97de088627d2a0290321b25541593345429ddb772ed02ecaa94865c8c6a553a1f88b5f6237f73ae1ac952ab18ebaa
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.2.0](https://github.com/Open-Pix/ruby-sdk/compare/v1.1.1...v1.2.0) (2023-07-04)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* add ability to accept custom api url and version ([#26](https://github.com/Open-Pix/ruby-sdk/issues/26)) ([cae73ef](https://github.com/Open-Pix/ruby-sdk/commit/cae73ef01bd474e27bcd5246ff3b374f9bfd76e1))
|
9
|
+
|
10
|
+
## [1.1.1](https://github.com/Open-Pix/ruby-sdk/compare/v1.1.0...v1.1.1) (2023-07-04)
|
11
|
+
|
12
|
+
|
13
|
+
### Bug Fixes
|
14
|
+
|
15
|
+
* Fix not authorized response parsing ([#24](https://github.com/Open-Pix/ruby-sdk/issues/24)) ([00f508d](https://github.com/Open-Pix/ruby-sdk/commit/00f508d4463b25b774ca4c0449c3cd050fdad549))
|
16
|
+
|
3
17
|
## [1.1.0](https://github.com/Open-Pix/ruby-sdk/compare/v1.0.0...v1.1.0) (2023-06-25)
|
4
18
|
|
5
19
|
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ Main class `openpix/ruby_sdk/client` is your entrypoint to the endpoints.
|
|
22
22
|
```ruby
|
23
23
|
require 'openpix/ruby_sdk'
|
24
24
|
|
25
|
-
# Your AppID from https://app.
|
25
|
+
# Your AppID from https://app.openpix.com/home/applications/tab/list
|
26
26
|
app_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
27
27
|
|
28
28
|
client = Openpix::RubySdk::Client.new(app_id)
|
@@ -4,19 +4,38 @@ module Openpix
|
|
4
4
|
module RubySdk
|
5
5
|
# An Object representing the response from a call to Woovi API
|
6
6
|
class ApiResponse
|
7
|
-
attr_reader :success, :
|
7
|
+
attr_reader :success, :body, :status
|
8
8
|
|
9
|
-
def initialize(status:,
|
9
|
+
def initialize(status:, body:, single_resource: nil, collection_resource: nil)
|
10
10
|
@success = status == 200
|
11
11
|
@status = status
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
12
|
+
@body = body
|
13
|
+
@single_resource = single_resource
|
14
|
+
@collection_resource = collection_resource
|
15
15
|
end
|
16
16
|
|
17
17
|
def success?
|
18
18
|
success
|
19
19
|
end
|
20
|
+
|
21
|
+
def resource_response
|
22
|
+
return @body[@single_resource] if @single_resource
|
23
|
+
|
24
|
+
@body[@collection_resource]
|
25
|
+
end
|
26
|
+
|
27
|
+
def error_response
|
28
|
+
return @body['error'] if @body['error']
|
29
|
+
return @body['errors'].first['message'] if @body['errors'] && !@body['errors'].empty?
|
30
|
+
|
31
|
+
''
|
32
|
+
end
|
33
|
+
|
34
|
+
def pagination_meta
|
35
|
+
return @body['pageInfo'] if @body['pageInfo']
|
36
|
+
|
37
|
+
{}
|
38
|
+
end
|
20
39
|
end
|
21
40
|
end
|
22
41
|
end
|
@@ -18,9 +18,9 @@ module Openpix
|
|
18
18
|
attr_reader :instance
|
19
19
|
end
|
20
20
|
|
21
|
-
def initialize_http_client(auth_token)
|
21
|
+
def initialize_http_client(auth_token, api_url = BASE_URL, api_version = API_VERSION)
|
22
22
|
@http_client = Faraday.new(
|
23
|
-
url: "#{
|
23
|
+
url: "#{api_url}#{api_version}",
|
24
24
|
headers: {
|
25
25
|
'Authorization' => auth_token
|
26
26
|
}
|
@@ -58,6 +58,10 @@ module Openpix
|
|
58
58
|
to_url
|
59
59
|
end
|
60
60
|
|
61
|
+
def to_collection_resource
|
62
|
+
to_url.pluralize
|
63
|
+
end
|
64
|
+
|
61
65
|
def create_attributes
|
62
66
|
raise NotImplementedError.new(method: __method__)
|
63
67
|
end
|
@@ -81,66 +85,69 @@ module Openpix
|
|
81
85
|
|
82
86
|
Openpix::RubySdk::ApiResponse.new(
|
83
87
|
status: response.status,
|
84
|
-
|
85
|
-
|
88
|
+
body: response.body,
|
89
|
+
single_resource: to_single_resource
|
86
90
|
)
|
87
91
|
end
|
88
92
|
|
89
93
|
def save!(extra_headers: {}, return_existing: false)
|
90
94
|
response = post_request(extra_headers, return_existing)
|
95
|
+
api_response = Openpix::RubySdk::ApiResponse.new(
|
96
|
+
status: response.status,
|
97
|
+
body: response.body,
|
98
|
+
single_resource: to_single_resource
|
99
|
+
)
|
91
100
|
|
92
101
|
if response.status != 200
|
93
102
|
raise(
|
94
103
|
RequestError,
|
95
|
-
"Error while saving, API response: #{
|
104
|
+
"Error while saving, API response: #{api_response.error_response}, status: #{api_response.status}"
|
96
105
|
)
|
97
106
|
end
|
98
107
|
|
99
|
-
|
100
|
-
status: response.status,
|
101
|
-
resource_response: response.body[to_single_resource]
|
102
|
-
)
|
108
|
+
api_response
|
103
109
|
end
|
104
110
|
|
105
111
|
def fetch(skip: nil, limit: nil, extra_headers: {}, params: {})
|
106
112
|
set_pagination(skip, limit)
|
107
113
|
|
108
114
|
response = get_request(extra_headers: extra_headers, params: @pagination_params.merge(params))
|
115
|
+
api_response = Openpix::RubySdk::ApiResponse.new(
|
116
|
+
status: response.status,
|
117
|
+
body: response.body,
|
118
|
+
collection_resource: to_collection_resource
|
119
|
+
)
|
109
120
|
|
110
|
-
@fetched =
|
121
|
+
@fetched = api_response.status == 200
|
111
122
|
|
112
|
-
set_pagination_meta(
|
123
|
+
set_pagination_meta(api_response.pagination_meta) if @fetched
|
113
124
|
@last_fetched_params = params if @fetched && !params.empty?
|
114
125
|
|
115
|
-
|
116
|
-
status: response.status,
|
117
|
-
resource_response: response.body[to_url.pluralize],
|
118
|
-
pagination_meta: response.body['pageInfo'],
|
119
|
-
error_response: response.body['error']
|
120
|
-
)
|
126
|
+
api_response
|
121
127
|
end
|
122
128
|
|
123
129
|
def fetch!(skip: nil, limit: nil, extra_headers: {}, params: {})
|
124
130
|
set_pagination(skip, limit)
|
125
131
|
|
126
132
|
response = get_request(extra_headers: extra_headers, params: @pagination_params.merge(params))
|
133
|
+
api_response = Openpix::RubySdk::ApiResponse.new(
|
134
|
+
status: response.status,
|
135
|
+
body: response.body,
|
136
|
+
collection_resource: to_collection_resource
|
137
|
+
)
|
127
138
|
|
128
139
|
if response.status != 200
|
129
140
|
raise(
|
130
141
|
RequestError,
|
131
|
-
"Error while fetching, API response: #{
|
142
|
+
"Error while fetching, API response: #{api_response.error_response}, status: #{api_response.status}"
|
132
143
|
)
|
133
144
|
end
|
134
145
|
|
135
146
|
@fetched = true
|
136
147
|
@last_fetched_params = params unless params.empty?
|
137
|
-
set_pagination_meta(
|
148
|
+
set_pagination_meta(api_response.pagination_meta)
|
138
149
|
|
139
|
-
|
140
|
-
status: response.status,
|
141
|
-
pagination_meta: response.body['pageInfo'],
|
142
|
-
resource_response: response.body[to_url.pluralize]
|
143
|
-
)
|
150
|
+
api_response
|
144
151
|
end
|
145
152
|
|
146
153
|
def fetch_next_page!(extra_headers: {})
|
@@ -156,25 +163,27 @@ module Openpix
|
|
156
163
|
|
157
164
|
Openpix::RubySdk::ApiResponse.new(
|
158
165
|
status: response.status,
|
159
|
-
|
160
|
-
|
166
|
+
body: response.body,
|
167
|
+
single_resource: to_single_resource
|
161
168
|
)
|
162
169
|
end
|
163
170
|
|
164
171
|
def find!(id:, extra_headers: {})
|
165
172
|
response = get_request(url: encoded_url(id), extra_headers: extra_headers)
|
173
|
+
api_response = Openpix::RubySdk::ApiResponse.new(
|
174
|
+
status: response.status,
|
175
|
+
body: response.body,
|
176
|
+
single_resource: to_single_resource
|
177
|
+
)
|
166
178
|
|
167
179
|
if response.status != 200
|
168
180
|
raise(
|
169
181
|
RequestError,
|
170
|
-
"Error while getting #{to_single_resource} of id = #{id}, API response: #{
|
182
|
+
"Error while getting #{to_single_resource} of id = #{id}, API response: #{api_response.error_response}, status: #{api_response.status}"
|
171
183
|
)
|
172
184
|
end
|
173
185
|
|
174
|
-
|
175
|
-
status: response.status,
|
176
|
-
resource_response: response.body[to_single_resource]
|
177
|
-
)
|
186
|
+
api_response
|
178
187
|
end
|
179
188
|
|
180
189
|
def destroy(id:, extra_headers: {})
|
@@ -182,23 +191,27 @@ module Openpix
|
|
182
191
|
|
183
192
|
Openpix::RubySdk::ApiResponse.new(
|
184
193
|
status: response.status,
|
185
|
-
|
194
|
+
body: response.body,
|
195
|
+
single_resource: to_single_resource
|
186
196
|
)
|
187
197
|
end
|
188
198
|
|
189
199
|
def destroy!(id:, extra_headers: {})
|
190
200
|
response = delete_request(url: encoded_url(id), extra_headers: extra_headers)
|
201
|
+
api_response = Openpix::RubySdk::ApiResponse.new(
|
202
|
+
status: response.status,
|
203
|
+
body: response.body,
|
204
|
+
single_resource: to_single_resource
|
205
|
+
)
|
191
206
|
|
192
207
|
if response.status != 200
|
193
208
|
raise(
|
194
209
|
RequestError,
|
195
|
-
"Error while deleting #{to_url} of id = #{id}, API response: #{
|
210
|
+
"Error while deleting #{to_url} of id = #{id}, API response: #{api_response.error_response}, status: #{api_response.status}"
|
196
211
|
)
|
197
212
|
end
|
198
213
|
|
199
|
-
|
200
|
-
status: response.status
|
201
|
-
)
|
214
|
+
api_response
|
202
215
|
end
|
203
216
|
|
204
217
|
private
|
@@ -272,26 +285,29 @@ module Openpix
|
|
272
285
|
end
|
273
286
|
|
274
287
|
calculate_pagination_params(page_orientation)
|
288
|
+
|
275
289
|
request_params = if @last_fetched_params.nil?
|
276
290
|
@pagination_params
|
277
291
|
else
|
278
292
|
@pagination_params.merge(@last_fetched_params)
|
279
293
|
end
|
280
294
|
response = get_request(extra_headers: extra_headers, params: request_params)
|
295
|
+
api_response = Openpix::RubySdk::ApiResponse.new(
|
296
|
+
status: response.status,
|
297
|
+
body: response.body,
|
298
|
+
collection_resource: to_collection_resource
|
299
|
+
)
|
281
300
|
|
282
301
|
if response.status != 200
|
283
302
|
raise(
|
284
303
|
RequestError,
|
285
|
-
"Error while fetching #{page_orientation} page, API response: #{
|
304
|
+
"Error while fetching #{page_orientation} page, API response: #{api_response.error_response}, status: #{api_response.status}"
|
286
305
|
)
|
287
306
|
end
|
288
307
|
|
289
|
-
set_pagination_meta(
|
290
|
-
|
291
|
-
|
292
|
-
pagination_meta: response.body['pageInfo'],
|
293
|
-
resource_response: response.body[to_url.pluralize]
|
294
|
-
)
|
308
|
+
set_pagination_meta(api_response.pagination_meta)
|
309
|
+
|
310
|
+
api_response
|
295
311
|
end
|
296
312
|
|
297
313
|
def encoded_url(id)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openpix-ruby_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erick Takeshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|