Class: Io::Flow::V0::Models::JsonpResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Overview

The jsonp_response defines the schema for all Flow APIs calls made over JSONP, providing access to the specific response status, headers, and body from the underlying service. See https://docs.flow.io/#jsonp for details

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ JsonpResponse

Returns a new instance of JsonpResponse.



34633
34634
34635
34636
34637
34638
34639
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 34633

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:status, :headers, :body], 'JsonpResponse')
  @status = HttpClient::Preconditions.assert_class('status', opts.delete(:status), Integer)
  @headers = HttpClient::Preconditions.assert_class('headers', opts.delete(:headers), Hash).inject({}) { |h, d| h[d[0]] = HttpClient::Preconditions.assert_class('headers', d[1], Array).map { |v| HttpClient::Preconditions.assert_class('headers', v, String) }; h }
  @body = HttpClient::Preconditions.assert_class('body', HttpClient::Helper.to_object(opts.delete(:body)), Hash)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



34631
34632
34633
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 34631

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



34631
34632
34633
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 34631

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



34631
34632
34633
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 34631

def status
  @status
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



34645
34646
34647
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 34645

def copy(incoming={})
  JsonpResponse.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
end

#to_hashObject



34649
34650
34651
34652
34653
34654
34655
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 34649

def to_hash
  {
    :status => status,
    :headers => headers.inject({}) { |hash, o| hash[o[0]] = o[1].nil? ? nil : o[1]; hash },
    :body => body
  }
end

#to_jsonObject



34641
34642
34643
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 34641

def to_json
  JSON.dump(to_hash)
end