selldotcom 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +3 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +5 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +20 -0
- data/README.md +27 -0
- data/Rakefile +33 -0
- data/gemspec.yml +17 -0
- data/lib/selldotcom.rb +16 -0
- data/lib/selldotcom/page.rb +31 -0
- data/lib/selldotcom/search.rb +42 -0
- data/lib/selldotcom/version.rb +3 -0
- data/selldotcom.gemspec +15 -0
- data/spec/selldotcom_spec.rb +8 -0
- data/spec/spec_helper.rb +4 -0
- metadata +126 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup rdoc --title "selldotcom Documentation" --protected
|
data/ChangeLog.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Ezekiel Templin
|
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,27 @@
|
|
1
|
+
selldotcom
|
2
|
+
==========
|
3
|
+
|
4
|
+
Please don't use me yet!
|
5
|
+
|
6
|
+
Examples
|
7
|
+
========
|
8
|
+
|
9
|
+
require 'selldotcom'
|
10
|
+
|
11
|
+
Requirements
|
12
|
+
============
|
13
|
+
|
14
|
+
* Typhoeus
|
15
|
+
* Nokogiri
|
16
|
+
|
17
|
+
Install
|
18
|
+
=======
|
19
|
+
|
20
|
+
gem install selldotcom
|
21
|
+
|
22
|
+
Copyright
|
23
|
+
=========
|
24
|
+
|
25
|
+
Copyright (c) 2011 Ezekiel Templin
|
26
|
+
|
27
|
+
See LICENSE.txt for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler'
|
5
|
+
rescue LoadError => e
|
6
|
+
STDERR.puts e.message
|
7
|
+
STDERR.puts "Run `gem install bundler` to install Bundler."
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
Bundler.setup(:development)
|
13
|
+
rescue Bundler::BundlerError => e
|
14
|
+
STDERR.puts e.message
|
15
|
+
STDERR.puts "Run `bundle install` to install missing gems."
|
16
|
+
exit e.status_code
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake'
|
20
|
+
|
21
|
+
require 'ore/tasks'
|
22
|
+
Ore::Tasks.new
|
23
|
+
|
24
|
+
require 'rspec/core/rake_task'
|
25
|
+
RSpec::Core::RakeTask.new
|
26
|
+
|
27
|
+
task :test => :spec
|
28
|
+
task :default => :spec
|
29
|
+
|
30
|
+
|
31
|
+
require 'yard'
|
32
|
+
YARD::Rake::YardocTask.new
|
33
|
+
task :doc => :yard
|
data/gemspec.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
name: selldotcom
|
2
|
+
summary: "Simple interface to Sell.com"
|
3
|
+
description: "A very simplistic interface for Sell.com that allows you to perform searches and parse item information from pages."
|
4
|
+
license: MIT
|
5
|
+
authors: "Ezekiel Templin"
|
6
|
+
email: "ezkl@me.com"
|
7
|
+
homepage: http://rubygems.org/gems/selldotcom
|
8
|
+
has_yard: true
|
9
|
+
|
10
|
+
runtime_dependencies:
|
11
|
+
typhoeus: ~> 0.2.4
|
12
|
+
nokogiri: ~> 1.4.4
|
13
|
+
|
14
|
+
development_dependencies:
|
15
|
+
bundler: ~> 1.0.0
|
16
|
+
yard: ~> 0.6.0
|
17
|
+
rspec: ~> 2.4
|
data/lib/selldotcom.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
require_relative 'selldotcom/version'
|
6
|
+
require_relative 'selldotcom/search'
|
7
|
+
require_relative 'selldotcom/page'
|
8
|
+
|
9
|
+
module SellDotCom
|
10
|
+
def self.is_active?(url)
|
11
|
+
suspended_image_xpath = "//img[@src='http://i.sell.com/i/i_suspend.gif']"
|
12
|
+
response = Typhoeus::Request.get(url)
|
13
|
+
doc = Nokogiri::HTML(response.body)
|
14
|
+
doc.xpath(suspended_image_xpath).count < 1 ? true : false
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module SellDotCom
|
2
|
+
class Page
|
3
|
+
attr_accessor :page
|
4
|
+
|
5
|
+
def initialize(result)
|
6
|
+
@page ||= {}
|
7
|
+
@page[:title] = result[:title]
|
8
|
+
@page[:url] = result[:url]
|
9
|
+
@page[:posted_on] = Time.parse(result[:posted_on])
|
10
|
+
@page[:item_id] = result[:item_id]
|
11
|
+
parse
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse
|
15
|
+
response = Typhoeus::Request.get(@page[:url])
|
16
|
+
doc = Nokogiri::HTML(response.body)
|
17
|
+
@page[:seller_name] = doc.xpath("//a[@class='member']/u").text
|
18
|
+
@page[:price] = parse_price(doc.xpath("//div[@id='action']//td/div[@style='text-align:center;font-family:verdana,arial,sans-serif;font-size:large;font-weight:bold;color:green;']").text)
|
19
|
+
@page[:description] = doc.xpath("//font[@face='Verdana,Geneva,Arial']/comment()[.=' google_ad_section_start '][1]/../..").text.strip
|
20
|
+
@page
|
21
|
+
end
|
22
|
+
|
23
|
+
################################################################################
|
24
|
+
private
|
25
|
+
|
26
|
+
def parse_price(text)
|
27
|
+
text.gsub(/([\$])/, "").to_f
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module SellDotCom
|
2
|
+
class Search
|
3
|
+
|
4
|
+
attr_accessor :search_phrase
|
5
|
+
attr_reader :search_uri, :results
|
6
|
+
|
7
|
+
def initialize(search_phrase)
|
8
|
+
@search_phrase ||= search_phrase
|
9
|
+
@search_uri ||= search_uri
|
10
|
+
end
|
11
|
+
|
12
|
+
def search
|
13
|
+
response = Typhoeus::Request.get(@search_uri)
|
14
|
+
@results = parse(response.body)
|
15
|
+
end
|
16
|
+
|
17
|
+
################################################################################
|
18
|
+
private
|
19
|
+
|
20
|
+
def parse(html)
|
21
|
+
doc = Nokogiri::XML(html)
|
22
|
+
results = []
|
23
|
+
doc.xpath("//item").each do |item|
|
24
|
+
title = item.xpath("title").text
|
25
|
+
url = item.xpath("link").text
|
26
|
+
posted_on = item.xpath("pubDate").text
|
27
|
+
item_id = parse_item_id(url)
|
28
|
+
results << { :title => title, :url => url, :item_id => item_id, :posted_on => posted_on }
|
29
|
+
end
|
30
|
+
results
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse_item_id(url)
|
34
|
+
/sell.com\/([\S]+)\z/.match(url)[1]
|
35
|
+
end
|
36
|
+
|
37
|
+
def search_uri
|
38
|
+
"http://www.sell.com/search/index.x?search=#{URI.encode(@search_phrase)}+per_page%3A500+category%3A759&format=rss"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
data/selldotcom.gemspec
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
begin
|
4
|
+
Ore::Specification.new do |gemspec|
|
5
|
+
# custom logic here
|
6
|
+
end
|
7
|
+
rescue NameError
|
8
|
+
begin
|
9
|
+
require 'ore/specification'
|
10
|
+
retry
|
11
|
+
rescue LoadError
|
12
|
+
STDERR.puts "The '#{__FILE__}' file requires Ore."
|
13
|
+
STDERR.puts "Run `gem install ore-core` to install Ore."
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: selldotcom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ezekiel Templin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-14 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: typhoeus
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.2.4
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: nokogiri
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.4.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.0.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: yard
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.6.0
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rspec
|
61
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "2.4"
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *id005
|
70
|
+
description: A very simplistic interface for Sell.com that allows you to perform searches and parse item information from pages.
|
71
|
+
email:
|
72
|
+
- ezkl@me.com
|
73
|
+
executables: []
|
74
|
+
|
75
|
+
extensions: []
|
76
|
+
|
77
|
+
extra_rdoc_files:
|
78
|
+
- README.md
|
79
|
+
- ChangeLog.md
|
80
|
+
- LICENSE.txt
|
81
|
+
files:
|
82
|
+
- .document
|
83
|
+
- .rspec
|
84
|
+
- .yardopts
|
85
|
+
- ChangeLog.md
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- gemspec.yml
|
91
|
+
- lib/selldotcom.rb
|
92
|
+
- lib/selldotcom/page.rb
|
93
|
+
- lib/selldotcom/search.rb
|
94
|
+
- lib/selldotcom/version.rb
|
95
|
+
- selldotcom.gemspec
|
96
|
+
- spec/selldotcom_spec.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
homepage: http://rubygems.org/gems/selldotcom
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: "0"
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.3.6
|
118
|
+
requirements: []
|
119
|
+
|
120
|
+
rubyforge_project: selldotcom
|
121
|
+
rubygems_version: 1.7.2
|
122
|
+
signing_key:
|
123
|
+
specification_version: 3
|
124
|
+
summary: Simple interface to Sell.com
|
125
|
+
test_files:
|
126
|
+
- spec/selldotcom_spec.rb
|