hotels_pro 0.2
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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +91 -0
- data/Rakefile +2 -0
- data/hotels_pro.gemspec +24 -0
- data/lib/hotels_pro.rb +69 -0
- data/lib/hotels_pro/api/api_method.rb +29 -0
- data/lib/hotels_pro/api/api_params.rb +29 -0
- data/lib/hotels_pro/api/elements/book_info.rb +27 -0
- data/lib/hotels_pro/api/elements/daily_rate.rb +12 -0
- data/lib/hotels_pro/api/elements/filter.rb +13 -0
- data/lib/hotels_pro/api/elements/hotel.rb +22 -0
- data/lib/hotels_pro/api/elements/lead_traveller.rb +15 -0
- data/lib/hotels_pro/api/elements/pax.rb +16 -0
- data/lib/hotels_pro/api/elements/pax_array.rb +17 -0
- data/lib/hotels_pro/api/elements/policy.rb +15 -0
- data/lib/hotels_pro/api/elements/room_response.rb +16 -0
- data/lib/hotels_pro/api/methods/allocate_hotel_code.rb +21 -0
- data/lib/hotels_pro/api/methods/amend_hotel_booking.rb +27 -0
- data/lib/hotels_pro/api/methods/cancel_hotel_booking.rb +20 -0
- data/lib/hotels_pro/api/methods/get_available_hotel.rb +28 -0
- data/lib/hotels_pro/api/methods/get_balance.rb +18 -0
- data/lib/hotels_pro/api/methods/get_hotel_booking_status.rb +21 -0
- data/lib/hotels_pro/api/methods/get_hotel_cancellation_policy.rb +19 -0
- data/lib/hotels_pro/api/methods/make_hotel_booking.rb +24 -0
- data/lib/hotels_pro/configuration.rb +14 -0
- data/lib/hotels_pro/query.rb +34 -0
- data/lib/hotels_pro/request.rb +43 -0
- data/lib/hotels_pro/response.rb +33 -0
- data/lib/hotels_pro/stubs.rb +66 -0
- data/lib/hotels_pro/stubs/stub.rb +23 -0
- data/lib/hotels_pro/underscorer.rb +21 -0
- data/lib/hotels_pro/version.rb +3 -0
- data/spec/api_params_helper.rb +8 -0
- data/spec/fixtures/allocate_hotel_code.json +1 -0
- data/spec/fixtures/amend_hotel_booking.json +1 -0
- data/spec/fixtures/cancel_hotel_booking.json +1 -0
- data/spec/fixtures/get_available_hotel.json +1 -0
- data/spec/fixtures/get_balance.json +1 -0
- data/spec/fixtures/get_hotel_booking_status.json +1 -0
- data/spec/fixtures/get_hotel_cancellation_policy.json +1 -0
- data/spec/fixtures/make_hotel_booking.json +1 -0
- data/spec/hotels_pro/api/.gitkeep +0 -0
- data/spec/hotels_pro/api/api_method_spec.rb +14 -0
- data/spec/hotels_pro/api/api_params_spec.rb +36 -0
- data/spec/hotels_pro/api/elements/pax_array_spec.rb +14 -0
- data/spec/hotels_pro/api/methods/allocate_hotel_code_spec.rb +34 -0
- data/spec/hotels_pro/api/methods/amend_hotel_booking_spec.rb +79 -0
- data/spec/hotels_pro/api/methods/cancel_hotel_booking_spec.rb +32 -0
- data/spec/hotels_pro/api/methods/get_available_hotel_spec.rb +83 -0
- data/spec/hotels_pro/api/methods/get_balance_spec.rb +26 -0
- data/spec/hotels_pro/api/methods/get_hotel_booking_status_spec.rb +31 -0
- data/spec/hotels_pro/api/methods/get_hotel_cancellation_policy_spec.rb +31 -0
- data/spec/hotels_pro/api/methods/make_hotel_booking_spec.rb +66 -0
- data/spec/hotels_pro/query_spec.rb +52 -0
- data/spec/hotels_pro/request_spec.rb +73 -0
- data/spec/hotels_pro/response_spec.rb +24 -0
- data/spec/hotels_pro/stubs/stub_spec.rb +41 -0
- data/spec/hotels_pro/stubs_spec.rb +37 -0
- data/spec/hotels_pro/underscorer_spec.rb +33 -0
- data/spec/request_helper.rb +6 -0
- data/spec/spec_helper.rb +15 -0
- metadata +222 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af5efa021ba1f29da56382ef13436559b83a742a
|
4
|
+
data.tar.gz: cde28945188e118c574f53717b5f0189a170a9d2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 974eb44538ce151f543ab04e1f8ed9041af9b6118ba6ce34469665b92c4c330ed1e6c33ed218ea5068a7e7ae0cb42042080ac8fba3053fff32435ba4f0975dca
|
7
|
+
data.tar.gz: ce797d5446e7b5354d46bdd92247a6016ca597193d44d97d19d5d331cf4cf20882a042f42a5139dba06b72741d0effeec74e2567603a21b3fb5b6518519c0664
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Michał Szajbe
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# HotelsPro
|
2
|
+
|
3
|
+
[](http://travis-ci.org/monterail/hotels_pro)
|
4
|
+
|
5
|
+
HotelsPro API wrapper
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'hotels_pro'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install hotels_pro
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
HotelsPro.configure do |config|
|
24
|
+
config.api_key = "your_api_key" # required
|
25
|
+
config.environment = "live" # "live" or "test"; defaults to "test"
|
26
|
+
config.logger = Logger.new(STDOUT) # optional
|
27
|
+
config.only_stubs = false # optional; defaults to "false"; see 'Stubbing requests' section for details
|
28
|
+
end
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
Since this is a really simple wrapper for HotelsPro API it only let's you build API method calls with Ruby and returns responses as Ruby objects. It uses [virtus](https://github.com/solnic/virtus) under the hood to build objects.
|
33
|
+
|
34
|
+
method = HotelsPro::Api::Methods::GetAvailableHotel.new(
|
35
|
+
:destination_id => "LD6J",
|
36
|
+
:client_nationality => "US",
|
37
|
+
:currency => "EUR",
|
38
|
+
:check_in => Date.parse("2012-08-14"),
|
39
|
+
:check_out => Date.parse("2012-08-21"),
|
40
|
+
:rooms => [
|
41
|
+
HotelsPro::Api::Elements::PaxArray.new(
|
42
|
+
:paxes => [
|
43
|
+
HotelsPro::Api::Elements::Pax.new(:pax_type => "Adult"),
|
44
|
+
HotelsPro::Api::Elements::Pax.new(:pax_type => "Adult")
|
45
|
+
]
|
46
|
+
),
|
47
|
+
HotelsPro::Api::Elements::PaxArray.new(
|
48
|
+
:paxes => [
|
49
|
+
HotelsPro::Api::Elements::Pax.new(:pax_type => "Adult"),
|
50
|
+
HotelsPro::Api::Elements::Pax.new(:pax_type => "Child", :age => 10)
|
51
|
+
]
|
52
|
+
)
|
53
|
+
]
|
54
|
+
)
|
55
|
+
|
56
|
+
result = method.perform
|
57
|
+
|
58
|
+
result.response_id
|
59
|
+
# => 4322779
|
60
|
+
|
61
|
+
result.available_hotels
|
62
|
+
# => Array of HotelsPro::Api::Elements::Hotel objects
|
63
|
+
|
64
|
+
result.total_found
|
65
|
+
# => 10
|
66
|
+
|
67
|
+
result.search_id
|
68
|
+
# => "SZ-91588250"
|
69
|
+
|
70
|
+
## Stubbing requests
|
71
|
+
|
72
|
+
You can stub requests for testing or to provide fixed responses.
|
73
|
+
|
74
|
+
HotelsPro::Stubs.get_available_hotel.response(json)
|
75
|
+
|
76
|
+
The above snippet will stub all requests to getAvailableHotel api method, so they return specified `json` response.
|
77
|
+
|
78
|
+
If you want to stub only some requests or to return different response depending on request params, provide a `matcher`.
|
79
|
+
|
80
|
+
matcher = lambda { |request| request.destination_id == "LD6J" }
|
81
|
+
HotelsPro::Stubs.get_available_hotel(matcher).response(json)
|
82
|
+
|
83
|
+
In testing no requests should hit the remote API. If `only_stubs` configuration option is enabled, exception will be raised anytime an unstubbed request is performed.
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
1. Fork it
|
88
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
89
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
90
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
91
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/hotels_pro.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/hotels_pro/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Michał Szajbe"]
|
6
|
+
gem.email = ["michal.szajbe@gmail.com"]
|
7
|
+
gem.description = %q{HotelsPro API wrapper}
|
8
|
+
gem.summary = %q{HotelsPro API wrapper}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "hotels_pro"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = HotelsPro::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "activesupport"
|
19
|
+
gem.add_dependency "json"
|
20
|
+
gem.add_dependency "typhoeus"
|
21
|
+
gem.add_dependency "virtus"
|
22
|
+
gem.add_development_dependency "rspec"
|
23
|
+
gem.add_development_dependency "ZenTest"
|
24
|
+
end
|
data/lib/hotels_pro.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'active_support'
|
4
|
+
require 'json'
|
5
|
+
require 'typhoeus'
|
6
|
+
require 'virtus'
|
7
|
+
|
8
|
+
require "hotels_pro/api/api_params"
|
9
|
+
require "hotels_pro/api/api_method"
|
10
|
+
require "hotels_pro/api/elements/book_info"
|
11
|
+
require "hotels_pro/api/elements/daily_rate"
|
12
|
+
require "hotels_pro/api/elements/filter"
|
13
|
+
require "hotels_pro/api/elements/room_response"
|
14
|
+
require "hotels_pro/api/elements/hotel"
|
15
|
+
require "hotels_pro/api/elements/lead_traveller"
|
16
|
+
require "hotels_pro/api/elements/pax"
|
17
|
+
require "hotels_pro/api/elements/pax_array"
|
18
|
+
require "hotels_pro/api/elements/policy"
|
19
|
+
require "hotels_pro/api/methods/allocate_hotel_code"
|
20
|
+
require "hotels_pro/api/methods/amend_hotel_booking"
|
21
|
+
require "hotels_pro/api/methods/cancel_hotel_booking"
|
22
|
+
require "hotels_pro/api/methods/get_available_hotel"
|
23
|
+
require "hotels_pro/api/methods/get_balance"
|
24
|
+
require "hotels_pro/api/methods/get_hotel_booking_status"
|
25
|
+
require "hotels_pro/api/methods/get_hotel_cancellation_policy"
|
26
|
+
require "hotels_pro/api/methods/make_hotel_booking"
|
27
|
+
require "hotels_pro/configuration"
|
28
|
+
require "hotels_pro/query"
|
29
|
+
require "hotels_pro/request"
|
30
|
+
require "hotels_pro/response"
|
31
|
+
require "hotels_pro/stubs"
|
32
|
+
require "hotels_pro/stubs/stub"
|
33
|
+
require "hotels_pro/underscorer"
|
34
|
+
require "hotels_pro/version"
|
35
|
+
|
36
|
+
module HotelsPro
|
37
|
+
class << self
|
38
|
+
def configuration
|
39
|
+
@configuration ||= Configuration.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def configure
|
43
|
+
yield(configuration)
|
44
|
+
end
|
45
|
+
|
46
|
+
def log(message)
|
47
|
+
if configuration.logger
|
48
|
+
configuration.logger.info("[HotelsPro] #{message}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_available_hotel(options={})
|
53
|
+
HotelsPro::Api::Methods::GetAvailableHotel.new(options).perform
|
54
|
+
end
|
55
|
+
|
56
|
+
def allocate_hotel_code(options={})
|
57
|
+
HotelsPro::Api::Methods::AllocateHotelCode.new(options).perform
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class ErrorResponse < ::StandardError
|
62
|
+
end
|
63
|
+
|
64
|
+
class RemoteError < ::StandardError
|
65
|
+
end
|
66
|
+
|
67
|
+
class UnstubbedRequest < ::StandardError
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module HotelsPro
|
2
|
+
module Api
|
3
|
+
class ApiMethod
|
4
|
+
include ApiParams
|
5
|
+
include Virtus
|
6
|
+
|
7
|
+
class Result
|
8
|
+
include Virtus
|
9
|
+
end
|
10
|
+
|
11
|
+
def perform
|
12
|
+
response = request.perform
|
13
|
+
|
14
|
+
if response.error?
|
15
|
+
raise response.error
|
16
|
+
else
|
17
|
+
"#{self.class.name}::Result".constantize.new(response.data)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def request
|
24
|
+
api_method = self.class.name.to_s.demodulize
|
25
|
+
Request.new(api_method, to_api_params)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module HotelsPro
|
4
|
+
module Api
|
5
|
+
module ApiParams
|
6
|
+
def to_api_params
|
7
|
+
(attributes || []).inject({}) do |params, (k, v)|
|
8
|
+
unless v.nil? or (v.respond_to?(:empty?) and v.empty?)
|
9
|
+
params[api_param_name(k)] = api_param_value(v)
|
10
|
+
end
|
11
|
+
params
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def api_param_name(attribute)
|
16
|
+
attribute.to_s.camelize(:lower)
|
17
|
+
end
|
18
|
+
|
19
|
+
def api_param_value(value)
|
20
|
+
case value
|
21
|
+
when Array
|
22
|
+
value.map{ |element| api_param_value(element) }
|
23
|
+
else
|
24
|
+
value.respond_to?(:to_api_params) ? value.to_api_params : value.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'hotels_pro/api/elements/pax_array'
|
2
|
+
require 'hotels_pro/api/elements/policy'
|
3
|
+
|
4
|
+
module HotelsPro
|
5
|
+
module Api
|
6
|
+
module Elements
|
7
|
+
class BookInfo
|
8
|
+
include Virtus
|
9
|
+
|
10
|
+
attribute :booking_status, Integer
|
11
|
+
attribute :confirmation_number, String
|
12
|
+
attribute :supplier, String
|
13
|
+
attribute :hotel_code, String
|
14
|
+
attribute :check_in, Date
|
15
|
+
attribute :check_out, Date
|
16
|
+
attribute :total_price, Float
|
17
|
+
attribute :total_sale_price, Float
|
18
|
+
attribute :currency, String
|
19
|
+
attribute :board_type, String
|
20
|
+
attribute :rooms, Array[HotelsPro::Api::Elements::PaxArray], :default => []
|
21
|
+
attribute :cancellation_policy, Array[HotelsPro::Api::Elements::Policy], :default => []
|
22
|
+
attribute :agency_reference_number, String
|
23
|
+
attribute :comments, String
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'hotels_pro/api/elements/room_response'
|
2
|
+
|
3
|
+
module HotelsPro
|
4
|
+
module Api
|
5
|
+
module Elements
|
6
|
+
class Hotel
|
7
|
+
include Virtus
|
8
|
+
|
9
|
+
attribute :process_id, String
|
10
|
+
attribute :hotel_code, String
|
11
|
+
attribute :availability_status, String
|
12
|
+
attribute :special_deal, Integer
|
13
|
+
attribute :total_price, Float
|
14
|
+
attribute :total_tax, Float, :default => 0
|
15
|
+
attribute :total_sale_price, Float, :default => 0
|
16
|
+
attribute :currency, String
|
17
|
+
attribute :board_type, String
|
18
|
+
attribute :rooms, Array[RoomResponse], :default => []
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'hotels_pro/api/elements/pax'
|
2
|
+
|
3
|
+
module HotelsPro
|
4
|
+
module Api
|
5
|
+
module Elements
|
6
|
+
class LeadTraveller
|
7
|
+
include ApiParams
|
8
|
+
include Virtus
|
9
|
+
|
10
|
+
attribute :pax_info, HotelsPro::Api::Elements::Pax
|
11
|
+
attribute :nationality, String
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module HotelsPro
|
2
|
+
module Api
|
3
|
+
module Elements
|
4
|
+
class Pax
|
5
|
+
include ApiParams
|
6
|
+
include Virtus
|
7
|
+
|
8
|
+
attribute :pax_type, String
|
9
|
+
attribute :age, Integer
|
10
|
+
attribute :title, String
|
11
|
+
attribute :first_name, String
|
12
|
+
attribute :last_name, String
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'hotels_pro/api/elements/pax'
|
2
|
+
|
3
|
+
module HotelsPro
|
4
|
+
module Api
|
5
|
+
module Elements
|
6
|
+
class PaxArray
|
7
|
+
include Virtus
|
8
|
+
|
9
|
+
attribute :paxes, Array[Pax], :default => []
|
10
|
+
|
11
|
+
def to_api_params
|
12
|
+
paxes.map(&:to_api_params)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|