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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be4a8b9e2ee993d3cd003dd5e4d38cca35538a2a
4
- data.tar.gz: 3365f665bd04026f2b4729ff590a626e5630b7c8
3
+ metadata.gz: fa7a2a512a5ae11e2d8a502558cee4fee401fe91
4
+ data.tar.gz: 70bec1819422233d2e3cbc474d05eaaf9e550d93
5
5
  SHA512:
6
- metadata.gz: 57dee1abe4dd2001fece333d24e8f47d94600f2342e383cdccc3cfd2148b947ca2bab924f547788b7e92ac41703cd5b02cc5f3ed9955672d94e80779a81ebca3
7
- data.tar.gz: 131a41b507b59a453a2bc3a18cb6bcd078f535ab9cbb8d2e3e157e437b8df5899502ecdf8c1d4dd447effeca69979f5ede694ed50ad2d89894d933ebbd424722
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
@@ -0,0 +1,14 @@
1
+ module VRBO
2
+ module ClassMethods
3
+
4
+ def method_missing(method_name, *arguments)
5
+ inst = new
6
+ if inst.respond_to?(method_name)
7
+ inst.send(method_name, *arguments)
8
+ else
9
+ super
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module VRBO
2
+ class Configuration
3
+ attr_accessor :calendar_id
4
+ end
5
+ end
data/lib/vrbo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module VRBO
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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.3
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: ''