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.
5952 5953 5954 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5952 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.
5982 5983 5984 5985 5986 5987 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5982 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.
5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5957 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.
5990 5991 5992 5993 5994 5995 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5990 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
5974 5975 5976 5977 5978 5979 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5974 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 |