tucano 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format Fuubar
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+
9
+ #I'm not 100% sure on how do to proper HTTP request yet, so I used Vacuum to interact with the API and parsed the results.
10
+ gem 'vacuum'
11
+
12
+ group :development do
13
+ gem "rspec", "~> 2.8.0"
14
+ gem "rdoc", "~> 3.12"
15
+ gem "bundler"
16
+ gem "jeweler", "~> 1.8.3"
17
+ gem "rcov", "0.9.11"
18
+ gem "fuubar"
19
+ gem "awesome_print"
20
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.7)
5
+ awesome_print (1.0.2)
6
+ diff-lcs (1.1.3)
7
+ faraday (0.7.6)
8
+ addressable (~> 2.2)
9
+ multipart-post (~> 1.1)
10
+ rack (~> 1.1)
11
+ fuubar (1.0.0)
12
+ rspec (~> 2.0)
13
+ rspec-instafail (~> 0.2.0)
14
+ ruby-progressbar (~> 0.0.10)
15
+ git (1.2.5)
16
+ jeweler (1.8.3)
17
+ bundler (~> 1.0)
18
+ git (>= 1.2.5)
19
+ rake
20
+ rdoc
21
+ json (1.6.6)
22
+ multipart-post (1.1.5)
23
+ nokogiri (1.5.2)
24
+ rack (1.4.1)
25
+ rake (0.9.2.2)
26
+ rcov (0.9.11)
27
+ rdoc (3.12)
28
+ json (~> 1.4)
29
+ rspec (2.8.0)
30
+ rspec-core (~> 2.8.0)
31
+ rspec-expectations (~> 2.8.0)
32
+ rspec-mocks (~> 2.8.0)
33
+ rspec-core (2.8.0)
34
+ rspec-expectations (2.8.0)
35
+ diff-lcs (~> 1.1.2)
36
+ rspec-instafail (0.2.4)
37
+ rspec-mocks (2.8.0)
38
+ ruby-progressbar (0.0.10)
39
+ vacuum (0.2.2)
40
+ addressable (~> 2.2)
41
+ faraday (~> 0.7.6)
42
+ nokogiri (~> 1.5)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ awesome_print
49
+ bundler
50
+ fuubar
51
+ jeweler (~> 1.8.3)
52
+ rcov (= 0.9.11)
53
+ rdoc (~> 3.12)
54
+ rspec (~> 2.8.0)
55
+ vacuum
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Mark Provan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Tucano
2
+ [![Build Status](https://secure.travis-ci.org/markprovan/tucano.png?branch=master)](http://travis-ci.org/markprovan/tucano)
3
+
4
+ When taking part in a hackathon recently I was looking for a simple gem to pull products from Amazon based on a search string. I found a few but none did exactly what I wanted, so I built this one. Tucano simply gives you an array of items with basic attributes.
5
+
6
+ ### Installation
7
+
8
+ `gem install tucano`
9
+
10
+ ### Usage
11
+ Before you start you will need an Amazon Product Advertising key, which you can aquire by signing up [here](https://affiliate-program.amazon.co.uk/gp/advertising/api/detail/main.html). You will also need and Affiliate Tag. Get one [here](https://affiliate-program.amazon.co.uk/).
12
+
13
+ Once all thats set up you can create a new Tucano Search object using your details:
14
+
15
+ `tucano = Tucano::ProductSearch.new('api-key', 'secret, affiliate-tag')`
16
+
17
+ Now it's as simple as searching:
18
+
19
+ `products = tucano.search("Ruby Book")`
20
+
21
+ This returns an Array of Tucano::Items with names, prices, currency, category and a large image.
22
+
23
+ `product = products.first`
24
+
25
+ => `Tucano::Item:0x007fb5e40edde0 @name="Ruby on Rails 3 Tutorial: Learn Rails by Example (Addison-Wesley Professional Ruby Series)", @category="Book", @price="3999", @currency="USD", @image="http://ecx.images-amazon.com/images/I/51TEzGZ%2BggL.jpg"`
26
+
27
+ So you can do stuff like:
28
+
29
+ `product.name => "Ruby on Rails 3 Tutorial: Learn Rails by Example (Addison-Wesley Professional Ruby Series)"
30
+
31
+ `Price #{product.price/100} #{product.currency} => 39.99USD`
32
+
33
+ The gem is still slightly unstable but I hope that I (or indeed you guys) can sort it out over the next few days.
34
+
35
+ ### Contributing to Tucano
36
+
37
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
38
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
39
+ * Fork the project.
40
+ * Start a feature/bugfix branch.
41
+ * Commit and push until you are happy with your contribution.
42
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
43
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
44
+
45
+ ## Copyright
46
+
47
+ Copyright (c) 2012 Mark Provan. See LICENSE.txt for
48
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "tucano"
18
+ gem.homepage = "http://github.com/markprovan/tucano"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A simple solution to pull products from Amazon.}
21
+ gem.description = %Q{When taking part in a hackathon recently I was looking for a simple gem to pull products from Amazon based on a search string. I found a few but none did exactly what I wanted, so I built this one.}
22
+ gem.email = "markgprovan@gmail.com"
23
+ gem.authors = ["Mark Provan"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "tucano #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/tucano.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'vacuum'
2
+ require 'awesome_print'
3
+
4
+ module Tucano
5
+ class Item
6
+ attr_accessor :name, :description, :price, :currency, :image, :category
7
+ end
8
+
9
+ class ProductSearch
10
+ def initialize(key, secret, associate_tag)
11
+ @request = ::Vacuum.new(:product_advertising)
12
+ @request.configure do |config|
13
+ config.key = key
14
+ config.secret = secret
15
+ config.tag = associate_tag
16
+ end
17
+ end
18
+
19
+ def convert_to_product(item)
20
+ i = Item.new
21
+ i.name = item["ItemAttributes"]["Title"]
22
+ i.category = item["ItemAttributes"]["ProductGroup"]
23
+ i.price = item["ItemAttributes"]["ListPrice"]["Amount"]
24
+ i.currency = item["ItemAttributes"]["ListPrice"]["CurrencyCode"]
25
+ #i.description = item["EditorialReviews"]["EditorialReview"]["Content"]
26
+ i.image = item["LargeImage"]["URL"]
27
+ return i
28
+ end
29
+
30
+ def parse_response(response)
31
+ products = []
32
+ response.find("Item") do |item|
33
+ product = convert_to_product(item)
34
+ products << product
35
+ end
36
+ products
37
+ end
38
+
39
+ def search(query)
40
+ rg = %W{ItemAttributes EditorialReview Images}
41
+ @request.build(:operation => "ItemSearch",
42
+ :search_index => "All",
43
+ :keywords => query,
44
+ :response_group => rg)
45
+ products = []
46
+ response = @request.get
47
+ products = parse_response(response)
48
+ products
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'tucano'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Tucano" do
4
+ before do
5
+ #Note: API keys here are for our testing account. Sign up for a Product Advertising Account to recieve your API Keys. The third attribute is your Associate ID.
6
+ @tucano = Tucano::ProductSearch.new('AKIAJ5HO5KJC4OISP7WQ', 'QqaxJ09GZbMZPcETeDOOoSQrdm4llVIf3jg1q8+g', 'voicsear-20')
7
+ @products = @tucano.search("Rails")
8
+ end
9
+ it "should be create a request when given a query string" do
10
+ @tucano.should be_an_instance_of Tucano::ProductSearch
11
+ end
12
+
13
+ it "should return an array" do
14
+ @products.should be_an_instance_of Array
15
+ end
16
+
17
+ it "should return an array of items" do
18
+ @products.first.should be_an_instance_of Tucano::Item
19
+ end
20
+
21
+ it "should set the attributes of each item" do
22
+ item = @products.first
23
+ item.name.length.should be > 0
24
+ item.image.length.should be > 0
25
+ item.category.length.should be > 0
26
+ item.currency.should == "USD"
27
+ end
28
+
29
+ it "should return an empty array when no results are found" do
30
+ @tucano.search("sofewfbewiofbewofinalskdn fnwlefbkf").should == []
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tucano
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mark Provan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: vacuum
16
+ requirement: &70168055257520 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70168055257520
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70168055256860 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.8.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70168055256860
36
+ - !ruby/object:Gem::Dependency
37
+ name: rdoc
38
+ requirement: &70168055299760 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '3.12'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70168055299760
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &70168055299160 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70168055299160
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &70168055298260 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.8.3
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70168055298260
69
+ - !ruby/object:Gem::Dependency
70
+ name: rcov
71
+ requirement: &70168055297160 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - =
75
+ - !ruby/object:Gem::Version
76
+ version: 0.9.11
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70168055297160
80
+ - !ruby/object:Gem::Dependency
81
+ name: fuubar
82
+ requirement: &70168055295860 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70168055295860
91
+ - !ruby/object:Gem::Dependency
92
+ name: awesome_print
93
+ requirement: &70168055293640 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70168055293640
102
+ description: When taking part in a hackathon recently I was looking for a simple gem
103
+ to pull products from Amazon based on a search string. I found a few but none did
104
+ exactly what I wanted, so I built this one.
105
+ email: markgprovan@gmail.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files:
109
+ - LICENSE.txt
110
+ - README.md
111
+ files:
112
+ - .document
113
+ - .rspec
114
+ - .travis.yml
115
+ - Gemfile
116
+ - Gemfile.lock
117
+ - LICENSE.txt
118
+ - README.md
119
+ - Rakefile
120
+ - VERSION
121
+ - lib/tucano.rb
122
+ - spec/spec_helper.rb
123
+ - spec/tucano_spec.rb
124
+ homepage: http://github.com/markprovan/tucano
125
+ licenses:
126
+ - MIT
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ segments:
138
+ - 0
139
+ hash: -890763358300281862
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 1.8.15
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: A simple solution to pull products from Amazon.
152
+ test_files: []