Class: Io::Flow::V0::Clients::Authorizations

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Authorizations

Returns a new instance of Authorizations.



3004
3005
3006
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3004

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

Instance Method Details

#delete_by_key(organization, key) ⇒ Object

Deprecated. This end point no longer deletes an authorization and is implemented by creating a reversal for the remaining balance on the auth.



3079
3080
3081
3082
3083
3084
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3079

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

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



3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3008

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) }),
    :key => (x = opts.delete(:key); x.nil? ? nil : HttpClient::Preconditions.assert_class('key', x, Array).map { |v| HttpClient::Preconditions.assert_class('key', v, String) }),
    :order_number => (x = opts.delete(:order_number); x.nil? ? nil : HttpClient::Preconditions.assert_class('order_number', x, 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),
    :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) })
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/authorizations").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Authorization.from_json(x) }
end

#get_by_key(organization, key, incoming = {}) ⇒ Object

Returns information about a specific authorization.



3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3052

def get_by_key(organization, key, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) })
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/authorizations/#{CGI.escape(key)}").with_query(query).get
  ::Io::Flow::V0::Models::Authorization.from_json(r)
end

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

Provides visibility into recent changes of each object, including deletion



3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3037

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) }),
    :authorization_id => (x = opts.delete(:authorization_id); x.nil? ? nil : HttpClient::Preconditions.assert_class('authorization_id', x, Array).map { |v| HttpClient::Preconditions.assert_class('authorization_id', 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)}/authorizations/versions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::AuthorizationVersion.new(x) }
end

#post(organization, authorization_form, incoming = {}) ⇒ Object

Create a new authorization.



3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3025

def post(organization, authorization_form, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) })
  }.delete_if { |k, v| v.nil? }
  (x = authorization_form; x.is_a?(::Io::Flow::V0::Models::AuthorizationForm) ? x : ::Io::Flow::V0::Models::AuthorizationForm.from_json(x))
  r = @client.request("/#{CGI.escape(organization)}/authorizations").with_query(query).with_json(authorization_form.to_json).post
  ::Io::Flow::V0::Models::Authorization.from_json(r)
end

#put_by_key(organization, key, authorization_form, incoming = {}) ⇒ Object

Attempts to create an authorization identified by the provided key. Multiple requests using the same key are idempotent.



3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3065

def put_by_key(organization, key, authorization_form, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) })
  }.delete_if { |k, v| v.nil? }
  (x = authorization_form; x.is_a?(::Io::Flow::V0::Models::AuthorizationForm) ? x : ::Io::Flow::V0::Models::AuthorizationForm.from_json(x))
  r = @client.request("/#{CGI.escape(organization)}/authorizations/#{CGI.escape(key)}").with_query(query).with_json(authorization_form.to_json).put
  ::Io::Flow::V0::Models::Authorization.from_json(r)
end