honeys-place 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/honey.rb +2 -0
- data/lib/honey/client.rb +3 -4
- data/lib/honey/error.rb +35 -0
- data/lib/honey/order.rb +85 -3
- data/lib/honey/response.rb +59 -0
- data/lib/honey/version.rb +1 -1
- data/test/honey/order_test.rb +11 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c8bcca4987d91d3dade107ade3eff462b8d999e
|
4
|
+
data.tar.gz: 2f33b11637765359f8879336be2115cd000fcaa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b59f1069e1952f9c79c79f0e4d8ba6db4cfde0e9670c25b4bee5b56561211d0279436d50b8b13e77ca03f317bded74dd16e7975b49cdf6755351f3d0484292ea
|
7
|
+
data.tar.gz: d4d5e02b8b92a742ff9b31e9a3f87a11ba0a357d7e729d7921f56b319121cae2a44376b7977e07d5e2e391c0c868fb1f4af393cfd228b91c7bf73a5942d21bac
|
data/lib/honey.rb
CHANGED
data/lib/honey/client.rb
CHANGED
@@ -5,7 +5,6 @@ module Honey
|
|
5
5
|
|
6
6
|
def initialize(username = '', password = '')
|
7
7
|
login(username, password)
|
8
|
-
self
|
9
8
|
end
|
10
9
|
|
11
10
|
# type :xml, :text
|
@@ -36,8 +35,8 @@ module Honey
|
|
36
35
|
skus = skus.first
|
37
36
|
end
|
38
37
|
skus.each_slice(25) do |sku_group|
|
39
|
-
response = post(build_stock_check(*sku_group))
|
40
|
-
data = response
|
38
|
+
response = post(build_stock_check(*sku_group))
|
39
|
+
data = response.stock["item"]
|
41
40
|
data = [data] if sku_group.count == 1 # Honey's API Quirk
|
42
41
|
data.each do |datum|
|
43
42
|
results[datum["sku"]] = datum["qty"]
|
@@ -61,7 +60,7 @@ module Honey
|
|
61
60
|
private
|
62
61
|
|
63
62
|
def post(xml)
|
64
|
-
self.class.post('', { query: { xmldata: xml }})
|
63
|
+
Honey::Response.new(self.class.post('', { query: { xmldata: xml }}))
|
65
64
|
end
|
66
65
|
|
67
66
|
def login(username, password)
|
data/lib/honey/error.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Honey
|
2
|
+
class Error < StandardError
|
3
|
+
def initialize(code)
|
4
|
+
@code = code
|
5
|
+
super(message)
|
6
|
+
end
|
7
|
+
|
8
|
+
def message
|
9
|
+
CODES[@code]
|
10
|
+
end
|
11
|
+
|
12
|
+
CODES = {
|
13
|
+
999 => "An invalid username / password has been submitted. Please contact Honey's Place.",
|
14
|
+
800 => "First Name is required.",
|
15
|
+
801 => "Last Name is required.",
|
16
|
+
802 => "Address1 is required.",
|
17
|
+
803 => "City is required.",
|
18
|
+
804 => "State is required.",
|
19
|
+
805 => "Zip Code is required.",
|
20
|
+
806 => "Zip Code is invalid.",
|
21
|
+
807 => "Country is invalid.",
|
22
|
+
808 => "E-Mail is invalid.",
|
23
|
+
809 => "State must be only 2 characters.",
|
24
|
+
700 => "Reference number already used.",
|
25
|
+
701 => "Reference number is required.",
|
26
|
+
600 => "Invalid Shipping Code.",
|
27
|
+
500 => "One or more of the submitted products have been discontinued by the manufacturer.",
|
28
|
+
501 => "One or more of the submitted products do not exist.",
|
29
|
+
400 => "Duplicate product within same order. Please combine SKU's and QTY.",
|
30
|
+
300 => "You are checking status on an order you have not yet submitted.",
|
31
|
+
100 => "Order accepted for processing.",
|
32
|
+
0 => "Unknown Error. Please contact Honey's Place."
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
data/lib/honey/order.rb
CHANGED
@@ -14,7 +14,7 @@ module Honey
|
|
14
14
|
self.class.attributes
|
15
15
|
end
|
16
16
|
|
17
|
-
attr_accessor :reference, :shipby, :items, :last, :first, :address1, :address2, :city, :state, :zip, :country, :phone, :emailaddress, :instructions
|
17
|
+
attr_accessor :reference, :shipby, :items, :last, :first, :address1, :address2, :city, :state, :zip, :country, :phone, :emailaddress, :instructions, :date
|
18
18
|
|
19
19
|
def initialize(args = {})
|
20
20
|
update(args)
|
@@ -26,6 +26,24 @@ module Honey
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
def reference=(id)
|
30
|
+
if id == :test
|
31
|
+
@reference = "TEST" << Digest::MD5.base64digest(Time.now.to_s).gsub(/\W/, '')
|
32
|
+
else
|
33
|
+
@reference = id
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def shipby=(code)
|
38
|
+
if code.is_a?(String)
|
39
|
+
@shipby = code
|
40
|
+
else
|
41
|
+
@shipby = shipping_option(code)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
alias_method :shipping, :shipby
|
45
|
+
alias_method :shipping=, :shipby=
|
46
|
+
|
29
47
|
def each_pair(&block)
|
30
48
|
present_attributes.each do |key|
|
31
49
|
yield(key, self.send(key), block)
|
@@ -33,7 +51,7 @@ module Honey
|
|
33
51
|
end
|
34
52
|
|
35
53
|
def valid?
|
36
|
-
(required_attributes - present_attributes)
|
54
|
+
(required_attributes - present_attributes).empty?
|
37
55
|
end
|
38
56
|
|
39
57
|
def invalid?
|
@@ -41,7 +59,7 @@ module Honey
|
|
41
59
|
end
|
42
60
|
|
43
61
|
def required_attributes
|
44
|
-
|
62
|
+
attributes - [:address2, :instructions, :phone]
|
45
63
|
end
|
46
64
|
|
47
65
|
def present_attributes
|
@@ -49,5 +67,69 @@ module Honey
|
|
49
67
|
attr unless self.send(attr).nil?
|
50
68
|
end.compact
|
51
69
|
end
|
70
|
+
|
71
|
+
def self.shipping_option(carrier: :special, service:)
|
72
|
+
carrier = carrier.to_s
|
73
|
+
service = service.to_s
|
74
|
+
unless carrier_options = shipping_options[carrier.downcase]
|
75
|
+
raise Honey::Error, "'#{carrier}' isn't a valid carrier. Valid carriers are: #{shipping_options.keys}"
|
76
|
+
end
|
77
|
+
unless option = carrier_options[service.downcase]
|
78
|
+
raise Honey::Error, "'#{service}' isn't a shipping option for #{carrier}. Valid options are: #{carrier_options.keys}"
|
79
|
+
end
|
80
|
+
option
|
81
|
+
end
|
82
|
+
|
83
|
+
def shipping_option(*args)
|
84
|
+
self.class.shipping_option(*args)
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.shipping_option_from_api_code(api_code)
|
88
|
+
shipping_options.each_pair do |carrier, options|
|
89
|
+
options.each_pair do |service, code|
|
90
|
+
return { carrier: carrier, service: service } if api_code == code
|
91
|
+
end
|
92
|
+
end
|
93
|
+
nil
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
def self.shipping_options
|
98
|
+
{
|
99
|
+
"special" => {
|
100
|
+
"pickup" => "PICKUP",
|
101
|
+
"best rate" => "RTSHOP",
|
102
|
+
"cheapest" => "RTSHOP"
|
103
|
+
},
|
104
|
+
"fedex" => {
|
105
|
+
"first overnight" => "F001",
|
106
|
+
"priority overnight" => "F002",
|
107
|
+
"standard overnight" => "F003",
|
108
|
+
"2 day air" => "F004",
|
109
|
+
"express saver" => "F005",
|
110
|
+
"ground north america" => "F006",
|
111
|
+
"ground home delivery" => "F007",
|
112
|
+
"international priority" => "F008",
|
113
|
+
"international economy" => "F009"
|
114
|
+
},
|
115
|
+
"usps" => {
|
116
|
+
"express mail" => "P001",
|
117
|
+
"priority mail" => "P002",
|
118
|
+
"first class" => "P003",
|
119
|
+
"parcel post" => "P004",
|
120
|
+
"international express" => "P005",
|
121
|
+
"international priority" => "P006",
|
122
|
+
"international first class" => "P007",
|
123
|
+
"priority flat rate" => "P008"
|
124
|
+
},
|
125
|
+
"ups" => {
|
126
|
+
"next day air" => "U001",
|
127
|
+
"2 day air" => "U002",
|
128
|
+
"3 day air" => "U003",
|
129
|
+
"ground" => "U004",
|
130
|
+
"standard" => "U005"
|
131
|
+
}
|
132
|
+
}
|
133
|
+
end
|
52
134
|
end
|
53
135
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module Honey
|
4
|
+
class Response
|
5
|
+
attr_accessor :data
|
6
|
+
|
7
|
+
def initialize(http_response)
|
8
|
+
@data = OpenStruct.new(http_response.parsed_response["message"])
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(method, *args, &block)
|
12
|
+
if method.to_s.end_with?('=')
|
13
|
+
data.try(method, *args)
|
14
|
+
else
|
15
|
+
data.try(method)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def inspect
|
20
|
+
data.inspect
|
21
|
+
end
|
22
|
+
|
23
|
+
def successful?
|
24
|
+
!failed?
|
25
|
+
end
|
26
|
+
|
27
|
+
def failed?
|
28
|
+
data.code.present? && data.code.to_i != 100
|
29
|
+
end
|
30
|
+
|
31
|
+
def cancelled?
|
32
|
+
data.cancelled == "Yes"
|
33
|
+
end
|
34
|
+
|
35
|
+
def shipped?
|
36
|
+
data.status == "Shipped"
|
37
|
+
end
|
38
|
+
|
39
|
+
def error
|
40
|
+
Honey::Error.new(data.code.to_i)
|
41
|
+
end
|
42
|
+
|
43
|
+
def log
|
44
|
+
"[#{data.code}] #{message}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def message
|
48
|
+
data.error || data.details
|
49
|
+
end
|
50
|
+
|
51
|
+
def tracking_numbers
|
52
|
+
(1..5).map { |i| data.try(:"trackingnumber#{i}") }.compact.join(',')
|
53
|
+
end
|
54
|
+
|
55
|
+
def notes
|
56
|
+
data.warehousenotes || ""
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/honey/version.rb
CHANGED
data/test/honey/order_test.rb
CHANGED
@@ -27,4 +27,15 @@ class OrderTest < Minitest::Test
|
|
27
27
|
@order.update(last: "Shreve", first: "Jacob")
|
28
28
|
assert_equal @order.present_attributes, [:last, :first]
|
29
29
|
end
|
30
|
+
|
31
|
+
def test_shipping_options_as_hash
|
32
|
+
@order.shipping = { carrier: :USPS, service: "first class" }
|
33
|
+
assert_equal "P003", @order.shipping
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_shipping_option_from_api_code
|
37
|
+
shipping_option = Honey::Order.shipping_option_from_api_code("P003")
|
38
|
+
assert_equal "usps", shipping_option[:carrier]
|
39
|
+
assert_equal "first class", shipping_option[:service]
|
40
|
+
end
|
30
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: honeys-place
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Evan Shreve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -75,7 +75,9 @@ files:
|
|
75
75
|
- lib/honey.rb
|
76
76
|
- lib/honey/builder.rb
|
77
77
|
- lib/honey/client.rb
|
78
|
+
- lib/honey/error.rb
|
78
79
|
- lib/honey/order.rb
|
80
|
+
- lib/honey/response.rb
|
79
81
|
- lib/honey/version.rb
|
80
82
|
- lib/nokogiri/xml/document_to_hash.rb
|
81
83
|
- test/honey/builder_test.rb
|
@@ -104,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
106
|
version: '0'
|
105
107
|
requirements: []
|
106
108
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.4.5
|
108
110
|
signing_key:
|
109
111
|
specification_version: 4
|
110
112
|
summary: A wrapper for the Honey's Place API
|