Class: ShopsavvyDataApi::APIResponse
- Inherits:
-
Object
- Object
- ShopsavvyDataApi::APIResponse
- Defined in:
- lib/shopsavvy_data_api/models.rb
Overview
Standard API response wrapper
Instance Attribute Summary collapse
-
#credits_remaining ⇒ Object
readonly
Returns the value of attribute credits_remaining.
-
#credits_used ⇒ Object
readonly
Returns the value of attribute credits_used.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
Instance Method Summary collapse
- #failure? ⇒ Boolean
-
#initialize(response_data, data_class: nil) ⇒ APIResponse
constructor
A new instance of APIResponse.
- #success? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(response_data, data_class: nil) ⇒ APIResponse
Returns a new instance of APIResponse.
249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/shopsavvy_data_api/models.rb', line 249 def initialize(response_data, data_class: nil) @success = response_data["success"] @message = response_data["message"] @credits_used = response_data["credits_used"] @credits_remaining = response_data["credits_remaining"] @data = if data_class && response_data["data"] parse_data(response_data["data"], data_class) else response_data["data"] end end |
Instance Attribute Details
#credits_remaining ⇒ Object (readonly)
Returns the value of attribute credits_remaining.
247 248 249 |
# File 'lib/shopsavvy_data_api/models.rb', line 247 def credits_remaining @credits_remaining end |
#credits_used ⇒ Object (readonly)
Returns the value of attribute credits_used.
247 248 249 |
# File 'lib/shopsavvy_data_api/models.rb', line 247 def credits_used @credits_used end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
247 248 249 |
# File 'lib/shopsavvy_data_api/models.rb', line 247 def data @data end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
247 248 249 |
# File 'lib/shopsavvy_data_api/models.rb', line 247 def @message end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
247 248 249 |
# File 'lib/shopsavvy_data_api/models.rb', line 247 def success @success end |
Instance Method Details
#failure? ⇒ Boolean
266 267 268 |
# File 'lib/shopsavvy_data_api/models.rb', line 266 def failure? !success? end |
#success? ⇒ Boolean
262 263 264 |
# File 'lib/shopsavvy_data_api/models.rb', line 262 def success? success == true end |
#to_h ⇒ Object
270 271 272 273 274 275 276 277 278 |
# File 'lib/shopsavvy_data_api/models.rb', line 270 def to_h { success: success, data: data.respond_to?(:to_h) ? data.to_h : data, message: , credits_used: credits_used, credits_remaining: credits_remaining } end |