bigcartel 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.mkd +8 -3
- data/lib/bigcartel/version.rb +1 -1
- data/lib/bigcartel.rb +91 -14
- metadata +7 -9
data/README.mkd
CHANGED
@@ -12,16 +12,21 @@ Usage
|
|
12
12
|
require 'bigcartel'
|
13
13
|
require 'pp'
|
14
14
|
|
15
|
-
s = BigCartel.store("tonkapark")
|
16
|
-
|
15
|
+
s = BigCartel.store("tonkapark")
|
16
|
+
|
17
17
|
pp s.description
|
18
18
|
|
19
19
|
s.products.each do |product|
|
20
20
|
pp product.name
|
21
|
-
pp product.
|
21
|
+
pp product.image.thumb
|
22
22
|
end
|
23
23
|
|
24
24
|
|
25
|
+
s = BigCartel.store("ugmonk")
|
26
|
+
#return products by category
|
27
|
+
products = s.products_by_category("prints")
|
28
|
+
|
29
|
+
|
25
30
|
|
26
31
|
Copyright
|
27
32
|
---------
|
data/lib/bigcartel/version.rb
CHANGED
data/lib/bigcartel.rb
CHANGED
@@ -30,29 +30,82 @@ module BigCartel
|
|
30
30
|
|
31
31
|
class Store < Base
|
32
32
|
|
33
|
-
attr_reader :id, :description, :categories, :website, :products_count, :pages, :name, :url, :currency, :country, :artists
|
33
|
+
attr_reader :id, :description, :categories, :website, :products_count, :pages, :name, :url, :currency, :country, :artists, :currency_sign, :products
|
34
34
|
|
35
35
|
def initialize(id, data={})
|
36
36
|
@id = id
|
37
37
|
@description = data['description']
|
38
38
|
@website = data['website']
|
39
39
|
@products_count = data['products_count']
|
40
|
-
@pages = data['pages'].map{|p| Page.
|
40
|
+
@pages = data['pages'].map{|p| Page.add(id, data['url'], p)} unless data['pages'].blank?
|
41
41
|
@name = data['name']
|
42
42
|
@url = data['url']
|
43
43
|
@currency = data['currency']['code']
|
44
|
+
@currency_sign = data['currency']['sign']
|
44
45
|
@country = data['country']['name']
|
45
|
-
@categories = data['categories'].map{|cat| Category.new(data['url'], cat)}
|
46
|
-
@artists = data['artists'].map{|cat| Artist.new(data['url'], cat)}
|
46
|
+
@categories = data['categories'].blank? ? [] : data['categories'].map{|cat| Category.new(data['url'], cat)}
|
47
|
+
@artists = data['artists'].blank? ? [] : data['artists'].map{|cat| Artist.new(data['url'], cat)}
|
48
|
+
@products = Product.all(@id, @url)
|
47
49
|
end
|
48
50
|
|
49
51
|
def self.find(id)
|
50
52
|
Store.new(id, self.fetch(id))
|
51
53
|
end
|
52
54
|
|
53
|
-
def
|
54
|
-
|
55
|
+
def product_find(permalink)
|
56
|
+
#self.products.select{|f| f["permalink"] == permalink}
|
57
|
+
@products.each do |p|
|
58
|
+
if p.permalink == permalink
|
59
|
+
return p
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def page(permalink)
|
65
|
+
self.pages.each do |p|
|
66
|
+
return p if p.permalink == permalink
|
67
|
+
end
|
55
68
|
end
|
69
|
+
|
70
|
+
def category(permalink)
|
71
|
+
self.categories.each do |cat, idx|
|
72
|
+
return cat if cat.permalink == permalink
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def artist(permalink)
|
77
|
+
self.artists.each do |a, idx|
|
78
|
+
return a if a.permalink == permalink
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def products_by_category(cat)
|
83
|
+
result = []
|
84
|
+
if self.categories.size > 0
|
85
|
+
self.products.each do |p|
|
86
|
+
cats = {}
|
87
|
+
if p.categories.size > 0
|
88
|
+
cats = p.categories.collect {|c| c.permalink}
|
89
|
+
result << p if cats.include?(cat)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
result
|
94
|
+
end
|
95
|
+
|
96
|
+
def products_by_artist(slug)
|
97
|
+
result = []
|
98
|
+
if self.artists.size > 0
|
99
|
+
self.products.each do |p|
|
100
|
+
temp = {}
|
101
|
+
if p.artists.size > 0
|
102
|
+
temp = p.artists.collect {|a| a.permalink}
|
103
|
+
result << p if temp.include?(slug)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
result
|
108
|
+
end
|
56
109
|
|
57
110
|
protected
|
58
111
|
def self.fetch(id)
|
@@ -91,38 +144,62 @@ module BigCartel
|
|
91
144
|
|
92
145
|
|
93
146
|
class Page < Base
|
94
|
-
attr_reader :name, :permalink, :url
|
147
|
+
attr_reader :id, :name, :permalink, :url, :content, :category
|
95
148
|
def initialize(store_url, data={})
|
149
|
+
@id = data['id']
|
96
150
|
@name = data['name']
|
97
151
|
@permalink = data['permalink']
|
98
152
|
@url = "#{store_url}/#{data['permalink']}"
|
153
|
+
@content = data['content']
|
154
|
+
@category = data['category']
|
99
155
|
end
|
156
|
+
|
157
|
+
def self.add(id, store_url, page)
|
158
|
+
Page.new(store_url, self.fetch(id, page['permalink']))
|
159
|
+
end
|
160
|
+
|
161
|
+
protected
|
162
|
+
def self.fetch(id, page)
|
163
|
+
get("/#{id}/page/#{page}.js", :headers => {'Accept' => 'application/json'})
|
164
|
+
end
|
100
165
|
end
|
101
166
|
|
102
167
|
class Product < Base
|
103
|
-
attr_reader :name, :permalink, :url, :description, :artists, :on_sale, :status, :categories, :price, :position, :url, :id, :tax, :images, :shipping, :options,:default_price
|
168
|
+
attr_reader :name, :permalink, :url, :full_url, :description, :artists, :on_sale, :status, :categories, :price, :position, :url, :id, :tax, :images, :shipping, :options,:default_price,:image, :image_count
|
104
169
|
def initialize(store_url, data={})
|
105
170
|
@name = data['name']
|
106
171
|
@description = data['description']
|
107
|
-
@artists = data['artists'].map{|cat| Artist.new(data['url'], cat)}
|
172
|
+
@artists = data['artists'].blank? ? [] : data['artists'].map{|cat| Artist.new(data['url'], cat)}
|
108
173
|
@on_sale= data['on_sale']
|
109
174
|
@status = data['status']
|
110
|
-
@categories = data['categories'].map{|cat| Category.new(data['url'], cat)}
|
175
|
+
@categories = data['categories'].blank? ? [] : data['categories'].map{|cat| Category.new(data['url'], cat)}
|
111
176
|
@price = data['price']
|
112
177
|
@default_price = data['default_price']
|
113
178
|
@position = data['position']
|
114
|
-
@
|
179
|
+
@full_url = "#{store_url}#{data['url']}"
|
180
|
+
@url = "#{data['url']}"
|
115
181
|
@id = data['id']
|
116
182
|
@tax = data['tax']
|
117
183
|
@permalink = data['permalink']
|
118
184
|
@images = data['images'].blank? ? [] : data['images'].map{|img| Image.new(img)}
|
185
|
+
@image_count = data['images'].blank? ? 0 : data['images'].size
|
119
186
|
@shipping = data['shipping'].map{|ship| Shipping.new(ship)} unless data['shipping'].blank?
|
120
187
|
@options = data['options'].map{|opt| ProductOption.new(opt)} unless data['options'].blank?
|
188
|
+
@image = Image.new(data['images'][0]) unless data['images'].blank?
|
189
|
+
end
|
190
|
+
|
191
|
+
def has_default_option
|
192
|
+
names = {}
|
193
|
+
if self.options.size <= 1
|
194
|
+
names = self.options.collect {|x| x.name }
|
195
|
+
end
|
196
|
+
return names.include?("Default")
|
197
|
+
end
|
198
|
+
|
199
|
+
def option
|
200
|
+
self.options.first
|
121
201
|
end
|
122
202
|
|
123
|
-
def img
|
124
|
-
self.images.first
|
125
|
-
end
|
126
203
|
|
127
204
|
def self.all(id, store_url)
|
128
205
|
self.fetch(id).map{|p| Product.new(store_url, p)}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bigcartel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-07-
|
13
|
-
default_executable:
|
12
|
+
date: 2011-07-26 00:00:00.000000000Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rspec
|
17
|
-
requirement: &
|
16
|
+
requirement: &9857376 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ~>
|
@@ -22,10 +21,10 @@ dependencies:
|
|
22
21
|
version: '2.3'
|
23
22
|
type: :development
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
24
|
+
version_requirements: *9857376
|
26
25
|
- !ruby/object:Gem::Dependency
|
27
26
|
name: httparty
|
28
|
-
requirement: &
|
27
|
+
requirement: &9857076 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
29
|
requirements:
|
31
30
|
- - ~>
|
@@ -33,7 +32,7 @@ dependencies:
|
|
33
32
|
version: 0.7.3
|
34
33
|
type: :runtime
|
35
34
|
prerelease: false
|
36
|
-
version_requirements: *
|
35
|
+
version_requirements: *9857076
|
37
36
|
description: A Ruby wrapper for the Big Cartel External REST API
|
38
37
|
email:
|
39
38
|
- matt@tonkapark.com
|
@@ -50,7 +49,6 @@ files:
|
|
50
49
|
- lib/bigcartel/version.rb
|
51
50
|
- spec/bigcartel_spec.rb
|
52
51
|
- spec/helper.rb
|
53
|
-
has_rdoc: true
|
54
52
|
homepage: ''
|
55
53
|
licenses: []
|
56
54
|
post_install_message:
|
@@ -71,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
69
|
version: '0'
|
72
70
|
requirements: []
|
73
71
|
rubyforge_project: bigcartel
|
74
|
-
rubygems_version: 1.
|
72
|
+
rubygems_version: 1.7.2
|
75
73
|
signing_key:
|
76
74
|
specification_version: 3
|
77
75
|
summary: Ruby wrapper for the Big Cartel API
|