openpix-ruby_sdk 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f2da0e8d196d0f8de84bbb882297bf72d8db63851d8f77af14870af9751b71e
4
- data.tar.gz: 651770374930d1e49a2c49ef0b05ac83a6a8c138f071c5cd20a1966d86e77de2
3
+ metadata.gz: 3310c2caec359545c07a46c319954794ccff9ef89a19f34c8726f1440433b7af
4
+ data.tar.gz: ebf2e933e28d2e8f6ffa79e9b73923ca34ad8317e121f5d065988da43acc5fc9
5
5
  SHA512:
6
- metadata.gz: 4df6938509465c2701d86954f42b5270c6b0dcff8a40a80ee7ecd21fb8a1201d6a22630991416b4bd02396ad82094ecce1870bc2b7ee6af2ec99679c042b7d97
7
- data.tar.gz: c84ca77a7e65899cc0c3d7a1343eedafee16e64a06867d8ec7f5d58610284abd5de25f8d23f5da11df79fdcf89d30dd4f059009ad036d51b56fe53c7824eca9f
6
+ metadata.gz: 652af0e17c4fc7de2d6b613ad7adcc91cee42ba70a71353bd9bc934355689319c3a76cecf17147d68c81e4d943971630fe03ad1102a01d8b7c3c1920f1068e23
7
+ data.tar.gz: 2cb979e8a7c5720db959873e58c116fc64abea665104239fd6c46a06491c1083e97399e112d6e9fbaa684ca922dd53a5984f4abddbd2b8f855338f5b384f2e9c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.1.1](https://github.com/Open-Pix/ruby-sdk/compare/v1.1.0...v1.1.1) (2023-07-04)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * 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))
9
+
3
10
  ## [1.1.0](https://github.com/Open-Pix/ruby-sdk/compare/v1.0.0...v1.1.0) (2023-06-25)
4
11
 
5
12
 
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.woovi.com/home/applications/tab/list
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, :resource_response, :pagination_meta, :error_response, :status
7
+ attr_reader :success, :body, :status
8
8
 
9
- def initialize(status:, resource_response: nil, error_response: nil, pagination_meta: {})
9
+ def initialize(status:, body:, single_resource: nil, collection_resource: nil)
10
10
  @success = status == 200
11
11
  @status = status
12
- @resource_response = resource_response
13
- @pagination_meta = pagination_meta
14
- @error_response = error_response
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
@@ -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
- resource_response: response.body[to_single_resource],
85
- error_response: response.body['error']
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: #{response.body['error']}, status: #{response.status}"
104
+ "Error while saving, API response: #{api_response.error_response}, status: #{api_response.status}"
96
105
  )
97
106
  end
98
107
 
99
- Openpix::RubySdk::ApiResponse.new(
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 = response.status == 200
121
+ @fetched = api_response.status == 200
111
122
 
112
- set_pagination_meta(response.body['pageInfo']) if @fetched
123
+ set_pagination_meta(api_response.pagination_meta) if @fetched
113
124
  @last_fetched_params = params if @fetched && !params.empty?
114
125
 
115
- Openpix::RubySdk::ApiResponse.new(
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: #{response.body['error']}, status: #{response.status}"
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(response.body['pageInfo'])
148
+ set_pagination_meta(api_response.pagination_meta)
138
149
 
139
- Openpix::RubySdk::ApiResponse.new(
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
- resource_response: response.body[to_single_resource],
160
- error_response: response.body['error']
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: #{response.body['error']}, status: #{response.status}"
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
- Openpix::RubySdk::ApiResponse.new(
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
- error_response: response.body['error']
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: #{response.body['error']}, status: #{response.status}"
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
- Openpix::RubySdk::ApiResponse.new(
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: #{response.body['error']}, status: #{response.status}"
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(response.body['pageInfo'])
290
- Openpix::RubySdk::ApiResponse.new(
291
- status: response.status,
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)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Openpix
4
4
  module RubySdk
5
- VERSION = '1.1.0'
5
+ VERSION = '1.1.1'
6
6
  end
7
7
  end
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.1.0
4
+ version: 1.1.1
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-06-25 00:00:00.000000000 Z
11
+ date: 2023-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport