Class: Io::Flow::V0::Clients::CustomerTokens
- Inherits:
-
Object
- Object
- Io::Flow::V0::Clients::CustomerTokens
- Defined in:
- lib/flow_commerce/flow_api_v0_client.rb
Instance Method Summary collapse
-
#delete_by_id(organization, id) ⇒ Object
Delete the token for this id.
-
#get(organization, incoming = {}) ⇒ Object
Search tokens.
-
#get_by_token(organization, token) ⇒ Object
Returns a token if it exists.
-
#initialize(client) ⇒ CustomerTokens
constructor
A new instance of CustomerTokens.
-
#post_latest_by_customer_number(organization, customer_number) ⇒ Object
If there exists at least one token for this customer number, returns the latest.
Constructor Details
#initialize(client) ⇒ CustomerTokens
Returns a new instance of CustomerTokens.
5857 5858 5859 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5857 def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client) end |
Instance Method Details
#delete_by_id(organization, id) ⇒ Object
Delete the token for this id.
5887 5888 5889 5890 5891 5892 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5887 def delete_by_id(organization, id) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('id', id, String) r = @client.request("/#{CGI.escape(organization)}/customer/tokens/#{CGI.escape(id)}").delete nil end |
#get(organization, incoming = {}) ⇒ Object
Search tokens.
5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5862 def get(organization, incoming={}) HttpClient::Preconditions.assert_class('organization', organization, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }), :token => (x = opts.delete(:token); x.nil? ? nil : HttpClient::Preconditions.assert_class('token', x, String)), :customer_number => (x = opts.delete(:customer_number); x.nil? ? nil : HttpClient::Preconditions.assert_class('customer_number', x, String)), :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer), :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer), :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "-created_at" : x), String) }.delete_if { |k, v| v.nil? } r = @client.request("/#{CGI.escape(organization)}/customer/tokens").with_query(query).get r.map { |x| ::Io::Flow::V0::Models::CustomerToken.new(x) } end |
#get_by_token(organization, token) ⇒ Object
Returns a token if it exists.
5895 5896 5897 5898 5899 5900 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5895 def get_by_token(organization, token) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('token', token, String) r = @client.request("/#{CGI.escape(organization)}/customer/tokens/#{CGI.escape(token)}").get ::Io::Flow::V0::Models::CustomerToken.new(r) end |
#post_latest_by_customer_number(organization, customer_number) ⇒ Object
If there exists at least one token for this customer number, returns the latest. Otherwise creates a new token and returns that
5879 5880 5881 5882 5883 5884 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5879 def post_latest_by_customer_number(organization, customer_number) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('customer_number', customer_number, String) r = @client.request("/#{CGI.escape(organization)}/customer/tokens/latest/#{CGI.escape(customer_number)}").post ::Io::Flow::V0::Models::CustomerToken.new(r) end |