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.



1771
1772
1773
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1771

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

Instance Method Details

#delete_by_key(organization, key) ⇒ Object



1811
1812
1813
1814
1815
1816
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1811

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



1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1775

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



1796
1797
1798
1799
1800
1801
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1796

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



1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1818

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



1789
1790
1791
1792
1793
1794
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1789

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



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

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