vrbo 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -3
- data/lib/vrbo.rb +3 -4
- data/lib/vrbo/availability.rb +8 -9
- data/lib/vrbo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a9ee349fb47a9b37f3cd5b3b78fd0426a10a938
|
4
|
+
data.tar.gz: 8e02ecf2792dfd8c38348ea248a16619476afc95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f04f9e38b094c1dbd827be4bb9b06b29e55c16956bcc9c6cb7c2c271b5313ee2c7f276a22d8cf7494fad9e1c63aa266039e02dc98b5a7e10952fc5a3e22083ef
|
7
|
+
data.tar.gz: 2957e0c4a7da8f0162b3ad3c2042f57315e82dad981af84eca91e24403bec46d2b2abb9d64aeea5ce6c25b66d5d667085ccde55d44d866928b9c60ab3ed3d037
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# VRBO Calendar Scraper
|
2
2
|
|
3
|
-
|
3
|
+
Uses mechanize to scrape a VRBO calendar and return a list of available dates. For instance, the gem can
|
4
|
+
scrape this calendar: [http://www.vrbo.com/293021/calendar](http://www.vrbo.com/293021/calendar)
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -18,7 +19,23 @@ Or install it yourself as:
|
|
18
19
|
|
19
20
|
## Usage
|
20
21
|
|
21
|
-
|
22
|
+
If you're just working with one calendar, then you can specify the VRBO calendar id in an initializer:
|
23
|
+
|
24
|
+
# config/initializers/vrbo_calendar.rb
|
25
|
+
|
26
|
+
VRBO.configure do |config|
|
27
|
+
config.calendar_id = 293021
|
28
|
+
end
|
29
|
+
|
30
|
+
Then to lookup available dates and see if a date range is available:
|
31
|
+
|
32
|
+
calendar = VRBO::Calendar.new
|
33
|
+
calendar.find_all_available_dates
|
34
|
+
calendar.available?(Date.today, Date.tomorrow)
|
35
|
+
#=> true/false
|
36
|
+
|
37
|
+
These two methods are also available as class methods, however `available?` will then need an array of dates
|
38
|
+
as the third parameter.
|
22
39
|
|
23
40
|
## Contributing
|
24
41
|
|
data/lib/vrbo.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
|
2
|
-
require 'mechanize'
|
1
|
+
require 'date'
|
3
2
|
require 'uri'
|
4
3
|
require 'net/https'
|
4
|
+
require 'mechanize'
|
5
5
|
|
6
|
-
|
7
|
-
require "vrbo/version"
|
6
|
+
require 'vrbo/version'
|
8
7
|
require 'vrbo/configuration'
|
9
8
|
require 'vrbo/availability'
|
10
9
|
require 'vrbo/calendar'
|
data/lib/vrbo/availability.rb
CHANGED
@@ -1,22 +1,21 @@
|
|
1
1
|
module VRBO
|
2
2
|
class Availability
|
3
3
|
|
4
|
-
attr_accessor :
|
4
|
+
attr_accessor :start_at, :duration, :error
|
5
5
|
|
6
6
|
def initialize(dates = [])
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
self.errors = []
|
7
|
+
dates = dates || []
|
8
|
+
if dates.any?
|
9
|
+
@start_at = Date.parse(dates.shift)
|
11
10
|
else
|
12
|
-
|
13
|
-
|
14
|
-
self.errors = %w[Maybe... But likely there was an error]
|
11
|
+
@start_at = Date.today
|
12
|
+
@error = 'Maybe... But likely there was an error.'
|
15
13
|
end
|
14
|
+
@duration = calc_duration(dates)
|
16
15
|
end
|
17
16
|
|
18
17
|
def calc_duration(dates)
|
19
|
-
1 + dates.each_with_index.sum { |the_date, i| Date.parse(the_date) - (
|
18
|
+
1 + dates.each_with_index.sum { |the_date, i| Date.parse(the_date) - (start_at + i) == 1 ? 1 : 0 }
|
20
19
|
end
|
21
20
|
end
|
22
21
|
end
|
data/lib/vrbo/version.rb
CHANGED