Class: Finale::Client
- Inherits:
-
Object
- Object
- Finale::Client
- Defined in:
- lib/finale/client.rb
Constant Summary collapse
- MAX_REQUESTS =
Finale API Usage: ‘support.finaleinventory.com/hc/en-us/articles/115007830648-Getting-Started’
100
- BASE_URL =
'https://app.finaleinventory.com'
Instance Method Summary collapse
- #get_order(id) ⇒ Object
- #get_order_from_shipment(shipment) ⇒ Object
- #get_orders(filter: nil) ⇒ Object
- #get_shipments(filter: nil) ⇒ Object
- #get_shipments_from_order(order) ⇒ Object
-
#initialize(account) ⇒ Client
constructor
A new instance of Client.
- #login(username: nil, password: nil) ⇒ Object
Constructor Details
#initialize(account) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 |
# File 'lib/finale/client.rb', line 15 def initialize(account) @cookies = nil @request_count = 0 @account = account @login_url = construct_url(:auth) @order_url = construct_url(:order) @shipment_url = construct_url(:shipment) end |
Instance Method Details
#get_order(id) ⇒ Object
33 34 35 36 |
# File 'lib/finale/client.rb', line 33 def get_order(id) response = request(verb: :GET, url: "#{@order_url}/#{id}") Order.new(response) end |
#get_order_from_shipment(shipment) ⇒ Object
52 53 54 |
# File 'lib/finale/client.rb', line 52 def get_order_from_shipment(shipment) get_order(shipment.order_id) end |
#get_orders(filter: nil) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/finale/client.rb', line 38 def get_orders(filter: nil) resp_orders = request(verb: :GET, url: @order_url, filter: filter ) rows = column_major_to_row_major(resp_orders) orders = rows.map { |r| Order.new(r) } orders end |
#get_shipments(filter: nil) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/finale/client.rb', line 45 def get_shipments(filter: nil) resp_shipments = request(verb: :GET, url: @shipment_url, filter: filter ) rows = column_major_to_row_major(resp_shipments) shipments = rows.map { |r| Shipment.new(r) } shipments end |
#get_shipments_from_order(order) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/finale/client.rb', line 56 def get_shipments_from_order(order) (order.shipmentUrlList || []).map do |suffix_url| url = "#{BASE_URL}#{suffix_url}" response = request(verb: :GET, url: url) Shipment.new(response) end end |
#login(username: nil, password: nil) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/finale/client.rb', line 24 def login(username: nil, password: nil) payload = { username: username || ENV['FINALE_USERNAME'], password: password || ENV['FINALE_PASSWORD'] } request(verb: :LOGIN, payload: payload) end |