bigcartel 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzY5MmFjOTZkYWJiNTY1NjNjZWY5ZjU1MTQ5YWM2MWJhYmYxNzIxZQ==
5
+ data.tar.gz: !binary |-
6
+ NjE3ZmUyODc4Yjc2OWM0NGE0NWNjOTI1NDE4ZDAxNTVlZTE5NzVmNA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YTM5MzM1YzJiN2E0ZDUyOTJhOWQ3YWNjZmE4MTFjNThjMzhkODUyNTMyYjZl
10
+ YzI4YTRlYTkyOGJiM2JhZjc3YzBkNDI2NDY5NjdiMWJlY2IwMTA1MzY0Yzgw
11
+ ZTRjZGE1NjhmYWUyMzc3MzE0ZWQ5ODRlODM4MGM0YWRiZmIxNmE=
12
+ data.tar.gz: !binary |-
13
+ YTExYWI5OGMwZjQzNjkyN2Y3MjhiODc3NGFjMjNjMWQ2ZmNlMDIwZWQ4YTFl
14
+ M2I0NjM5NDBhNTQxYzliNTIzOWQ3ZDliNzAwZDcyOWE2ZTIxNmRjODVhZDUw
15
+ OWMwNzBlODdlMzBkZTllZDg0ZDY4ZDdlODZmMjMxNDNiZDQ1NzQ=
@@ -6,31 +6,50 @@ module BigCartel
6
6
  class Client
7
7
 
8
8
  include HTTParty
9
+ debug_output
9
10
  base_uri "http://api.bigcartel.com"
10
11
  headers 'Content-Type' => 'application/json'
11
12
 
12
- def initialize(options={})
13
- end
13
+ def initialize(options={})
14
+ @@maintenance_mode = false
15
+ end
16
+
17
+ def maintenance_mode
18
+ @@maintenance_mode
19
+ end
14
20
 
15
21
  def self.fetch(path)
16
- response = get(path)
17
- Hashie::Mash.new(response)
22
+ response = get(path)
23
+ if response.code == 403
24
+ @@maintenance_mode = true
25
+ response.merge!({maintenance_mode: true})
26
+ end
27
+ Hashie::Mash.new(response)
18
28
  end
19
29
 
20
30
  def self.list(path, opts={})
21
- # opts = { :limit => 100 }.merge opts
22
31
 
23
- response = get(path, :query => {'limit' => opts[:limit]})
24
- response.map { |c| Hashie::Mash.new(c)}
32
+ response = get(path, :query => {'limit' => opts[:limit]})
33
+ case response.code
34
+ when 403
35
+ @@maintenance_mode = true
36
+ Hashie::Mash.new(response.merge!({maintenance_mode: true}))
37
+ else
38
+ response.map { |c| Hashie::Mash.new(c)}
39
+ end
40
+
25
41
  end
26
42
 
27
43
 
28
44
  def store(account, opts={})
29
45
  opts = { :show_products => true, :product_limit => 100 }.merge opts
30
46
 
31
- store = self.class.fetch("/#{account}/store.js")
47
+ store = self.class.fetch("/#{account}/store.js")
32
48
  store.account = account
33
- store.products = opts[:show_products] ? products(account,{:limit => opts[:product_limit]}) : {}
49
+ store.maintenance_mode = @@maintenance_mode
50
+ unless @@maintenance_mode
51
+ store.products = opts[:show_products] ? products(account,{:limit => opts[:product_limit]}) : {}
52
+ end
34
53
  store
35
54
  end
36
55
 
@@ -39,10 +58,12 @@ module BigCartel
39
58
  opts = { :limit => 100 }.merge opts
40
59
  products = self.class.list("/#{account}/products.js", opts)
41
60
 
42
- products.each do |p|
43
- p.images = images_helper(p.images) if p.has_key?("images")
44
- p.has_default_option = has_default_option?(p.options)
45
- p.option = p.options.first
61
+ unless @@maintenance_mode
62
+ products.each do |p|
63
+ p.images = images_helper(p.images) if p.has_key?("images")
64
+ p.has_default_option = has_default_option?(p.options)
65
+ p.option = p.options.first
66
+ end
46
67
  end
47
68
 
48
69
  products
@@ -1,3 +1,3 @@
1
1
  module BigCartel
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
@@ -33,6 +33,12 @@ describe BigCartel::Client do
33
33
 
34
34
  stub_request(:get, /api.bigcartel.com\/park\/page\/\w+.js/).
35
35
  to_return(:body=>fixture("page.json"), :headers => {:content_type => "application/json; charset=utf-8"})
36
+
37
+ stub_request(:get, "api.bigcartel.com/maintenance/store.js").
38
+ to_return(:body=>fixture("maintenance.json"), :headers => {:content_type => "application/json; charset=utf-8"}, :status => 403)
39
+
40
+ stub_request(:get, /api.bigcartel.com\/maintenance\/products.js\?limit=\d+/).
41
+ to_return(:body=>fixture("maintenance.json"), :headers => {:content_type => "application/json; charset=utf-8"}, :status => 403)
36
42
  end
37
43
 
38
44
 
@@ -67,6 +73,18 @@ describe BigCartel::Client do
67
73
  @client = BigCartel::Client.new
68
74
  end
69
75
 
76
+ it "in maintenance mode" do
77
+ store = @client.store("maintenance")
78
+ a_request(:get, "api.bigcartel.com/maintenance/store.js").
79
+ should have_been_made
80
+
81
+ a_request(:get, "api.bigcartel.com/maintenance/products.js").
82
+ should_not have_been_made
83
+
84
+ expect(store.account).to eq("maintenance")
85
+ expect(store.maintenance_mode).to be_true
86
+ end
87
+
70
88
  it "with no options makes 1 http call" do
71
89
  store = @client.store("park")
72
90
  a_request(:get, "api.bigcartel.com/park/store.js").
@@ -179,7 +197,21 @@ describe BigCartel::Client do
179
197
  it { @product.id.should be_an Integer }
180
198
  it { @product.options.should be_an Array }
181
199
 
182
- end
200
+ end
201
+
202
+ context "in maintenance mode" do
203
+
204
+ it 'should return no products' do
205
+ products = @client.products("maintenance")
206
+ a_request(:get, "api.bigcartel.com/maintenance/store.js").
207
+ should_not have_been_made
208
+
209
+ a_request(:get, "api.bigcartel.com/maintenance/products.js?limit=100").
210
+ should have_been_made
211
+
212
+ expect(products.maintenance_mode).to be_true
213
+ end
214
+ end
183
215
 
184
216
  end
185
217
 
@@ -0,0 +1 @@
1
+ {"reason":"Store Front Is Under Maintenance"}
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigcartel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
5
- prerelease:
4
+ version: 1.0.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Matt Anderson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-29 00:00:00.000000000 Z
11
+ date: 2013-08-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: httparty
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: hashie
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: webmock
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -93,36 +84,37 @@ files:
93
84
  - lib/bigcartel/client.rb
94
85
  - lib/bigcartel/version.rb
95
86
  - spec/bigcartel_spec.rb
87
+ - spec/fixtures/maintenance.json
96
88
  - spec/fixtures/page.json
97
89
  - spec/fixtures/products.json
98
90
  - spec/fixtures/store.json
99
91
  - spec/helper.rb
100
92
  homepage: http://tonkapark.com
101
93
  licenses: []
94
+ metadata: {}
102
95
  post_install_message:
103
96
  rdoc_options: []
104
97
  require_paths:
105
98
  - lib
106
99
  required_ruby_version: !ruby/object:Gem::Requirement
107
- none: false
108
100
  requirements:
109
101
  - - ! '>='
110
102
  - !ruby/object:Gem::Version
111
103
  version: '0'
112
104
  required_rubygems_version: !ruby/object:Gem::Requirement
113
- none: false
114
105
  requirements:
115
106
  - - ! '>='
116
107
  - !ruby/object:Gem::Version
117
108
  version: '0'
118
109
  requirements: []
119
110
  rubyforge_project: bigcartel
120
- rubygems_version: 1.8.25
111
+ rubygems_version: 2.0.7
121
112
  signing_key:
122
- specification_version: 3
113
+ specification_version: 4
123
114
  summary: Ruby wrapper for the Big Cartel API
124
115
  test_files:
125
116
  - spec/bigcartel_spec.rb
117
+ - spec/fixtures/maintenance.json
126
118
  - spec/fixtures/page.json
127
119
  - spec/fixtures/products.json
128
120
  - spec/fixtures/store.json