shipwire 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env +4 -0
- data/.env.example +4 -0
- data/.gitignore +26 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +57 -0
- data/Rakefile +7 -0
- data/lib/shipwire.rb +46 -0
- data/lib/shipwire/configuration.rb +9 -0
- data/lib/shipwire/fulfillment.rb +100 -0
- data/lib/shipwire/inventory.rb +72 -0
- data/lib/shipwire/service_request.rb +42 -0
- data/lib/shipwire/shipping_rate.rb +86 -0
- data/lib/shipwire/tracking.rb +7 -0
- data/lib/shipwire/version.rb +3 -0
- data/shipwire.gemspec +35 -0
- data/spec/shipwire/fulfillment_spec.rb +36 -0
- data/spec/shipwire/inventory_spec.rb +25 -0
- data/spec/shipwire/shipping_rate_spec.rb +42 -0
- data/spec/shipwire/tracking_spec.rb +5 -0
- data/spec/spec_helper.rb +20 -0
- metadata +224 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f525a6d09dadb0aad42adbed55c08e926231ded
|
4
|
+
data.tar.gz: 2cdbbb4bc4c3c1d6cfb1e1a05a7d1c43458f26a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 91cbb7af2c124a73355926f782b0fc283eb039e519159f4c4470ddd922e5aa8d3dcb73bd755ec94ece238d411b112dd3c3b9080690f97e7070b87f758d556943
|
7
|
+
data.tar.gz: 18ca37d66f4288967099bc8af70c0b6250d0f789bd3045f4cc115aa8d0cce195d5f86f4320adccb71161dae499cfd5696f8a66809c5502ae8b3086b34ca38b9e
|
data/.env
ADDED
data/.env.example
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
*.rbc
|
2
|
+
capybara-*.html
|
3
|
+
.rspec
|
4
|
+
/log
|
5
|
+
/tmp
|
6
|
+
/db/*.sqlite3
|
7
|
+
/public/system
|
8
|
+
/coverage/
|
9
|
+
/spec/tmp
|
10
|
+
**.orig
|
11
|
+
rerun.txt
|
12
|
+
pickle-email-*.html
|
13
|
+
config/initializers/secret_token.rb
|
14
|
+
config/secrets.yml
|
15
|
+
|
16
|
+
## Environment normalisation:
|
17
|
+
/.bundle
|
18
|
+
/vendor/bundle
|
19
|
+
|
20
|
+
# these should all be checked in to normalise the environment:
|
21
|
+
# Gemfile.lock, .ruby-version, .ruby-gemset
|
22
|
+
|
23
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
24
|
+
.rvmrc
|
25
|
+
|
26
|
+
*.gem
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Morbid Enterprises
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
Shipwire
|
2
|
+
========
|
3
|
+
|
4
|
+
Ruby gem to integrate with Shipwire's fulfillment API.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
`gem 'shipwire'`
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
`$ bundle`
|
15
|
+
|
16
|
+
You can install it locally as:
|
17
|
+
|
18
|
+
`$ gem install shipwire`
|
19
|
+
|
20
|
+
## Getting Started
|
21
|
+
|
22
|
+
Get a Shipwire sandbox account for development & testing:
|
23
|
+
|
24
|
+
`http://beta.shipwire.com/`
|
25
|
+
|
26
|
+
Your credentials, endpoint, and sever environment variables need to be set:
|
27
|
+
|
28
|
+
SHIPWIRE_USERNAME
|
29
|
+
SHIPWIRE_PASSWORD
|
30
|
+
SHIPWIRE_SERVER
|
31
|
+
SHIPWIRE_ENDPOINT
|
32
|
+
|
33
|
+
SHIPWIRE_SERVER is either `Test` or `Production`. SHIPWIRE_ENDPOINT is one of their API hosts:
|
34
|
+
|
35
|
+
`https://api.shipwire.com/exec/`
|
36
|
+
|
37
|
+
Or
|
38
|
+
|
39
|
+
`https://api.beta.shipwire.com/exec/`
|
40
|
+
|
41
|
+
Use `api.beta` for any development or testing.
|
42
|
+
|
43
|
+
## Running Tests
|
44
|
+
|
45
|
+
If making contributions to this gem, make sure you write tests for any new functionality. Contributions will be rejected if there are no tests or tests do not pass.
|
46
|
+
|
47
|
+
#### Shipping Quotes
|
48
|
+
|
49
|
+
Shipwire relies on product SKUs being present to return a shipping quote. In your Sandbox environment, create a test product with SKU `123456` to get quote tests to pass.
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it ( https://github.com/[my-github-username]/shipwire/fork )
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/shipwire.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'shipwire/version'
|
2
|
+
require 'shipwire/configuration'
|
3
|
+
|
4
|
+
require 'shipwire/service_request'
|
5
|
+
require 'shipwire/fulfillment'
|
6
|
+
require 'shipwire/shipping_rate'
|
7
|
+
require 'shipwire/tracking'
|
8
|
+
require 'shipwire/inventory'
|
9
|
+
|
10
|
+
module Shipwire
|
11
|
+
class << self
|
12
|
+
attr_accessor :configuration
|
13
|
+
|
14
|
+
def configure(&block)
|
15
|
+
@configuration = Configuration.new(&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def configuration
|
19
|
+
@configuration ||= Configuration.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def endpoint
|
23
|
+
configuration.nil? ? nil : configuration.endpoint
|
24
|
+
end
|
25
|
+
|
26
|
+
def username
|
27
|
+
configuration.nil? ? nil : configuration.username
|
28
|
+
end
|
29
|
+
|
30
|
+
def password
|
31
|
+
configuration.nil? ? nil : configuration.password
|
32
|
+
end
|
33
|
+
|
34
|
+
def server
|
35
|
+
configuration.nil? ? nil : configuration.server
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Error < Exception; end
|
40
|
+
class ApiEndpointNotSet < Error; end
|
41
|
+
class ApiUsernameNotSet < Error; end
|
42
|
+
class ApiPasswordNotSet < Error; end
|
43
|
+
class ApiServerNotSet < Error; end
|
44
|
+
class ServerErrorEncountered < Error; end
|
45
|
+
class AccessDenied < Error; end
|
46
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Shipwire
|
4
|
+
class Fulfillment < Shipwire::ServiceRequest
|
5
|
+
attr_reader :order_responses
|
6
|
+
|
7
|
+
API_PATH = 'FulfillmentServices.php'
|
8
|
+
|
9
|
+
def initialize(params={})
|
10
|
+
super
|
11
|
+
|
12
|
+
@order_responses = []
|
13
|
+
@api_path = Fulfillment::API_PATH
|
14
|
+
@orders = params[:orders]
|
15
|
+
|
16
|
+
self.build_payload
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse_response
|
20
|
+
if @response != nil
|
21
|
+
xml = Nokogiri::XML(@response.body)
|
22
|
+
@fulfillment_response = xml.xpath('//SubmitOrderResponse')
|
23
|
+
end
|
24
|
+
|
25
|
+
if @fulfillment_response != nil
|
26
|
+
if is_ok?(@fulfillment_response)
|
27
|
+
orders = @fulfillment_response.xpath('//Order')
|
28
|
+
|
29
|
+
orders.each do |order|
|
30
|
+
order_number = order.attributes['number'].value
|
31
|
+
fulfillment_id = order.attributes['id'].value
|
32
|
+
status = order.attributes['status'].value
|
33
|
+
|
34
|
+
shipping = order.xpath('Shipping')
|
35
|
+
|
36
|
+
shipping_cost = shipping.xpath('Cost').text
|
37
|
+
shipping_service = shipping.xpath('Service').text
|
38
|
+
|
39
|
+
@order_responses << {
|
40
|
+
order_number: order_number,
|
41
|
+
fulfillment_id: fulfillment_id,
|
42
|
+
status: status,
|
43
|
+
shipping: {
|
44
|
+
service: shipping_service,
|
45
|
+
cost: shipping_cost
|
46
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
else
|
50
|
+
@errors << 'Unsuccessful request'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
protected
|
56
|
+
def build_payload
|
57
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
58
|
+
xml.OrderList {
|
59
|
+
xml.Username Shipwire.username
|
60
|
+
xml.Password Shipwire.password
|
61
|
+
xml.Server Shipwire.server
|
62
|
+
|
63
|
+
@orders.each do |order|
|
64
|
+
xml.Order(id: order[:order_number]) {
|
65
|
+
xml.Warehouse '00'
|
66
|
+
|
67
|
+
xml.AddressInfo(type: 'ship') {
|
68
|
+
xml.Name {
|
69
|
+
xml.Full "#{order[:address][:first_name]} #{order[:address][:last_name]}"
|
70
|
+
}
|
71
|
+
xml.Address1 order[:address][:address1]
|
72
|
+
xml.Address2 order[:address][:address2]
|
73
|
+
xml.City order[:address][:city]
|
74
|
+
xml.State order[:address][:state]
|
75
|
+
xml.Country order[:address][:country]
|
76
|
+
xml.Zip order[:address][:zip]
|
77
|
+
xml.Phone order[:address][:phone]
|
78
|
+
xml.Email order[:email]
|
79
|
+
}
|
80
|
+
|
81
|
+
xml.Shipping order[:shipping]
|
82
|
+
|
83
|
+
count = 0
|
84
|
+
order[:items].each do |item|
|
85
|
+
xml.Item(num: count) {
|
86
|
+
xml.Code item[:code]
|
87
|
+
xml.Quantity item[:quantity]
|
88
|
+
}
|
89
|
+
|
90
|
+
count += 1
|
91
|
+
end
|
92
|
+
}
|
93
|
+
end
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
self.payload = builder.to_xml
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Shipwire
|
4
|
+
class Inventory < Shipwire::ServiceRequest
|
5
|
+
attr_reader :inventory_responses
|
6
|
+
|
7
|
+
API_PATH = 'InventoryServices.php'
|
8
|
+
|
9
|
+
def initialize(params={})
|
10
|
+
super
|
11
|
+
|
12
|
+
@inventory_responses = []
|
13
|
+
@api_path = Inventory::API_PATH
|
14
|
+
|
15
|
+
@product_code = params[:product_code] || nil
|
16
|
+
|
17
|
+
self.build_payload
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse_response
|
21
|
+
if @response != nil
|
22
|
+
xml = Nokogiri::XML(@response.body)
|
23
|
+
@inventory_response = xml.xpath('//InventoryUpdateResponse')
|
24
|
+
end
|
25
|
+
|
26
|
+
if @inventory_response != nil
|
27
|
+
if is_ok?(@inventory_response)
|
28
|
+
|
29
|
+
products = @inventory_response.xpath('//Product')
|
30
|
+
|
31
|
+
products.each do |product|
|
32
|
+
code = product.attributes['code'].value
|
33
|
+
quantity = product.attributes['quantity'].value
|
34
|
+
good = product.attributes['good'].value
|
35
|
+
pending = product.attributes['pending'].value
|
36
|
+
backordered = product.attributes['backordered'].value
|
37
|
+
|
38
|
+
@inventory_responses << {
|
39
|
+
code: code,
|
40
|
+
inventory: {
|
41
|
+
quantity: quantity,
|
42
|
+
good: good,
|
43
|
+
pending: pending,
|
44
|
+
backordered: backordered
|
45
|
+
}
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
else
|
50
|
+
@errors << 'Unsuccessful request'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
protected
|
55
|
+
def build_payload
|
56
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
57
|
+
xml.InventoryUpdate {
|
58
|
+
xml.Username Shipwire.username
|
59
|
+
xml.Password Shipwire.password
|
60
|
+
xml.Server Shipwire.server
|
61
|
+
|
62
|
+
if @product_code != nil
|
63
|
+
xml.ProductCode @product_code
|
64
|
+
end
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
self.payload = builder.to_xml
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Shipwire
|
4
|
+
class ServiceRequest
|
5
|
+
attr_accessor :payload, :api_path
|
6
|
+
attr_reader :response, :errors
|
7
|
+
|
8
|
+
def initialize(params={})
|
9
|
+
@errors = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def send
|
13
|
+
begin
|
14
|
+
connection = Faraday.new(url: Shipwire.endpoint) do |faraday|
|
15
|
+
faraday.request :url_encoded
|
16
|
+
faraday.adapter Faraday.default_adapter
|
17
|
+
end
|
18
|
+
|
19
|
+
@response = connection.post @api_path, @payload
|
20
|
+
rescue Faraday::ConnectionFailed
|
21
|
+
@errors << 'Unable to connect to Shipwire'
|
22
|
+
rescue
|
23
|
+
@errors << 'Unknown error'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def is_ok?(element)
|
28
|
+
status = element.xpath('//Status').text
|
29
|
+
|
30
|
+
return status == 'OK' || status == "0" || status == "Test"
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse_response
|
34
|
+
raise 'Override this'
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
def build_payload
|
39
|
+
raise 'Override this'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Shipwire
|
4
|
+
class ShippingRate < Shipwire::ServiceRequest
|
5
|
+
attr_reader :shipping_quotes
|
6
|
+
|
7
|
+
API_PATH = 'RateServices.php'
|
8
|
+
|
9
|
+
def initialize(params={})
|
10
|
+
super
|
11
|
+
|
12
|
+
@shipping_quotes = []
|
13
|
+
@api_path = ShippingRate::API_PATH
|
14
|
+
@address = params[:address]
|
15
|
+
@items = params[:items] || [] # [ { code: '123456', quantity: 1 } ]
|
16
|
+
|
17
|
+
self.build_payload
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse_response
|
21
|
+
if @response != nil
|
22
|
+
xml = Nokogiri::XML(@response.body)
|
23
|
+
@rate_response = xml.xpath('//RateResponse')
|
24
|
+
end
|
25
|
+
|
26
|
+
if @rate_response != nil
|
27
|
+
if is_ok?(@rate_response)
|
28
|
+
quotes = @rate_response.xpath('//Quote')
|
29
|
+
quotes.each do |quote|
|
30
|
+
service = quote.xpath('Service').text
|
31
|
+
carrier_code = quote.xpath('CarrierCode').text
|
32
|
+
cost = quote.xpath('Cost').text
|
33
|
+
|
34
|
+
@shipping_quotes << {
|
35
|
+
service: service,
|
36
|
+
carrier_code: carrier_code,
|
37
|
+
code: quote.attributes['method'].value,
|
38
|
+
cost: cost
|
39
|
+
}
|
40
|
+
end
|
41
|
+
else
|
42
|
+
@errors << 'Unsuccessful request'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
if @shipping_quotes.count <= 0
|
47
|
+
@errors << 'Unable to get shipping rates from Shipwire'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
def build_payload
|
53
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
54
|
+
xml.RateRequest {
|
55
|
+
xml.Username Shipwire.username
|
56
|
+
xml.Password Shipwire.password
|
57
|
+
|
58
|
+
xml.Order {
|
59
|
+
xml.Warehouse '00'
|
60
|
+
|
61
|
+
xml.AddressInfo(type: 'ship') {
|
62
|
+
xml.Address1 @address[:address1]
|
63
|
+
xml.Address2 @address[:address2]
|
64
|
+
xml.City @address[:city]
|
65
|
+
xml.State @address[:state]
|
66
|
+
xml.Country @address[:country]
|
67
|
+
xml.Zip @address[:zip]
|
68
|
+
}
|
69
|
+
|
70
|
+
count = 0
|
71
|
+
@items.each do |item|
|
72
|
+
xml.Item(num: count) {
|
73
|
+
xml.Code item[:code]
|
74
|
+
xml.Quantity item[:quantity]
|
75
|
+
}
|
76
|
+
|
77
|
+
count += 1
|
78
|
+
end
|
79
|
+
}
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
self.payload = builder.to_xml
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/shipwire.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'shipwire/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "shipwire"
|
8
|
+
spec.version = Shipwire::VERSION
|
9
|
+
spec.authors = ["Bill Rowell"]
|
10
|
+
spec.email = ["billr578@gmail.com"]
|
11
|
+
spec.summary = %q{Exchange data with Shipwire fullfillment}
|
12
|
+
spec.description = %q{Provides a wrapper for API calls to Shipwire fullfillment}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "faraday"
|
22
|
+
spec.add_dependency "nokogiri"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "mocha"
|
28
|
+
spec.add_development_dependency "rack-test"
|
29
|
+
|
30
|
+
spec.add_development_dependency "dotenv"
|
31
|
+
|
32
|
+
spec.add_development_dependency "webmock"
|
33
|
+
spec.add_development_dependency "vcr"
|
34
|
+
spec.add_development_dependency "pry"
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shipwire::Fulfillment, vcr: true do
|
4
|
+
let(:configuration) { Shipwire.configuration }
|
5
|
+
|
6
|
+
let(:address) {
|
7
|
+
{
|
8
|
+
first_name: 'Bill',
|
9
|
+
last_name: 'Rowell',
|
10
|
+
address1: '540 West Boylston St.',
|
11
|
+
city: 'Worcester',
|
12
|
+
state: 'MA',
|
13
|
+
country: 'US',
|
14
|
+
zip: '01606',
|
15
|
+
phone: '555-555-5555'
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
let(:orders) { [
|
20
|
+
order_number: 'W0000001',
|
21
|
+
shipping: 'GD',
|
22
|
+
email: 'test@example.com',
|
23
|
+
items: [{ code: '123456', quantity: 1 }],
|
24
|
+
address: address
|
25
|
+
] }
|
26
|
+
|
27
|
+
it 'should get back a valid fulfillment response' do
|
28
|
+
fulfillment = Shipwire::Fulfillment.new({
|
29
|
+
orders: orders
|
30
|
+
})
|
31
|
+
|
32
|
+
fulfillment.send
|
33
|
+
fulfillment.parse_response
|
34
|
+
expect(fulfillment.order_responses.count).to be > 0
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shipwire::Inventory, vcr: true do
|
4
|
+
let(:configuration) { Shipwire.configuration }
|
5
|
+
|
6
|
+
let(:product_code) { 'GD802-024' }
|
7
|
+
|
8
|
+
it 'should get back a valid response for all items' do
|
9
|
+
inventory = Shipwire::Inventory.new()
|
10
|
+
|
11
|
+
inventory.send
|
12
|
+
inventory.parse_response
|
13
|
+
expect(inventory.inventory_responses.count).to be > 0
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should get back a valid response for a single item' do
|
17
|
+
pending 'Shipwire always returns 2 products. Grrrr!'
|
18
|
+
|
19
|
+
inventory = Shipwire::Inventory.new({ product_code: product_code })
|
20
|
+
|
21
|
+
inventory.send
|
22
|
+
inventory.parse_response
|
23
|
+
expect(inventory.inventory_responses.count).to eql 1
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shipwire::ShippingRate, vcr: true do
|
4
|
+
let(:configuration) { Shipwire.configuration }
|
5
|
+
|
6
|
+
let(:address) {
|
7
|
+
{
|
8
|
+
address1: '540 West Boylston St.',
|
9
|
+
city: 'Worcester',
|
10
|
+
state: 'MA',
|
11
|
+
country: 'US',
|
12
|
+
zip: '01606'
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
let(:items) { [{ code: '123456', quantity: 1 }] }
|
17
|
+
|
18
|
+
let(:non_existing_items) { [{ code: 'ABCDEFG', quantity: 1 } ]}
|
19
|
+
|
20
|
+
it 'should get back a valid shipping response' do
|
21
|
+
shipping_rate = Shipwire::ShippingRate.new({
|
22
|
+
address: address,
|
23
|
+
items: items
|
24
|
+
})
|
25
|
+
|
26
|
+
shipping_rate.send
|
27
|
+
shipping_rate.parse_response
|
28
|
+
expect(shipping_rate.shipping_quotes.count).to be > 0
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should have no shipping rates for an unknown item code' do
|
32
|
+
shipping_rate = Shipwire::ShippingRate.new({
|
33
|
+
address: address,
|
34
|
+
items: non_existing_items
|
35
|
+
})
|
36
|
+
|
37
|
+
shipping_rate.send
|
38
|
+
shipping_rate.parse_response
|
39
|
+
expect(shipping_rate.shipping_quotes.count).to eql(0)
|
40
|
+
expect(shipping_rate.errors.count).to be > 0
|
41
|
+
end
|
42
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'mocha/api'
|
3
|
+
require 'shipwire'
|
4
|
+
|
5
|
+
require 'dotenv'
|
6
|
+
require 'pry'
|
7
|
+
Dotenv.load
|
8
|
+
|
9
|
+
Shipwire.configure do |config|
|
10
|
+
config.endpoint = ENV['SHIPWIRE_ENDPOINT']
|
11
|
+
config.server = ENV['SHIPWIRE_SERVER']
|
12
|
+
config.username = ENV['SHIPWIRE_USERNAME']
|
13
|
+
config.password = ENV['SHIPWIRE_PASSWORD']
|
14
|
+
end
|
15
|
+
|
16
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.mock_framework = 'mocha'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,224 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shipwire
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bill Rowell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mocha
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rack-test
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: dotenv
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: vcr
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: pry
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description: Provides a wrapper for API calls to Shipwire fullfillment
|
168
|
+
email:
|
169
|
+
- billr578@gmail.com
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- ".env"
|
175
|
+
- ".env.example"
|
176
|
+
- ".gitignore"
|
177
|
+
- Gemfile
|
178
|
+
- LICENSE
|
179
|
+
- README.md
|
180
|
+
- Rakefile
|
181
|
+
- lib/shipwire.rb
|
182
|
+
- lib/shipwire/configuration.rb
|
183
|
+
- lib/shipwire/fulfillment.rb
|
184
|
+
- lib/shipwire/inventory.rb
|
185
|
+
- lib/shipwire/service_request.rb
|
186
|
+
- lib/shipwire/shipping_rate.rb
|
187
|
+
- lib/shipwire/tracking.rb
|
188
|
+
- lib/shipwire/version.rb
|
189
|
+
- shipwire.gemspec
|
190
|
+
- spec/shipwire/fulfillment_spec.rb
|
191
|
+
- spec/shipwire/inventory_spec.rb
|
192
|
+
- spec/shipwire/shipping_rate_spec.rb
|
193
|
+
- spec/shipwire/tracking_spec.rb
|
194
|
+
- spec/spec_helper.rb
|
195
|
+
homepage: ''
|
196
|
+
licenses:
|
197
|
+
- MIT
|
198
|
+
metadata: {}
|
199
|
+
post_install_message:
|
200
|
+
rdoc_options: []
|
201
|
+
require_paths:
|
202
|
+
- lib
|
203
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - ">="
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
|
+
requirements:
|
210
|
+
- - ">="
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: '0'
|
213
|
+
requirements: []
|
214
|
+
rubyforge_project:
|
215
|
+
rubygems_version: 2.4.1
|
216
|
+
signing_key:
|
217
|
+
specification_version: 4
|
218
|
+
summary: Exchange data with Shipwire fullfillment
|
219
|
+
test_files:
|
220
|
+
- spec/shipwire/fulfillment_spec.rb
|
221
|
+
- spec/shipwire/inventory_spec.rb
|
222
|
+
- spec/shipwire/shipping_rate_spec.rb
|
223
|
+
- spec/shipwire/tracking_spec.rb
|
224
|
+
- spec/spec_helper.rb
|