shipping_easy 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebd04dbdd41ee01468d230b49d8a09d96b1b710f
4
- data.tar.gz: f5e968ca055a2b3d815256a9b29bfa2512f2ff0e
3
+ metadata.gz: 5c62015eb66f896c021b5f30a2ba96f89dbc86cd
4
+ data.tar.gz: def4083bb09525e7b70b41273a04e34839870941
5
5
  SHA512:
6
- metadata.gz: b18d15c901061061fe5c098cefb0124abf42b92f551110887a5282336cd0330bcfec3b2ba0a1a82457ec3b020a858342727771163dd3ac50772ec3e0d25fc0e1
7
- data.tar.gz: 7a59cec9864af8dc7e3fd70bb49898960574839acf00e78efaa780f37d5479f8caadf8b8f3f6e4d1a8505418596a627b4f28c971561ebe3cf217d0a8204bfe82
6
+ metadata.gz: 73254bc040b76b38f58f8579753674dddfc62b7a5e862a6e9c2dee25d699c097fd6a8ff23c82e300cde572a64a4c4e5631499a79eab2a60974658c6878f12207
7
+ data.tar.gz: a4a5a5c5f57a7a0642f143b9bb392534878d5546f3f8930794078941f2550116054be20f72230e25d96fc54238ebf280558baf98219d75beaf80eea7bc4c25dd
@@ -13,19 +13,30 @@
13
13
  #
14
14
  module ShippingEasy
15
15
  class Configuration
16
+ LEGACY_URL = "https://app.shippingeasy.com"
17
+ DEFAULT_URL = "https://api.shippingeasy.com"
16
18
 
19
+ attr_reader :base_url
17
20
  attr_accessor :api_key,
18
21
  :api_secret,
19
22
  :partner_api_key,
20
23
  :partner_api_secret,
21
24
  :api_version,
22
- :base_url,
23
25
  :http_adapter
24
26
 
25
27
  # Creates a configuration object, setting the default attributes.
26
28
  def initialize
27
29
  @http_adapter = ShippingEasy::Http::FaradayAdapter
28
- @base_url = "https://app.shippingeasy.com"
30
+ @base_url = DEFAULT_URL
31
+ end
32
+
33
+ def base_url=(val)
34
+ if val == LEGACY_URL
35
+ warn "Legacy URL detected, updating to api.shippingeasy.com"
36
+ @base_url = DEFAULT_URL
37
+ else
38
+ @base_url = val
39
+ end
29
40
  end
30
41
  end
31
42
  end
@@ -1,3 +1,4 @@
1
+ require 'faraday_middleware'
1
2
  class ShippingEasy::Http::FaradayAdapter
2
3
 
3
4
  extend Forwardable
@@ -30,8 +31,21 @@ class ShippingEasy::Http::FaradayAdapter
30
31
 
31
32
  def connection
32
33
  @connection ||= Faraday.new(url: base_url) do |faraday|
34
+ faraday.use FaradayMiddleware::FollowRedirects, limit: 3, standards_compliant: true
35
+ faraday.use CustomUserAgent, "shipping_easy-ruby/#{ShippingEasy::VERSION}"
33
36
  faraday.adapter Faraday.default_adapter
34
37
  end
35
38
  end
39
+
40
+ class CustomUserAgent < Faraday::Middleware
41
+ def initialize(app, agent_string)
42
+ super(app)
43
+ @agent_string = agent_string
44
+ end
36
45
 
46
+ def call(env)
47
+ env[:request_headers]['User-Agent'] = @agent_string
48
+ @app.call(env)
49
+ end
50
+ end
37
51
  end
@@ -5,7 +5,7 @@ class ShippingEasy::Http::Request
5
5
  def initialize(options = {})
6
6
  @http_method = options.fetch(:http_method, :get)
7
7
  @params = options.fetch(:params, {})
8
- @body = options.fetch(:payload, {}).to_json
8
+ @body = options[:payload] && options[:payload].to_json
9
9
  @relative_path = options.delete(:relative_path)
10
10
  end
11
11
 
@@ -1,3 +1,3 @@
1
1
  module ShippingEasy
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -19,9 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency('faraday', '>= 0.8.7')
22
+ spec.add_dependency('faraday_middleware', '>= 0.9.2')
22
23
  spec.add_dependency('rack', ">= 1.4.5")
23
24
  spec.add_dependency('json', "~> 1.8.0")
24
25
  spec.add_development_dependency "bundler", "~> 1.3"
25
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "webmock"
26
28
  spec.add_development_dependency "rake"
27
29
  end
@@ -20,12 +20,17 @@ describe ShippingEasy::Configuration do
20
20
 
21
21
  describe "base_url" do
22
22
  it "gets set to a default" do
23
- subject.base_url.should == "https://app.shippingeasy.com"
23
+ subject.base_url.should == "https://api.shippingeasy.com"
24
24
  end
25
25
 
26
26
  it "can be overidden" do
27
27
  subject.base_url = String
28
28
  subject.base_url.should == String
29
29
  end
30
+
31
+ it "ignores if set to the legacy URL" do
32
+ subject.base_url = "https://app.shippingeasy.com"
33
+ subject.base_url.should == "https://api.shippingeasy.com"
34
+ end
30
35
  end
31
36
  end
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ require 'webmock/rspec'
2
3
 
3
4
  describe ShippingEasy::Http::FaradayAdapter do
4
5
 
@@ -39,4 +40,21 @@ describe ShippingEasy::Http::FaradayAdapter do
39
40
  end
40
41
  end
41
42
 
43
+ it "redirects, preserving method" do
44
+ stub_request(:post, "https://app.shippingeasy.com").to_return(
45
+ :status => 307,
46
+ :headers => { "Location" => "https://app1.shippingeasy.com/" })
47
+ stub_request(:post, "https://app1.shippingeasy.com/")
48
+
49
+ response = subject.connection.post("https://app.shippingeasy.com")
50
+
51
+ expect(response.env[:method]).to eq(:post)
52
+ expect(response.env[:url].to_s).to eq("https://app1.shippingeasy.com/")
53
+ end
54
+
55
+ it "adds a custom user agent" do
56
+ stub_request(:post, "https://app.shippingeasy.com")
57
+ response = subject.connection.post("https://app.shippingeasy.com")
58
+ expect(response.env.request_headers["User-Agent"]).to eq("shipping_easy-ruby/#{ShippingEasy::VERSION}")
59
+ end
42
60
  end
@@ -9,7 +9,8 @@ describe ShippingEasy::Http::Request do
9
9
  let(:body) { { order_number: "1234" } }
10
10
  let(:api_key) { "12345678ASGHSGHJ" }
11
11
  let(:api_secret) { "12345678ASGHSGHJ123213321312" }
12
- let(:signature) { ShippingEasy::Signature.new(api_secret: api_secret, method: http_method, path: "/api#{relative_path}", params: params.dup, body: body.to_json) }
12
+ let(:signed_body) { body && body.to_json }
13
+ let(:signature) { ShippingEasy::Signature.new(api_secret: api_secret, method: http_method, path: "/api#{relative_path}", params: params.dup, body: signed_body) }
13
14
 
14
15
  before do
15
16
  ShippingEasy.configure do |config|
@@ -50,6 +51,25 @@ describe ShippingEasy::Http::Request do
50
51
  end
51
52
  end
52
53
 
54
+ describe 'body is nil for GET requests with nil body' do
55
+ let(:http_method) { "get" }
56
+ let(:body) { nil }
57
+ specify do
58
+ subject.body.should == nil
59
+ subject.signature.to_s.should == signature.to_s
60
+ end
61
+ end
62
+
63
+ describe 'body is nil for GET requests with omitted payload key' do
64
+ let(:http_method) { "get" }
65
+ let(:body) { nil }
66
+ subject { ShippingEasy::Http::Request.new(http_method: http_method, params: params, relative_path: relative_path) }
67
+ specify do
68
+ subject.body.should == nil
69
+ subject.signature.to_s.should == signature.to_s
70
+ end
71
+ end
72
+
53
73
  describe "#sign_request!" do
54
74
  before { subject.sign_request! }
55
75
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shipping_easy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ShippingEasy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-01 00:00:00.000000000 Z
11
+ date: 2016-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.8.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.2
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rack
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
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'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: rake
85
113
  requirement: !ruby/object:Gem::Requirement