hostelify 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hostelify (0.6.0)
4
+ hostelify (0.6.2)
5
5
  nibbler (>= 1.2.1)
6
- nokogiri
6
+ nokogiri (>= 1.4.4)
7
7
  rest-client (>= 1.6.1)
8
+ robotstxt (>= 0.5.4)
8
9
 
9
10
  GEM
10
11
  remote: http://rubygems.org/
@@ -15,6 +16,7 @@ GEM
15
16
  nokogiri (1.4.4)
16
17
  rest-client (1.6.1)
17
18
  mime-types (>= 1.16)
19
+ robotstxt (0.5.4)
18
20
  rspec (2.5.0)
19
21
  rspec-core (~> 2.5.0)
20
22
  rspec-expectations (~> 2.5.0)
@@ -30,6 +32,7 @@ PLATFORMS
30
32
  DEPENDENCIES
31
33
  hostelify!
32
34
  nibbler (>= 1.2.1)
33
- nokogiri
35
+ nokogiri (>= 1.4.4)
34
36
  rest-client (>= 1.6.1)
35
- rspec
37
+ robotstxt (>= 0.5.4)
38
+ rspec (= 2.5.0)
data/hostelify.gemspec CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.add_dependency('rest-client', '>= 1.6.1')
16
16
  s.add_dependency('nokogiri', '>= 1.4.4')
17
17
  s.add_dependency('nibbler', '>= 1.2.1')
18
+ s.add_dependency('robotstxt', '>= 0.5.4')
18
19
  s.add_development_dependency('rspec', '2.5.0')
19
20
 
20
21
  s.rubyforge_project = "hostelify"
@@ -1,3 +1,3 @@
1
1
  module Hostelify
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
data/lib/hostelify.rb CHANGED
@@ -2,28 +2,36 @@ require 'rubygems'
2
2
  require 'date'
3
3
  require 'rest_client'
4
4
  require 'nibbler'
5
+ require 'robotstxt'
5
6
  require 'hostelify/hostelworld'
6
7
 
7
8
  module Hostelify
8
9
 
9
10
  def self.find(*args, &block)
10
- options = { :currency => 'EUR', :date_from => Date.today+14, :directions => false }
11
+ options = { :currency => 'EUR', :date_from => Date.today+14, :directions => false, :robotstxt_check => false }
11
12
  options.merge!(args.pop) if args.last.kind_of? Hash
12
13
 
13
- RestClient.head 'http://www.hostelworld.com/hosteldetails.php/' + options[:id].to_s do |response, request, result|
14
- redirect = response.headers[:location]
15
- redirect = redirect + '/directions' if options[:directions]
16
- date = Date.strptime(options[:date_from].to_s)
14
+ if options[:robotstxt_check]
15
+ robot_friendly = Robotstxt.allowed?('http://www.hostelworld.com', 'rowbot')
16
+ else
17
+ robot_friendly = true
18
+ end
19
+
20
+ if robot_friendly
21
+ RestClient.head 'http://www.hostelworld.com/hosteldetails.php/' + options[:id].to_s do |response, request, result|
22
+ redirect = response.headers[:location]
23
+ redirect = redirect + '/directions' if options[:directions]
24
+ date = Date.strptime(options[:date_from].to_s)
17
25
 
18
- @resource = RestClient.post redirect,
19
- :date_from => date+1,
20
- :date_to => date+8,
21
- :searchperformedflag => 1,
22
- :currency => options[:currency]
26
+ @resource = RestClient.post redirect,
27
+ :date_from => date+1,
28
+ :date_to => date+8,
29
+ :searchperformedflag => 1,
30
+ :currency => options[:currency]
31
+ end
23
32
  end
24
33
 
25
34
  result = HostelWorld.parse @resource
26
- end
27
-
35
+ end
28
36
 
29
37
  end
@@ -18,5 +18,13 @@ describe "hostelworld" do
18
18
  it "should have at least 4 images" do
19
19
  @hostel.should have_at_least(6).photos
20
20
  end
21
+
22
+ it "should have one available spot" do
23
+ @hostel.beds.last.nights.last.spots.to_i.should be >= 1
24
+ end
25
+
26
+ it "should have a price above $5" do
27
+ @hostel.beds.last.nights.last.price.to_i.should be >= 5
28
+ end
21
29
 
22
30
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hostelify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 1
10
- version: 0.6.1
9
+ - 2
10
+ version: 0.6.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Holden Thomas
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-31 00:00:00 +02:00
18
+ date: 2011-04-01 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -67,9 +67,25 @@ dependencies:
67
67
  type: :runtime
68
68
  version_requirements: *id003
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec
70
+ name: robotstxt
71
71
  prerelease: false
72
72
  requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ - 5
81
+ - 4
82
+ version: 0.5.4
83
+ type: :runtime
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: rspec
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
73
89
  none: false
74
90
  requirements:
75
91
  - - "="
@@ -81,7 +97,7 @@ dependencies:
81
97
  - 0
82
98
  version: 2.5.0
83
99
  type: :development
84
- version_requirements: *id004
100
+ version_requirements: *id005
85
101
  description: scrapper for publicly accessible data from hostelworld hostelbookers etc.
86
102
  email:
87
103
  - holden@wombie.com