hotel_beds 1.0.3 → 1.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: 3a0eb6974633d7a50969cd29be704d6df8ad89e9
4
- data.tar.gz: 15bf5cce7a88c87179692d1495c0f8cbe064a836
3
+ metadata.gz: d4943a29f21c229180aeba0145ba50bef3ce492b
4
+ data.tar.gz: 9bbedd521584b624e9fc620976a1cd033a9d28c7
5
5
  SHA512:
6
- metadata.gz: 0e408d399f1e8e84abc407b566af0c997233d0aff1b310e121c9d18bd0b2e62ade3839f679f2d6445b50537904ffda4a0f41140989de51f2c911ae40a0906f60
7
- data.tar.gz: 05fa8e8b6ee9d7ab0807ee56aa64122fd37cd5880e247e692b84c0d3a6b686a9f2edd85a582693790678425c7353dd4d8c38daa02e4d06f5f5684d2b3fa3e65a
6
+ metadata.gz: d07e2dbc48855227610008aaf00573904278a4a6faef7046f008925ebe44a66b1cf45b8503d41fdf11ed9b07f7dd6f5de9aed65eca0761c29006966b6d8bb2b5
7
+ data.tar.gz: e3f56d092137f67964326e1de715e12be08193c21446f955162db7fec884f322249bf7f68555e3ea3f9971582b4f967bae687628a12b7c3781731b326caec8c7
@@ -1,4 +1,5 @@
1
1
  require "hotel_beds/model/hotel"
2
+ require "hotel_beds/model/reference"
2
3
 
3
4
  module HotelBeds
4
5
  module Model
@@ -11,6 +12,7 @@ module HotelBeds
11
12
  attribute :date_to, Date
12
13
  attribute :currency, String
13
14
  attribute :amount, BigDecimal
15
+ attribute :reference, HotelBeds::Model::Reference
14
16
  end
15
17
  end
16
18
  end
@@ -14,6 +14,8 @@ module HotelBeds
14
14
  attribute :amount, selector: "TotalAmount"
15
15
  attribute :supplier, selector: "Supplier",
16
16
  parser: HotelBeds::Parser::Supplier
17
+ attribute :reference, selector: "Reference",
18
+ parser: HotelBeds::Parser::Reference
17
19
  end
18
20
  end
19
21
  end
@@ -2,7 +2,9 @@ require "hotel_beds/parser/hotel"
2
2
 
3
3
  module HotelBeds
4
4
  module Parser
5
- class Supplier < Hotel
5
+ class Supplier
6
+ include HotelBeds::Parser
7
+
6
8
  # attributes
7
9
  attribute :name, attr: "name"
8
10
  attribute :vat_number, attr: "vatNumber"
@@ -1,3 +1,3 @@
1
1
  module HotelBeds
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -0,0 +1,36 @@
1
+ require "ox"
2
+
3
+ module HotelBeds
4
+ class XmlHandler < ::Ox::Sax
5
+ attr_accessor :object, :selectors
6
+
7
+ def initialize(object)
8
+ self.object = object
9
+ self.selectors = Array.new
10
+ end
11
+
12
+ def start_element(name)
13
+ self.selectors.push(name.to_sym)
14
+ end
15
+
16
+ def end_element(name)
17
+ self.selectors.pop
18
+ end
19
+
20
+ def attr(name, value)
21
+ object.properties.select do |property|
22
+ selectors == property.selectors && name.to_sym == property.attribute
23
+ end.each do |property|
24
+ property.value = value
25
+ end
26
+ end
27
+
28
+ def text(value)
29
+ object.properties.select do |property|
30
+ selectors == property.selectors && property.content?
31
+ end.each do |property|
32
+ property.value = value
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,99 @@
1
+ require "stringio"
2
+ require "ox"
3
+ require "hotel_beds/xml_handler"
4
+
5
+ RSpec.describe HotelBeds::XmlHandler do
6
+ let(:io) do
7
+ StringIO.new(%Q(
8
+ <root name="Test">
9
+ <inner value="6">
10
+ <attr>contained text</attr>
11
+ <ignore>me</ignore>
12
+ <alsoignore />
13
+ <boolean yes="true" no="false" />
14
+ </inner>
15
+
16
+ <urls>
17
+ <url>http://example.com/123</url>
18
+ <url>http://example.com/456</url>
19
+ <non-url>A label</non-url>
20
+ </urls>
21
+
22
+ <images>
23
+ <image src="http://example.com/123.jpg" />
24
+ <image src="http://example.com/456.jpg" />
25
+ <image />
26
+ </image>
27
+ </root>
28
+ ))
29
+ end
30
+
31
+ let(:object) do
32
+ Class.new do
33
+ class Property
34
+ attr_accessor :name, :attribute, :selectors, :array, :content
35
+ attr_reader :value
36
+ private :name=, :attribute=, :selectors=, :array=, :content=
37
+
38
+ def initialize(name:, selectors:, attribute: nil, array: false, content: false)
39
+ self.name = name.to_sym
40
+ self.selectors = selectors.map(&:to_sym)
41
+ self.attribute = attribute.to_sym if attribute
42
+ self.array = !!array
43
+ self.content = !!content
44
+ @value = Array.new if array?
45
+ end
46
+
47
+ def value=(value)
48
+ if array?
49
+ @value.push(value)
50
+ else
51
+ @value = value
52
+ end
53
+ end
54
+
55
+ def content?
56
+ !!content
57
+ end
58
+
59
+ def array?
60
+ !!array
61
+ end
62
+ end
63
+
64
+ def properties
65
+ @properties ||= [
66
+ Property.new(name: :name, attribute: :name, selectors: %w(root)),
67
+ Property.new(name: :value, attribute: :value, selectors: %w(root inner)),
68
+ Property.new(name: :contents, content: true, selectors: %w(root inner attr)),
69
+ Property.new(name: :yes, attribute: :yes, selectors: %w(root inner boolean)),
70
+ Property.new(name: :no, attribute: :no, selectors: %w(root inner boolean)),
71
+ Property.new(name: :urls, content: true, selectors: %w(root urls url), array: true),
72
+ Property.new(name: :image_urls, attribute: :src, selectors: %w(root images image), array: true),
73
+ ]
74
+ end
75
+
76
+ def method_missing(name, *args, &block)
77
+ if args.size == 0 && !block_given? && (property = properties.find { |p| p.name == name.to_sym })
78
+ property.value
79
+ else
80
+ super
81
+ end
82
+ end
83
+ end.new
84
+ end
85
+
86
+ let(:handler) { HotelBeds::XmlHandler.new(object) }
87
+
88
+ before(:each) { Ox.sax_parse(handler, io) }
89
+
90
+ it "should parse out the properties correctly" do
91
+ expect(object.name).to eq("Test")
92
+ expect(object.value).to eq("6")
93
+ expect(object.contents).to eq("contained text")
94
+ expect(object.yes).to eq("true")
95
+ expect(object.no).to eq("false")
96
+ expect(object.urls).to eq(["http://example.com/123", "http://example.com/456"])
97
+ expect(object.image_urls).to eq(["http://example.com/123.jpg", "http://example.com/456.jpg"])
98
+ end
99
+ 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: 1.0.3
4
+ version: 1.0.4
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-09-22 00:00:00.000000000 Z
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: savon
@@ -232,6 +232,7 @@ files:
232
232
  - lib/hotel_beds/purchase_flush/request.rb
233
233
  - lib/hotel_beds/purchase_flush/response.rb
234
234
  - lib/hotel_beds/version.rb
235
+ - lib/hotel_beds/xml_handler.rb
235
236
  - spec/features/flushing_the_basket_spec.rb
236
237
  - spec/features/ordering_a_hotel_room_spec.rb
237
238
  - spec/features/removing_a_basket_item_spec.rb
@@ -243,6 +244,7 @@ files:
243
244
  - spec/lib/hotel_beds/parser/hotel_service_spec.rb
244
245
  - spec/lib/hotel_beds/parser/room_grouper_spec.rb
245
246
  - spec/lib/hotel_beds/version_spec.rb
247
+ - spec/lib/hotel_beds/xml_handler_spec.rb
246
248
  - spec/spec_helper.rb
247
249
  homepage: https://www.hotelsindex.com/open-source
248
250
  licenses:
@@ -280,4 +282,5 @@ test_files:
280
282
  - spec/lib/hotel_beds/parser/hotel_service_spec.rb
281
283
  - spec/lib/hotel_beds/parser/room_grouper_spec.rb
282
284
  - spec/lib/hotel_beds/version_spec.rb
285
+ - spec/lib/hotel_beds/xml_handler_spec.rb
283
286
  - spec/spec_helper.rb