vend 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +57 -0
  3. data/README.rdoc +1 -1
  4. data/Rakefile +1 -1
  5. data/example.rb +3 -3
  6. data/lib/vend.rb +2 -1
  7. data/lib/vend/base.rb +12 -12
  8. data/lib/vend/base_factory.rb +2 -6
  9. data/lib/vend/client.rb +5 -5
  10. data/lib/vend/http_client.rb +30 -31
  11. data/lib/vend/null_logger.rb +9 -5
  12. data/lib/vend/oauth2/auth_code.rb +7 -10
  13. data/lib/vend/oauth2/client.rb +1 -5
  14. data/lib/vend/pagination_info.rb +2 -1
  15. data/lib/vend/resource/customer.rb +1 -3
  16. data/lib/vend/resource/outlet.rb +0 -2
  17. data/lib/vend/resource/payment_type.rb +0 -2
  18. data/lib/vend/resource/product.rb +0 -2
  19. data/lib/vend/resource/register.rb +0 -2
  20. data/lib/vend/resource/register_sale.rb +2 -5
  21. data/lib/vend/resource/register_sale_product.rb +1 -1
  22. data/lib/vend/resource/supplier.rb +23 -0
  23. data/lib/vend/resource/tax.rb +0 -2
  24. data/lib/vend/resource/user.rb +0 -2
  25. data/lib/vend/resource_collection.rb +11 -15
  26. data/lib/vend/scope.rb +1 -2
  27. data/lib/vend/version.rb +1 -1
  28. data/spec/integration/customer_spec.rb +12 -9
  29. data/spec/integration/outlet_spec.rb +2 -3
  30. data/spec/integration/payment_types_spec.rb +1 -2
  31. data/spec/integration/product_spec.rb +26 -29
  32. data/spec/integration/register_sale_spec.rb +9 -10
  33. data/spec/integration/register_spec.rb +1 -2
  34. data/spec/integration/supplier_spec.rb +14 -0
  35. data/spec/integration/tax_spec.rb +1 -2
  36. data/spec/integration/user_spec.rb +1 -2
  37. data/spec/mock_responses/suppliers.json +36 -0
  38. data/spec/spec_helper.rb +1 -2
  39. data/spec/support/matchers/have_attributes.rb +3 -3
  40. data/spec/support/shared_examples/integration.rb +7 -9
  41. data/spec/support/shared_examples/logger.rb +21 -10
  42. data/spec/vend/base_factory_spec.rb +11 -12
  43. data/spec/vend/base_spec.rb +22 -23
  44. data/spec/vend/client_spec.rb +40 -39
  45. data/spec/vend/http_client_spec.rb +70 -62
  46. data/spec/vend/null_logger_spec.rb +1 -1
  47. data/spec/vend/oauth2/auth_code_spec.rb +18 -17
  48. data/spec/vend/oauth2/client_spec.rb +21 -21
  49. data/spec/vend/pagination_info_spec.rb +40 -17
  50. data/spec/vend/resource/register_sale_product_spec.rb +8 -6
  51. data/spec/vend/resource/register_sale_spec.rb +7 -8
  52. data/spec/vend/resource_collection_spec.rb +108 -95
  53. data/spec/vend/scope_spec.rb +20 -12
  54. data/vend.gemspec +5 -6
  55. metadata +10 -20
@@ -1,29 +1,38 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Vend::HttpClient do
4
-
5
4
  let(:base_url) { "https://foo/bar/" }
6
5
  let(:username) { "username" }
7
6
  let(:password) { "password" }
8
- let(:options) {
9
- {:base_url => base_url, :username => username, :password => password}
10
- }
7
+ let(:options) do
8
+ {base_url: base_url, username: username, password: password}
9
+ end
11
10
 
12
- subject {
11
+ subject do
13
12
  described_class.new(options)
14
- }
13
+ end
14
+
15
+ it_behaves_like "it has a logger"
15
16
 
16
- it_should_behave_like "it has a logger"
17
+ specify :base_url do
18
+ expect(subject.base_url).to eq base_url
19
+ end
20
+
21
+ specify :username do
22
+ expect(subject.username).to eq username
23
+ end
17
24
 
18
- its(:base_url) { should == base_url }
19
- its(:username) { should == username }
20
- its(:password) { should == password }
25
+ specify :password do
26
+ expect(subject.password).to eq password
27
+ end
21
28
 
22
29
  describe "#verify_ssl?" do
23
- its(:verify_ssl) { should be_truthy }
30
+ specify :verify_ssl do
31
+ expect(subject.verify_ssl).to be_truthy
32
+ end
24
33
 
25
34
  context "when overridden in the options" do
26
- subject { described_class.new(options.merge(:verify_ssl => false)) }
35
+ subject { described_class.new(options.merge(verify_ssl: false)) }
27
36
  end
28
37
  end
29
38
 
@@ -34,115 +43,114 @@ describe Vend::HttpClient do
34
43
  let(:port) { 42 }
35
44
 
36
45
  before do
37
- subject.stub(:verify_mode => verify_mode)
38
- http.should_receive(:use_ssl=).with(true)
39
- http.should_receive(:verify_mode=).with(verify_mode)
40
- http.should_receive(:read_timeout=).with(240)
46
+ subject.stub(verify_mode: verify_mode)
47
+ expect(http).to receive(:use_ssl=).with(true)
48
+ expect(http).to receive(:verify_mode=).with(verify_mode)
49
+ expect(http).to receive(:read_timeout=).with(240)
41
50
  Net::HTTP.stub(:new).with(host, port) { http }
42
51
  end
43
52
 
44
53
  it "returns the http_connection" do
45
- subject.get_http_connection(host, port).should == http
54
+ expect(subject.get_http_connection(host, port)).to eq http
46
55
  end
47
56
  end
48
57
 
49
58
  describe "#verify_mode" do
50
-
51
59
  context "when verify_ssl? is true" do
52
60
  before do
53
- subject.stub(:verify_ssl? => true)
61
+ subject.stub(verify_ssl?: true)
62
+ end
63
+ specify :verify_mode do
64
+ expect(subject.verify_mode).to eq OpenSSL::SSL::VERIFY_PEER
54
65
  end
55
- its(:verify_mode) { should == OpenSSL::SSL::VERIFY_PEER }
56
66
  end
57
67
 
58
68
  context "when verify_ssl? is false" do
59
69
  before do
60
- subject.stub(:verify_ssl? => false)
70
+ subject.stub(verify_ssl?: false)
71
+ end
72
+ specify :verify_mode do
73
+ expect(subject.verify_mode).to eq OpenSSL::SSL::VERIFY_NONE
61
74
  end
62
- its(:verify_mode) { should == OpenSSL::SSL::VERIFY_NONE }
63
75
  end
64
-
65
76
  end
66
77
 
67
78
  describe "#request" do
68
-
69
79
  context "when using invalid credentials" do
70
-
71
80
  let(:username) { "invalid" }
72
81
 
73
82
  it "raises an error" do
74
- stub_request(:get, "https://invalid:password@foo/bar/products").
75
- to_return(:status => 401)
83
+ stub_request(:get, "https://invalid:password@foo/bar/products")
84
+ .to_return(status: 401)
76
85
 
77
- expect {
86
+ expect do
78
87
  subject.request('products')
79
- }.to raise_error(Vend::Unauthorized)
88
+ end.to raise_error(Vend::Unauthorized)
80
89
  end
81
-
82
90
  end
83
91
 
84
92
  it "throws an error when an invalid request is made" do
85
- stub_request(:get, "https://username:password@foo/bar/invalid").
86
- to_return(:status => 404, :body => '{"foo":"bar"}', :headers => {})
93
+ stub_request(:get, "https://username:password@foo/bar/invalid")
94
+ .to_return(status: 404, body: '{"foo":"bar"}', headers: {})
87
95
 
88
- expect {
96
+ expect do
89
97
  subject.request('invalid')
90
- }.to raise_error(Vend::HTTPError)
98
+ end.to raise_error(Vend::HTTPError)
91
99
  end
92
100
 
93
101
  it "returns parsed JSON" do
94
- stub_request(:get, "https://username:password@foo/bar/bun").
95
- to_return(:status => 200, :body => '{"foo":"bar"}', :headers => {})
96
- subject.request("bun").should == {"foo" => "bar"}
102
+ stub_request(:get, "https://username:password@foo/bar/bun")
103
+ .to_return(status: 200, body: '{"foo":"bar"}', headers: {})
104
+ expect(subject.request("bun")).to eq({"foo" => "bar"})
97
105
  end
98
106
 
99
107
  it "returns nil if the response was empty" do
100
- stub_request(:get, "https://username:password@foo/bar/bun").
101
- to_return(:status => 200, :body => '', :headers => {})
102
- subject.request("bun").should be_nil
108
+ stub_request(:get, "https://username:password@foo/bar/bun")
109
+ .to_return(status: 200, body: '', headers: {})
110
+ expect(subject.request("bun")).to be_nil
103
111
  end
104
112
  it "allows us to specify HTTP method" do
105
- stub_request(:post, "https://username:password@foo/bar/foo").
106
- to_return(:status => 200, :body => '{"foo":"bar"}', :headers => {})
113
+ stub_request(:post, "https://username:password@foo/bar/foo")
114
+ .to_return(status: 200, body: '{"foo":"bar"}', headers: {})
107
115
 
108
- response = subject.request('foo', :method => :post)
109
- response.should == {"foo" => "bar"}
116
+ response = subject.request('foo', method: :post)
117
+ expect(response).to eq({"foo" => "bar"})
110
118
  end
111
119
 
112
120
  it "allows us to set a request body" do
113
- stub_request(:post, "https://username:password@foo/bar/foo").
114
- with(:body => "{\"post\":\"data\"}").
115
- to_return(:status => 200, :body => '{"foo":"bar"}', :headers => {})
121
+ stub_request(:post, "https://username:password@foo/bar/foo")
122
+ .with(body: "{\"post\":\"data\"}")
123
+ .to_return(status: 200, body: '{"foo":"bar"}', headers: {})
116
124
 
117
- response = subject.request('foo', :method => :post, :body => '{"post":"data"}')
118
- response.should == {"foo" => "bar"}
125
+ response = subject.request('foo', method: :post, body: '{"post":"data"}')
126
+ expect(response).to eq({"foo" => "bar"})
119
127
  end
120
128
 
121
129
  it "allows us to specify url parameters" do
122
- stub_request(:get, "https://username:password@foo/bar/foo?foo=bar&baz=baloo&flum%5B0%5D=blob&flum%5B1%5D=splat").
123
- to_return(:status => 200, :body => '{"foo":"bar"}', :headers => {})
130
+ stub_request(:get, "https://username:password@foo/bar/foo?foo=bar&baz=baloo&flum%5B0%5D=blob&flum%5B1%5D=splat")
131
+ .to_return(status: 200, body: '{"foo":"bar"}', headers: {})
124
132
 
125
- response = subject.request('foo', :url_params => {:foo => "bar", :baz => "baloo", :flum => ["blob","splat"]})
126
- response.should == {"foo" => "bar"}
133
+ response = subject.request('foo', url_params: {foo: "bar", baz: "baloo", flum: ["blob", "splat"]})
134
+ expect(response).to eq({"foo" => "bar"})
127
135
  end
128
136
 
129
137
  it "follows redirects" do
130
- stub_request(:get, "https://username:password@foo/bar/foo").
131
- to_return(:status => 302, :body => '{"bar":"baz"}', :headers => {"Location" => "http://username:password@foo/bar/floo"})
138
+ stub_request(:get, "https://username:password@foo/bar/foo")
139
+ .to_return(status: 302, body: '{"bar":"baz"}', headers: {"Location" => "http://username:password@foo/bar/floo"})
132
140
 
133
- stub_request(:get, "http://username:password@foo/bar/floo").
134
- to_return(:status => 200, :body => '{"foo":"bar"}', :headers => {})
141
+ stub_request(:get, "http://username:password@foo/bar/floo")
142
+ .to_return(status: 200, body: '{"foo":"bar"}', headers: {})
135
143
 
136
144
  response = subject.request('foo')
137
- response.should == {"foo" => "bar"}
145
+ expect(response).to eq({"foo" => "bar"})
138
146
  end
139
147
 
140
148
  it "raises an exception when the redirection limit is exceeded" do
141
- stub_request(:get, "https://username:password@foo/bar/foo").
142
- to_return(:status => 302, :body => '{"bar":"baz"}', :headers => {"Location" => "https://username:password@foo/bar/foo"})
143
- expect {
149
+ stub_request(:get, "https://username:password@foo/bar/foo")
150
+ .to_return(status: 302, body: '{"bar":"baz"}', headers: {"Location" => "https://username:password@foo/bar/foo"})
151
+ expect do
144
152
  subject.request('foo')
145
- }.to raise_exception(Vend::RedirectionLimitExceeded)
153
+ end.to raise_exception(Vend::RedirectionLimitExceeded)
146
154
  end
147
155
  end
148
156
  end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Vend::NullLogger do
4
- it_should_behave_like "a logger"
4
+ it_behaves_like "a logger"
5
5
  end
@@ -1,13 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Vend::Oauth2::AuthCode do
4
-
5
4
  subject { described_class.new('store', 'client_id', 'secret', 'redirect_uri') }
6
5
 
7
- its(:store) { is_expected.to eq('store') }
8
- its(:client_id) { is_expected.to eq('client_id') }
9
- its(:secret) { is_expected.to eq('secret') }
10
- its(:redirect_uri) { is_expected.to eq('redirect_uri') }
6
+ describe "#initialize" do
7
+ it "sets up the attr_readers" do
8
+ expect(subject.store).to eq 'store'
9
+ expect(subject.client_id).to eq 'client_id'
10
+ expect(subject.secret).to eq 'secret'
11
+ expect(subject.redirect_uri).to eq 'redirect_uri'
12
+ end
13
+ end
11
14
 
12
15
  it "creates an instance of Client" do
13
16
  expect(subject).to be_a Vend::Oauth2::AuthCode
@@ -19,21 +22,20 @@ describe Vend::Oauth2::AuthCode do
19
22
  end
20
23
  end
21
24
 
22
-
23
25
  describe "#token_from_code" do
24
- let(:store) {"store"}
26
+ let(:store) { "store" }
25
27
  let(:token_type) { "Bearer" }
26
- let(:access_token) { "Uy4eObSRn1RwzQbAitDMEkY6thdHsDJjwdGehpgr"}
27
- let(:refresh_token) {"nbCoejmJp1XZgs7as6FeQQ5QZLlUfefzaBjrxvtV"}
28
+ let(:access_token) { "Uy4eObSRn1RwzQbAitDMEkY6thdHsDJjwdGehpgr" }
29
+ let(:refresh_token) { "nbCoejmJp1XZgs7as6FeQQ5QZLlUfefzaBjrxvtV" }
28
30
 
29
31
  before do
30
- stub_request(:post, "https://store.vendhq.com/api/1.0/token").
31
- to_return(:status => 200, :body => {token_type: token_type,
32
- expires: 2435942384,
33
- domain_prefix: store,
34
- access_token: access_token,
35
- refresh_token: refresh_token,
36
- expires_at: 2435942383}.to_json, :headers=>{ 'Content-Type' => 'application/json' })
32
+ stub_request(:post, "https://store.vendhq.com/api/1.0/token")
33
+ .to_return(status: 200, body: {token_type: token_type,
34
+ expires: 2435942384,
35
+ domain_prefix: store,
36
+ access_token: access_token,
37
+ refresh_token: refresh_token,
38
+ expires_at: 2435942383}.to_json, headers: { 'Content-Type' => 'application/json' })
37
39
  end
38
40
 
39
41
  it "return access token" do
@@ -43,5 +45,4 @@ describe Vend::Oauth2::AuthCode do
43
45
  expect(token.refresh_token).to eq(refresh_token)
44
46
  end
45
47
  end
46
-
47
48
  end
@@ -1,13 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Vend::Oauth2::Client do
4
-
5
4
  subject { described_class.new('store', 'auth_token') }
6
5
 
7
- it_should_behave_like "it has a logger"
6
+ it_behaves_like "it has a logger"
8
7
 
9
- its(:store) { is_expected.to eq('store') }
10
- its(:auth_token) { is_expected.to eq('auth_token') }
8
+ describe "#initialize" do
9
+ it "sets up the attr_readers" do
10
+ expect(subject.store).to eq('store')
11
+ expect(subject.auth_token).to eq('auth_token')
12
+ end
13
+ end
11
14
 
12
15
  it "creates an instance of Client" do
13
16
  expect(subject).to be_a Vend::Oauth2::Client
@@ -15,33 +18,30 @@ describe Vend::Oauth2::Client do
15
18
 
16
19
  describe "resource factories" do
17
20
  it "gets all products" do
18
- Vend::Resource::Product.should_receive(:all).and_return([])
19
- subject.Product.all.should == []
21
+ expect(Vend::Resource::Product).to receive(:all).and_return([])
22
+ expect(subject.Product.all).to eq []
20
23
  end
21
24
  end
22
25
 
23
26
  describe "#http_client_options" do
24
-
25
- let(:options) { {:foo => 'bar'} }
27
+ let(:options) { {foo: 'bar'} }
26
28
  let(:base_url) { "http://foo/" }
27
29
  let(:auth_token) { "auth_token" }
28
30
 
29
31
  before do
30
32
  subject.stub(
31
- :options => options,
32
- :base_url => base_url,
33
- :auth_token => auth_token
33
+ options: options,
34
+ base_url: base_url,
35
+ auth_token: auth_token
34
36
  )
35
37
  end
36
38
 
37
- its(:http_client_options) {
38
- should == {
39
- :foo => 'bar',
40
- :base_url => base_url,
41
- :auth_token => auth_token
42
- }
43
- }
39
+ specify :http_client_options do
40
+ expect(subject.http_client_options).to eq({
41
+ foo: 'bar',
42
+ base_url: base_url,
43
+ auth_token: auth_token
44
+ })
45
+ end
44
46
  end
45
-
46
-
47
- end
47
+ end
@@ -1,48 +1,71 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Vend::PaginationInfo do
4
-
5
4
  subject { described_class.new(response) }
6
5
 
7
6
  let(:response) { double("response") }
8
7
 
9
- its(:response) { should == response }
8
+ specify :response do
9
+ expect(subject.response).to eq response
10
+ end
10
11
 
11
12
  context "when response has pagination info" do
12
- let(:response) {
13
+ let(:response) do
13
14
  {
14
15
  "pagination" => {
15
16
  "results" => 7461,
16
17
  "page" => 41,
17
18
  "page_size" => 100,
18
- "pages" => 75
19
+ "pages" => 75
19
20
  }
20
21
  }
21
- }
22
+ end
22
23
 
23
- its(:pages) { should == 75 }
24
- its(:page) { should == 41 }
25
- it { should be_paged }
24
+ specify :pages do
25
+ expect(subject.pages).to eq 75
26
+ end
26
27
 
27
- describe "#last_page?" do
28
+ specify :page do
29
+ expect(subject.page).to eq 41
30
+ end
31
+
32
+ specify :paged do
33
+ expect(subject).to be_paged
34
+ end
28
35
 
29
- it { should_not be_last_page }
36
+ describe "#last_page?" do
37
+ specify :is_not_last_page do
38
+ expect(subject).to_not be_last_page
39
+ end
30
40
 
31
41
  context "when page is equal to pages" do
32
42
  before do
33
- subject.stub(:page => 42, :pages => 42)
43
+ subject.stub(page: 42, pages: 42)
34
44
  end
35
- it { should be_last_page }
36
- end
37
45
 
46
+ specify :is_last_page do
47
+ expect(subject).to be_last_page
48
+ end
49
+ end
38
50
  end
39
51
  end
40
52
 
41
53
  context "when response does not have pagination info" do
42
54
  let(:response) { Hash.new }
43
- its(:pages) { should == 1 }
44
- its(:page) { should == 1 }
45
- it { should be_last_page }
46
- it { should_not be_paged }
55
+ specify :pages do
56
+ expect(subject.pages).to eq 1
57
+ end
58
+
59
+ specify :page do
60
+ expect(subject.page).to eq 1
61
+ end
62
+
63
+ specify :is_last_page do
64
+ expect(subject).to be_last_page
65
+ end
66
+
67
+ specify :is_paged do
68
+ expect(subject).to_not be_paged
69
+ end
47
70
  end
48
71
  end
@@ -5,23 +5,25 @@ describe Vend::Resource::RegisterSaleProduct do
5
5
 
6
6
  subject { described_class.new(attrs) }
7
7
 
8
- its(:attrs) { should == attrs }
8
+ specify :attrs do
9
+ expect(subject.attrs).to eq attrs
10
+ end
9
11
 
10
12
  describe "provides an attr reader for the attributes in attrs" do
11
13
  let(:attr1) { double("attr1") }
12
14
 
13
- let(:attrs) {
14
- {
15
+ let(:attrs) do
16
+ {
15
17
  "attr1" => attr1
16
18
  }
17
- }
19
+ end
18
20
 
19
21
  it "responds to attr1" do
20
- subject.send(:attr1).should == attr1
22
+ expect(subject.send(:attr1)).to eq attr1
21
23
  end
22
24
 
23
25
  it "does not respond to attr2" do
24
- lambda { subject.send(:attr2) }.should raise_error NoMethodError
26
+ expect { subject.send(:attr2) }.to raise_error NoMethodError
25
27
  end
26
28
  end
27
29
  end