bigcartel 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,3 +1,3 @@
1
- rvm:
2
- - 1.8.7
1
+ rvm:
2
+ - 1.8.7
3
3
  - 1.9.2
data/Gemfile CHANGED
@@ -1,10 +1,10 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in bigcartel.gemspec
4
- gemspec
5
-
6
-
7
- gem 'rake'
8
- gem 'rspec'
9
- gem 'webmock'
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bigcartel.gemspec
4
+ gemspec
5
+
6
+
7
+ gem 'rake'
8
+ gem 'rspec'
9
+ gem 'webmock'
10
10
  gem 'hashie'
data/README.mkd CHANGED
@@ -1,78 +1,78 @@
1
- The Big Cartel Ruby Gem
2
- ====================
3
- A Ruby wrapper for the Big Cartel External REST API.
4
-
5
- [![Build Status](https://secure.travis-ci.org/tonkapark/bigcartel.png)](http://travis-ci.org/tonkapark/bigcartel)
6
-
7
- Version 1.0
8
- -----------
9
-
10
- With the release of 1.0 I changed some of the design of the gem and should be considered a breaking change if you were using the 0.* versions of the gem. I hope this new design of the gem will be faster and also more useful in your applications.
11
-
12
-
13
- Installation
14
- ------------
15
- gem install bigcartel
16
-
17
- Usage
18
- ------
19
- require 'rubygems'
20
- require 'bigcartel', '>~ 1.0.0'
21
- require 'pp'
22
-
23
-
24
- client = BigCartel::Client.new
25
-
26
- client.store("tonkapark", {:show_products => true, :product_limit => 2})
27
-
28
- client.products("tonkapark", {:limit => 100})
29
-
30
- client.page("tonkapark", "page-permalink")
31
-
32
-
33
- store = BigCartel.store("tonkapark")
34
-
35
- pp store.description
36
-
37
- store.products.each do |product|
38
- pp product.name
39
- pp product.image.thumb
40
- end
41
-
42
-
43
-
44
-
45
- What you can do with the gem
46
- ---------
47
-
48
- As part of the [Big Cartel Themes and Templates](http://themes.tonkapark.com) available from Tonka Park there was a small web app built using the BigCartel gem to generate google products xml and also create a theme preview.
49
-
50
- See the gem in action at http://carteltools.heroku.com
51
-
52
-
53
- Supported Rubies
54
- ----------------
55
- * 1.8.7
56
- * 1.9.2
57
-
58
-
59
- Change Log
60
- ==========
61
-
62
- 1.0.0 - November 17, 2011
63
- --------------
64
- * redesigned wrapper from the ground up
65
- * added rspec tests
66
- * support for ruby 1.9.2 and 1.8.7
67
-
68
-
69
-
70
- Copyright
71
- ---------
72
- Copyright (c) 2011 Matt Anderson, [Tonka Park](http://tonkapark.com)
73
-
74
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
75
-
76
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
77
-
1
+ The Big Cartel Ruby Gem
2
+ ====================
3
+ A Ruby wrapper for the Big Cartel External REST API.
4
+
5
+ [![Build Status](https://secure.travis-ci.org/tonkapark/bigcartel.png)](http://travis-ci.org/tonkapark/bigcartel)
6
+
7
+ Version 1.0
8
+ -----------
9
+
10
+ With the release of 1.0 I changed some of the design of the gem and should be considered a breaking change if you were using the 0.* versions of the gem. I hope this new design of the gem will be faster and also more useful in your applications.
11
+
12
+
13
+ Installation
14
+ ------------
15
+ gem install bigcartel
16
+
17
+ Usage
18
+ ------
19
+ require 'rubygems'
20
+ require 'bigcartel', '>~ 1.0.0'
21
+ require 'pp'
22
+
23
+
24
+ client = BigCartel::Client.new
25
+
26
+ client.store("tonkapark", {:show_products => true, :product_limit => 2})
27
+
28
+ client.products("tonkapark", {:limit => 100})
29
+
30
+ client.page("tonkapark", "page-permalink")
31
+
32
+
33
+ store = BigCartel.store("tonkapark")
34
+
35
+ pp store.description
36
+
37
+ store.products.each do |product|
38
+ pp product.name
39
+ pp product.image.thumb
40
+ end
41
+
42
+
43
+
44
+
45
+ What you can do with the gem
46
+ ---------
47
+
48
+ As part of the [Big Cartel Themes and Templates](http://themes.tonkapark.com) available from Tonka Park there was a small web app built using the BigCartel gem to generate google products xml and also create a theme preview.
49
+
50
+ See the gem in action at http://carteltools.heroku.com
51
+
52
+
53
+ Supported Rubies
54
+ ----------------
55
+ * 1.8.7
56
+ * 1.9.2
57
+
58
+
59
+ Change Log
60
+ ==========
61
+
62
+ 1.0.0 - November 17, 2011
63
+ --------------
64
+ * redesigned wrapper from the ground up
65
+ * added rspec tests
66
+ * support for ruby 1.9.2 and 1.8.7
67
+
68
+
69
+
70
+ Copyright
71
+ ---------
72
+ Copyright (c) 2011 Matt Anderson, [Tonka Park](http://tonkapark.com)
73
+
74
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
75
+
76
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
77
+
78
78
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,15 +1,15 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- Bundler::GemHelper.install_tasks
4
-
5
- require 'rspec/core/rake_task'
6
-
7
- desc "Default: run unit tests"
8
- task :default => :spec
9
- task :test => :spec
10
-
11
- desc "Run all specs"
12
- RSpec::Core::RakeTask.new do |t|
13
- t.pattern = 'spec/**/*_spec.rb'
14
- end
15
-
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require 'rspec/core/rake_task'
6
+
7
+ desc "Default: run unit tests"
8
+ task :default => :spec
9
+ task :test => :spec
10
+
11
+ desc "Run all specs"
12
+ RSpec::Core::RakeTask.new do |t|
13
+ t.pattern = 'spec/**/*_spec.rb'
14
+ end
15
+
data/bigcartel.gemspec CHANGED
@@ -1,29 +1,29 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "bigcartel/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "bigcartel"
7
- s.version = BigCartel::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Matt Anderson"]
10
- s.email = ["matt@tonkapark.com"]
11
- s.homepage = "http://tonkapark.com"
12
- s.summary = %q{Ruby wrapper for the Big Cartel API}
13
- s.description = %q{A Ruby wrapper for the Big Cartel External REST API}
14
-
15
-
16
- s.add_runtime_dependency('httparty', '~> 0.8.1')
17
- s.add_runtime_dependency('hashie', '~> 1.2.0')
18
-
19
- s.add_development_dependency 'rspec'
20
- s.add_development_dependency 'webmock'
21
-
22
-
23
- s.rubyforge_project = s.name
24
-
25
- s.files = `git ls-files`.split("\n")
26
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
- s.require_paths = ["lib"]
29
- end
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bigcartel/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "bigcartel"
7
+ s.version = BigCartel::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Matt Anderson"]
10
+ s.email = ["matt@tonkapark.com"]
11
+ s.homepage = "http://tonkapark.com"
12
+ s.summary = %q{Ruby wrapper for the Big Cartel API}
13
+ s.description = %q{A Ruby wrapper for the Big Cartel External REST API}
14
+
15
+
16
+ s.add_runtime_dependency('httparty', '~> 0.8.1')
17
+ s.add_runtime_dependency('hashie', '~> 1.2.0')
18
+
19
+ s.add_development_dependency 'rspec'
20
+ s.add_development_dependency 'webmock'
21
+
22
+
23
+ s.rubyforge_project = s.name
24
+
25
+ s.files = `git ls-files`.split("\n")
26
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
+ s.require_paths = ["lib"]
29
+ end
@@ -1,81 +1,81 @@
1
- require 'httparty'
2
- require 'hashie'
3
-
4
- module BigCartel
5
-
6
- class Client
7
-
8
- include HTTParty
9
- base_uri "http://api.bigcartel.com"
10
- headers 'Content-Type' => 'application/json'
11
-
12
- def initialize(options={})
13
- end
14
-
15
- def self.fetch(path)
16
- response = get(path)
17
- Hashie::Mash.new(response)
18
- end
19
-
20
- def self.list(path, opts={})
21
- # opts = { :limit => 100 }.merge opts
22
-
23
- response = get(path, :query => {'limit' => opts[:limit]})
24
- response.map { |c| Hashie::Mash.new(c)}
25
- end
26
-
27
-
28
- def store(account, opts={})
29
- opts = { :show_products => true, :product_limit => 100 }.merge opts
30
-
31
- store = self.class.fetch("/#{account}/store.js")
32
- store.account = account
33
- store.products = opts[:show_products] ? products(account,{:limit => opts[:product_limit]}) : {}
34
- store
35
- end
36
-
37
-
38
- def products(account, opts={})
39
- opts = { :limit => 100 }.merge opts
40
- products = self.class.list("/#{account}/products.js", opts)
41
-
42
- products.each do |p|
43
- p.images = images_helper(p.images)
44
- p.has_default_option = has_default_option?(p.options)
45
- p.option = p.options.first
46
- end
47
-
48
- products
49
- end
50
-
51
-
52
- def page(account, permalink=nil)
53
- self.class.fetch(URI.encode("/#{account}/page/#{permalink}.js"))
54
- end
55
-
56
- ##############################################
57
- ## HELPERS
58
- private
59
-
60
- def has_default_option?(options)
61
- names = {}
62
- if options.size <= 1
63
- names = options.collect {|x| x.name }
64
- end
65
- return names.include?("Default")
66
- end
67
-
68
- def images_helper(images)
69
- output = Array.new
70
- images.each do |img|
71
- url_parts = img.url.scan(/(http:\/\/cache(0|1).bigcartel.com\/product_images\/\d*\/)(.*).(jpg|png|gif|jpeg)/i)
72
-
73
- img.thumb = "#{url_parts[0][0]}75.#{url_parts[0][3]}"
74
- img.medium = "#{url_parts[0][0]}175.#{url_parts[0][3]}"
75
- img.large = "#{url_parts[0][0]}300.#{url_parts[0][3]}"
76
- end
77
- images
78
- end
79
-
80
- end
81
- end
1
+ require 'httparty'
2
+ require 'hashie'
3
+
4
+ module BigCartel
5
+
6
+ class Client
7
+
8
+ include HTTParty
9
+ base_uri "http://api.bigcartel.com"
10
+ headers 'Content-Type' => 'application/json'
11
+
12
+ def initialize(options={})
13
+ end
14
+
15
+ def self.fetch(path)
16
+ response = get(path)
17
+ Hashie::Mash.new(response)
18
+ end
19
+
20
+ def self.list(path, opts={})
21
+ # opts = { :limit => 100 }.merge opts
22
+
23
+ response = get(path, :query => {'limit' => opts[:limit]})
24
+ response.map { |c| Hashie::Mash.new(c)}
25
+ end
26
+
27
+
28
+ def store(account, opts={})
29
+ opts = { :show_products => true, :product_limit => 100 }.merge opts
30
+
31
+ store = self.class.fetch("/#{account}/store.js")
32
+ store.account = account
33
+ store.products = opts[:show_products] ? products(account,{:limit => opts[:product_limit]}) : {}
34
+ store
35
+ end
36
+
37
+
38
+ def products(account, opts={})
39
+ opts = { :limit => 100 }.merge opts
40
+ products = self.class.list("/#{account}/products.js", opts)
41
+
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
46
+ end
47
+
48
+ products
49
+ end
50
+
51
+
52
+ def page(account, permalink=nil)
53
+ self.class.fetch(URI.encode("/#{account}/page/#{permalink}.js"))
54
+ end
55
+
56
+ ##############################################
57
+ ## HELPERS
58
+ private
59
+
60
+ def has_default_option?(options)
61
+ names = {}
62
+ if options.size <= 1
63
+ names = options.collect {|x| x.name }
64
+ end
65
+ return names.include?("Default")
66
+ end
67
+
68
+ def images_helper(images)
69
+ output = Array.new
70
+ images.each do |img|
71
+ url_parts = img.url.scan(/(http:\/\/cache(0|1).bigcartel.com\/product_images\/\d*\/)(.*).(jpg|png|gif|jpeg)/i)
72
+
73
+ img.thumb = "#{url_parts[0][0]}75.#{url_parts[0][3]}"
74
+ img.medium = "#{url_parts[0][0]}175.#{url_parts[0][3]}"
75
+ img.large = "#{url_parts[0][0]}300.#{url_parts[0][3]}"
76
+ end
77
+ images
78
+ end
79
+
80
+ end
81
+ end
@@ -1,3 +1,3 @@
1
- module BigCartel
2
- VERSION = "1.0.0"
3
- end
1
+ module BigCartel
2
+ VERSION = "1.0.1"
3
+ end
data/lib/bigcartel.rb CHANGED
@@ -1,22 +1,22 @@
1
- require 'bigcartel/client'
2
-
3
- module BigCartel
4
- class << self
5
- # Alias for BigCartel::Client.new
6
- #
7
- # @return [BigCartel::Client]
8
- def new(options={})
9
- BigCartel::Client.new(options)
10
- end
11
-
12
- # Delegate to Twitter::Client
13
- def method_missing(method, *args, &block)
14
- return super unless new.respond_to?(method)
15
- new.send(method, *args, &block)
16
- end
17
-
18
- def respond_to?(method, include_private=false)
19
- new.respond_to?(method, include_private) || super(method, include_private)
20
- end
21
- end
22
- end
1
+ require 'bigcartel/client'
2
+
3
+ module BigCartel
4
+ class << self
5
+ # Alias for BigCartel::Client.new
6
+ #
7
+ # @return [BigCartel::Client]
8
+ def new(options={})
9
+ BigCartel::Client.new(options)
10
+ end
11
+
12
+ # Delegate to Twitter::Client
13
+ def method_missing(method, *args, &block)
14
+ return super unless new.respond_to?(method)
15
+ new.send(method, *args, &block)
16
+ end
17
+
18
+ def respond_to?(method, include_private=false)
19
+ new.respond_to?(method, include_private) || super(method, include_private)
20
+ end
21
+ end
22
+ end