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.



909
910
911
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 909

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



952
953
954
955
956
957
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 952

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.



914
915
916
917
918
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 914

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.



921
922
923
924
925
926
927
928
929
930
931
932
933
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 921

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 specific globally restricted item.



936
937
938
939
940
941
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 936

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.



960
961
962
963
964
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 960

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) ⇒ Object

Upsert a global restriction



944
945
946
947
948
949
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 944

def put_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)}").put
  ::Io::Flow::V0::Models::Item.new(r)
end