Class: Honey::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/honey/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username = '', password = '') ⇒ Client

Returns a new instance of Client.



6
7
8
9
# File 'lib/honey/client.rb', line 6

def initialize(username = '', password = '')
  (username, password)
  self
end

Class Method Details

.data_feed(type = :xml, path = '/tmp/honey') ⇒ Object

type :xml, :text



12
13
14
# File 'lib/honey/client.rb', line 12

def self.data_feed(type = :xml, path = '/tmp/honey')
  IO.popen("curl #{self.class.base_uri}/#{data_feed_url(type)} -o #{path}.#{type}")
end

.data_feed_url(type = :xml) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/honey/client.rb', line 16

def self.data_feed_url(type = :xml)
  "xml/honeysinventory" << case type
  when :xml
    "v2_0.xml"
  when :txt
    "_v_1.0.txt"
  end
end

Instance Method Details

#build_order(order) ⇒ Object



49
50
51
# File 'lib/honey/client.rb', line 49

def build_order(order)
  request(order: order)
end

#build_order_status(reference_number) ⇒ Object



53
54
55
# File 'lib/honey/client.rb', line 53

def build_order_status(reference_number)
  request(orderstatus: reference_number)
end

#build_stock_check(*skus) ⇒ Object



57
58
59
# File 'lib/honey/client.rb', line 57

def build_stock_check(*skus)
  request(stockcheck: skus.map { |sku| { sku: sku } })
end

#order_status(reference_number) ⇒ Object



29
30
31
# File 'lib/honey/client.rb', line 29

def order_status(reference_number)
  post build_order_status(reference_number)
end

#stock_check(*skus) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/honey/client.rb', line 33

def stock_check(*skus)
  results = {}
  if skus.first.is_a? Array
    skus = skus.first
  end
  skus.each_slice(25) do |sku_group|
    response = post(build_stock_check(*sku_group)).parsed_response
    data = response["message"]["stock"]["item"]
    data = [data] if sku_group.count == 1 # Honey's API Quirk
    data.each do |datum|
      results[datum["sku"]] = datum["qty"]
    end
  end
  results
end

#submit_order(order) ⇒ Object



25
26
27
# File 'lib/honey/client.rb', line 25

def submit_order(order)
  post build_order(order)
end