gilt 0.1.0

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.
@@ -0,0 +1,146 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gilt::Sale do
4
+ before do
5
+ @apikey = "my-api-key"
6
+ @affid = "my-affiliate-id"
7
+ @sale_key = "shoshanna-019"
8
+ stub_request(:any, /api\.gilt\.com\/.+\/sales\/.+\/detail\.json/).to_return fixture('sale_detail.json')
9
+ stub_request(:any, /api\.gilt\.com\/.+\/sales\/.*(active|upcoming)\.json/).to_return fixture('active.json')
10
+ stub_request(:any, /api\.gilt\.com\/.+\/products\/.+\/detail\.json/).to_return fixture('product.json')
11
+ end
12
+
13
+ describe "::client" do
14
+ it "creates a new instance of the Sales client" do
15
+ described_class.client(@apikey, @affid).should be_kind_of Gilt::Client::Sales
16
+ end
17
+ end
18
+
19
+ describe "::create" do
20
+ it "creates an instance of Sale from the request response" do
21
+ sale = described_class.create(Gilt::Stores::WOMEN, @sale_key, @apikey)
22
+ sale.should be_instance_of described_class
23
+ end
24
+ end
25
+
26
+ Gilt::Client::Sales.resources.keys.each do |key|
27
+ describe "::#{key}" do
28
+ it "creates a set of instances of Sale" do
29
+ set = described_class.send(key, :store => Gilt::Stores::WOMEN, :sale_key => @sale_key, :apikey => @apikey)
30
+ set.should be_all {|sale| sale.is_a? described_class }
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "#name" do
36
+ before do
37
+ @sale = described_class.create(Gilt::Stores::WOMEN, @sale_key, @apikey)
38
+ end
39
+
40
+ it "returns the sale's name" do
41
+ @sale.name.should match /Shoshanna/
42
+ end
43
+ end
44
+
45
+ describe "#store" do
46
+ before do
47
+ @sale = described_class.create(Gilt::Stores::WOMEN, @sale_key, @apikey)
48
+ end
49
+
50
+ it "returns the sale's store" do
51
+ @sale.store.should eq Gilt::Stores::WOMEN
52
+ end
53
+ end
54
+
55
+ describe "#sale_key" do
56
+ before do
57
+ @sale = described_class.create(Gilt::Stores::WOMEN, @sale_key, @apikey)
58
+ end
59
+
60
+ it "returns the sale's sale key" do
61
+ @sale.sale_key.should match /^shoshanna/
62
+ end
63
+ end
64
+
65
+ describe "#sale" do
66
+ before do
67
+ @sale = described_class.create(Gilt::Stores::WOMEN, @sale_key, @apikey)
68
+ end
69
+
70
+ it "returns a URI representation of the sale's endpoint" do
71
+ @sale.sale.to_s.should match "/sales/#{Gilt::Stores::WOMEN}/#{@sale.sale_key}/"
72
+ end
73
+ end
74
+
75
+ describe "#sale_url" do
76
+ before do
77
+ @sale = described_class.create(Gilt::Stores::WOMEN, @sale_key, @apikey)
78
+ end
79
+
80
+ it "returns a URI representation of the sale page" do
81
+ @sale.sale_url.to_s.should match "www.gilt.com/sale/women/#{@sale.sale_key}"
82
+ end
83
+ end
84
+
85
+ describe "#begins" do
86
+ before do
87
+ @sale = described_class.create(Gilt::Stores::WOMEN, @sale_key, @apikey)
88
+ end
89
+
90
+ it "returns a Time representation of the sale begin time" do
91
+ @sale.begins.day.should eql 5
92
+ end
93
+ end
94
+
95
+ describe "#ends" do
96
+ before do
97
+ @sale = described_class.create(Gilt::Stores::WOMEN, @sale_key, @apikey)
98
+ end
99
+
100
+ it "returns a Time representation of the sale end time" do
101
+ @sale.ends.day.should eql 7
102
+ end
103
+ end
104
+
105
+ describe "#ended?" do
106
+ before do
107
+ @sale = described_class.create(Gilt::Stores::WOMEN, @sale_key, @apikey)
108
+ end
109
+
110
+ it "is true unless you have traveled back in time" do
111
+ @sale.ended?.should be_true
112
+ end
113
+ end
114
+
115
+ describe "#duration" do
116
+ before do
117
+ @sale = described_class.create(Gilt::Stores::WOMEN, @sale_key, @apikey)
118
+ end
119
+
120
+ it "returns the number of seconds between begin and end" do
121
+ (@sale.duration / 60 / 60).should eql 36
122
+ end
123
+ end
124
+
125
+ describe "#products" do
126
+ before do
127
+ @sale = described_class.create(Gilt::Stores::WOMEN, @sale_key, @apikey)
128
+ end
129
+
130
+ it "returns a map of product requests" do
131
+ @sale.products.should be_all {|p| p.is_a? Gilt::Product }
132
+ end
133
+ end
134
+
135
+ describe "#length" do
136
+ before do
137
+ @sale = described_class.create(Gilt::Stores::WOMEN, @sale_key, @apikey)
138
+ end
139
+
140
+ it "returns the size of the products array" do
141
+ @sale.length.should eq @sale.products.length
142
+ end
143
+
144
+ end
145
+
146
+ end
@@ -0,0 +1,147 @@
1
+ require 'spec_helper'
2
+ require 'gilt/sku'
3
+
4
+ describe Gilt::Sku do
5
+ before do
6
+ @body = {
7
+ :id => 1445982,
8
+ :inventory_status => "sold out",
9
+ :msrp_price => "449.00",
10
+ :sale_price => "340.00",
11
+ :attributes => [{
12
+ :name => "color",
13
+ :value => "choc brown"
14
+ }]
15
+ }
16
+ @json = MultiJson.encode(@body)
17
+ end
18
+
19
+ describe "#id" do
20
+ it "returns the sku id" do
21
+ sku = Gilt::Sku.new(MultiJson.decode(@json))
22
+ sku.id.should eql 1445982
23
+ end
24
+ end
25
+
26
+ describe "#inventory_status" do
27
+ it "returns the inventory state of the sku" do
28
+ sku = Gilt::Sku.new(MultiJson.decode(@json))
29
+ sku.inventory_status.should eql Gilt::Sku::SOLD_OUT
30
+ end
31
+ end
32
+
33
+ describe "#for_sale?" do
34
+ before do
35
+ @sku_body = MultiJson.decode(@json)
36
+ end
37
+
38
+ it "is true when the sku is for sale" do
39
+ @sku_body["inventory_status"] = Gilt::Sku::FOR_SALE
40
+ sku = Gilt::Sku.new(@sku_body)
41
+ sku.for_sale?.should be_true
42
+ end
43
+
44
+ it "is false when the sku is sold out or reserved" do
45
+ @sku_body["inventory_status"] = Gilt::Sku::SOLD_OUT
46
+ sku = Gilt::Sku.new(@sku_body)
47
+ sku.for_sale?.should_not be_true
48
+ end
49
+ end
50
+
51
+ describe "#reserved?" do
52
+ before do
53
+ @sku_body = MultiJson.decode(@json)
54
+ end
55
+
56
+ it "is true when the sku is reserved" do
57
+ @sku_body["inventory_status"] = Gilt::Sku::RESERVED
58
+ sku = Gilt::Sku.new(@sku_body)
59
+ sku.reserved?.should be_true
60
+ end
61
+
62
+ it "is false when the sku is for sale or sold out" do
63
+ @sku_body["inventory_status"] = Gilt::Sku::SOLD_OUT
64
+ sku = Gilt::Sku.new(@sku_body)
65
+ sku.reserved?.should_not be_true
66
+ end
67
+ end
68
+
69
+ describe "#sold_out?" do
70
+ before do
71
+ @sku_body = MultiJson.decode(@json)
72
+ end
73
+
74
+ it "is true when the sku is sold out" do
75
+ @sku_body["inventory_status"] = Gilt::Sku::SOLD_OUT
76
+ sku = Gilt::Sku.new(@sku_body)
77
+ sku.sold_out?.should be_true
78
+ end
79
+
80
+ it "is false when the sku is for sale or reserved" do
81
+ @sku_body["inventory_status"] = Gilt::Sku::FOR_SALE
82
+ sku = Gilt::Sku.new(@sku_body)
83
+ sku.sold_out?.should_not be_true
84
+ end
85
+ end
86
+
87
+ describe "#msrp_price" do
88
+ it "returns the price as a Money object" do
89
+ sku = Gilt::Sku.new MultiJson.decode(@json)
90
+ sku.msrp_price.should be_kind_of ::Money
91
+ end
92
+ end
93
+
94
+ describe "#sale_price" do
95
+ it "returns the price as a Money object" do
96
+ sku = Gilt::Sku.new MultiJson.decode(@json)
97
+ sku.sale_price.should be_kind_of ::Money
98
+ end
99
+ end
100
+
101
+ describe "#shipping_surcharge" do
102
+ before do
103
+ @sku_body = MultiJson.decode(@json)
104
+ end
105
+
106
+ it "returns the surcharge as a Money object" do
107
+ sku = Gilt::Sku.new @sku_body
108
+ sku.shipping_surcharge.should be_kind_of ::Money
109
+ end
110
+
111
+ it "is zero dollars when there is no surcharge" do
112
+ sku = Gilt::Sku.new @sku_body
113
+ sku.shipping_surcharge.should be_zero
114
+ end
115
+ end
116
+
117
+ describe "#subtotal" do
118
+ before do
119
+ @sku_body = MultiJson.decode(@json)
120
+ end
121
+
122
+ it "returns a Money object of the sale price plus the shipping surcharge" do
123
+ @sku_body["shipping_surcharge"] = "5.00"
124
+ sku = Gilt::Sku.new @sku_body
125
+ sku.subtotal.to_s.should eql "345.00"
126
+ end
127
+ end
128
+
129
+ describe "#sale?" do
130
+ it "is true if the sale price and the msrp price do not match" do
131
+ sku = Gilt::Sku.new MultiJson.decode(@json)
132
+ sku.sale?.should be_true
133
+ end
134
+ end
135
+
136
+ describe "#attributes" do
137
+ before do
138
+ @sku_body = MultiJson.decode(@json)
139
+ end
140
+
141
+ it "maps the names of the attribute to their values as symbols" do
142
+ sku = Gilt::Sku.new @sku_body
143
+ sku.attributes[:color].should match /brown/
144
+ end
145
+ end
146
+
147
+ end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1,12 @@
1
+ require 'gilt'
2
+ require 'webmock/rspec'
3
+
4
+ WebMock.disable_net_connect!
5
+
6
+ def fixture_path
7
+ File.expand_path("../fixtures", __FILE__)
8
+ end
9
+
10
+ def fixture(filename)
11
+ File.new("#{fixture_path}/#{filename}")
12
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gilt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mark Wunsch
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: money
16
+ requirement: &70282983416480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 4.0.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70282983416480
25
+ - !ruby/object:Gem::Dependency
26
+ name: weary
27
+ requirement: &70282983414860 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70282983414860
36
+ description: Ruby client for the Gilt public API (http://dev.gilt.com). Written with
37
+ the Weary framework.
38
+ email:
39
+ - mwunsch@gilt.com
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - .travis.yml
46
+ - Gemfile
47
+ - Gemfile.lock
48
+ - README.md
49
+ - Rakefile
50
+ - gilt.gemspec
51
+ - lib/gilt.rb
52
+ - lib/gilt/client.rb
53
+ - lib/gilt/client/products.rb
54
+ - lib/gilt/client/sales.rb
55
+ - lib/gilt/product.rb
56
+ - lib/gilt/sale.rb
57
+ - lib/gilt/sku.rb
58
+ - lib/gilt/version.rb
59
+ - spec/fixtures/active.json
60
+ - spec/fixtures/product.json
61
+ - spec/fixtures/sale_detail.json
62
+ - spec/gilt/client/products_spec.rb
63
+ - spec/gilt/client/sales_spec.rb
64
+ - spec/gilt/product_spec.rb
65
+ - spec/gilt/sale_spec.rb
66
+ - spec/gilt/sku_spec.rb
67
+ - spec/gilt_spec.rb
68
+ - spec/spec_helper.rb
69
+ homepage: http://github.com/mwunsch/gilt
70
+ licenses: []
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ segments:
82
+ - 0
83
+ hash: 3087332207602570870
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ segments:
91
+ - 0
92
+ hash: 3087332207602570870
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.11
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Ruby client for the Gilt public API.
99
+ test_files:
100
+ - spec/fixtures/active.json
101
+ - spec/fixtures/product.json
102
+ - spec/fixtures/sale_detail.json
103
+ - spec/gilt/client/products_spec.rb
104
+ - spec/gilt/client/sales_spec.rb
105
+ - spec/gilt/product_spec.rb
106
+ - spec/gilt/sale_spec.rb
107
+ - spec/gilt/sku_spec.rb
108
+ - spec/gilt_spec.rb
109
+ - spec/spec_helper.rb