Class: Io::Flow::V0::Clients::Cards

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Cards

Returns a new instance of Cards.



3348
3349
3350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3348

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

Instance Method Details

#delete_by_token(organization, token) ⇒ Object

Deletes the specified card



3410
3411
3412
3413
3414
3415
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3410

def delete_by_token(organization, token)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('token', token, String)
  r = @client.request("/#{CGI.escape(organization)}/cards/#{CGI.escape(token)}").delete
  nil
end

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



3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3352

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, Array).map { |v| HttpClient::Preconditions.assert_class('token', v, 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)}/cards").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Card.new(x) }
end

#get_by_token(organization, token) ⇒ Object

Returns information about a specific card.



3402
3403
3404
3405
3406
3407
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3402

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)}/cards/#{CGI.escape(token)}").get
  ::Io::Flow::V0::Models::Card.new(r)
end

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

Provides visibility into recent changes of each object, including deletion



3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3386

def get_versions(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, Integer) }),
    :card_id => (x = opts.delete(:card_id); x.nil? ? nil : HttpClient::Preconditions.assert_class('card_id', x, Array).map { |v| HttpClient::Preconditions.assert_class('card_id', v, String) }),
    :card_token => (x = opts.delete(:card_token); x.nil? ? nil : HttpClient::Preconditions.assert_class('card_token', x, Array).map { |v| HttpClient::Preconditions.assert_class('card_token', v, 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? ? "journal_timestamp" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/cards/versions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::CardVersion.new(x) }
end

#post(organization, card_form) ⇒ Object

Create a new card. Note that when using JSONP to submit a card, you do not need to authenticate.



3368
3369
3370
3371
3372
3373
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3368

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

#post_nonces(organization, card_nonce_form) ⇒ Object

Creates a card from a one time nonce. Each nonce can be used at most once and you will receive a validation error if the nonce has already been exchanged.



3378
3379
3380
3381
3382
3383
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3378

def post_nonces(organization, card_nonce_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  (x = card_nonce_form; x.is_a?(::Io::Flow::V0::Models::CardNonceForm) ? x : ::Io::Flow::V0::Models::CardNonceForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/cards/nonces").with_json(card_nonce_form.to_json).post
  ::Io::Flow::V0::Models::Card.new(r)
end