vrbo 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/vrbo/availability.rb +22 -0
- data/lib/vrbo/calendar.rb +57 -0
- data/lib/vrbo/class_methods.rb +14 -0
- data/lib/vrbo/configuration.rb +5 -0
- data/lib/vrbo/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa7a2a512a5ae11e2d8a502558cee4fee401fe91
|
4
|
+
data.tar.gz: 70bec1819422233d2e3cbc474d05eaaf9e550d93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b210088a4de46f9ec8d3845c90be6c1dfa8ce7f8a91432e12bc4f561968d78d56583762cc2f485bba647bcf9408dea05166bbd92a223eb4ed899763d66f0801a
|
7
|
+
data.tar.gz: e9ddbfae0e3216d9e43dbe4159cd6d793dbeab339efd5a2ec8cd4f7c217f8a3bff02ffaeb9724134df5d6cc144caaf37cc784accfc2b047c5da60192410d9b0d
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module VRBO
|
2
|
+
class Availability
|
3
|
+
|
4
|
+
attr_accessor :first, :duration, :errors
|
5
|
+
|
6
|
+
def initialize(dates = [])
|
7
|
+
if dates.try(:any?)
|
8
|
+
self.first = Date.parse(dates.shift)
|
9
|
+
self.duration = self.calc_duration(dates)
|
10
|
+
self.errors = []
|
11
|
+
else
|
12
|
+
self.first = Date.today
|
13
|
+
self.duration = 1
|
14
|
+
self.errors = %w[Maybe... But likely there was an error]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def calc_duration(dates)
|
19
|
+
1 + dates.each_with_index.sum { |the_date, i| Date.parse(the_date) - (first + i.days) == 1 ? 1 : 0 }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'vrbo/class_methods'
|
2
|
+
|
3
|
+
module VRBO
|
4
|
+
class Calendar
|
5
|
+
extend ClassMethods
|
6
|
+
|
7
|
+
attr_accessor :id, :available_dates, :cells
|
8
|
+
|
9
|
+
def initialize(calendar_id = nil)
|
10
|
+
@id = calendar_id || VRBO.config.calendar_id
|
11
|
+
@cells = {}
|
12
|
+
@available_dates = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def available?(arrival, depart, my_dates = nil)
|
16
|
+
dates = my_dates || available_dates
|
17
|
+
available = dates.any? # should be true
|
18
|
+
arrival.upto(depart - 1.day).each do |date|
|
19
|
+
available = false if dates.exclude?(date.to_s)
|
20
|
+
end
|
21
|
+
available
|
22
|
+
end
|
23
|
+
|
24
|
+
def find_all_available_dates
|
25
|
+
today = Date.today
|
26
|
+
@available_dates = today.upto(today + 1.year).map { |date| availability_for(date) }.compact
|
27
|
+
end
|
28
|
+
|
29
|
+
def availability_for(date)
|
30
|
+
m = date.month.to_s
|
31
|
+
cells[m] ||= find_cells_for(date).map { |cell| cell.children.to_s.strip }
|
32
|
+
|
33
|
+
if cells[m].include?(date.day.to_s)
|
34
|
+
date.to_s
|
35
|
+
else
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def find_cells_for(date)
|
41
|
+
calendar.search('.cal-month').at(table_xpath(date)).search('td:not(.strike)')
|
42
|
+
end
|
43
|
+
|
44
|
+
def calendar
|
45
|
+
@calendar ||= agent.get("http://www.vrbo.com/#{id}/calendar")
|
46
|
+
end
|
47
|
+
|
48
|
+
def agent
|
49
|
+
@agent ||= Mechanize.new
|
50
|
+
end
|
51
|
+
|
52
|
+
# March 2014
|
53
|
+
def table_xpath(date)
|
54
|
+
"//b[contains(text(), '#{date.strftime('%B %Y')}')]/following-sibling::table"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/vrbo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vrbo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Buckley
|
@@ -65,6 +65,10 @@ files:
|
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
67
|
- lib/vrbo.rb
|
68
|
+
- lib/vrbo/availability.rb
|
69
|
+
- lib/vrbo/calendar.rb
|
70
|
+
- lib/vrbo/class_methods.rb
|
71
|
+
- lib/vrbo/configuration.rb
|
68
72
|
- lib/vrbo/version.rb
|
69
73
|
- vrbo.gemspec
|
70
74
|
homepage: ''
|