Class: Io::Flow::V0::Clients::OrganizationTokens

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ OrganizationTokens

Returns a new instance of OrganizationTokens.



7775
7776
7777
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7775

def initialize(client)
  @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client)
end

Instance Method Details

#get(organization, incoming = {}) ⇒ Object

Get all tokens for the specified organization



7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7780

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) }),
    :mine => (x = opts.delete(:mine); x.nil? ? nil : HttpClient::Preconditions.assert_boolean('mine', x)),
    :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)}/tokens").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::OrganizationToken.new(x) }
end

#post(organization, organization_token_form) ⇒ Object

Create a new organization



7795
7796
7797
7798
7799
7800
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7795

def post(organization, organization_token_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  (x = organization_token_form; x.is_a?(::Io::Flow::V0::Models::OrganizationTokenForm) ? x : ::Io::Flow::V0::Models::OrganizationTokenForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/tokens").with_json(organization_token_form.to_json).post
  ::Io::Flow::V0::Models::OrganizationToken.new(r)
end