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.



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

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



583
584
585
586
587
588
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 583

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.



545
546
547
548
549
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 545

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.



552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 552

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.



567
568
569
570
571
572
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 567

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.



591
592
593
594
595
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 591

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



575
576
577
578
579
580
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 575

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