springboard-retail 4.3.0 → 5.0.0.beta1

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
  SHA256:
3
- metadata.gz: fd35455f3b848e238263429302242ec4897b99f9190841b9cc03cd78e7fe70c9
4
- data.tar.gz: 1f768fc9359ac7ec8daff47888b647eedb7b84f9f91cf2a1b8fa24b474afe266
3
+ metadata.gz: e3f1c34c2de4f27e11f8f93d315320fda31dc5ce77cae64ff5bfd8ad05b1a829
4
+ data.tar.gz: 32a2792c3918475a048016e65abf4a94f9bb49390f8e814f8bcd9ffae715f6de
5
5
  SHA512:
6
- metadata.gz: 3e1ea9566b62cd2cfc1676ef8ddb2aa9627cecb56b0d4a8d47ce8536586ff824d81bd44cc06bad91f91239ae84be33c4915abff21ae08bf759da4c9c4e7793bf
7
- data.tar.gz: 7ad3f24caf64aa63b0608f63bd047c3472abbb6e81c51388de342089953cfedc3c1d441a10e714b3c482254c0146d2123eeca78e7b7cec2b35d5e17be6719b3d
6
+ metadata.gz: f3163fe21165c88658f48c473059fd3e780ec831ad48ee1dbc385e0f1a91227663bb193fd2bf4f20f1f6891017cbf0c863dfb9ee89599f5eb68f8e27d96e9daa
7
+ data.tar.gz: 5374e740213dfe9ffe0c5e2e7f76dc3b9f6b7dcebd5afc2292fa696e129aedc79cfe7124ba2f1971f9accaa6610d8cd45ca44b2329d60a98dd2ab0fa95ebc230
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- springboard-retail (4.3.0)
4
+ springboard-retail (5.0.0.beta1)
5
+ faraday
5
6
  hashie
6
7
  json (>= 1.7.4)
7
- patron (= 0.4.18)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -23,13 +23,15 @@ GEM
23
23
  safe_yaml (~> 1.0.0)
24
24
  diff-lcs (1.2.5)
25
25
  docile (1.1.5)
26
+ faraday (0.15.3)
27
+ multipart-post (>= 1.2, < 3)
26
28
  hashie (3.6.0)
27
29
  json (2.1.0)
28
30
  method_source (0.8.2)
29
31
  mime-types (2.4.3)
30
32
  multi_json (1.11.0)
33
+ multipart-post (2.0.0)
31
34
  netrc (0.10.3)
32
- patron (0.4.18)
33
35
  pry (0.10.1)
34
36
  coderay (~> 1.1.0)
35
37
  method_source (~> 0.8.1)
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  This is the [Springboard Retail](http://springboardretail.com/) (a point-of-sale/retail management system) client library for Ruby. It provides access to the Springboard Retail HTTP API.
9
9
 
10
- It is a wrapper around the [Patron](http://toland.github.com/patron/) HTTP client library. Supports MRI 1.9+.
10
+ It is a wrapper around the [Faraday](https://github.com/lostisland/faraday) HTTP client library.
11
11
 
12
12
  You can find [documentation here](http://rdoc.info/github/springboardretail/springboard-client-ruby).
13
13
 
data/Rakefile CHANGED
@@ -11,6 +11,7 @@ task :default => :spec
11
11
  desc "Start a console with a Springboard::Client instance"
12
12
  task :console do
13
13
  require 'springboard/client'
14
+ require 'pry'
14
15
  CLIENT = Springboard::Client.new(ENV['URI'])
15
16
  CLIENT.auth :username => ENV['USER'], :password => ENV['PASSWORD']
16
17
  Pry.start
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
- require 'patron'
2
+ require 'faraday'
3
3
  require 'json'
4
+ require 'logger'
4
5
 
5
6
  require 'springboard/client/errors'
6
7
 
@@ -33,6 +34,10 @@ module Springboard
33
34
  # @return [URI] The client's base URI
34
35
  attr_reader :base_uri
35
36
 
37
+ ##
38
+ # @return [Faraday::Connection] Faraday's connection
39
+ attr_reader :connection
40
+
36
41
  ##
37
42
  # @param [String] base_uri Base URI
38
43
  # @option opts [Boolean, String] :debug Pass true to debug to stdout. Pass a String to debug to given filename.
@@ -40,17 +45,8 @@ module Springboard
40
45
  # @option opts [String] :token Springboard API Token
41
46
  def initialize(base_uri, opts={})
42
47
  @base_uri = URI.parse(base_uri)
43
- configure_session(base_uri, opts)
44
- end
45
-
46
- ##
47
- # Returns the underlying Patron session
48
- #
49
- # @see http://patron.rubyforge.org/Patron/Session.html Patron::Session docs
50
- #
51
- # @return [Patron::Session]
52
- def session
53
- @session ||= Patron::Session.new
48
+ @opts = opts
49
+ configure_connection!
54
50
  end
55
51
 
56
52
  ##
@@ -61,7 +57,8 @@ module Springboard
61
57
  #
62
58
  # @return [String, Boolean] The debug argument
63
59
  def debug=(debug)
64
- session.enable_debug(debug == true ? nil : debug)
60
+ @opts[:debug] = debug
61
+ configure_connection!
65
62
  end
66
63
 
67
64
  ##
@@ -85,7 +82,13 @@ module Springboard
85
82
  :password => opts[:password]
86
83
  response = post '/auth/identity/callback', body,
87
84
  'Content-Type' => 'application/x-www-form-urlencoded'
88
- response.success? or raise AuthFailed, "Springboard auth failed"
85
+
86
+ if response.success?
87
+ @session_cookie = response.headers['set-cookie']
88
+ return true
89
+ else
90
+ raise AuthFailed, "Springboard auth failed"
91
+ end
89
92
  end
90
93
 
91
94
  ##
@@ -214,20 +217,26 @@ module Springboard
214
217
 
215
218
  private
216
219
 
220
+ attr_reader :opts, :session_cookie
221
+
217
222
  def prepare_request_body(body)
218
223
  body.is_a?(Hash) ? JSON.dump(body) : body
219
224
  end
220
225
 
221
226
  def make_request(method, uri, headers=false, body=false)
222
- args = [prepare_uri(uri).to_s]
223
- args.push prepare_request_body(body) unless body === false
224
- args.push headers unless headers === false
225
- new_response session.__send__(method, *args)
227
+ response = connection.__send__( method, prepare_uri(uri)) do |request|
228
+ request.headers = headers unless headers === false
229
+ request.headers['Cookie'] = session_cookie if session_cookie
230
+
231
+ request.body = prepare_request_body(body) unless body === false
232
+ end
233
+
234
+ new_response(response)
226
235
  end
227
236
 
228
237
  def raise_on_fail(response)
229
238
  if !response.success?
230
- error = RequestFailed.new "Request failed with status: #{response.status_line}"
239
+ error = RequestFailed.new "Request failed with status: #{response.status}"
231
240
  error.response = response
232
241
  raise error
233
242
  end
@@ -236,22 +245,35 @@ module Springboard
236
245
 
237
246
  def prepare_uri(uri)
238
247
  uri = URI.parse(uri)
239
- uri.to_s.gsub(/^#{base_uri.to_s}|^#{base_uri.path}/, '')
248
+ uri.to_s
249
+ .gsub(/^#{base_uri.to_s}|^#{base_uri.path}/, '')
250
+ .gsub(/^\//, '')
240
251
  end
241
252
 
242
- def new_response(patron_response)
243
- Response.new patron_response, self
253
+ def new_response(faraday_response)
254
+ Response.new faraday_response, self
255
+ end
256
+
257
+ def configure_connection!
258
+ @connection = Faraday.new
259
+
260
+ connection.url_prefix= base_uri.to_s
261
+
262
+ connection.headers['Content-Type'] = 'application/json'
263
+ connection.headers['Authorization'] = "Bearer #{opts[:token]}" if opts[:token]
264
+
265
+ connection.ssl[:verify] = false if opts.has_key?(:insecure)
266
+
267
+ connection.options.timeout = DEFAULT_TIMEOUT
268
+ connection.options.open_timeout = DEFAULT_CONNECT_TIMEOUT
269
+
270
+ if debug = opts[:debug]
271
+ connection.response :logger, debug_logger(debug), bodies: true
272
+ end
244
273
  end
245
274
 
246
- def configure_session(base_url, opts)
247
- session.base_url = base_url
248
- session.headers['Content-Type'] = 'application/json'
249
- session.headers['Authorization'] = "Bearer #{opts[:token]}" if opts[:token]
250
- session.handle_cookies
251
- session.insecure = opts[:insecure] if opts.has_key?(:insecure)
252
- session.timeout = DEFAULT_TIMEOUT
253
- session.connect_timeout = DEFAULT_CONNECT_TIMEOUT
254
- self.debug = opts[:debug] if opts.has_key?(:debug)
275
+ def debug_logger(debug)
276
+ Logger.new(debug == true ? STDOUT : debug)
255
277
  end
256
278
  end
257
279
  end
@@ -44,9 +44,9 @@ module Springboard
44
44
  end
45
45
 
46
46
  ##
47
- # Delegates missing methods to the underlying Patron::Response.
47
+ # Delegates missing methods to the underlying Faraday::Response.
48
48
  #
49
- # @see http://patron.rubyforge.org/Patron/Response.html Patron::Response docs
49
+ # @see https://www.rubydoc.info/gems/faraday/Faraday/Response Faraday::Response docs
50
50
  def method_missing(method, *args, &block)
51
51
  @response.respond_to?(method) ? @response.__send__(method, *args, &block) : super
52
52
  end
@@ -1,5 +1,5 @@
1
1
  shared_context "client" do
2
2
  let(:base_url) { "http://bozo.com/api" }
3
3
  let(:client) { Springboard::Client.new(base_url) }
4
- let(:session) { client.session }
4
+ let(:connection) { client.connection }
5
5
  end
@@ -4,11 +4,16 @@ describe Springboard::Client::Response do
4
4
  include_context "client"
5
5
 
6
6
  let(:raw_body) { '{"key":"value"}' }
7
- let(:raw_headers) { 'X-Custom-Header: Hi' }
7
+ let(:raw_headers) { { 'X-Custom-Header' => 'Hi' } }
8
8
  let(:status_code) { 200 }
9
9
  let(:path) { '/path' }
10
- let(:patron_response) { Patron::Response.new(path, status_code, 0, raw_headers, raw_body) }
11
- let(:response) { Springboard::Client::Response.new(patron_response, client) }
10
+ let(:faraday_response) do
11
+ env = Faraday::Env.new(:get, raw_body, path, nil, nil, nil, nil,
12
+ nil, raw_body, raw_headers, status_code)
13
+
14
+ Faraday::Response.new(env)
15
+ end
16
+ let(:response) { Springboard::Client::Response.new(faraday_response, client) }
12
17
 
13
18
  describe "body" do
14
19
  describe "if raw body is valid JSON" do
@@ -54,7 +59,7 @@ describe Springboard::Client::Response do
54
59
 
55
60
  describe "resource" do
56
61
  describe "when Location header is returned" do
57
- let(:raw_headers) { 'Location: /new/path' }
62
+ let(:raw_headers) { { Location: '/new/path' } }
58
63
 
59
64
  it "should be a Springboard::Client::Resource" do
60
65
  expect(response.resource).to be_a Springboard::Client::Resource
@@ -66,7 +71,7 @@ describe Springboard::Client::Response do
66
71
  end
67
72
 
68
73
  describe "when Location header is not returned" do
69
- let(:raw_headers) { '' }
74
+ let(:raw_headers) { Hash.new }
70
75
 
71
76
  it "should be nil" do
72
77
  expect(response.resource).to be_nil
@@ -3,17 +3,19 @@ require 'spec_helper'
3
3
  describe Springboard::Client do
4
4
  include_context "client"
5
5
 
6
- describe "session" do
7
- it "should be a Patron::Session" do
8
- expect(client.session).to be_a Patron::Session
6
+ describe "connection" do
7
+ it "should be a Faraday::Connection" do
8
+ expect(client.connection).to be_a Faraday::Connection
9
9
  end
10
10
  end
11
11
 
12
12
  describe "auth" do
13
13
  it "should attempt to authenticate with the given username and password" do
14
- request_stub = stub_request(:post, "#{base_url}/auth/identity/callback").with \
14
+ request_stub = stub_request(:post, "#{base_url}/auth/identity/callback").with(
15
15
  :body => "auth_key=coco&password=boggle",
16
16
  :headers => {'Content-Type' => 'application/x-www-form-urlencoded'}
17
+ )
18
+
17
19
  client.auth(:username => 'coco', :password => 'boggle')
18
20
  expect(request_stub).to have_been_requested
19
21
  end
@@ -34,51 +36,55 @@ describe Springboard::Client do
34
36
  expect { client.auth(:username => 'someone', :password => 'wrong') }.to \
35
37
  raise_error(Springboard::Client::AuthFailed, "Springboard auth failed")
36
38
  end
39
+
40
+ it "should store the session cookie" do
41
+ stub_request(:post, "#{base_url}/auth/identity/callback").to_return(headers: {'set-cookie' => '123'})
42
+ client.auth(:username => 'someone', :password => 'right')
43
+ expect(client.instance_variable_get(:@session_cookie)).to eq('123')
44
+ end
37
45
  end
38
46
 
39
47
  describe "initialize" do
40
- it "should call configure_session" do
41
- expect_any_instance_of(Springboard::Client).to receive(:configure_session).with(base_url, {:x => 'y'})
48
+ it "should call configure_connection!" do
49
+ expect_any_instance_of(Springboard::Client).to receive(:configure_connection!)
42
50
  Springboard::Client.new(base_url, :x => 'y')
43
51
  end
44
52
  end
45
53
 
46
- describe "configure_session" do
47
- it "should set the session's base_url" do
48
- expect(session).to receive(:base_url=).with(base_url)
49
- client.__send__(:configure_session, base_url, :x => 'y')
54
+ describe "configure_connection" do
55
+ it "should set the connection's url_prefix" do
56
+ client.__send__(:configure_connection!)
57
+ expect(connection.url_prefix.to_s).to eq(base_url)
50
58
  end
51
59
 
52
- it "should enable cookies" do
53
- expect(session).to receive(:handle_cookies)
54
- client.__send__(:configure_session, base_url, :x => 'y')
55
- end
56
-
57
- it "should allow setting insecure on the session" do
58
- expect(session).to receive(:insecure=).with(true)
59
- client.__send__(:configure_session, base_url, :insecure => true)
60
+ it "should allow setting insecure on the connection" do
61
+ client.__send__(:opts)[:insecure] = true
62
+ client.__send__(:configure_connection!)
63
+ expect(connection.ssl[:verify]).to be false
60
64
  end
61
65
 
62
66
  it "set the default timeout" do
63
- client.__send__(:configure_session, base_url, {})
64
- expect(client.session.timeout).to eq(Springboard::Client::DEFAULT_TIMEOUT)
67
+ client.__send__(:configure_connection!)
68
+ expect(connection.options.timeout).to eq(Springboard::Client::DEFAULT_TIMEOUT)
65
69
  end
66
70
 
67
71
  it "set the default connect timeout" do
68
- client.__send__(:configure_session, base_url, {})
69
- expect(client.session.connect_timeout).to eq(Springboard::Client::DEFAULT_CONNECT_TIMEOUT)
72
+ client.__send__(:configure_connection!)
73
+ expect(connection.options.open_timeout).to eq(Springboard::Client::DEFAULT_CONNECT_TIMEOUT)
70
74
  end
71
75
 
72
76
  context 'headers' do
73
77
  let(:headers) { double('headers') }
74
78
  before do
75
- allow(session).to receive(:headers).and_return(headers)
79
+ connection = double('Connection').as_null_object
80
+ allow(Faraday).to receive(:new).and_return(connection)
81
+ allow(connection).to receive(:headers).and_return(headers)
76
82
  end
77
83
 
78
84
  it 'sets Content-Type header' do
79
85
  expect(headers).to receive(:[]=).once.with('Content-Type', 'application/json')
80
86
  expect(headers).to receive(:[]=).once.with('Authorization', 'Bearer token')
81
- client.__send__(:configure_session, base_url, :token => 'token')
87
+ Springboard::Client.new(base_url, token: 'token')
82
88
  end
83
89
  end
84
90
  end
@@ -110,26 +116,29 @@ describe Springboard::Client do
110
116
  end
111
117
 
112
118
  describe "debug=" do
113
- context "with a file path" do
114
- it "should pass the path to enable_debug on the Patron session" do
115
- expect(client.session).to receive(:enable_debug).with('/path/to/log')
116
- client.debug = '/path/to/log'
117
- end
119
+ it "should set opts[:debug]" do
120
+ logger = double
121
+ allow(Logger).to receive(:new).with('/path/to/log').and_return(logger)
122
+
123
+ client.debug = '/path/to/log'
124
+ expect(client.__send__(:opts)[:debug]).to eq('/path/to/log')
118
125
  end
119
126
 
120
- context "with true" do
121
- it "should pass nil to enable_debug on the Patron session" do
122
- expect(client.session).to receive(:enable_debug).with(nil)
123
- client.debug = true
124
- end
127
+ it "should reconfigure connection" do
128
+ logger = double
129
+ allow(Logger).to receive(:new).with('/path/to/log').and_return(logger)
130
+
131
+ expect(client).to receive(:configure_connection!)
132
+ client.debug = '/path/to/log'
125
133
  end
126
134
  end
127
135
 
128
136
  [:get, :head, :delete].each do |method|
129
137
  bang_method = "#{method}!"
130
138
  describe method do
131
- it "should call session's #{method}" do
132
- expect(session).to receive(method).with('/relative/path')
139
+ it "should call connection's #{method}" do
140
+ expect(connection).to receive(method).with('relative/path')
141
+
133
142
  client.__send__(method, '/relative/path')
134
143
  end
135
144
 
@@ -157,7 +166,7 @@ describe Springboard::Client do
157
166
  it "should raise an exception on failure" do
158
167
  response = double(Springboard::Client::Response)
159
168
  expect(response).to receive(:success?).and_return(false)
160
- expect(response).to receive(:status_line).and_return('404 Not Found')
169
+ expect(response).to receive(:status).and_return(404)
161
170
  expect(client).to receive(method).with('/path', false).and_return(response)
162
171
  expect { client.send(bang_method, '/path') }.to raise_error(Springboard::Client::RequestFailed)
163
172
  end
@@ -168,8 +177,12 @@ describe Springboard::Client do
168
177
  [:put, :post].each do |method|
169
178
  bang_method = "#{method}!"
170
179
  describe method do
171
- it "should call session's #{method}" do
172
- expect(session).to receive(method).with('/relative/path', 'body')
180
+ it "should call connection's #{method}" do
181
+ request = double.as_null_object
182
+
183
+ expect(request).to receive(:body=).with('body')
184
+ expect(connection).to receive(method).with('relative/path').and_yield(request)
185
+
173
186
  client.__send__(method, '/relative/path', 'body')
174
187
  end
175
188
 
@@ -180,8 +193,12 @@ describe Springboard::Client do
180
193
  end
181
194
 
182
195
  it "should serialize the request body as JSON if it is a hash" do
196
+ request = double.as_null_object
183
197
  body_hash = {:key1 => 'val1', :key2 => 'val2'}
184
- expect(session).to receive(method).with('/path', body_hash.to_json)
198
+
199
+ expect(connection).to receive(method).and_yield(request)
200
+ expect(request).to receive(:body=).with(body_hash.to_json)
201
+
185
202
  client.__send__(method, '/path', body_hash)
186
203
  end
187
204
 
@@ -211,7 +228,7 @@ describe Springboard::Client do
211
228
  it "should raise an exception on failure" do
212
229
  response = double(Springboard::Client::Response)
213
230
  expect(response).to receive(:success?).and_return(false)
214
- expect(response).to receive(:status_line).and_return('404 Not Found')
231
+ expect(response).to receive(:status).and_return(404)
215
232
  expect(client).to receive(method).with('/path', 'body', false).and_return(response)
216
233
  expect { client.send(bang_method, '/path', 'body') }.to raise_error { |error|
217
234
  expect(error).to be_a(Springboard::Client::RequestFailed)
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'springboard-retail'
3
- s.version = '4.3.0'
3
+ s.version = '5.0.0.beta1'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ['Jay Stotz']
6
6
  s.summary = 'Springboard Retail API client library'
7
7
 
8
8
  s.required_rubygems_version = '>= 1.3.6'
9
9
 
10
- s.add_runtime_dependency 'patron', '0.4.18'
10
+ s.add_runtime_dependency 'faraday'
11
11
  s.add_runtime_dependency 'json', '>= 1.7.4'
12
12
  s.add_runtime_dependency 'hashie'
13
13
 
Binary file
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: springboard-retail
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 5.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Stotz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-19 00:00:00.000000000 Z
11
+ date: 2018-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: patron
14
+ name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.4.18
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.4.18
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -90,13 +90,14 @@ files:
90
90
  - vendor/cache/crack-0.4.2.gem
91
91
  - vendor/cache/diff-lcs-1.2.5.gem
92
92
  - vendor/cache/docile-1.1.5.gem
93
+ - vendor/cache/faraday-0.15.3.gem
93
94
  - vendor/cache/hashie-3.6.0.gem
94
95
  - vendor/cache/json-2.1.0.gem
95
96
  - vendor/cache/method_source-0.8.2.gem
96
97
  - vendor/cache/mime-types-2.4.3.gem
97
98
  - vendor/cache/multi_json-1.11.0.gem
99
+ - vendor/cache/multipart-post-2.0.0.gem
98
100
  - vendor/cache/netrc-0.10.3.gem
99
- - vendor/cache/patron-0.4.18.gem
100
101
  - vendor/cache/pry-0.10.1.gem
101
102
  - vendor/cache/rake-10.4.2.gem
102
103
  - vendor/cache/rest-client-1.7.3.gem
Binary file