amzwish 0.0.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,16 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ load '../keys.rb'
4
+
5
+ SAMPLE_DIR="uk"
6
+ PAGE_1 = "34VGL4IX1RMYO?reveal=unpurchased&filter=all&sort=date-added&layout=compact"
7
+ PAGE_2 = "ref=cm_wl_sortbar_o_n_page_4?_encoding=UTF8&filter=all&sort=date-added&layout=compact&reveal=unpurchased&page=4"
8
+ PAGE_3 = "ref=cm_wl_sortbar_o_page_2?_encoding=UTF8&filter=all&sort=date-added&layout=compact&reveal=unpurchased&page=2"
9
+ PAGE_4 = "ref=cm_wl_sortbar_o_page_3?_encoding=UTF8&filter=all&sort=date-added&layout=compact&reveal=unpurchased&page=3"
10
+
11
+ doc = Nokogiri::HTML(open(File.join(SAMPLE_DIR, PAGE_1)))
12
+ doc.xpath('//tbody[@class="itemWrapper"]').each do |e|
13
+ name = e.xpath('.//a[1]/text()').to_s
14
+ ref_num = e.xpath("@name").to_s.split('.').last
15
+ p "#{ref_num} : #{name}"
16
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module Amzwish
4
+ describe Book do
5
+ describe "equality" do
6
+ let(:fixture){ Book.new("Title", "123") }
7
+ describe "is based on asin number" do
8
+ example "books with the same asin number are equal" do
9
+ (fixture == Book.new("Title", "123")).should == true
10
+ end
11
+ example "books with different asin numbers are not equal" do
12
+ (fixture == Book.new("Title", "321")).should == false
13
+ end
14
+ example "books are not equal to things that are not books" do
15
+ (fixture == "Title").should == false
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require 'open-uri'
3
+
4
+ module Amzwish
5
+ describe Wishlist::Page do
6
+ describe "an empty page" do
7
+ let(:fixture){ create_page_from("empty.html") }
8
+ it "should not have another page" do
9
+ fixture.should_not be_has_next
10
+ end
11
+
12
+ it "should_not_have_any_books" do
13
+ fixture.books.should be_empty
14
+ end
15
+ end
16
+ describe "the first page of many" do
17
+ let(:fixture){ create_page_from("multipage-page1.html") }
18
+ it "should have another page" do
19
+ fixture.should be_has_next
20
+ end
21
+ it "should have books on it" do
22
+ fixture.books.should_not be_empty
23
+ end
24
+
25
+ it "should have iterable books" do
26
+ books = fixture.books
27
+ end
28
+ end
29
+
30
+ describe "the last page of many" do
31
+ let(:fixture){ create_page_from("multipage-page4.html") }
32
+ it "should not have another page" do
33
+ fixture.should_not be_has_next
34
+ end
35
+ end
36
+
37
+ describe "a page with one item on it" do
38
+ let(:fixture){ create_page_from("single-item.html") }
39
+ it "should return the correct book" do
40
+ fixture.books.first.should == Book.new("Language Myths", "0140260234")
41
+ end
42
+ end
43
+
44
+
45
+ def create_page_from(html_file)
46
+ Wishlist::Page.new(open(File.join(PROJECT_DIR, "samples", "uk", html_file)))
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ module Amzwish
4
+ module Services
5
+ PREVENT_WEB_REQUESTS = false
6
+
7
+ describe WebsiteWrapper do
8
+
9
+ let(:mock_client){ mock("rest_client")}
10
+ let(:fixture){ WebsiteWrapper.new(mock_client) }
11
+
12
+ describe "getting wishlist id" do
13
+ describe "wishlist not found" do
14
+ it "should return an empty array" do
15
+ mock_client.should_receive(:post).with("address@email.com").and_return({:code => 200})
16
+ fixture.find_for("address@email.com").should == []
17
+ end
18
+ end
19
+ describe "single wishlist found" do
20
+ it "should return an array with one hash" do
21
+ mock_client.should_receive(:post).with("address@email.com").and_return(
22
+ { :code => 302,
23
+ :headers=> {
24
+ :location=>"http://www.amazon.co.uk/gp/registry/registry.html/276-3987950-0414363?ie=UTF8&type=wishlist&id=WISH_LIST_ID"}
25
+ })
26
+ fixture.find_for("address@email.com").should == [{:id=>"WISH_LIST_ID"}]
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "getting wishlist content html" do
32
+ describe "getting page 1" do
33
+ it "should return the page as a string" do
34
+ mock_client.should_receive(:get).with("WISH_LIST_ID", 1).and_return("Page Content")
35
+ fixture.get_page("WISH_LIST_ID", 1).should == "Page Content"
36
+ end
37
+ end
38
+ end
39
+
40
+ context "examples that make actual web requests" do
41
+ let(:fixture){ WebsiteWrapper.new() }
42
+ example "get wishlist html" do
43
+ fixture.get_page("34VGL4IX1RMYO", 1).should =~ /Chris Tinning/
44
+ end
45
+ example "get wishlist id" do
46
+ fixture.find_for("chris.tinning@gmail.com").should == [{:id=>"34VGL4IX1RMYO"}]
47
+ end
48
+ end unless PREVENT_WEB_REQUESTS
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'open-uri'
3
+
4
+ module Amzwish
5
+ describe Wishlist do
6
+ context "empty wishlist" do
7
+ let(:mock_wrapper){ mock_website_wrapper( %w{ empty.html } ) }
8
+ let(:fixture){ Wishlist.new("address@email.com", mock_wrapper) }
9
+ it "returns an empty list of books" do
10
+ fixture.books.size.should == 0
11
+ end
12
+ end
13
+
14
+ context "single item wishlist" do
15
+ let(:mock_wrapper){ mock_website_wrapper( %w{ single-item.html } ) }
16
+ let(:fixture){ Wishlist.new("address@email.com", mock_wrapper) }
17
+ it "returns a list of books" do
18
+ books = fixture.books
19
+ books.size.should == 1
20
+ books[0].title.should == "Language Myths"
21
+ end
22
+
23
+ it "should be enumerable" do
24
+ books = []
25
+ fixture.each_book{|b| books << b}
26
+ books.size.should == 1
27
+ end
28
+ end
29
+
30
+ context "multipage wishlist" do
31
+ let(:mock_wrapper){ mock_website_wrapper(%w{ multipage-page1.html multipage-page2.html multipage-page3.html multipage-page4.html}) }
32
+ let(:fixture){ Wishlist.new("address@email.com", mock_wrapper) }
33
+ it "returns a list of books" do
34
+ fixture = Wishlist.new("address@email.com", mock_wrapper)
35
+ fixture.books.size.should be > 0
36
+ end
37
+ end
38
+
39
+ def mock_website_wrapper(html_files, wishlist_id = "WISHLIST-ID", email = "address@email.com")
40
+ mock_wrapper = mock(Services::WebsiteWrapper)
41
+ mock_wrapper.should_receive(:find_for).with(email).and_return([{:id=>wishlist_id}])
42
+ html_files.each_with_index do |f, i|
43
+ page_num = i+1
44
+ page = open(File.join(PROJECT_DIR, "samples","uk", f )).read
45
+ mock_wrapper.should_receive(:get_page).with( wishlist_id, page_num).and_return(page)
46
+ end
47
+ mock_wrapper
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require "spec"
4
+ require "amzwish"
5
+
6
+ PROJECT_DIR = File.join(File.dirname(__FILE__), "..")
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amzwish
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ version: 0.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Chris Tinning
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-10 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: nokogiri
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :development
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: nokogiri
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ type: :runtime
55
+ version_requirements: *id003
56
+ - !ruby/object:Gem::Dependency
57
+ name: rest-client
58
+ prerelease: false
59
+ requirement: &id004 !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ type: :runtime
67
+ version_requirements: *id004
68
+ description: Since you can no longer access wishlists through the Amazon api this gem aims to address this by combining some screen scraping with api calls.
69
+ email: chris.tinning@gmail.com
70
+ executables:
71
+ - amzwish
72
+ - amzwish
73
+ extensions: []
74
+
75
+ extra_rdoc_files:
76
+ - LICENSE
77
+ - README.rdoc
78
+ files:
79
+ - .autotest
80
+ - .gitignore
81
+ - .rvmrc
82
+ - LICENSE
83
+ - README.rdoc
84
+ - Rakefile
85
+ - VERSION
86
+ - amzwish.gemspec
87
+ - autotest/discover.rb
88
+ - bin/amzwish
89
+ - lib/amzwish.rb
90
+ - lib/amzwish/book.rb
91
+ - lib/amzwish/services/website_wrapper.rb
92
+ - lib/amzwish/wishlist.rb
93
+ - pkg/amzwish-0.0.0.gem
94
+ - samples/create_key_sample.rb
95
+ - samples/uk/empty.html
96
+ - samples/uk/multipage-page1.html
97
+ - samples/uk/multipage-page2.html
98
+ - samples/uk/multipage-page3.html
99
+ - samples/uk/multipage-page4.html
100
+ - samples/uk/single-item.html
101
+ - samples/wishlist_scrape_sample.rb
102
+ - spec/amzwish/book_spec.rb
103
+ - spec/amzwish/page_spec.rb
104
+ - spec/amzwish/services/website_wrapper_spec.rb
105
+ - spec/amzwish/wishlist_spec.rb
106
+ - spec/spec.opts
107
+ - spec/spec_helper.rb
108
+ has_rdoc: true
109
+ homepage: http://github.com/tinman/amzwish
110
+ licenses: []
111
+
112
+ post_install_message:
113
+ rdoc_options:
114
+ - --charset=UTF-8
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ requirements: []
132
+
133
+ rubyforge_project:
134
+ rubygems_version: 1.3.6
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Get at Amazon wishlists combines scraping and the api
138
+ test_files:
139
+ - spec/amzwish/book_spec.rb
140
+ - spec/amzwish/page_spec.rb
141
+ - spec/amzwish/services/website_wrapper_spec.rb
142
+ - spec/amzwish/wishlist_spec.rb
143
+ - spec/spec_helper.rb