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.



2572
2573
2574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2572

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



2608
2609
2610
2611
2612
2613
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2608

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



2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2576

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.



2600
2601
2602
2603
2604
2605
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2600

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



2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2626

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.



2592
2593
2594
2595
2596
2597
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2592

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.



2618
2619
2620
2621
2622
2623
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2618

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