Class: Io::Flow::V0::Clients::Catalogs

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Catalogs

Returns a new instance of Catalogs.



488
489
490
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 488

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

Instance Method Details

#delete_catalog_and_restrictions_by_number(organization, number) ⇒ Object

Delete the global restriction for this catalog item number



532
533
534
535
536
537
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 532

def delete_catalog_and_restrictions_by_number(organization, number)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  r = @client.request("/#{CGI.escape(organization)}/catalog/restrictions/#{CGI.escape(number)}").delete
  nil
end

#get_catalog(organization) ⇒ Object

Returns information about a specific catalog.



493
494
495
496
497
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 493

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

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

Search global restrictions. Always paginated.



500
501
502
503
504
505
506
507
508
509
510
511
512
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 500

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

#get_catalog_and_restrictions_by_number(organization, number) ⇒ Object

Returns a spcifical globally restricted item.



515
516
517
518
519
520
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 515

def get_catalog_and_restrictions_by_number(organization, number)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  r = @client.request("/#{CGI.escape(organization)}/catalog/restrictions/#{CGI.escape(number)}").get
  ::Io::Flow::V0::Models::Item.new(r)
end

#get_catalog_and_statistics(organization) ⇒ Object

Get statistics for this organization’s catalog.



540
541
542
543
544
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 540

def get_catalog_and_statistics(organization)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  r = @client.request("/#{CGI.escape(organization)}/catalog/statistics").get
  ::Io::Flow::V0::Models::CatalogStatistics.new(r)
end

#put_catalog_and_restrictions_by_number(organization, number, hash) ⇒ Object

Upsert a global restriction



523
524
525
526
527
528
529
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 523

def put_catalog_and_restrictions_by_number(organization, number, hash)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  HttpClient::Preconditions.assert_class('hash', hash, Hash)
  r = @client.request("/#{CGI.escape(organization)}/catalog/restrictions/#{CGI.escape(number)}").with_json(hash.to_json).put
  ::Io::Flow::V0::Models::Item.new(r)
end