Class: Io::Flow::V0::Clients::ReturnPolicies

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ReturnPolicies

Returns a new instance of ReturnPolicies.



8064
8065
8066
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8064

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

Instance Method Details

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

Returns a list of return policies



8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8069

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

#get_by_id(organization, id) ⇒ Object



8103
8104
8105
8106
8107
8108
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8103

def get_by_id(organization, id)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/#{CGI.escape(organization)}/return/policies/#{CGI.escape(id)}").get
  ::Io::Flow::V0::Models::ReturnPolicy.new(r)
end

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



8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8089

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) }),
    :return_policy_id => (x = opts.delete(:return_policy_id); x.nil? ? nil : HttpClient::Preconditions.assert_class('return_policy_id', x, Array).map { |v| HttpClient::Preconditions.assert_class('return_policy_id', 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)}/return/policies/versions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::ReturnPolicyVersion.new(x) }
end

#post(organization, return_policy_form) ⇒ Object



8082
8083
8084
8085
8086
8087
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8082

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

#put_by_id(organization, id, return_policy_form) ⇒ Object

Updates the specified return policy.



8111
8112
8113
8114
8115
8116
8117
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8111

def put_by_id(organization, id, return_policy_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  (x = return_policy_form; x.is_a?(::Io::Flow::V0::Models::ReturnPolicyForm) ? x : ::Io::Flow::V0::Models::ReturnPolicyForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/return/policies/#{CGI.escape(id)}").with_json(return_policy_form.to_json).put
  ::Io::Flow::V0::Models::ReturnPolicy.new(r)
end

#put_deletion_by_id(organization, id) ⇒ Object

Marks the return policy deleted. Once updated, the policy itself will be deleted.



8121
8122
8123
8124
8125
8126
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8121

def put_deletion_by_id(organization, id)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/#{CGI.escape(organization)}/return/policies/#{CGI.escape(id)}/deletion").put
  ::Io::Flow::V0::Models::ReturnPolicy.new(r)
end