Class: HasOffers::Response
- Inherits:
-
Object
- Object
- HasOffers::Response
- Defined in:
- lib/hasoffers/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#http_headers ⇒ Object
readonly
Returns the value of attribute http_headers.
-
#http_message ⇒ Object
readonly
Returns the value of attribute http_message.
-
#http_status_code ⇒ Object
readonly
Returns the value of attribute http_status_code.
-
#test ⇒ Object
readonly
Returns the value of attribute test.
Instance Method Summary collapse
- #data ⇒ Object
- #error_messages ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #page_info ⇒ Object
- #raw_data ⇒ Object
-
#set_data(data) ⇒ Object
allows specific api calls to post-process the data for ease of use.
- #status ⇒ Object
- #success? ⇒ Boolean
- #test? ⇒ Boolean
- #totals ⇒ Object
- #validation_error? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/hasoffers/response.rb', line 65 def initialize(response) if response.is_a? DummyResponse @test = true @body = response.body else @test = false @body = Yajl::Parser.parse(response.body) end @http_status_code = response.code @http_message = response. @http_headers = response.to_hash end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/hasoffers/response.rb', line 3 def body @body end |
#http_headers ⇒ Object (readonly)
Returns the value of attribute http_headers.
3 4 5 |
# File 'lib/hasoffers/response.rb', line 3 def http_headers @http_headers end |
#http_message ⇒ Object (readonly)
Returns the value of attribute http_message.
3 4 5 |
# File 'lib/hasoffers/response.rb', line 3 def @http_message end |
#http_status_code ⇒ Object (readonly)
Returns the value of attribute http_status_code.
3 4 5 |
# File 'lib/hasoffers/response.rb', line 3 def http_status_code @http_status_code end |
#test ⇒ Object (readonly)
Returns the value of attribute test.
3 4 5 |
# File 'lib/hasoffers/response.rb', line 3 def test @test end |
Instance Method Details
#data ⇒ Object
26 27 28 |
# File 'lib/hasoffers/response.rb', line 26 def data @processed_data || (paginated_response? ? @body['response']['data']['data'] : @body['response']['data']) end |
#error_messages ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/hasoffers/response.rb', line 55 def if data.is_a? Hash and data["errors"] and data["errors"]["error"] get_error_values data["errors"]["error"] elsif @body["response"]["errors"] get_error_values @body["response"]["errors"] else [] end end |
#page_info ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/hasoffers/response.rb', line 40 def page_info if paginated_response? {'page_count' => @body['response']['data']['pageCount'], 'current' => @body['response']['data']['current'], 'count' => @body['response']['data']['count'], 'page' => @body['response']['data']['page']} else {} end end |
#raw_data ⇒ Object
22 23 24 |
# File 'lib/hasoffers/response.rb', line 22 def raw_data @body end |
#set_data(data) ⇒ Object
allows specific api calls to post-process the data for ease of use
18 19 20 |
# File 'lib/hasoffers/response.rb', line 18 def set_data(data) @processed_data = data end |
#status ⇒ Object
13 14 15 |
# File 'lib/hasoffers/response.rb', line 13 def status @body['response']['status'] end |
#success? ⇒ Boolean
5 6 7 |
# File 'lib/hasoffers/response.rb', line 5 def success? @http_status_code.to_s == '200' and status == 1 end |
#test? ⇒ Boolean
9 10 11 |
# File 'lib/hasoffers/response.rb', line 9 def test? @test end |
#totals ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/hasoffers/response.rb', line 30 def totals # this is ready to go for Report.GetStats... not sure if totals is used elsewhere in which case the 'Stat' # check here may not be generic enough if @body['response']['data'] and @body['response']['data']['totals'] and @body['response']['data']['totals'].is_a?(Hash) @body['response']['data']['totals']['Stat'] else {} end end |
#validation_error? ⇒ Boolean
51 52 53 |
# File 'lib/hasoffers/response.rb', line 51 def validation_error? status == -1 and data['error_code'] == 1 end |