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.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +7 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +22 -0
  7. data/README.md +91 -0
  8. data/Rakefile +2 -0
  9. data/hotels_pro.gemspec +24 -0
  10. data/lib/hotels_pro.rb +69 -0
  11. data/lib/hotels_pro/api/api_method.rb +29 -0
  12. data/lib/hotels_pro/api/api_params.rb +29 -0
  13. data/lib/hotels_pro/api/elements/book_info.rb +27 -0
  14. data/lib/hotels_pro/api/elements/daily_rate.rb +12 -0
  15. data/lib/hotels_pro/api/elements/filter.rb +13 -0
  16. data/lib/hotels_pro/api/elements/hotel.rb +22 -0
  17. data/lib/hotels_pro/api/elements/lead_traveller.rb +15 -0
  18. data/lib/hotels_pro/api/elements/pax.rb +16 -0
  19. data/lib/hotels_pro/api/elements/pax_array.rb +17 -0
  20. data/lib/hotels_pro/api/elements/policy.rb +15 -0
  21. data/lib/hotels_pro/api/elements/room_response.rb +16 -0
  22. data/lib/hotels_pro/api/methods/allocate_hotel_code.rb +21 -0
  23. data/lib/hotels_pro/api/methods/amend_hotel_booking.rb +27 -0
  24. data/lib/hotels_pro/api/methods/cancel_hotel_booking.rb +20 -0
  25. data/lib/hotels_pro/api/methods/get_available_hotel.rb +28 -0
  26. data/lib/hotels_pro/api/methods/get_balance.rb +18 -0
  27. data/lib/hotels_pro/api/methods/get_hotel_booking_status.rb +21 -0
  28. data/lib/hotels_pro/api/methods/get_hotel_cancellation_policy.rb +19 -0
  29. data/lib/hotels_pro/api/methods/make_hotel_booking.rb +24 -0
  30. data/lib/hotels_pro/configuration.rb +14 -0
  31. data/lib/hotels_pro/query.rb +34 -0
  32. data/lib/hotels_pro/request.rb +43 -0
  33. data/lib/hotels_pro/response.rb +33 -0
  34. data/lib/hotels_pro/stubs.rb +66 -0
  35. data/lib/hotels_pro/stubs/stub.rb +23 -0
  36. data/lib/hotels_pro/underscorer.rb +21 -0
  37. data/lib/hotels_pro/version.rb +3 -0
  38. data/spec/api_params_helper.rb +8 -0
  39. data/spec/fixtures/allocate_hotel_code.json +1 -0
  40. data/spec/fixtures/amend_hotel_booking.json +1 -0
  41. data/spec/fixtures/cancel_hotel_booking.json +1 -0
  42. data/spec/fixtures/get_available_hotel.json +1 -0
  43. data/spec/fixtures/get_balance.json +1 -0
  44. data/spec/fixtures/get_hotel_booking_status.json +1 -0
  45. data/spec/fixtures/get_hotel_cancellation_policy.json +1 -0
  46. data/spec/fixtures/make_hotel_booking.json +1 -0
  47. data/spec/hotels_pro/api/.gitkeep +0 -0
  48. data/spec/hotels_pro/api/api_method_spec.rb +14 -0
  49. data/spec/hotels_pro/api/api_params_spec.rb +36 -0
  50. data/spec/hotels_pro/api/elements/pax_array_spec.rb +14 -0
  51. data/spec/hotels_pro/api/methods/allocate_hotel_code_spec.rb +34 -0
  52. data/spec/hotels_pro/api/methods/amend_hotel_booking_spec.rb +79 -0
  53. data/spec/hotels_pro/api/methods/cancel_hotel_booking_spec.rb +32 -0
  54. data/spec/hotels_pro/api/methods/get_available_hotel_spec.rb +83 -0
  55. data/spec/hotels_pro/api/methods/get_balance_spec.rb +26 -0
  56. data/spec/hotels_pro/api/methods/get_hotel_booking_status_spec.rb +31 -0
  57. data/spec/hotels_pro/api/methods/get_hotel_cancellation_policy_spec.rb +31 -0
  58. data/spec/hotels_pro/api/methods/make_hotel_booking_spec.rb +66 -0
  59. data/spec/hotels_pro/query_spec.rb +52 -0
  60. data/spec/hotels_pro/request_spec.rb +73 -0
  61. data/spec/hotels_pro/response_spec.rb +24 -0
  62. data/spec/hotels_pro/stubs/stub_spec.rb +41 -0
  63. data/spec/hotels_pro/stubs_spec.rb +37 -0
  64. data/spec/hotels_pro/underscorer_spec.rb +33 -0
  65. data/spec/request_helper.rb +6 -0
  66. data/spec/spec_helper.rb +15 -0
  67. metadata +222 -0
@@ -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
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,7 @@
1
+ script: "bundle exec rspec ./spec/"
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - 1.8.7
7
+ - ree
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hotels_pro.gemspec
4
+ gemspec
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.
@@ -0,0 +1,91 @@
1
+ # HotelsPro
2
+
3
+ [![Build Status](https://secure.travis-ci.org/monterail/hotels_pro.png)](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
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -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
@@ -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,12 @@
1
+ module HotelsPro
2
+ module Api
3
+ module Elements
4
+ class DailyRate
5
+ include Virtus
6
+
7
+ attribute :date, Date
8
+ attribute :amount, Float
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module HotelsPro
2
+ module Api
3
+ module Elements
4
+ class Filter
5
+ include ApiParams
6
+ include Virtus
7
+
8
+ attribute :filter_type, String
9
+ attribute :filter_value, String
10
+ end
11
+ end
12
+ end
13
+ 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