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.



2522
2523
2524
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2522

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



2558
2559
2560
2561
2562
2563
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2558

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



2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2526

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.



2550
2551
2552
2553
2554
2555
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2550

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



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

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.



2542
2543
2544
2545
2546
2547
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2542

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.



2568
2569
2570
2571
2572
2573
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2568

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