Class: Io::Flow::V0::Clients::Centers

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Centers

Returns a new instance of Centers.



2339
2340
2341
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2339

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

Instance Method Details

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



2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2343

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) }),
    :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? ? "name" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/centers").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Center.new(x) }
end

#get_by_key(organization, key) ⇒ Object



2364
2365
2366
2367
2368
2369
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2364

def get_by_key(organization, key)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  r = @client.request("/#{CGI.escape(organization)}/centers/#{CGI.escape(key)}").get
  ::Io::Flow::V0::Models::Center.new(r)
end

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



2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2379

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, 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) }),
    :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)}/centers/versions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::CenterVersion.new(x) }
end

#post(organization, center_form) ⇒ Object



2357
2358
2359
2360
2361
2362
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2357

def post(organization, center_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('center_form', center_form, ::Io::Flow::V0::Models::CenterForm)
  r = @client.request("/#{CGI.escape(organization)}/centers").with_json(center_form.to_json).post
  ::Io::Flow::V0::Models::Center.new(r)
end

#put_by_key(organization, key, center_form) ⇒ Object



2371
2372
2373
2374
2375
2376
2377
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2371

def put_by_key(organization, key, center_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  HttpClient::Preconditions.assert_class('center_form', center_form, ::Io::Flow::V0::Models::CenterForm)
  r = @client.request("/#{CGI.escape(organization)}/centers/#{CGI.escape(key)}").with_json(center_form.to_json).put
  ::Io::Flow::V0::Models::Center.new(r)
end