Class: Io::Flow::V0::Clients::Centers

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Centers

Returns a new instance of Centers.



2863
2864
2865
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2863

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

Instance Method Details

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



2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2867

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

#get_by_key(organization, key) ⇒ Object



2888
2889
2890
2891
2892
2893
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2888

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

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



2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2903

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

#post(organization, center_form) ⇒ Object



2881
2882
2883
2884
2885
2886
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2881

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

#put_by_key(organization, key, center_form) ⇒ Object



2895
2896
2897
2898
2899
2900
2901
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2895

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