class Honey::Client
Public Class Methods
new(account = '', token = '')
click to toggle source
# File lib/honey/client.rb, line 7 def initialize(account = '', token = '') login(account, token) end
Public Instance Methods
build_order(order)
click to toggle source
# File lib/honey/client.rb, line 31 def build_order(order) request(order: order) end
build_order_status(reference_number)
click to toggle source
# File lib/honey/client.rb, line 35 def build_order_status(reference_number) request(orderstatus: reference_number) end
build_stock_check(*skus)
click to toggle source
# File lib/honey/client.rb, line 39 def build_stock_check(*skus) request(stockcheck: skus.map { |sku| { sku: sku } }) end
data_feed(code, format)
click to toggle source
# File lib/honey/client.rb, line 27 def data_feed(code, format) DataFeed.new(code, format) end
order_status(reference_number)
click to toggle source
# File lib/honey/client.rb, line 15 def order_status(reference_number) post build_order_status(reference_number) end
stock_check(*skus)
click to toggle source
# File lib/honey/client.rb, line 19 def stock_check(*skus) skus = skus.first if skus.first.is_a? Array skus.each_slice(25).map do |sku_group| data = post(build_stock_check(*sku_group)).stock['item'] stock_hash(data) end.reduce({}, :merge) end
submit_order(order)
click to toggle source
# File lib/honey/client.rb, line 11 def submit_order(order) post build_order(order) end
Private Instance Methods
login(account, token)
click to toggle source
# File lib/honey/client.rb, line 58 def login(account, token) @builder = Honey::Builder.new(account, token) end
post(xml)
click to toggle source
# File lib/honey/client.rb, line 54 def post(xml) Honey::Response.new(self.class.post('', { query: { xmldata: xml }})) end
request(object)
click to toggle source
# File lib/honey/client.rb, line 62 def request(object) @builder.build(object) end
stock_hash(data)
click to toggle source
# File lib/honey/client.rb, line 45 def stock_hash(data) # API returns single element not wrapped in array data = [data] unless data.is_a?(Array) data.map do |datum| [datum['sku'], datum['qty'].to_i] end.to_h end