Class: Io::Flow::V0::Clients::TierRules

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ TierRules

Returns a new instance of TierRules.



4510
4511
4512
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4510

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

Instance Method Details

#delete_by_id(organization, tier_id, id) ⇒ Object



4568
4569
4570
4571
4572
4573
4574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4568

def delete_by_id(organization, tier_id, id)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('tier_id', tier_id, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/#{CGI.escape(organization)}/tiers/#{CGI.escape(tier_id)}/rules/#{CGI.escape(id)}").delete
  nil
end

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



4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4514

def get(organization, tier_id, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('tier_id', tier_id, 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)}/tiers/#{CGI.escape(tier_id)}/rules").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::TierRule.new(x) }
end

#get_by_id(organization, tier_id, id) ⇒ Object



4551
4552
4553
4554
4555
4556
4557
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4551

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

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



4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4536

def get_versions(organization, tier_id, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('tier_id', tier_id, 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) }),
    :tier_rule => (x = opts.delete(:tier_rule); x.nil? ? nil : HttpClient::Preconditions.assert_class('tier_rule', x, Array).map { |v| HttpClient::Preconditions.assert_class('tier_rule', 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)}/tiers/#{CGI.escape(tier_id)}/rules/versions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::TierRuleVersion.new(x) }
end

#post(organization, tier_id, tier_rule_form) ⇒ Object



4528
4529
4530
4531
4532
4533
4534
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4528

def post(organization, tier_id, tier_rule_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('tier_id', tier_id, String)
  (x = tier_rule_form; x.is_a?(::Io::Flow::V0::Models::TierRuleForm) ? x : ::Io::Flow::V0::Models::TierRuleForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/tiers/#{CGI.escape(tier_id)}/rules").with_json(tier_rule_form.to_json).post
  ::Io::Flow::V0::Models::TierRule.new(r)
end

#put_by_id(organization, tier_id, id, tier_rule_form) ⇒ Object



4559
4560
4561
4562
4563
4564
4565
4566
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4559

def put_by_id(organization, tier_id, id, tier_rule_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('tier_id', tier_id, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  (x = tier_rule_form; x.is_a?(::Io::Flow::V0::Models::TierRuleForm) ? x : ::Io::Flow::V0::Models::TierRuleForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/tiers/#{CGI.escape(tier_id)}/rules/#{CGI.escape(id)}").with_json(tier_rule_form.to_json).put
  ::Io::Flow::V0::Models::TierRule.new(r)
end