Class: Io::Flow::V0::Clients::CustomerTokens

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ CustomerTokens

Returns a new instance of CustomerTokens.



6553
6554
6555
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6553

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.



6583
6584
6585
6586
6587
6588
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6583

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.



6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6558

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.



6591
6592
6593
6594
6595
6596
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6591

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



6575
6576
6577
6578
6579
6580
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6575

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