booking-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +71 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/booking.gemspec +26 -0
- data/lib/booking.rb +16 -0
- data/lib/booking/client.rb +58 -0
- data/lib/booking/http_service.rb +27 -0
- data/lib/booking/version.rb +3 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 274ba23c03adb0fab962f6970612ff5973179fad
|
4
|
+
data.tar.gz: d2399764e6a9766112c3543ae91dbb8086e0b8e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d86777252dec63c6c3b2253737f085e81a4f2b126a693c78199ac1dc202c0a38fb40d589cd558cd192d8e8d4bbe84145eac2c9256ae5455aff516c3215f3bdae
|
7
|
+
data.tar.gz: de397ff871b90c299e431ecfab4b31854f68225acbdfd45b06551eec0dbfeb1f58f33cd8b925e8ca292a79d9f34fd6220364fad4c8690f991e34dd4caaaf49f0
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Booking
|
2
|
+
|
3
|
+
This is a wrapper for the Booking.com API. Currently only the `gethotelavailbilityV2` is supported.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'booking-ruby'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install booking-ruby
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Initialize the the gem by setting your username and password:
|
24
|
+
|
25
|
+
```
|
26
|
+
Booking.username = 'your-username'
|
27
|
+
Booking.password = 'your-password'
|
28
|
+
```
|
29
|
+
|
30
|
+
Right now only one endpoint is supported.
|
31
|
+
|
32
|
+
```
|
33
|
+
params = {
|
34
|
+
checkin: Time.now.strftime("%F"),
|
35
|
+
checkout: (Time.now + (60 * 60 * 24 * 7 * 2)).strftime("%F"),
|
36
|
+
hotel_ids: [303762]
|
37
|
+
}
|
38
|
+
response = Booking::Client.new.get_hotel_availabillity(request_parameters: params)
|
39
|
+
|
40
|
+
# the parsed response is in the body
|
41
|
+
=> response.body
|
42
|
+
|
43
|
+
{
|
44
|
+
"checkout": "2016-04-04",
|
45
|
+
"hotels": [
|
46
|
+
{
|
47
|
+
"room_min_price": {
|
48
|
+
"price": "750.00"
|
49
|
+
},
|
50
|
+
"hotel_id": "303762",
|
51
|
+
"hotel_currency_code": "EUR"
|
52
|
+
}
|
53
|
+
],
|
54
|
+
"checkin": "2016-03-21",
|
55
|
+
"guest_groups": [
|
56
|
+
{
|
57
|
+
"guests": 2,
|
58
|
+
"children": [
|
59
|
+
|
60
|
+
]
|
61
|
+
}
|
62
|
+
],
|
63
|
+
"hotel_ids": [
|
64
|
+
"303762"
|
65
|
+
]
|
66
|
+
}
|
67
|
+
|
68
|
+
```
|
69
|
+
|
70
|
+
## FAQ
|
71
|
+
To get access to the API you have to signup as an affiliate for booking.com. They will then send you the API documentation with credentials to obtain data.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "booking"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/booking.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'booking/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "booking-ruby"
|
8
|
+
spec.version = Booking::VERSION
|
9
|
+
spec.authors = ["Hendrik Kleinwaechter"]
|
10
|
+
spec.email = ["hendrik.kleinwaechter@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Wrapper for the Booking.com API written in ruby.}
|
13
|
+
spec.homepage = "https://github.com/hendricius/booking"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
spec.license = 'MIT'
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "minitest", '~> 0'
|
24
|
+
spec.add_dependency "faraday", "~> 0.9"
|
25
|
+
spec.add_dependency "faraday_middleware", "~> 0.10"
|
26
|
+
end
|
data/lib/booking.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
require "json"
|
4
|
+
require "booking/version"
|
5
|
+
require "booking/client"
|
6
|
+
require "booking/http_service"
|
7
|
+
|
8
|
+
module Booking
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :username, :password
|
12
|
+
end
|
13
|
+
|
14
|
+
self.username = self.username || ENV["BOOKING_RUBY_USERNAME"]
|
15
|
+
self.password = self.password || ENV["BOOKING_RUBY_PASSWORD"]
|
16
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Booking
|
2
|
+
class Client
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@http_service = HttpService.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def http_service
|
9
|
+
@http_service
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_hotel_availabillity(request_parameters: {})
|
13
|
+
default_parameters = {
|
14
|
+
room1: "A,A",
|
15
|
+
}
|
16
|
+
http_service.request_post("/json/getHotelAvailabilityV2", default_parameters.merge(request_parameters))
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
__END__
|
26
|
+
|
27
|
+
params = {
|
28
|
+
checkin: Time.now.strftime("%F"),
|
29
|
+
checkout: (Time.now + (60 * 60 * 24 * 7 * 2)).strftime("%F"),
|
30
|
+
hotel_ids: [303762]
|
31
|
+
}
|
32
|
+
response = Booking::Client.new.get_hotel_availabillity(request_parameters: params)
|
33
|
+
|
34
|
+
puts response.body
|
35
|
+
{
|
36
|
+
"checkout": "2016-04-04",
|
37
|
+
"hotels": [
|
38
|
+
{
|
39
|
+
"room_min_price": {
|
40
|
+
"price": "750.00"
|
41
|
+
},
|
42
|
+
"hotel_id": "303762",
|
43
|
+
"hotel_currency_code": "EUR"
|
44
|
+
}
|
45
|
+
],
|
46
|
+
"checkin": "2016-03-21",
|
47
|
+
"guest_groups": [
|
48
|
+
{
|
49
|
+
"guests": 2,
|
50
|
+
"children": [
|
51
|
+
|
52
|
+
]
|
53
|
+
}
|
54
|
+
],
|
55
|
+
"hotel_ids": [
|
56
|
+
"303762"
|
57
|
+
]
|
58
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Booking
|
2
|
+
class HttpService
|
3
|
+
def initialize
|
4
|
+
@auth_username = Booking.username
|
5
|
+
@auth_password = Booking.password
|
6
|
+
end
|
7
|
+
|
8
|
+
def connection
|
9
|
+
@connection ||= begin
|
10
|
+
Faraday.new(:url => 'https://distribution-xml.booking.com') do |faraday|
|
11
|
+
faraday.basic_auth @auth_username, @auth_password
|
12
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
13
|
+
faraday.response :json, :content_type => /\bjson$/
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def request_post(url, data)
|
19
|
+
connection.post do |req|
|
20
|
+
req.url url
|
21
|
+
req.headers['Content-Type'] = 'application/json'
|
22
|
+
req.body = data.to_json
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: booking-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hendrik Kleinwaechter
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday_middleware
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- hendrik.kleinwaechter@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- booking.gemspec
|
98
|
+
- lib/booking.rb
|
99
|
+
- lib/booking/client.rb
|
100
|
+
- lib/booking/http_service.rb
|
101
|
+
- lib/booking/version.rb
|
102
|
+
homepage: https://github.com/hendricius/booking
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.4.5
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Wrapper for the Booking.com API written in ruby.
|
126
|
+
test_files: []
|
127
|
+
has_rdoc:
|