Class: Io::Flow::V0::Clients::Provinces

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Provinces

Returns a new instance of Provinces.



5013
5014
5015
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5013

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

Instance Method Details

#get(incoming = {}) ⇒ Object

Returns a list of provinces.



5018
5019
5020
5021
5022
5023
5024
5025
5026
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5018

def get(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :q => (x = opts.delete(:q); x.nil? ? nil : HttpClient::Preconditions.assert_class('q', x, String)),
    :countries => (x = opts.delete(:countries); x.nil? ? nil : HttpClient::Preconditions.assert_class('countries', x, Array).map { |v| HttpClient::Preconditions.assert_class('countries', v, String) })
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/reference/provinces").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Province.new(x) }
end

#get_by_id(id) ⇒ Object

Returns the province with the specifed id.



5029
5030
5031
5032
5033
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5029

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