vend 0.0.4 → 0.0.5

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.
@@ -147,6 +147,17 @@ module Vend
147
147
  false
148
148
  end
149
149
 
150
+ # Override this with arguments that are required on every collection
151
+ # request. I.e, to default to 500 items per page:
152
+ #
153
+ # def default_collection_request_args
154
+ # super.merge(:url_params => {:page_size => 500})
155
+ # end
156
+ #
157
+ def self.default_collection_request_args
158
+ {}
159
+ end
160
+
150
161
  # Overrides respond_to? to query the attrs hash for the key before
151
162
  # proxying it to the object
152
163
  def respond_to?(method_name)
@@ -13,6 +13,10 @@ module Vend
13
13
  RegisterSaleProduct.new(sale_product_attrs)
14
14
  end
15
15
  end
16
+
17
+ def self.default_collection_request_args
18
+ super.merge(:url_params => {:page_size => 200})
19
+ end
16
20
  end
17
21
 
18
22
  end
@@ -21,7 +21,7 @@ module Vend
21
21
  @client = client
22
22
  @target_class = target_class
23
23
  @endpoint = endpoint
24
- @request_args = request_args
24
+ @request_args = target_class.default_collection_request_args.merge(request_args)
25
25
  end
26
26
 
27
27
  def each
@@ -1,3 +1,3 @@
1
1
  module Vend #:nodoc:
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -19,7 +19,9 @@ describe Vend::Resource::RegisterSale do
19
19
  let(:expected_collection_length) { 1 }
20
20
 
21
21
  it_should_behave_like "a resource with a singular GET endpoint"
22
- it_should_behave_like "a resource with a collection GET endpoint"
22
+ it_should_behave_like "a resource with a collection GET endpoint" do
23
+ let(:append_to_url) { '?page_size=200' }
24
+ end
23
25
 
24
26
  specify "register_sales are findable by state" do
25
27
  client.RegisterSale.should respond_to(:find_by_state)
@@ -22,14 +22,20 @@ shared_examples "a resource with a collection GET endpoint" do
22
22
  let(:username) {"foo"}
23
23
  let(:password) {"bar"}
24
24
  let(:store) {"baz"}
25
+ let(:append_to_url) { '' }
25
26
 
26
27
  let(:client) do
27
28
  Vend::Client.new(store, username, password)
28
29
  end
29
30
 
30
31
  it "gets the collection" do
31
- stub_request(:get, "https://#{username}:#{password}@#{store}.vendhq.com/api/#{class_basename.to_s.underscore.pluralize}").
32
- to_return(:status => 200, :body => get_mock_from_path(:get))
32
+ url = "https://%s:%s@%s.vendhq.com/api/%s%s" % [
33
+ username, password, store, class_basename.to_s.underscore.pluralize,
34
+ append_to_url
35
+ ]
36
+ stub_request(:get, url).to_return(
37
+ :status => 200, :body => get_mock_from_path(:get)
38
+ )
33
39
 
34
40
  collection = build_receiver.all
35
41
  collection.count.should == expected_collection_length
@@ -270,6 +270,11 @@ describe Vend::Base do
270
270
 
271
271
  end
272
272
 
273
+ describe '.default_collection_request_args' do
274
+ subject { Vend::Resource::Foo }
275
+ its(:default_collection_request_args) { should == {} }
276
+ end
277
+
273
278
  describe ".paginates?" do
274
279
 
275
280
  subject { Vend::Resource::Foo }
@@ -3,9 +3,11 @@ require 'spec_helper'
3
3
  describe Vend::ResourceCollection do
4
4
 
5
5
  let(:client) { mock("client") }
6
- let(:target_class) { mock("target_class") }
6
+ let(:target_class) {
7
+ mock("target_class", :default_collection_request_args => {})
8
+ }
7
9
  let(:endpoint) { "endpoint" }
8
- let(:request_args) { mock("request_args") }
10
+ let(:request_args) { {} }
9
11
 
10
12
  subject { described_class.new(client, target_class, endpoint, request_args) }
11
13
 
@@ -25,6 +27,14 @@ describe Vend::ResourceCollection do
25
27
  its(:request_args) { should == {} }
26
28
  end
27
29
 
30
+ context "when target class has default request args" do
31
+ subject {
32
+ described_class.new(client, target_class, endpoint)
33
+ }
34
+ before { target_class.stub(:default_collection_request_args => {:foo => :bar}) }
35
+ its(:request_args) { should == {:foo => :bar}}
36
+ end
37
+
28
38
  end
29
39
 
30
40
  describe "#each" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-24 00:00:00.000000000 Z
12
+ date: 2012-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -160,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
160
  version: '0'
161
161
  segments:
162
162
  - 0
163
- hash: 100082207733883280
163
+ hash: 2360460495322174527
164
164
  required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  none: false
166
166
  requirements:
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  version: '0'
170
170
  segments:
171
171
  - 0
172
- hash: 100082207733883280
172
+ hash: 2360460495322174527
173
173
  requirements: []
174
174
  rubyforge_project: vend
175
175
  rubygems_version: 1.8.24