Class: Io::Flow::V0::Clients::RatecardRates

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ RatecardRates

Returns a new instance of RatecardRates.



4534
4535
4536
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4534

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

Instance Method Details

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



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

def get(organization, ratecard_id, lane_id, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('ratecard_id', ratecard_id, String)
  HttpClient::Preconditions.assert_class('lane_id', lane_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) }),
    :weight => (x = opts.delete(:weight); x.nil? ? nil : HttpClient::Preconditions.assert_class('weight', x, Array).map { |v| HttpClient::Preconditions.assert_class('weight', v, Numeric) }),
    :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)}/ratecards/#{CGI.escape(ratecard_id)}/lanes/#{CGI.escape(lane_id)}/rates").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::RatecardRate.new(x) }
end

#get_by_id(organization, ratecard_id, lane_id, id) ⇒ Object



4578
4579
4580
4581
4582
4583
4584
4585
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4578

def get_by_id(organization, ratecard_id, lane_id, id)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('ratecard_id', ratecard_id, String)
  HttpClient::Preconditions.assert_class('lane_id', lane_id, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/#{CGI.escape(organization)}/ratecards/#{CGI.escape(ratecard_id)}/lanes/#{CGI.escape(lane_id)}/rates/#{CGI.escape(id)}").get
  ::Io::Flow::V0::Models::RatecardRate.new(r)
end

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



4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4563

def get_versions(organization, ratecard_id, lane_id, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('ratecard_id', ratecard_id, String)
  HttpClient::Preconditions.assert_class('lane_id', lane_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? ? "journal_timestamp" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/ratecards/#{CGI.escape(ratecard_id)}/lanes/#{CGI.escape(lane_id)}/rates/versions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::RatecardRateVersion.new(x) }
end

#post(organization, ratecard_id, lane_id, ratecard_rate_form) ⇒ Object



4554
4555
4556
4557
4558
4559
4560
4561
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4554

def post(organization, ratecard_id, lane_id, ratecard_rate_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('ratecard_id', ratecard_id, String)
  HttpClient::Preconditions.assert_class('lane_id', lane_id, String)
  (x = ratecard_rate_form; x.is_a?(::Io::Flow::V0::Models::RatecardRateForm) ? x : ::Io::Flow::V0::Models::RatecardRateForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/ratecards/#{CGI.escape(ratecard_id)}/lanes/#{CGI.escape(lane_id)}/rates").with_json(ratecard_rate_form.to_json).post
  ::Io::Flow::V0::Models::RatecardRate.new(r)
end

#put_by_id(organization, ratecard_id, lane_id, id, ratecard_rate_form) ⇒ Object



4587
4588
4589
4590
4591
4592
4593
4594
4595
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4587

def put_by_id(organization, ratecard_id, lane_id, id, ratecard_rate_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('ratecard_id', ratecard_id, String)
  HttpClient::Preconditions.assert_class('lane_id', lane_id, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  (x = ratecard_rate_form; x.is_a?(::Io::Flow::V0::Models::RatecardRateForm) ? x : ::Io::Flow::V0::Models::RatecardRateForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/ratecards/#{CGI.escape(ratecard_id)}/lanes/#{CGI.escape(lane_id)}/rates/#{CGI.escape(id)}").with_json(ratecard_rate_form.to_json).put
  ::Io::Flow::V0::Models::RatecardRate.new(r)
end