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.



3452
3453
3454
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3452

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



3514
3515
3516
3517
3518
3519
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3514

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



3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3456

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.



3506
3507
3508
3509
3510
3511
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3506

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



3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3490

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.



3472
3473
3474
3475
3476
3477
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3472

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.



3482
3483
3484
3485
3486
3487
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3482

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