Class: Dawanda::Response
- Inherits:
-
Object
- Object
- Dawanda::Response
- Defined in:
- lib/dawanda/response.rb
Overview
Response
Basic wrapper around the Dawanda JSON response data
Instance Method Summary collapse
-
#entries ⇒ Object
Number of records in the response.
-
#initialize(data) ⇒ Response
constructor
Create a new response based on the raw JSON.
-
#pages ⇒ Object
Number of pages in the response.
- #params ⇒ Object
- #pluralized_type ⇒ Object
-
#result ⇒ Object
Result of the API request that expect exactly one result.
-
#results ⇒ Object
Results of the API request that expect an arry of results.
-
#to_hash ⇒ Object
Convert the raw JSON data to a hash.
- #type ⇒ Object
Constructor Details
#initialize(data) ⇒ Response
Create a new response based on the raw JSON
10 11 12 |
# File 'lib/dawanda/response.rb', line 10 def initialize(data) @data = data end |
Instance Method Details
#entries ⇒ Object
Number of records in the response
21 22 23 |
# File 'lib/dawanda/response.rb', line 21 def entries to_hash['entries'] end |
#pages ⇒ Object
Number of pages in the response
26 27 28 |
# File 'lib/dawanda/response.rb', line 26 def pages to_hash['pages'] end |
#params ⇒ Object
38 39 40 |
# File 'lib/dawanda/response.rb', line 38 def params to_hash['params'] end |
#pluralized_type ⇒ Object
34 35 36 |
# File 'lib/dawanda/response.rb', line 34 def pluralized_type type.to_s.pluralize end |
#result ⇒ Object
Result of the API request that expect exactly one result
42 43 44 |
# File 'lib/dawanda/response.rb', line 42 def result to_hash['result'][type] end |
#results ⇒ Object
Results of the API request that expect an arry of results
47 48 49 |
# File 'lib/dawanda/response.rb', line 47 def results to_hash['result'].values.first end |
#to_hash ⇒ Object
Convert the raw JSON data to a hash
15 16 17 18 |
# File 'lib/dawanda/response.rb', line 15 def to_hash @hash ||= JSON.parse(@data) @hash['response'] end |
#type ⇒ Object
30 31 32 |
# File 'lib/dawanda/response.rb', line 30 def type to_hash['type'] end |