locomotive_wubook_plugin 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/locomotive/wubook/plugin/available_days_tag.rb +62 -0
- data/lib/locomotive/wubook/plugin/check_interval_tag.rb +80 -0
- data/lib/locomotive/wubook/plugin/plugin_helper.rb +12 -5
- data/lib/locomotive/wubook/plugin/prices_tag.rb +65 -0
- data/lib/locomotive/wubook/plugin/set_as_booked_tag.rb +72 -0
- data/lib/locomotive/wubook/plugin/version.rb +1 -1
- data/lib/locomotive/wubook/plugin.rb +9 -189
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c8a215a611d26d0679b420ba54fd5a9dda53e79
|
4
|
+
data.tar.gz: 9439ac588ce891c63ac9b5fef40695c87a72373e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 593c8f18db945eb5ab5ad5414401fafdae98de6a895a23649eb0dbaf08fa94aa8b2f39a1ea09a387e24913a572d5edbdeda3b44f14d5c5caee220601ab42bbee
|
7
|
+
data.tar.gz: 8d7cf8efa18344713011544ce3726141a3a5fb564ba4558dcf8bcab3ca38f14378e91235d2d4f4a54745723adef2b871e8257a9c7cd3d437897ed21dfe7387d4
|
data/Gemfile
CHANGED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
require 'wired'
|
4
|
+
require 'locomotive_plugins'
|
5
|
+
require_relative 'plugin_helper'
|
6
|
+
|
7
|
+
module Locomotive
|
8
|
+
module WuBook
|
9
|
+
class AvailableDaysTag < ::Liquid::Tag
|
10
|
+
include PluginHelper
|
11
|
+
def initialize(tag_name, markup, tokens, context)
|
12
|
+
@options = {
|
13
|
+
room_ident: ''
|
14
|
+
}
|
15
|
+
|
16
|
+
markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') }
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def render(context)
|
21
|
+
@plugin_obj = context.registers[:plugin_object]
|
22
|
+
config = @plugin_obj.config
|
23
|
+
|
24
|
+
returned_string = "["
|
25
|
+
|
26
|
+
# Evaluate variables and use the return of the evaluation if it exists..
|
27
|
+
raise "Missing parameter 'room_ident'" if @options[:room_ident].empty?
|
28
|
+
room_ident_evaluated = context[@options[:room_ident]]
|
29
|
+
@options[:room_ident] = room_ident_evaluated unless room_ident_evaluated.nil? || room_ident_evaluated.empty?
|
30
|
+
::Locomotive.log "**> AvailableDaysTag room_ident: #{@options[:room_ident]}"
|
31
|
+
|
32
|
+
today = Date.today
|
33
|
+
last_day = today.next_month(config['months_ahead'].to_i)
|
34
|
+
|
35
|
+
wired = Wired.new(config)
|
36
|
+
wired.aquire_token
|
37
|
+
|
38
|
+
room_data = request_room_data(wired, config['lcode'], @options[:room_ident], today, last_day)
|
39
|
+
|
40
|
+
# Create one entry for each day from now to then.. put a 1 if the day is available or 0 if not.
|
41
|
+
(today .. last_day).each_with_index do |date, i|
|
42
|
+
returned_string += "," if i > 0
|
43
|
+
|
44
|
+
if room_data[i] != nil && room_data[i]['avail'] >= 1
|
45
|
+
then
|
46
|
+
returned_string += "1"
|
47
|
+
else
|
48
|
+
returned_string += "0"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
wired.release_token
|
53
|
+
|
54
|
+
returned_string + "]"
|
55
|
+
end
|
56
|
+
|
57
|
+
def render_disabled(context)
|
58
|
+
"[]"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
require 'wired'
|
4
|
+
require 'locomotive_plugins'
|
5
|
+
require_relative 'plugin_helper'
|
6
|
+
|
7
|
+
module Locomotive
|
8
|
+
module WuBook
|
9
|
+
class CheckIntervalTag < ::Liquid::Tag
|
10
|
+
include PluginHelper
|
11
|
+
def initialize(tag_name, markup, tokens, context)
|
12
|
+
@options = {
|
13
|
+
room_ident: '',
|
14
|
+
date_start: '',
|
15
|
+
date_end: ''
|
16
|
+
}
|
17
|
+
|
18
|
+
markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') }
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def render(context)
|
23
|
+
@plugin_obj = context.registers[:plugin_object]
|
24
|
+
config = @plugin_obj.config
|
25
|
+
|
26
|
+
# Evaluate variables and use the return of the evaluation if it exists..
|
27
|
+
raise "Missing parameter 'room_ident'" if @options[:room_ident].empty?
|
28
|
+
room_ident_evaluated = context[@options[:room_ident]]
|
29
|
+
@options[:room_ident] = room_ident_evaluated unless room_ident_evaluated.nil? || room_ident_evaluated.empty?
|
30
|
+
::Locomotive.log "**> CheckIntervalTag room_ident: #{@options[:room_ident]}"
|
31
|
+
|
32
|
+
raise "Missing parameter 'date_start'" if @options[:date_start].empty?
|
33
|
+
date_start_evaluated = context[@options[:date_start]]
|
34
|
+
@options[:date_start] = date_start_evaluated unless date_start_evaluated.nil?
|
35
|
+
::Locomotive.log "**> CheckIntervalTag date_start_evaluated: #{@options[:date_start]}"
|
36
|
+
|
37
|
+
raise "Missing parameter 'date_end'" if @options[:date_end].empty?
|
38
|
+
date_end_evaluated = context[@options[:date_end]]
|
39
|
+
@options[:date_end] = date_end_evaluated unless date_end_evaluated.nil?
|
40
|
+
::Locomotive.log "**> CheckIntervalTag date_end: #{@options[:date_end]}"
|
41
|
+
|
42
|
+
start_day = @options[:date_start]
|
43
|
+
last_day = @options[:date_end]
|
44
|
+
::Locomotive.log "**> CheckIntervalTag: Date Interval: #{start_day} - #{last_day}"
|
45
|
+
|
46
|
+
wired = Wired.new(config)
|
47
|
+
wired.aquire_token
|
48
|
+
room_data = request_room_data(wired, config['lcode'], @options[:room_ident], start_day, last_day)
|
49
|
+
wired.release_token
|
50
|
+
|
51
|
+
# Check whether first day is available. If this is _not_ the case we have to add one day (vacation == departure is allowed)
|
52
|
+
is_first_available = room_data[0]['avail'] === 1
|
53
|
+
|
54
|
+
# Check wheter the last day is not available. If this is _not_ the case we have to reduce one day (vacation == departure is allowed)
|
55
|
+
is_last_available = room_data[last_day.mjd - start_day.mjd]['avail'] === 1
|
56
|
+
|
57
|
+
# Remove the first or last day from the array.
|
58
|
+
room_data.shift unless is_first_available # Remove first element
|
59
|
+
room_data[0..-1] unless is_last_available # Remove last element
|
60
|
+
|
61
|
+
# Now check the (modified) interval regarding availability
|
62
|
+
is_available = true
|
63
|
+
room_data.each do |data|
|
64
|
+
::Locomotive.log "**> CheckIntervalTag: check: #{data}"
|
65
|
+
if data['avail'] === 0 then
|
66
|
+
is_available = false;
|
67
|
+
break
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
is_available ? "Ok" : "Err"
|
72
|
+
end
|
73
|
+
|
74
|
+
def render_disabled(context)
|
75
|
+
"Ok"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
@@ -1,13 +1,20 @@
|
|
1
1
|
require 'wired'
|
2
2
|
|
3
3
|
module PluginHelper
|
4
|
+
def fetch_room_base_data(wired, lcode, room_id)
|
5
|
+
rooms = wired.fetch_rooms(lcode)
|
6
|
+
filtered_room = rooms.select { |room_hash| room_hash['shortname'] == room_id }
|
7
|
+
::Locomotive.log "**> Filtered rooms #{filtered_room} "
|
8
|
+
|
9
|
+
filtered_room
|
10
|
+
end
|
11
|
+
|
4
12
|
def fetch_room_id(wired, lcode, room_id)
|
5
13
|
# Start with finding the room-id for the room with a special name
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
room_identifier = filtered_rooms[0]['id']
|
14
|
+
filtered_room = fetch_room_base_data(wired, lcode, room_id)
|
15
|
+
::Locomotive.log "**> Filtered rooms #{filtered_room} "
|
16
|
+
raise "Unable to find a room with identifier: #{room_id}" if filtered_room.length == 0
|
17
|
+
room_identifier = filtered_room[0]['id']
|
11
18
|
raise "Unable to get the room id." if room_identifier == nil
|
12
19
|
|
13
20
|
room_identifier
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
require 'wired'
|
4
|
+
require 'locomotive_plugins'
|
5
|
+
require_relative 'plugin_helper'
|
6
|
+
|
7
|
+
module Locomotive
|
8
|
+
module WuBook
|
9
|
+
class PricesTag < ::Liquid::Tag
|
10
|
+
include PluginHelper
|
11
|
+
def initialize(tag_name, markup, tokens, context)
|
12
|
+
@options = {
|
13
|
+
room_ident: ''
|
14
|
+
}
|
15
|
+
|
16
|
+
markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') }
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def render(context)
|
21
|
+
@plugin_obj = context.registers[:plugin_object]
|
22
|
+
config = @plugin_obj.config
|
23
|
+
|
24
|
+
returned_string = "["
|
25
|
+
|
26
|
+
# Evaluate variables and use the return of the evaluation if it exists..
|
27
|
+
raise "Missing parameter 'room_ident'" if @options[:room_ident].empty?
|
28
|
+
room_ident_evaluated = context[@options[:room_ident]]
|
29
|
+
@options[:room_ident] = room_ident_evaluated unless room_ident_evaluated.nil? || room_ident_evaluated.empty?
|
30
|
+
::Locomotive.log "**> AvailableDaysTag room_ident: #{@options[:room_ident]}"
|
31
|
+
|
32
|
+
today = Date.today
|
33
|
+
last_day = today.next_month(config['months_ahead'].to_i)
|
34
|
+
|
35
|
+
wired = Wired.new(config)
|
36
|
+
wired.aquire_token
|
37
|
+
|
38
|
+
base_room_data = fetch_room_base_data(wired, config['lcode'], @options[:room_ident])
|
39
|
+
base_price = base_room_data[0]["price"]
|
40
|
+
|
41
|
+
room_data = request_room_data(wired, config['lcode'], @options[:room_ident], today, last_day)
|
42
|
+
|
43
|
+
# Create one entry for each day from now to then.. put a 1 if the day is available or 0 if not.
|
44
|
+
(today .. last_day).each_with_index do |date, i|
|
45
|
+
returned_string += "," if i > 0
|
46
|
+
|
47
|
+
if room_data[i] != nil && room_data[i].has_key?("price")
|
48
|
+
then
|
49
|
+
returned_string += room_data[i]["price"].to_s
|
50
|
+
else
|
51
|
+
returned_string += base_price.to_s
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
wired.release_token
|
56
|
+
|
57
|
+
returned_string + "]"
|
58
|
+
end
|
59
|
+
|
60
|
+
def render_disabled(context)
|
61
|
+
"[]"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
require 'wired'
|
4
|
+
require 'locomotive_plugins'
|
5
|
+
require_relative 'plugin_helper'
|
6
|
+
|
7
|
+
module Locomotive
|
8
|
+
module WuBook
|
9
|
+
# This tag sets the availability of the given days to 0 (false)
|
10
|
+
class SetAsBookedTag < ::Liquid::Tag
|
11
|
+
include PluginHelper
|
12
|
+
def initialize(tag_name, markup, tokens, context)
|
13
|
+
@options = {
|
14
|
+
room_ident: '',
|
15
|
+
date_start: '',
|
16
|
+
date_end: ''
|
17
|
+
}
|
18
|
+
|
19
|
+
markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') }
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def render(context)
|
24
|
+
@plugin_obj = context.registers[:plugin_object]
|
25
|
+
config = @plugin_obj.config
|
26
|
+
|
27
|
+
raise "Missing parameter 'room_ident'" if @options[:room_ident].empty?
|
28
|
+
room_ident_evaluated = context[@options[:room_ident]]
|
29
|
+
@options[:room_ident] = room_ident_evaluated unless room_ident_evaluated.nil? || room_ident_evaluated.empty?
|
30
|
+
::Locomotive.log "**> SetAsBookedTag room_ident: #{@options[:room_ident]}"
|
31
|
+
|
32
|
+
raise "Missing parameter 'date_start'" if @options[:date_start].empty?
|
33
|
+
date_start_evaluated = context[@options[:date_start]]
|
34
|
+
@options[:date_start] = date_start_evaluated unless date_start_evaluated.nil?
|
35
|
+
::Locomotive.log "**> SetAsBookedTag date_start_evaluated: #{@options[:date_start_evaluated]}"
|
36
|
+
|
37
|
+
raise "Missing parameter 'date_end'" if @options[:date_end].empty?
|
38
|
+
date_end_evaluated = context[@options[:date_end]]
|
39
|
+
@options[:date_end] = date_end_evaluated unless date_end_evaluated.nil?
|
40
|
+
::Locomotive.log "**> SetAsBookedTag date_end: #{@options[:date_end]}"
|
41
|
+
|
42
|
+
start_day = @options[:date_start]
|
43
|
+
last_day = @options[:date_end]
|
44
|
+
::Locomotive.log "**> SetAsBookedTag: Date Interval: #{start_day} - #{last_day}"
|
45
|
+
|
46
|
+
wired = Wired.new(config)
|
47
|
+
wired.aquire_token
|
48
|
+
room_id = fetch_room_id(wired, config['lcode'], @options[:room_ident])
|
49
|
+
|
50
|
+
# Set availability for given date interval to 0
|
51
|
+
days = []
|
52
|
+
(start_day .. last_day).each do |date|
|
53
|
+
# Ignore date.. I will just iterate over every day..
|
54
|
+
days.push({ 'avail' => 0 })
|
55
|
+
end
|
56
|
+
avail_data = [ {'id' => room_id, 'days' => days} ]
|
57
|
+
::Locomotive.log "**> SetAsBookedTag: Set avail to 0 for: #{start_day}: #{avail_data}"
|
58
|
+
wired.update_rooms_values(config['lcode'], start_day, avail_data)
|
59
|
+
|
60
|
+
wired.release_token
|
61
|
+
|
62
|
+
# Return a html comment that shows us that everything is fine.
|
63
|
+
"<!-- Availability was set to 0 for room #{@options[:room_ident]} from #{@options[:date_start]} to #{@options[:date_end]} -->"
|
64
|
+
end
|
65
|
+
|
66
|
+
def render_disabled(context)
|
67
|
+
"<!-- Locomotive_wubook_plugin is disabled! -->"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
@@ -5,7 +5,11 @@ require 'date'
|
|
5
5
|
|
6
6
|
require 'wired'
|
7
7
|
require 'locomotive_plugins'
|
8
|
-
|
8
|
+
|
9
|
+
require_relative 'plugin/available_days_tag'
|
10
|
+
require_relative 'plugin/check_interval_tag'
|
11
|
+
require_relative 'plugin/set_as_booked_tag'
|
12
|
+
require_relative 'plugin/prices_tag'
|
9
13
|
|
10
14
|
module Locomotive
|
11
15
|
module WuBook
|
@@ -26,199 +30,15 @@ module Locomotive
|
|
26
30
|
|
27
31
|
def self.liquid_tags
|
28
32
|
{
|
29
|
-
:available =>
|
30
|
-
:checkInterval =>
|
31
|
-
:setAsBooked =>
|
33
|
+
:available => AvailableDaysTag,
|
34
|
+
:checkInterval => CheckIntervalTag,
|
35
|
+
:setAsBooked => SetAsBookedTag,
|
36
|
+
:prices => PricesTag
|
32
37
|
}
|
33
38
|
end
|
34
39
|
|
35
40
|
protected
|
36
41
|
|
37
42
|
end
|
38
|
-
|
39
|
-
class AvailableDaysBlock < ::Liquid::Tag
|
40
|
-
include PluginHelper
|
41
|
-
def initialize(tag_name, markup, tokens, context)
|
42
|
-
@options = {
|
43
|
-
room_ident: ''
|
44
|
-
}
|
45
|
-
|
46
|
-
markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') }
|
47
|
-
super
|
48
|
-
end
|
49
|
-
|
50
|
-
def render(context)
|
51
|
-
@plugin_obj = context.registers[:plugin_object]
|
52
|
-
config = @plugin_obj.config
|
53
|
-
|
54
|
-
returned_string = "["
|
55
|
-
|
56
|
-
# Evaluate variables and use the return of the evaluation if it exists..
|
57
|
-
raise "Missing parameter 'room_ident'" if @options[:room_ident].empty?
|
58
|
-
room_ident_evaluated = context[@options[:room_ident]]
|
59
|
-
@options[:room_ident] = room_ident_evaluated unless room_ident_evaluated.nil? || room_ident_evaluated.empty?
|
60
|
-
::Locomotive.log "**> AvailableDaysBlock room_ident: #{@options[:room_ident]}"
|
61
|
-
|
62
|
-
today = Date.today
|
63
|
-
last_day = today.next_month(config['months_ahead'].to_i)
|
64
|
-
|
65
|
-
wired = Wired.new(config)
|
66
|
-
wired.aquire_token
|
67
|
-
|
68
|
-
room_data = request_room_data(wired, config['lcode'], @options[:room_ident], today, last_day)
|
69
|
-
|
70
|
-
# Create one entry for each day from now to then.. put a 1 if the day is available or 0 if not.
|
71
|
-
(today .. last_day).each_with_index do |date, i|
|
72
|
-
returned_string += "," if i > 0
|
73
|
-
|
74
|
-
if room_data[i] != nil && room_data[i]['avail'] === 1
|
75
|
-
then
|
76
|
-
returned_string += "1"
|
77
|
-
else
|
78
|
-
returned_string += "0"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
wired.release_token
|
83
|
-
|
84
|
-
returned_string + "]"
|
85
|
-
end
|
86
|
-
|
87
|
-
def render_disabled(context)
|
88
|
-
"[]"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class CheckInterval < ::Liquid::Tag
|
93
|
-
include PluginHelper
|
94
|
-
def initialize(tag_name, markup, tokens, context)
|
95
|
-
@options = {
|
96
|
-
room_ident: '',
|
97
|
-
date_start: '',
|
98
|
-
date_end: ''
|
99
|
-
}
|
100
|
-
|
101
|
-
markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') }
|
102
|
-
super
|
103
|
-
end
|
104
|
-
|
105
|
-
def render(context)
|
106
|
-
@plugin_obj = context.registers[:plugin_object]
|
107
|
-
config = @plugin_obj.config
|
108
|
-
|
109
|
-
# Evaluate variables and use the return of the evaluation if it exists..
|
110
|
-
raise "Missing parameter 'room_ident'" if @options[:room_ident].empty?
|
111
|
-
room_ident_evaluated = context[@options[:room_ident]]
|
112
|
-
@options[:room_ident] = room_ident_evaluated unless room_ident_evaluated.nil? || room_ident_evaluated.empty?
|
113
|
-
::Locomotive.log "**> CheckInterval room_ident: #{@options[:room_ident]}"
|
114
|
-
|
115
|
-
raise "Missing parameter 'date_start'" if @options[:date_start].empty?
|
116
|
-
date_start_evaluated = context[@options[:date_start]]
|
117
|
-
@options[:date_start] = date_start_evaluated unless date_start_evaluated.nil?
|
118
|
-
::Locomotive.log "**> CheckInterval date_start_evaluated: #{@options[:date_start]}"
|
119
|
-
|
120
|
-
raise "Missing parameter 'date_end'" if @options[:date_end].empty?
|
121
|
-
date_end_evaluated = context[@options[:date_end]]
|
122
|
-
@options[:date_end] = date_end_evaluated unless date_end_evaluated.nil?
|
123
|
-
::Locomotive.log "**> CheckInterval date_end: #{@options[:date_end]}"
|
124
|
-
|
125
|
-
start_day = @options[:date_start]
|
126
|
-
last_day = @options[:date_end]
|
127
|
-
::Locomotive.log "**> CheckInterval: Date Interval: #{start_day} - #{last_day}"
|
128
|
-
|
129
|
-
wired = Wired.new(config)
|
130
|
-
wired.aquire_token
|
131
|
-
room_data = request_room_data(wired, config['lcode'], @options[:room_ident], start_day, last_day)
|
132
|
-
wired.release_token
|
133
|
-
|
134
|
-
# Check whether first day is available. If this is _not_ the case we have to add one day (vacation == departure is allowed)
|
135
|
-
is_first_available = room_data[0]['avail'] === 1
|
136
|
-
|
137
|
-
# Check wheter the last day is not available. If this is _not_ the case we have to reduce one day (vacation == departure is allowed)
|
138
|
-
is_last_available = room_data[last_day.mjd - start_day.mjd]['avail'] === 1
|
139
|
-
|
140
|
-
# Remove the first or last day from the array.
|
141
|
-
room_data.shift unless is_first_available # Remove first element
|
142
|
-
room_data[0..-1] unless is_last_available # Remove last element
|
143
|
-
|
144
|
-
# Now check the (modified) interval regarding availability
|
145
|
-
is_available = true
|
146
|
-
room_data.each do |data|
|
147
|
-
::Locomotive.log "**> CheckInterval: check: #{data}"
|
148
|
-
if data['avail'] === 0 then
|
149
|
-
is_available = false;
|
150
|
-
break
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
is_available ? "Ok" : "Err"
|
155
|
-
end
|
156
|
-
|
157
|
-
def render_disabled(context)
|
158
|
-
"Ok"
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
# This tag sets the availability of the given days to 0 (false)
|
163
|
-
class SetAsBooked < ::Liquid::Tag
|
164
|
-
include PluginHelper
|
165
|
-
def initialize(tag_name, markup, tokens, context)
|
166
|
-
@options = {
|
167
|
-
room_ident: '',
|
168
|
-
date_start: '',
|
169
|
-
date_end: ''
|
170
|
-
}
|
171
|
-
|
172
|
-
markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') }
|
173
|
-
super
|
174
|
-
end
|
175
|
-
|
176
|
-
def render(context)
|
177
|
-
@plugin_obj = context.registers[:plugin_object]
|
178
|
-
config = @plugin_obj.config
|
179
|
-
|
180
|
-
raise "Missing parameter 'room_ident'" if @options[:room_ident].empty?
|
181
|
-
room_ident_evaluated = context[@options[:room_ident]]
|
182
|
-
@options[:room_ident] = room_ident_evaluated unless room_ident_evaluated.nil? || room_ident_evaluated.empty?
|
183
|
-
::Locomotive.log "**> SetAsBooked room_ident: #{@options[:room_ident]}"
|
184
|
-
|
185
|
-
raise "Missing parameter 'date_start'" if @options[:date_start].empty?
|
186
|
-
date_start_evaluated = context[@options[:date_start]]
|
187
|
-
@options[:date_start] = date_start_evaluated unless date_start_evaluated.nil?
|
188
|
-
::Locomotive.log "**> SetAsBooked date_start_evaluated: #{@options[:date_start_evaluated]}"
|
189
|
-
|
190
|
-
raise "Missing parameter 'date_end'" if @options[:date_end].empty?
|
191
|
-
date_end_evaluated = context[@options[:date_end]]
|
192
|
-
@options[:date_end] = date_end_evaluated unless date_end_evaluated.nil?
|
193
|
-
::Locomotive.log "**> SetAsBooked date_end: #{@options[:date_end]}"
|
194
|
-
|
195
|
-
start_day = @options[:date_start]
|
196
|
-
last_day = @options[:date_end]
|
197
|
-
::Locomotive.log "**> SetAsBooked: Date Interval: #{start_day} - #{last_day}"
|
198
|
-
|
199
|
-
wired = Wired.new(config)
|
200
|
-
wired.aquire_token
|
201
|
-
room_id = fetch_room_id(wired, config['lcode'], @options[:room_ident])
|
202
|
-
|
203
|
-
# Set availability for given date interval to 0
|
204
|
-
days = []
|
205
|
-
(start_day .. last_day).each do |date|
|
206
|
-
# Ignore date.. I will just iterate over every day..
|
207
|
-
days.push({ 'avail' => 0 })
|
208
|
-
end
|
209
|
-
avail_data = [ {'id' => room_id, 'days' => days} ]
|
210
|
-
::Locomotive.log "**> SetAsBooked: Set avail to 0 for: #{start_day}: #{avail_data}"
|
211
|
-
wired.update_rooms_values(config['lcode'], start_day, avail_data)
|
212
|
-
|
213
|
-
wired.release_token
|
214
|
-
|
215
|
-
# Return a html comment that shows us that everything is fine.
|
216
|
-
"<!-- Availability was set to 0 for room #{@options[:room_ident]} from #{@options[:date_start]} to #{@options[:date_end]} -->"
|
217
|
-
end
|
218
|
-
|
219
|
-
def render_disabled(context)
|
220
|
-
"<!-- Locomotive_wubook_plugin is disabled! -->"
|
221
|
-
end
|
222
|
-
end
|
223
43
|
end
|
224
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locomotive_wubook_plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Eilers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: locomotive_plugins
|
@@ -47,8 +47,12 @@ files:
|
|
47
47
|
- Gemfile
|
48
48
|
- lib/locomotive/wubook/plugin.rb
|
49
49
|
- lib/locomotive/wubook/plugin.rb.orig
|
50
|
+
- lib/locomotive/wubook/plugin/available_days_tag.rb
|
51
|
+
- lib/locomotive/wubook/plugin/check_interval_tag.rb
|
50
52
|
- lib/locomotive/wubook/plugin/config.haml
|
51
53
|
- lib/locomotive/wubook/plugin/plugin_helper.rb
|
54
|
+
- lib/locomotive/wubook/plugin/prices_tag.rb
|
55
|
+
- lib/locomotive/wubook/plugin/set_as_booked_tag.rb
|
52
56
|
- lib/locomotive/wubook/plugin/version.rb
|
53
57
|
- lib/locomotive_wubook_plugin.rb
|
54
58
|
homepage: https://github.com/eilers/locomotive_wubook_plugin
|