Class: Moip2::OrderApi
- Inherits:
-
Object
- Object
- Moip2::OrderApi
- Defined in:
- lib/moip2/order_api.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #base_path ⇒ Object
- #create(order) ⇒ Object
- #find_all(limit: nil, offset: nil, q: nil, filters: nil) ⇒ Object
-
#initialize(client) ⇒ OrderApi
constructor
A new instance of OrderApi.
- #show(id) ⇒ Object
Constructor Details
#initialize(client) ⇒ OrderApi
Returns a new instance of OrderApi.
5 6 7 |
# File 'lib/moip2/order_api.rb', line 5 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/moip2/order_api.rb', line 3 def client @client end |
Instance Method Details
#base_path ⇒ Object
9 10 11 |
# File 'lib/moip2/order_api.rb', line 9 def base_path "/v2/orders" end |
#create(order) ⇒ Object
13 14 15 |
# File 'lib/moip2/order_api.rb', line 13 def create(order) Resource::Order.new client, client.post(base_path, order) end |
#find_all(limit: nil, offset: nil, q: nil, filters: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/moip2/order_api.rb', line 21 def find_all(limit: nil, offset: nil, q: nil, filters: nil) encoded_filters = Moip2::Util::FiltersEncoder.encode(filters) # `URI.encode...` will accept nil params, but they will pollute the URI params = { limit: limit, offset: offset, q: q, filters: encoded_filters, }.reject { |_, value| value.nil? } query_string = URI.encode_www_form(params) path = "#{base_path}?#{query_string}" response = client.get(path) # We need to transform raw JSON in Order objects response.orders.collect! { |order| Resource::Order.new client, order } Resource::Order.new client, response end |