hotel_beds 0.4.0 → 0.5.0
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/hotel_beds/action/envelope.rb +11 -0
- data/lib/hotel_beds/action/operation.rb +57 -0
- data/lib/hotel_beds/action/request.rb +15 -0
- data/lib/hotel_beds/action/response.rb +27 -0
- data/lib/hotel_beds/basket_remove/envelope.rb +2 -2
- data/lib/hotel_beds/basket_remove/operation.rb +8 -28
- data/lib/hotel_beds/basket_remove/request.rb +2 -7
- data/lib/hotel_beds/basket_remove/response.rb +2 -21
- data/lib/hotel_beds/builder/hotel_occupancy.rb +46 -0
- data/lib/hotel_beds/core_ext/array.rb +15 -0
- data/lib/hotel_beds/hotel_basket_add/envelope.rb +4 -19
- data/lib/hotel_beds/hotel_basket_add/operation.rb +8 -28
- data/lib/hotel_beds/hotel_basket_add/request.rb +2 -5
- data/lib/hotel_beds/hotel_basket_add/response.rb +2 -21
- data/lib/hotel_beds/hotel_search/envelope.rb +4 -19
- data/lib/hotel_beds/hotel_search/operation.rb +8 -28
- data/lib/hotel_beds/hotel_search/request.rb +3 -8
- data/lib/hotel_beds/hotel_search/response.rb +2 -17
- data/lib/hotel_beds/model.rb +10 -0
- data/lib/hotel_beds/purchase_confirm/envelope.rb +2 -2
- data/lib/hotel_beds/purchase_confirm/operation.rb +8 -28
- data/lib/hotel_beds/purchase_confirm/request.rb +2 -5
- data/lib/hotel_beds/purchase_confirm/response.rb +2 -21
- data/lib/hotel_beds/purchase_flush/envelope.rb +2 -2
- data/lib/hotel_beds/purchase_flush/operation.rb +8 -28
- data/lib/hotel_beds/purchase_flush/request.rb +2 -6
- data/lib/hotel_beds/purchase_flush/response.rb +3 -18
- data/lib/hotel_beds/version.rb +1 -1
- data/spec/lib/hotel_beds/model_spec.rb +22 -0
- metadata +10 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5048cf0a8d957dca8fe68b51795053d73fb6b710
|
|
4
|
+
data.tar.gz: 2179c960f5ac433275cea5f79b948555edbec331
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8ee7a4b8ea7890aaf4bd1c0421c2170828ae72e04babd58f55d4ef7fb43e059c782da9968acba6481070be532368c0b850c28caaaf163923cb8e44a85b76259f
|
|
7
|
+
data.tar.gz: fb550b1d74573d78ef0a7a8fcf412deeafa6f58928e7fbb370415e446516df558d8ec88b8d291f408194345a46aff329e8ca98e09483ca04bfd98585526363b1
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module HotelBeds
|
|
2
|
+
module Action
|
|
3
|
+
class Operation
|
|
4
|
+
def self.remote_method(value = nil)
|
|
5
|
+
@remote_method = value if value
|
|
6
|
+
@remote_method
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.remote_namespace(value = nil)
|
|
10
|
+
@remote_namespace = value if value
|
|
11
|
+
@remote_namespace
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.request_class(value = nil)
|
|
15
|
+
@request_class = value if value
|
|
16
|
+
@request_class
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.response_class(value = nil)
|
|
20
|
+
@response_class = value if value
|
|
21
|
+
@response_class
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.envelope_class(value = nil)
|
|
25
|
+
@envelope_class = value if value
|
|
26
|
+
@envelope_class
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
attr_accessor :request, :response, :errors, :action_module
|
|
30
|
+
private :request=, :response=, :errors=, :action_module, :action_module=
|
|
31
|
+
|
|
32
|
+
def initialize(*args)
|
|
33
|
+
self.request = self.class.request_class.new(*args)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def perform(connection:)
|
|
37
|
+
if request.valid?
|
|
38
|
+
self.response = self.class.response_class.new(request, retrieve(connection))
|
|
39
|
+
self.errors = response.errors
|
|
40
|
+
else
|
|
41
|
+
self.errors = request.errors
|
|
42
|
+
end
|
|
43
|
+
freeze
|
|
44
|
+
self
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
def retrieve(connection)
|
|
49
|
+
connection.call({
|
|
50
|
+
method: self.class.remote_method,
|
|
51
|
+
namespace: self.class.remote_namespace,
|
|
52
|
+
data: self.class.envelope_class.new(request).attributes
|
|
53
|
+
})
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require "hotel_beds/model"
|
|
2
|
+
|
|
3
|
+
module HotelBeds
|
|
4
|
+
module Action
|
|
5
|
+
class Request
|
|
6
|
+
include HotelBeds::Model
|
|
7
|
+
|
|
8
|
+
# attributes
|
|
9
|
+
attribute :language, String, default: "ENG"
|
|
10
|
+
|
|
11
|
+
# validation
|
|
12
|
+
validates :language, length: { is: 3 }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require "nokogiri"
|
|
2
|
+
require "hotel_beds/parser/errors"
|
|
3
|
+
|
|
4
|
+
module HotelBeds
|
|
5
|
+
module Action
|
|
6
|
+
class Response
|
|
7
|
+
attr_accessor :request, :headers, :body, :errors
|
|
8
|
+
private :request=, :headers=, :body=, :errors=
|
|
9
|
+
|
|
10
|
+
def initialize(request, response)
|
|
11
|
+
self.request = request
|
|
12
|
+
self.headers = response.header
|
|
13
|
+
self.body = Nokogiri::XML(response.body.values.first)
|
|
14
|
+
self.errors = HotelBeds::Parser::Errors.new(response).to_model(self)
|
|
15
|
+
freeze
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def inspect
|
|
19
|
+
"<#{self.class.name} errors=#{errors.inspect} headers=#{headers.inspect} body=#{body.to_s}>"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def success?
|
|
23
|
+
errors.empty?
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -1,36 +1,16 @@
|
|
|
1
|
+
require "hotel_beds/action/operation"
|
|
2
|
+
require_relative "envelope"
|
|
1
3
|
require_relative "request"
|
|
2
4
|
require_relative "response"
|
|
3
|
-
require_relative "envelope"
|
|
4
5
|
|
|
5
6
|
module HotelBeds
|
|
6
7
|
module BasketRemove
|
|
7
|
-
class Operation
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def perform(connection:)
|
|
16
|
-
if request.valid?
|
|
17
|
-
self.response = Response.new(request, retrieve(connection))
|
|
18
|
-
self.errors = response.errors
|
|
19
|
-
else
|
|
20
|
-
self.errors = request.errors
|
|
21
|
-
end
|
|
22
|
-
freeze
|
|
23
|
-
self
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
def retrieve(connection)
|
|
28
|
-
connection.call({
|
|
29
|
-
method: :serviceRemove,
|
|
30
|
-
namespace: :ServiceRemoveRQ,
|
|
31
|
-
data: Envelope.new(request).attributes
|
|
32
|
-
})
|
|
33
|
-
end
|
|
8
|
+
class Operation < HotelBeds::Action::Operation
|
|
9
|
+
remote_method :serviceRemove
|
|
10
|
+
remote_namespace :ServiceRemoveRQ
|
|
11
|
+
envelope_class Envelope
|
|
12
|
+
request_class Request
|
|
13
|
+
response_class Response
|
|
34
14
|
end
|
|
35
15
|
end
|
|
36
16
|
end
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
require "hotel_beds/
|
|
1
|
+
require "hotel_beds/action/request"
|
|
2
2
|
|
|
3
3
|
module HotelBeds
|
|
4
4
|
module BasketRemove
|
|
5
|
-
class Request
|
|
6
|
-
include HotelBeds::Model
|
|
7
|
-
|
|
5
|
+
class Request < HotelBeds::Action::Request
|
|
8
6
|
# attributes
|
|
9
|
-
attribute :language, String, default: "ENG"
|
|
10
7
|
attribute :purchase_token, String
|
|
11
8
|
attribute :service_id, String
|
|
12
9
|
|
|
13
|
-
|
|
14
10
|
# validation
|
|
15
|
-
validates :language, length: { is: 3 }
|
|
16
11
|
validates :service_id, :purchase_token, presence: true
|
|
17
12
|
end
|
|
18
13
|
end
|
|
@@ -1,28 +1,9 @@
|
|
|
1
|
-
require "hotel_beds/
|
|
1
|
+
require "hotel_beds/action/response"
|
|
2
2
|
require "hotel_beds/parser/purchase"
|
|
3
3
|
|
|
4
4
|
module HotelBeds
|
|
5
5
|
module BasketRemove
|
|
6
|
-
class Response
|
|
7
|
-
attr_accessor :request, :headers, :body, :errors
|
|
8
|
-
private :request=, :headers=, :body=, :errors=
|
|
9
|
-
|
|
10
|
-
def initialize(request, response)
|
|
11
|
-
self.request = request
|
|
12
|
-
self.headers = response.header
|
|
13
|
-
self.body = Nokogiri::XML(response.body.fetch(:service_remove))
|
|
14
|
-
self.errors = HotelBeds::Parser::Errors.new(response).to_model(self)
|
|
15
|
-
freeze
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def inspect
|
|
19
|
-
"<#{self.class.name} errors=#{errors.inspect} headers=#{headers.inspect} body=#{body.to_s}>"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def success?
|
|
23
|
-
errors.empty?
|
|
24
|
-
end
|
|
25
|
-
|
|
6
|
+
class Response < HotelBeds::Action::Response
|
|
26
7
|
def purchase
|
|
27
8
|
HotelBeds::Parser::Purchase.new(body.at_css("Purchase")).to_model
|
|
28
9
|
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require "hotel_beds/core_ext/array"
|
|
2
|
+
|
|
3
|
+
using HotelBeds::CoreExt::Array
|
|
4
|
+
|
|
5
|
+
module HotelBeds
|
|
6
|
+
module Builder
|
|
7
|
+
class HotelOccupancy
|
|
8
|
+
attr_accessor :rooms
|
|
9
|
+
private :rooms=
|
|
10
|
+
|
|
11
|
+
def initialize(rooms)
|
|
12
|
+
self.rooms = rooms
|
|
13
|
+
freeze
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def child_ages
|
|
17
|
+
rooms.map(&:child_ages).flatten_children
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def adult_count
|
|
21
|
+
rooms.map(&:adult_count).sum
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def child_count
|
|
25
|
+
rooms.map(&:child_count).sum
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def to_h
|
|
29
|
+
{
|
|
30
|
+
RoomCount: rooms.size,
|
|
31
|
+
Occupancy: {
|
|
32
|
+
AdultCount: adult_count,
|
|
33
|
+
ChildCount: child_count,
|
|
34
|
+
GuestList: {
|
|
35
|
+
Customer: 1.upto(adult_count).map {
|
|
36
|
+
{ :@type => "AD" }
|
|
37
|
+
} + 1.upto(child_count).map { |i|
|
|
38
|
+
{ :@type => "CH", :Age => Integer(child_ages.fetch(i - 1)) }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "hotel_beds/action/envelope"
|
|
2
|
+
require "hotel_beds/builder/hotel_occupancy"
|
|
2
3
|
|
|
3
4
|
module HotelBeds
|
|
4
5
|
module HotelBasketAdd
|
|
5
|
-
class Envelope <
|
|
6
|
+
class Envelope < HotelBeds::Action::Envelope
|
|
6
7
|
def attributes
|
|
7
8
|
{
|
|
8
9
|
Language: language,
|
|
@@ -48,23 +49,7 @@ module HotelBeds
|
|
|
48
49
|
end
|
|
49
50
|
|
|
50
51
|
def build_room(rooms)
|
|
51
|
-
|
|
52
|
-
adult_count = rooms.map(&:adult_count).inject(0, :+)
|
|
53
|
-
child_count = rooms.map(&:child_count).inject(0, :+)
|
|
54
|
-
{
|
|
55
|
-
RoomCount: rooms.size,
|
|
56
|
-
Occupancy: {
|
|
57
|
-
AdultCount: adult_count,
|
|
58
|
-
ChildCount: child_count,
|
|
59
|
-
GuestList: {
|
|
60
|
-
Customer: (1..adult_count).map {
|
|
61
|
-
{ :@type => "AD" }
|
|
62
|
-
} + (1..child_count).map { |i|
|
|
63
|
-
{ :@type => "CH", :Age => Integer(child_ages[i - 1]) }
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
52
|
+
HotelBeds::Builder::HotelOccupancy.new(rooms).to_h
|
|
68
53
|
end
|
|
69
54
|
end
|
|
70
55
|
end
|
|
@@ -1,36 +1,16 @@
|
|
|
1
|
+
require "hotel_beds/action/operation"
|
|
2
|
+
require_relative "envelope"
|
|
1
3
|
require_relative "request"
|
|
2
4
|
require_relative "response"
|
|
3
|
-
require_relative "envelope"
|
|
4
5
|
|
|
5
6
|
module HotelBeds
|
|
6
7
|
module HotelBasketAdd
|
|
7
|
-
class Operation
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def perform(connection:)
|
|
16
|
-
if request.valid?
|
|
17
|
-
self.response = Response.new(request, retrieve(connection))
|
|
18
|
-
self.errors = response.errors
|
|
19
|
-
else
|
|
20
|
-
self.errors = request.errors
|
|
21
|
-
end
|
|
22
|
-
freeze
|
|
23
|
-
self
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
def retrieve(connection)
|
|
28
|
-
connection.call({
|
|
29
|
-
method: :serviceAdd,
|
|
30
|
-
namespace: :ServiceAddRQ,
|
|
31
|
-
data: Envelope.new(request).attributes
|
|
32
|
-
})
|
|
33
|
-
end
|
|
8
|
+
class Operation < HotelBeds::Action::Operation
|
|
9
|
+
remote_method :serviceAdd
|
|
10
|
+
remote_namespace :ServiceAddRQ
|
|
11
|
+
envelope_class Envelope
|
|
12
|
+
request_class Request
|
|
13
|
+
response_class Response
|
|
34
14
|
end
|
|
35
15
|
end
|
|
36
16
|
end
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
require "securerandom"
|
|
2
|
+
require "hotel_beds/action/request"
|
|
2
3
|
require "hotel_beds/model"
|
|
3
4
|
require "hotel_beds/model/available_room"
|
|
4
5
|
|
|
5
6
|
module HotelBeds
|
|
6
7
|
module HotelBasketAdd
|
|
7
|
-
class Request
|
|
8
|
+
class Request < HotelBeds::Action::Request
|
|
8
9
|
class HotelService
|
|
9
10
|
include HotelBeds::Model
|
|
10
11
|
|
|
@@ -34,15 +35,11 @@ module HotelBeds
|
|
|
34
35
|
end
|
|
35
36
|
end
|
|
36
37
|
|
|
37
|
-
include HotelBeds::Model
|
|
38
|
-
|
|
39
38
|
# attributes
|
|
40
39
|
attribute :session_id, String, default: SecureRandom.hex[0..15]
|
|
41
|
-
attribute :language, String, default: "ENG"
|
|
42
40
|
attribute :service, HotelService
|
|
43
41
|
|
|
44
42
|
# validation
|
|
45
|
-
validates :language, length: { is: 3 }
|
|
46
43
|
validates :session_id, :service, presence: true
|
|
47
44
|
end
|
|
48
45
|
end
|
|
@@ -1,32 +1,13 @@
|
|
|
1
|
-
require "hotel_beds/
|
|
1
|
+
require "hotel_beds/action/response"
|
|
2
2
|
require "hotel_beds/parser/purchase"
|
|
3
3
|
|
|
4
4
|
module HotelBeds
|
|
5
5
|
module HotelBasketAdd
|
|
6
|
-
class Response
|
|
7
|
-
attr_accessor :request, :headers, :body, :errors
|
|
8
|
-
private :request=, :headers=, :body=, :errors=
|
|
9
|
-
|
|
10
|
-
def initialize(request, response)
|
|
11
|
-
self.request = request
|
|
12
|
-
self.headers = response.header
|
|
13
|
-
self.body = Nokogiri::XML(response.body.fetch(:service_add))
|
|
14
|
-
self.errors = HotelBeds::Parser::Errors.new(response).to_model(self)
|
|
15
|
-
freeze
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def inspect
|
|
19
|
-
"<#{self.class.name} errors=#{errors.inspect} headers=#{headers.inspect} body=#{body.to_s}>"
|
|
20
|
-
end
|
|
21
|
-
|
|
6
|
+
class Response < HotelBeds::Action::Response
|
|
22
7
|
def session_id
|
|
23
8
|
request.session_id
|
|
24
9
|
end
|
|
25
10
|
|
|
26
|
-
def success?
|
|
27
|
-
errors.empty?
|
|
28
|
-
end
|
|
29
|
-
|
|
30
11
|
def purchase
|
|
31
12
|
HotelBeds::Parser::Purchase.new(body.at_css("Purchase")).to_model
|
|
32
13
|
end
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "hotel_beds/action/envelope"
|
|
2
|
+
require "hotel_beds/builder/hotel_occupancy"
|
|
2
3
|
|
|
3
4
|
module HotelBeds
|
|
4
5
|
module HotelSearch
|
|
5
|
-
class Envelope <
|
|
6
|
+
class Envelope < HotelBeds::Action::Envelope
|
|
6
7
|
def attributes
|
|
7
8
|
{
|
|
8
9
|
:@sessionId => session_id,
|
|
@@ -70,23 +71,7 @@ module HotelBeds
|
|
|
70
71
|
end
|
|
71
72
|
|
|
72
73
|
def build_room(rooms)
|
|
73
|
-
|
|
74
|
-
adult_count = rooms.map(&:adult_count).inject(0, :+)
|
|
75
|
-
child_count = rooms.map(&:child_count).inject(0, :+)
|
|
76
|
-
{
|
|
77
|
-
RoomCount: rooms.size,
|
|
78
|
-
Occupancy: {
|
|
79
|
-
AdultCount: adult_count,
|
|
80
|
-
ChildCount: child_count,
|
|
81
|
-
GuestList: {
|
|
82
|
-
Customer: (1..adult_count).map {
|
|
83
|
-
{ :@type => "AD" }
|
|
84
|
-
} + (1..child_count).map { |i|
|
|
85
|
-
{ :@type => "CH", :Age => Integer(child_ages[i - 1]) }
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
74
|
+
HotelBeds::Builder::HotelOccupancy.new(rooms).to_h
|
|
90
75
|
end
|
|
91
76
|
end
|
|
92
77
|
end
|
|
@@ -1,36 +1,16 @@
|
|
|
1
|
+
require "hotel_beds/action/operation"
|
|
2
|
+
require_relative "envelope"
|
|
1
3
|
require_relative "request"
|
|
2
4
|
require_relative "response"
|
|
3
|
-
require_relative "envelope"
|
|
4
5
|
|
|
5
6
|
module HotelBeds
|
|
6
7
|
module HotelSearch
|
|
7
|
-
class Operation
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def perform(connection:)
|
|
16
|
-
if request.valid?
|
|
17
|
-
self.response = Response.new(request, retrieve(connection))
|
|
18
|
-
self.errors = response.errors
|
|
19
|
-
else
|
|
20
|
-
self.errors = request.errors
|
|
21
|
-
end
|
|
22
|
-
freeze
|
|
23
|
-
self
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
def retrieve(connection)
|
|
28
|
-
connection.call({
|
|
29
|
-
method: :getHotelValuedAvail,
|
|
30
|
-
namespace: :HotelValuedAvailRQ,
|
|
31
|
-
data: Envelope.new(request).attributes
|
|
32
|
-
})
|
|
33
|
-
end
|
|
8
|
+
class Operation < HotelBeds::Action::Operation
|
|
9
|
+
remote_method :getHotelValuedAvail
|
|
10
|
+
remote_namespace :HotelValuedAvailRQ
|
|
11
|
+
envelope_class Envelope
|
|
12
|
+
request_class Request
|
|
13
|
+
response_class Response
|
|
34
14
|
end
|
|
35
15
|
end
|
|
36
16
|
end
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
require "securerandom"
|
|
2
|
-
require "hotel_beds/
|
|
2
|
+
require "hotel_beds/action/request"
|
|
3
3
|
require "hotel_beds/model/requested_room"
|
|
4
4
|
|
|
5
5
|
module HotelBeds
|
|
6
6
|
module HotelSearch
|
|
7
|
-
class Request
|
|
8
|
-
include HotelBeds::Model
|
|
9
|
-
|
|
7
|
+
class Request < HotelBeds::Action::Request
|
|
10
8
|
# attributes
|
|
11
9
|
attribute :session_id, String, default: SecureRandom.hex[0..15]
|
|
12
10
|
attribute :page_number, Integer, default: 1
|
|
13
11
|
attribute :items_per_page, Integer, default: 50
|
|
14
|
-
attribute :language, String, default: "ENG"
|
|
15
12
|
attribute :check_in_date, Date
|
|
16
13
|
attribute :check_out_date, Date
|
|
17
14
|
attribute :destination_code, String
|
|
@@ -19,9 +16,7 @@ module HotelBeds
|
|
|
19
16
|
attribute :rooms, Array[HotelBeds::Model::RequestedRoom]
|
|
20
17
|
|
|
21
18
|
# validation
|
|
22
|
-
validates :
|
|
23
|
-
is: 3, allow_blank: false
|
|
24
|
-
}
|
|
19
|
+
validates :destination_code, length: { is: 3, allow_blank: false }
|
|
25
20
|
validates :session_id, :check_in_date, :check_out_date, presence: true
|
|
26
21
|
validates :rooms, length: { minimum: 1, maximum: 5 }
|
|
27
22
|
validates :page_number, numericality: {
|
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
require "hotel_beds/
|
|
1
|
+
require "hotel_beds/action/response"
|
|
2
2
|
require "hotel_beds/parser/hotel"
|
|
3
3
|
|
|
4
4
|
module HotelBeds
|
|
5
5
|
module HotelSearch
|
|
6
|
-
class Response
|
|
7
|
-
attr_accessor :request, :headers, :body, :errors
|
|
8
|
-
private :request=, :headers=, :body=, :errors=
|
|
9
|
-
|
|
10
|
-
def initialize(request, response)
|
|
11
|
-
self.request = request
|
|
12
|
-
self.headers = response.header
|
|
13
|
-
self.body = Nokogiri::XML(response.body.fetch(:get_hotel_valued_avail))
|
|
14
|
-
self.errors = HotelBeds::Parser::Errors.new(response).to_model(self)
|
|
15
|
-
freeze
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def inspect
|
|
19
|
-
"<#{self.class.name} errors=#{errors.inspect} headers=#{headers.inspect} body=#{body.to_s}>"
|
|
20
|
-
end
|
|
21
|
-
|
|
6
|
+
class Response < HotelBeds::Action::Response
|
|
22
7
|
def session_id
|
|
23
8
|
request.session_id
|
|
24
9
|
end
|
data/lib/hotel_beds/model.rb
CHANGED
|
@@ -9,5 +9,15 @@ module HotelBeds
|
|
|
9
9
|
include ActiveModel::Validations
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
|
+
|
|
13
|
+
def deep_attributes
|
|
14
|
+
attributes.inject(Hash.new) do |result, (key, value)|
|
|
15
|
+
if value.respond_to?(:deep_attributes)
|
|
16
|
+
result.merge(key => value.deep_attributes)
|
|
17
|
+
else
|
|
18
|
+
result.merge(key => value)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
12
22
|
end
|
|
13
23
|
end
|
|
@@ -1,36 +1,16 @@
|
|
|
1
|
+
require "hotel_beds/action/operation"
|
|
2
|
+
require_relative "envelope"
|
|
1
3
|
require_relative "request"
|
|
2
4
|
require_relative "response"
|
|
3
|
-
require_relative "envelope"
|
|
4
5
|
|
|
5
6
|
module HotelBeds
|
|
6
7
|
module PurchaseConfirm
|
|
7
|
-
class Operation
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def perform(connection:)
|
|
16
|
-
if request.valid?
|
|
17
|
-
self.response = Response.new(request, retrieve(connection))
|
|
18
|
-
self.errors = response.errors
|
|
19
|
-
else
|
|
20
|
-
self.errors = request.errors
|
|
21
|
-
end
|
|
22
|
-
freeze
|
|
23
|
-
self
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
def retrieve(connection)
|
|
28
|
-
connection.call({
|
|
29
|
-
method: :purchaseConfirm,
|
|
30
|
-
namespace: :PurchaseConfirmRQ,
|
|
31
|
-
data: Envelope.new(request).attributes
|
|
32
|
-
})
|
|
33
|
-
end
|
|
8
|
+
class Operation < HotelBeds::Action::Operation
|
|
9
|
+
remote_method :purchaseConfirm
|
|
10
|
+
remote_namespace :PurchaseConfirmRQ
|
|
11
|
+
envelope_class Envelope
|
|
12
|
+
request_class Request
|
|
13
|
+
response_class Response
|
|
34
14
|
end
|
|
35
15
|
end
|
|
36
16
|
end
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
require "securerandom"
|
|
2
|
+
require "hotel_beds/action/request"
|
|
2
3
|
require "hotel_beds/model"
|
|
3
4
|
require "hotel_beds/model/customer"
|
|
4
5
|
|
|
5
6
|
module HotelBeds
|
|
6
7
|
module PurchaseConfirm
|
|
7
|
-
class Request
|
|
8
|
+
class Request < HotelBeds::Action::Request
|
|
8
9
|
class Service
|
|
9
10
|
include HotelBeds::Model
|
|
10
11
|
|
|
@@ -51,14 +52,10 @@ module HotelBeds
|
|
|
51
52
|
end
|
|
52
53
|
end
|
|
53
54
|
|
|
54
|
-
include HotelBeds::Model
|
|
55
|
-
|
|
56
55
|
# attributes
|
|
57
|
-
attribute :language, String, default: "ENG"
|
|
58
56
|
attribute :purchase, Purchase
|
|
59
57
|
|
|
60
58
|
# validation
|
|
61
|
-
validates :language, length: { is: 3 }
|
|
62
59
|
validates :purchase, presence: true
|
|
63
60
|
validate do |request|
|
|
64
61
|
if request.purchase && request.purchase.invalid?
|
|
@@ -1,28 +1,9 @@
|
|
|
1
|
-
require "hotel_beds/
|
|
1
|
+
require "hotel_beds/action/response"
|
|
2
2
|
require "hotel_beds/parser/purchase"
|
|
3
3
|
|
|
4
4
|
module HotelBeds
|
|
5
5
|
module PurchaseConfirm
|
|
6
|
-
class Response
|
|
7
|
-
attr_accessor :request, :headers, :body, :errors
|
|
8
|
-
private :request=, :headers=, :body=, :errors=
|
|
9
|
-
|
|
10
|
-
def initialize(request, response)
|
|
11
|
-
self.request = request
|
|
12
|
-
self.headers = response.header
|
|
13
|
-
self.body = Nokogiri::XML(response.body.fetch(:purchase_confirm))
|
|
14
|
-
self.errors = HotelBeds::Parser::Errors.new(response).to_model(self)
|
|
15
|
-
freeze
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def inspect
|
|
19
|
-
"<#{self.class.name} errors=#{errors.inspect} headers=#{headers.inspect} body=#{body.to_s}>"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def success?
|
|
23
|
-
errors.empty?
|
|
24
|
-
end
|
|
25
|
-
|
|
6
|
+
class Response < HotelBeds::Action::Response
|
|
26
7
|
def purchase
|
|
27
8
|
HotelBeds::Parser::Purchase.new(body.at_css("Purchase")).to_model
|
|
28
9
|
end
|
|
@@ -1,36 +1,16 @@
|
|
|
1
|
+
require "hotel_beds/action/operation"
|
|
2
|
+
require_relative "envelope"
|
|
1
3
|
require_relative "request"
|
|
2
4
|
require_relative "response"
|
|
3
|
-
require_relative "envelope"
|
|
4
5
|
|
|
5
6
|
module HotelBeds
|
|
6
7
|
module PurchaseFlush
|
|
7
|
-
class Operation
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def perform(connection:)
|
|
16
|
-
if request.valid?
|
|
17
|
-
self.response = Response.new(request, retrieve(connection))
|
|
18
|
-
self.errors = response.errors
|
|
19
|
-
else
|
|
20
|
-
self.errors = request.errors
|
|
21
|
-
end
|
|
22
|
-
freeze
|
|
23
|
-
self
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
def retrieve(connection)
|
|
28
|
-
connection.call({
|
|
29
|
-
method: :purchaseFlush,
|
|
30
|
-
namespace: :PurchaseFlushRQ,
|
|
31
|
-
data: Envelope.new(request).attributes
|
|
32
|
-
})
|
|
33
|
-
end
|
|
8
|
+
class Operation < HotelBeds::Action::Operation
|
|
9
|
+
remote_method :purchaseFlush
|
|
10
|
+
remote_namespace :PurchaseFlushRQ
|
|
11
|
+
envelope_class Envelope
|
|
12
|
+
request_class Request
|
|
13
|
+
response_class Response
|
|
34
14
|
end
|
|
35
15
|
end
|
|
36
16
|
end
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
require "hotel_beds/
|
|
1
|
+
require "hotel_beds/action/request"
|
|
2
2
|
|
|
3
3
|
module HotelBeds
|
|
4
4
|
module PurchaseFlush
|
|
5
|
-
class Request
|
|
6
|
-
include HotelBeds::Model
|
|
7
|
-
|
|
5
|
+
class Request < HotelBeds::Action::Request
|
|
8
6
|
# attributes
|
|
9
|
-
attribute :language, String, default: "ENG"
|
|
10
7
|
attribute :purchase_token, String
|
|
11
8
|
|
|
12
9
|
# validation
|
|
13
|
-
validates :language, length: { is: 3 }
|
|
14
10
|
validates :purchase_token, presence: true
|
|
15
11
|
end
|
|
16
12
|
end
|
|
@@ -1,25 +1,10 @@
|
|
|
1
|
-
require "hotel_beds/
|
|
1
|
+
require "hotel_beds/action/response"
|
|
2
2
|
|
|
3
3
|
module HotelBeds
|
|
4
4
|
module PurchaseFlush
|
|
5
|
-
class Response
|
|
6
|
-
attr_accessor :request, :headers, :body, :errors
|
|
7
|
-
private :request=, :headers=, :body=, :errors=
|
|
8
|
-
|
|
9
|
-
def initialize(request, response)
|
|
10
|
-
self.request = request
|
|
11
|
-
self.headers = response.header
|
|
12
|
-
self.body = Nokogiri::XML(response.body.fetch(:purchase_flush))
|
|
13
|
-
self.errors = HotelBeds::Parser::Errors.new(response).to_model(self)
|
|
14
|
-
freeze
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def inspect
|
|
18
|
-
"<#{self.class.name} errors=#{errors.inspect} headers=#{headers.inspect} body=#{body.to_s}>"
|
|
19
|
-
end
|
|
20
|
-
|
|
5
|
+
class Response < HotelBeds::Action::Response
|
|
21
6
|
def success?
|
|
22
|
-
|
|
7
|
+
super && body.at_css("Status").content == "Y"
|
|
23
8
|
end
|
|
24
9
|
end
|
|
25
10
|
end
|
data/lib/hotel_beds/version.rb
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require "hotel_beds/model"
|
|
2
|
+
|
|
3
|
+
RSpec.describe HotelBeds::Model do
|
|
4
|
+
describe "#deep_attributes" do
|
|
5
|
+
let(:attributes) do
|
|
6
|
+
Hash({ nested: { nested_again: { title: "test" } } })
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
let(:instance_with_nesting) do
|
|
10
|
+
base = Class.new { include HotelBeds::Model }
|
|
11
|
+
deeply_nested = Class.new(base) { attribute :title, String }
|
|
12
|
+
nested = Class.new(base) { attribute :nested_again, deeply_nested }
|
|
13
|
+
Class.new(base) { attribute :nested, nested }.new(attributes)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
subject { instance_with_nesting.deep_attributes }
|
|
17
|
+
|
|
18
|
+
it "should return a nested hash of attributes" do
|
|
19
|
+
expect(subject).to eq(attributes)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hotel_beds
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryan Townsend
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-08-
|
|
11
|
+
date: 2014-08-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: savon
|
|
@@ -171,13 +171,19 @@ files:
|
|
|
171
171
|
- Rakefile
|
|
172
172
|
- hotel_beds.gemspec
|
|
173
173
|
- lib/hotel_beds.rb
|
|
174
|
+
- lib/hotel_beds/action/envelope.rb
|
|
175
|
+
- lib/hotel_beds/action/operation.rb
|
|
176
|
+
- lib/hotel_beds/action/request.rb
|
|
177
|
+
- lib/hotel_beds/action/response.rb
|
|
174
178
|
- lib/hotel_beds/basket_remove/envelope.rb
|
|
175
179
|
- lib/hotel_beds/basket_remove/operation.rb
|
|
176
180
|
- lib/hotel_beds/basket_remove/request.rb
|
|
177
181
|
- lib/hotel_beds/basket_remove/response.rb
|
|
182
|
+
- lib/hotel_beds/builder/hotel_occupancy.rb
|
|
178
183
|
- lib/hotel_beds/client.rb
|
|
179
184
|
- lib/hotel_beds/configuration.rb
|
|
180
185
|
- lib/hotel_beds/connection.rb
|
|
186
|
+
- lib/hotel_beds/core_ext/array.rb
|
|
181
187
|
- lib/hotel_beds/hotel_basket_add/envelope.rb
|
|
182
188
|
- lib/hotel_beds/hotel_basket_add/operation.rb
|
|
183
189
|
- lib/hotel_beds/hotel_basket_add/request.rb
|
|
@@ -229,6 +235,7 @@ files:
|
|
|
229
235
|
- spec/lib/hotel_beds/configuration_spec.rb
|
|
230
236
|
- spec/lib/hotel_beds/connection_spec.rb
|
|
231
237
|
- spec/lib/hotel_beds/hotel_search/request_spec.rb
|
|
238
|
+
- spec/lib/hotel_beds/model_spec.rb
|
|
232
239
|
- spec/lib/hotel_beds/parser/room_grouper_spec.rb
|
|
233
240
|
- spec/lib/hotel_beds/parser/service_spec.rb
|
|
234
241
|
- spec/lib/hotel_beds/version_spec.rb
|
|
@@ -265,6 +272,7 @@ test_files:
|
|
|
265
272
|
- spec/lib/hotel_beds/configuration_spec.rb
|
|
266
273
|
- spec/lib/hotel_beds/connection_spec.rb
|
|
267
274
|
- spec/lib/hotel_beds/hotel_search/request_spec.rb
|
|
275
|
+
- spec/lib/hotel_beds/model_spec.rb
|
|
268
276
|
- spec/lib/hotel_beds/parser/room_grouper_spec.rb
|
|
269
277
|
- spec/lib/hotel_beds/parser/service_spec.rb
|
|
270
278
|
- spec/lib/hotel_beds/version_spec.rb
|