amazon_seller_central 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +24 -0
- data/Gemfile.lock +62 -0
- data/Guardfile +10 -0
- data/LICENSE.txt +20 -0
- data/README.md +54 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/lib/amazon_seller_central/configuration.rb +15 -0
- data/lib/amazon_seller_central/feedback.rb +13 -0
- data/lib/amazon_seller_central/feedback_page.rb +81 -0
- data/lib/amazon_seller_central/mechanizer.rb +47 -0
- data/lib/amazon_seller_central.rb +18 -0
- data/spec/amazon_seller_central_spec.rb +33 -0
- data/spec/lib/feedback_page_spec.rb +68 -0
- data/spec/lib/feedback_spec.rb +14 -0
- data/spec/lib/mechanizer_spec.rb +45 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/sample_pages/Feedback Manager.html +1361 -0
- data/spec/support/sample_pages/Feedback Page 1.html +2219 -0
- data/spec/support/sample_pages/Feedback Page 2.html +2224 -0
- data/spec/support/sample_pages/Feedback Page Last.html +1810 -0
- data/spec/support/sample_pages/Seller Central Homepage.html +2187 -0
- data/spec/support/sample_pages/Seller Central Redirect.html +750 -0
- data/spec/support/sample_pages/Seller Central.html +16 -0
- data/spec/support/sample_pages.rb +19 -0
- metadata +299 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "mechanize", ">= 1.0.0"
|
4
|
+
# Add dependencies required to use your gem here.
|
5
|
+
# Example:
|
6
|
+
# gem "activesupport", ">= 2.3.5"
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "rspec", "~> 2.3.0"
|
12
|
+
gem "bundler", "~> 1.0.0"
|
13
|
+
gem "jeweler", "~> 1.6.3"
|
14
|
+
gem "rcov", ">= 0"
|
15
|
+
gem 'yard'
|
16
|
+
gem 'guard'
|
17
|
+
gem 'guard-rspec'
|
18
|
+
gem 'rb-inotify', '>= 0.8.5'
|
19
|
+
gem 'libnotify'
|
20
|
+
gem 'ffi'
|
21
|
+
gem 'faker'
|
22
|
+
gem 'fakeweb'
|
23
|
+
gem 'ruby-debug'
|
24
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
columnize (0.3.2)
|
5
|
+
diff-lcs (1.1.2)
|
6
|
+
faker (0.9.5)
|
7
|
+
i18n (~> 0.4)
|
8
|
+
fakeweb (1.3.0)
|
9
|
+
ffi (1.0.9)
|
10
|
+
git (1.2.5)
|
11
|
+
guard (0.5.0)
|
12
|
+
thor (~> 0.14.6)
|
13
|
+
guard-rspec (0.4.0)
|
14
|
+
guard (>= 0.4.0)
|
15
|
+
i18n (0.6.0)
|
16
|
+
jeweler (1.6.3)
|
17
|
+
bundler (~> 1.0)
|
18
|
+
git (>= 1.2.5)
|
19
|
+
rake
|
20
|
+
libnotify (0.5.6)
|
21
|
+
linecache (0.43)
|
22
|
+
mechanize (1.0.0)
|
23
|
+
nokogiri (>= 1.2.1)
|
24
|
+
nokogiri (1.4.4)
|
25
|
+
rake (0.9.2)
|
26
|
+
rb-inotify (0.8.5)
|
27
|
+
ffi (>= 0.5.0)
|
28
|
+
rcov (0.9.9)
|
29
|
+
rspec (2.3.0)
|
30
|
+
rspec-core (~> 2.3.0)
|
31
|
+
rspec-expectations (~> 2.3.0)
|
32
|
+
rspec-mocks (~> 2.3.0)
|
33
|
+
rspec-core (2.3.1)
|
34
|
+
rspec-expectations (2.3.0)
|
35
|
+
diff-lcs (~> 1.1.2)
|
36
|
+
rspec-mocks (2.3.0)
|
37
|
+
ruby-debug (0.10.4)
|
38
|
+
columnize (>= 0.1)
|
39
|
+
ruby-debug-base (~> 0.10.4.0)
|
40
|
+
ruby-debug-base (0.10.4)
|
41
|
+
linecache (>= 0.3)
|
42
|
+
thor (0.14.6)
|
43
|
+
yard (0.7.2)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
ruby
|
47
|
+
|
48
|
+
DEPENDENCIES
|
49
|
+
bundler (~> 1.0.0)
|
50
|
+
faker
|
51
|
+
fakeweb
|
52
|
+
ffi
|
53
|
+
guard
|
54
|
+
guard-rspec
|
55
|
+
jeweler (~> 1.6.3)
|
56
|
+
libnotify
|
57
|
+
mechanize (>= 1.0.0)
|
58
|
+
rb-inotify (>= 0.8.5)
|
59
|
+
rcov
|
60
|
+
rspec (~> 2.3.0)
|
61
|
+
ruby-debug
|
62
|
+
yard
|
data/Guardfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :cli => '-d -c -f doc', :version => 2, :notification => false do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch(%r{^lib/amazon_seller_central/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
8
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
9
|
+
watch('spec/spec_helper.rb') { "spec" }
|
10
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Optoro, Inc.
|
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,54 @@
|
|
1
|
+
# amazon_seller_central
|
2
|
+
|
3
|
+
This gem is intended to wrap Amazon's SellerCentral pages with a Ruby API. Currently this gem supports accessing buyer feedback only.
|
4
|
+
|
5
|
+
## Configuration
|
6
|
+
|
7
|
+
You need to provide the email address and password you use to login to
|
8
|
+
Amazon SellerCentral via the `AmazonSellerCentral.configure` method:
|
9
|
+
|
10
|
+
AmazonSellerCentral.configure do |config|
|
11
|
+
config.login_email "seller@mydomain.com"
|
12
|
+
config.login_password "secret"
|
13
|
+
end
|
14
|
+
|
15
|
+
## Feedback Access
|
16
|
+
|
17
|
+
After configuration, the easiest way to access your feedback is using
|
18
|
+
the block form:
|
19
|
+
|
20
|
+
AmazonSellerCentral::FeedbackPage.each_page do |page|
|
21
|
+
feedbacks = page.feedbacks
|
22
|
+
feedback = feedbacks.first
|
23
|
+
|
24
|
+
feedback.arrived_on_time # true, false, or nil
|
25
|
+
feedback.comments # The feedback left ("Excellent transaction!")
|
26
|
+
feedback.customer_service # true, false, or nil
|
27
|
+
feedback.date # A Time object
|
28
|
+
feedback.item_as_described # true, false, or nil
|
29
|
+
feedback.order_id # An Amazon Order ID, like 123-1234567-1234567
|
30
|
+
feedback.rater_email # something_scrambled@marketplace.amazon.com
|
31
|
+
feedback.rater_role # typically "Buyer"
|
32
|
+
feedback.rating # an integer, 1 - 5
|
33
|
+
end
|
34
|
+
|
35
|
+
## ToDo
|
36
|
+
|
37
|
+
* Access to more sections of Amazon SellerCentral.
|
38
|
+
* Rework Mechanize access to allow parallel / thread-safe usage
|
39
|
+
* **Note**: This library is likely not thread-safe. (It's untested)
|
40
|
+
|
41
|
+
## Contributing to amazon_seller_central
|
42
|
+
|
43
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
44
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
45
|
+
* Fork the project
|
46
|
+
* Start a feature/bugfix branch
|
47
|
+
* Commit and push until you are happy with your contribution
|
48
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
49
|
+
* 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.
|
50
|
+
|
51
|
+
## Copyright
|
52
|
+
|
53
|
+
Copyright (c) 2011 Optoro, Inc. See LICENSE.txt for
|
54
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
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 = "amazon_seller_central"
|
18
|
+
gem.homepage = "http://github.com/optoro/amazon_seller_central"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Ruby API to access Amazon's SellerCentral}
|
21
|
+
gem.description = %Q{This gem is intended to wrap Amazon's SellerCentral pages with a Ruby API. Currently this gem supports accessing buyer feedback only.}
|
22
|
+
gem.email = "dev@optoro.com"
|
23
|
+
gem.authors = ["optoro"]
|
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 'yard'
|
42
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module AmazonSellerCentral
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :login_email, :login_password
|
4
|
+
|
5
|
+
def login_email(val=nil)
|
6
|
+
return @login_email unless val
|
7
|
+
@login_email = val
|
8
|
+
end
|
9
|
+
|
10
|
+
def login_password(val=nil)
|
11
|
+
return @login_password unless val
|
12
|
+
@login_password = val
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module AmazonSellerCentral
|
2
|
+
class FeedbackPage
|
3
|
+
attr_accessor :body
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
@page = options.delete(:page)
|
7
|
+
@body = @page ? @page.body : ""
|
8
|
+
end
|
9
|
+
|
10
|
+
def has_next?
|
11
|
+
@has_next ||= @page.search('a').map(&:text).grep(/Next/).count > 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def last_page?
|
15
|
+
!has_next?
|
16
|
+
end
|
17
|
+
|
18
|
+
def next_page
|
19
|
+
@next_page ||= begin
|
20
|
+
raise NoNextPageAvailableError unless has_next?
|
21
|
+
page = AmazonSellerCentral.mechanizer.follow_link_with(:text => 'Next')
|
22
|
+
FeedbackPage.new(:page => page)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse
|
27
|
+
rows = @page.search('.//table[@width="100%"]').first.search('.//tr')
|
28
|
+
rows[1..-1].map do |row|
|
29
|
+
feedback_row_to_object(row)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
alias feedbacks parse
|
33
|
+
|
34
|
+
module ClassMethods
|
35
|
+
|
36
|
+
def load_first_page
|
37
|
+
AmazonSellerCentral.mechanizer.login_to_seller_central
|
38
|
+
feedback_home = AmazonSellerCentral.mechanizer.follow_link_with(:text => "Feedback")
|
39
|
+
feedback_page = AmazonSellerCentral.mechanizer.follow_link_with(:text => "View all your feedback")
|
40
|
+
FeedbackPage.new(:page => feedback_page)
|
41
|
+
end
|
42
|
+
|
43
|
+
def load_all_pages
|
44
|
+
pages = [load_first_page]
|
45
|
+
while pages.last.has_next?
|
46
|
+
pages << pages.last.next_page
|
47
|
+
yield pages.last if block_given?
|
48
|
+
end
|
49
|
+
pages
|
50
|
+
end
|
51
|
+
alias each_page load_all_pages
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
extend ClassMethods
|
56
|
+
|
57
|
+
class NoNextPageAvailableError < StandardError
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
def feedback_row_to_object(row)
|
62
|
+
data = row.search('.//td').map(&:text)
|
63
|
+
{
|
64
|
+
:date => Time.parse(data[0]),
|
65
|
+
:rating => data[1].to_i,
|
66
|
+
:comments => data[2].gsub(/\n\nRespond$/,''),
|
67
|
+
:arrived_on_time => yes_no_nil(data[3]),
|
68
|
+
:item_as_described => yes_no_nil(data[4]),
|
69
|
+
:customer_service => yes_no_nil(data[5]),
|
70
|
+
:order_id => data[6],
|
71
|
+
:rater_email => data[7].gsub(/\s/, ''), # has a lot of \n\n\t\t crap
|
72
|
+
:rater_role => data[8]
|
73
|
+
}.inject(Feedback.new){|fb, (k,v)| fb.send("#{k}=", v); fb }
|
74
|
+
end
|
75
|
+
|
76
|
+
def yes_no_nil(v)
|
77
|
+
return nil if v == "-"
|
78
|
+
v == "Yes"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
require 'singleton'
|
3
|
+
module AmazonSellerCentral
|
4
|
+
class Mechanizer
|
5
|
+
include Singleton
|
6
|
+
MASQUERADE_AGENTS = ['Mac Safari', 'Mac FireFox', 'Linux Firefox']
|
7
|
+
|
8
|
+
attr_reader :agent, :last_page
|
9
|
+
|
10
|
+
def login_email
|
11
|
+
AmazonSellerCentral.configuration.login_email
|
12
|
+
end
|
13
|
+
|
14
|
+
def login_password
|
15
|
+
AmazonSellerCentral.configuration.login_password
|
16
|
+
end
|
17
|
+
|
18
|
+
def agent
|
19
|
+
@agent ||= Mechanize.new {|ag| ag.user_agent_alias = MASQUERADE_AGENTS.rand }
|
20
|
+
end
|
21
|
+
|
22
|
+
def login_to_seller_central
|
23
|
+
page = agent.get('https://sellercentral.amazon.com/')
|
24
|
+
form = page.form_with(:name => 'signin')
|
25
|
+
|
26
|
+
form.email = login_email
|
27
|
+
form.password = login_password
|
28
|
+
@last_page = form.submit
|
29
|
+
end
|
30
|
+
|
31
|
+
def follow_link_with(options)
|
32
|
+
raise AgentResetError unless last_page
|
33
|
+
link = last_page.link_with(options)
|
34
|
+
raise LinkNotFoundError unless link
|
35
|
+
@last_page = agent.click(link)
|
36
|
+
end
|
37
|
+
|
38
|
+
def reset!
|
39
|
+
@agent = nil
|
40
|
+
@last_page = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
class LinkNotFoundError < StandardError; end
|
44
|
+
class AgentResetError < StandardError; end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'amazon_seller_central/configuration'
|
2
|
+
require 'amazon_seller_central/mechanizer'
|
3
|
+
require 'amazon_seller_central/feedback'
|
4
|
+
require 'amazon_seller_central/feedback_page'
|
5
|
+
|
6
|
+
module AmazonSellerCentral
|
7
|
+
def self.configuration
|
8
|
+
@configuration ||= AmazonSellerCentral::Configuration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configure
|
12
|
+
yield configuration if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.mechanizer
|
16
|
+
AmazonSellerCentral::Mechanizer.instance
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "AmazonSellerCentral" do
|
4
|
+
before :each do
|
5
|
+
@email = Faker::Internet.email
|
6
|
+
@password = Faker::Lorem.words
|
7
|
+
end
|
8
|
+
|
9
|
+
it "allows configuration" do
|
10
|
+
AmazonSellerCentral.configure do |config|
|
11
|
+
config.login_email @email
|
12
|
+
config.login_password @password
|
13
|
+
end
|
14
|
+
|
15
|
+
AmazonSellerCentral.configuration.login_email.should == @email
|
16
|
+
AmazonSellerCentral.configuration.login_password.should == @password
|
17
|
+
end
|
18
|
+
|
19
|
+
it "allows configuration in another format" do
|
20
|
+
AmazonSellerCentral.configure do |config|
|
21
|
+
config.login_email = @email
|
22
|
+
config.login_password = @password
|
23
|
+
end
|
24
|
+
|
25
|
+
AmazonSellerCentral.configuration.login_email.should == @email
|
26
|
+
AmazonSellerCentral.configuration.login_password.should == @password
|
27
|
+
end
|
28
|
+
|
29
|
+
it "allows access to a singleton mechanizer" do
|
30
|
+
mech = AmazonSellerCentral.mechanizer
|
31
|
+
mech.should be_instance_of(AmazonSellerCentral::Mechanizer)
|
32
|
+
end
|
33
|
+
end
|