Class: Dawanda::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/dawanda/response.rb

Overview

Response

Basic wrapper around the Dawanda JSON response data

Instance Method Summary collapse

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

#entriesObject

Number of records in the response



21
22
23
# File 'lib/dawanda/response.rb', line 21

def entries
  to_hash['entries']
end

#pagesObject

Number of pages in the response



26
27
28
# File 'lib/dawanda/response.rb', line 26

def pages
  to_hash['pages']
end

#paramsObject



38
39
40
# File 'lib/dawanda/response.rb', line 38

def params
  to_hash['params']
end

#pluralized_typeObject



34
35
36
# File 'lib/dawanda/response.rb', line 34

def pluralized_type
  type.to_s.pluralize
end

#resultObject

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

#resultsObject

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_hashObject

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

#typeObject



30
31
32
# File 'lib/dawanda/response.rb', line 30

def type
  to_hash['type']
end