Class: Io::Flow::V0::Clients::Targetings

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Targetings

Returns a new instance of Targetings.



1784
1785
1786
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1784

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

Instance Method Details

#delete_by_key(organization, key) ⇒ Object



1824
1825
1826
1827
1828
1829
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1824

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)}/catalog/targetings/#{CGI.escape(key)}").delete
  nil
end

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



1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1788

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

#get_by_key(organization, key) ⇒ Object



1809
1810
1811
1812
1813
1814
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1809

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)}/catalog/targetings/#{CGI.escape(key)}").get
  ::Io::Flow::V0::Models::Targeting.new(r)
end

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



1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1831

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

#post(organization, targeting_form) ⇒ Object



1802
1803
1804
1805
1806
1807
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1802

def post(organization, targeting_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  (x = targeting_form; x.is_a?(::Io::Flow::V0::Models::TargetingForm) ? x : ::Io::Flow::V0::Models::TargetingForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/catalog/targetings").with_json(targeting_form.to_json).post
  ::Io::Flow::V0::Models::Targeting.new(r)
end

#put_by_key(organization, key, targeting_form) ⇒ Object



1816
1817
1818
1819
1820
1821
1822
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1816

def put_by_key(organization, key, targeting_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  (x = targeting_form; x.is_a?(::Io::Flow::V0::Models::TargetingForm) ? x : ::Io::Flow::V0::Models::TargetingForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/catalog/targetings/#{CGI.escape(key)}").with_json(targeting_form.to_json).put
  ::Io::Flow::V0::Models::Targeting.new(r)
end