ioffer 0.1.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,3 @@
1
+ -
2
+ ChangeLog.*
3
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
@@ -0,0 +1 @@
1
+ --markup rdoc --title "ioffer Documentation" --protected
@@ -0,0 +1,6 @@
1
+ 0.1.0 / 2011-04-04
2
+ ------------------
3
+
4
+ * Initial release:
5
+ * Basic search and page parser.
6
+
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source :rubygems
2
+
3
+ gem "nibbler", "~> 1.2.1"
4
+ gem "nokogiri", "~> 1.4.4"
5
+ gem "sanitize", "~> 2.0.1"
6
+
7
+ gemspec
8
+
9
+ group :development do
10
+ gem 'rake', '~> 0.8.7'
11
+ gem 'ore-tasks', '~> 0.4'
12
+ gem 'rspec', '~> 2.4'
13
+ gem 'yard', '~> 0.6.0'
14
+ gem 'bluecloth', '~> 2.1.0'
15
+ end
@@ -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.
@@ -0,0 +1,48 @@
1
+ ioffer
2
+ ======
3
+
4
+ * [Homepage](http://rubygems.org/gems/ioffer)
5
+ * [Documentation](http://rubydoc.info/gems/ioffer/frames)
6
+
7
+ Description
8
+ -----------
9
+
10
+ Very basic parser for [iOffer.com](http://www.ioffer.com/) using [Nibbler](https://github.com/mislav/nibbler).
11
+
12
+ Features
13
+ --------
14
+
15
+ * Parses iOffer search URLs
16
+ * Parses iOffer pages.
17
+
18
+ Examples
19
+ --------
20
+
21
+ require 'ioffer'
22
+ require 'open-uri'
23
+
24
+ search = IOfferSearch.parse open("http://www.ioffer.com/si/saxphones")
25
+
26
+ search.results.each do |result|
27
+ puts result.title
28
+ puts result.url
29
+ end
30
+
31
+ result_url = search.results.first.url
32
+
33
+ page = IOfferPage.parse open(result_url)
34
+ puts page.seller_name
35
+ puts page.item_id
36
+ puts page.price
37
+
38
+ Install
39
+ -------
40
+
41
+ $ gem install ioffer
42
+
43
+ Copyright
44
+ ---------
45
+
46
+ Copyright (c) 2011 Ezekiel Templin
47
+
48
+ See LICENSE.txt for details.
@@ -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
@@ -0,0 +1,12 @@
1
+ name: ioffer
2
+ summary: "Basic iOffer Search/Page Parser"
3
+ description: "Very basic iOffer.com parser using Nibbler."
4
+ license: MIT
5
+ authors: "Ezekiel Templin"
6
+ email: "ezkl@me.com"
7
+ homepage: http://rubygems.org/gems/ioffer
8
+ has_yard: true
9
+
10
+ development_dependencies:
11
+ bundler: ~> 1.0.0
12
+ yard: ~> 0.6.0
@@ -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
@@ -0,0 +1,8 @@
1
+ require 'nibbler'
2
+
3
+ require 'ioffer/version'
4
+ require 'ioffer/search'
5
+ require 'ioffer/page'
6
+
7
+ module Ioffer
8
+ end
@@ -0,0 +1,34 @@
1
+ require 'nokogiri'
2
+ require 'date'
3
+ require 'sanitize'
4
+
5
+ class IOfferPage < Nibbler
6
+ element 'div#itemDetailSellerName a[href^="/users/"]' => :seller_name
7
+ element 'div[@id="header-status-bar"]' => :item_id, :with => lambda { |element| parse_item_id(element) }
8
+ element 'div[@id="header-status-bar"]' => :posted_on, :with => lambda { |element| parse_posted_date(element) }
9
+ element 'div.primary-action-cell span[id^=price]' => :price, :with => lambda { |element| make_price(element) }
10
+ element "//div[@id='item_description_description_p']" => :description, :with => lambda { |element| parse_description(element.to_html) }
11
+ end
12
+
13
+ def make_price(element)
14
+ /\$([\d,]+\.?[\d]{2})/.match(element)[1]
15
+ end
16
+
17
+ def parse_item_id(element)
18
+ /Item #([\d]*)/.match(element.inner_text)[1]
19
+ end
20
+
21
+ def parse_posted_date(element)
22
+ date = /Listed: ([\d]{2,}-[\d]{2,}-[\d]{2,})/.match(element.inner_text)[1]
23
+ Date.strptime(date, '%m-%d-%y')
24
+ end
25
+
26
+ def parse_description(element)
27
+ Sanitize.clean(element).strip
28
+ end
29
+
30
+ def page_active?(html)
31
+ doc = Nokogiri::HTML(html)
32
+ doc.xpath('//span[@id="inactive-no-longer-available"]').any? ||
33
+ doc.xpath('//div[contains(@class, "bold") and contains(@class,"color-gray-dark")]').text.empty? ? false : true
34
+ end
@@ -0,0 +1,15 @@
1
+ class IOfferSearchResults < Nibbler
2
+ element 'a[@class="title"]/@href' => :url
3
+ element 'a[@class="title"]/span' => :title, :with => lambda { |title| parse_title(title) }
4
+ end
5
+
6
+ class IOfferSearch < Nibbler
7
+ elements 'div[@class="search-results-list-item"]' => :results,
8
+ :with => IOfferSearchResults
9
+ element 'span[@class="current"]' => :current_page
10
+ element 'a[@class="next_page"]/@href' => :next_page_url
11
+ end
12
+
13
+ def parse_title(title)
14
+ title.inner_text.gsub(/[\s]{2,}/, " ")
15
+ end
@@ -0,0 +1,4 @@
1
+ module Ioffer
2
+ # ioffer version
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'ioffer'
3
+
4
+ describe Ioffer do
5
+ it "should have a VERSION constant" do
6
+ subject.const_get('VERSION').should_not be_empty
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec'
2
+ require 'ioffer/version'
3
+
4
+ include Ioffer
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ioffer
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-05 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: yard
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ description: Very basic iOffer.com parser using Nibbler.
38
+ email:
39
+ - ezkl@me.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - README.md
46
+ - ChangeLog.md
47
+ - LICENSE.txt
48
+ files:
49
+ - .document
50
+ - .rspec
51
+ - .yardopts
52
+ - ChangeLog.md
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - gemspec.yml
58
+ - ioffer.gemspec
59
+ - lib/ioffer.rb
60
+ - lib/ioffer/page.rb
61
+ - lib/ioffer/search.rb
62
+ - lib/ioffer/version.rb
63
+ - spec/ioffer_spec.rb
64
+ - spec/spec_helper.rb
65
+ homepage: http://rubygems.org/gems/ioffer
66
+ licenses:
67
+ - MIT
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 1.3.6
85
+ requirements: []
86
+
87
+ rubyforge_project: ioffer
88
+ rubygems_version: 1.7.1
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Basic iOffer Search/Page Parser
92
+ test_files:
93
+ - spec/ioffer_spec.rb