travelpayouts_api 0.0.1
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 +11 -0
- data/Gemfile +2 -0
- data/LICENSE.md +19 -0
- data/README.md +179 -0
- data/lib/travelpayouts_api.rb +36 -0
- data/lib/travelpayouts_api/api.rb +19 -0
- data/lib/travelpayouts_api/calendar.rb +19 -0
- data/lib/travelpayouts_api/data_access.rb +128 -0
- data/lib/travelpayouts_api/error.rb +4 -0
- data/lib/travelpayouts_api/flight.rb +47 -0
- data/lib/travelpayouts_api/hotel.rb +124 -0
- data/lib/travelpayouts_api/map.rb +39 -0
- data/lib/travelpayouts_api/request.rb +111 -0
- data/lib/travelpayouts_api/version.rb +3 -0
- data/travelpayouts_api.gemspec +21 -0
- metadata +114 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 1d4ca155d4f05477a34c76a9912bc241eb27e9e6
|
|
4
|
+
data.tar.gz: a7e83bd6465ab9dfbfc935b4d577bac4406fee61
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a44883669e1a346d4ac92fb43155acc8d5548cfa360b8131d4727be44a4cc868d1f4dda7bcd07e73087518b1996ea7f0483310efd7db2c71c98755e194821cd1
|
|
7
|
+
data.tar.gz: 43941d225cdfa71e7892813c114ad8d4f57be01689b770c0fde9b9dcc804b0cb2de09c66b07d95ee9bbb1e133f5a61cc514ce232bd47685c7ee9d9fc79d56543
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2015 Vitaly Dyatlov
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# TravelPayouts API
|
|
2
|
+
|
|
3
|
+
[][gem]
|
|
4
|
+
|
|
5
|
+
[gem]: https://rubygems.org/gems/travelpayouts_api
|
|
6
|
+
|
|
7
|
+
** This gem supports `ruby 2.2` and above. It won't work on earlier ruby versions due to extensive use of positional parameters.
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
This gem supports
|
|
12
|
+
|
|
13
|
+
* Data Access API ( http://support.travelpayouts.com/hc/ru/articles/203956163 )
|
|
14
|
+
* Map API ( http://support.travelpayouts.com/hc/ru/articles/203755406 )
|
|
15
|
+
* Calendar API ( http://support.travelpayouts.com/hc/ru/articles/203972143 )
|
|
16
|
+
* Flights API ( http://support.travelpayouts.com/hc/ru/articles/203956173 )
|
|
17
|
+
* Hotels API ( http://support.travelpayouts.com/hc/ru/articles/203956133 )
|
|
18
|
+
|
|
19
|
+
## How to use
|
|
20
|
+
|
|
21
|
+
Include it in your `Gemfile`:
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
gem 'travelpayouts_api'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Create an initializer in config/initializers:
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
# config/initializers/travelpayouts_api.rb
|
|
31
|
+
TravelPayouts.configure do |config|
|
|
32
|
+
config.token = '<token>'
|
|
33
|
+
config.marker = '<marker>'
|
|
34
|
+
config.host = 'localhost'
|
|
35
|
+
config.currency = 'rub'
|
|
36
|
+
config.locale = 'en'
|
|
37
|
+
end
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
where
|
|
41
|
+
|
|
42
|
+
* `token` - your api token
|
|
43
|
+
* `marker` - your client id in travelpayouts system
|
|
44
|
+
* `currency` - currency 3-digit code
|
|
45
|
+
* `host` - should be set to your site host
|
|
46
|
+
* `locale` - language of results
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
And now in your controller you can do something like this:
|
|
50
|
+
|
|
51
|
+
```ruby
|
|
52
|
+
@api = TravelPayouts.api
|
|
53
|
+
prices = @api.cheap_prices(origin: 'ODS', destination: 'MOW', depart_date: '2015-04-01')
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
All API calls will return hash objects or raise exceptions on failure.
|
|
57
|
+
|
|
58
|
+
## Data Access API
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
cheap_prices(origin:, destination:, depart_date: nil, return_date: nil)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
direct_prices(origin:, destination:, depart_date: nil, return_date: nil)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
calendar_prices(origin:, destination:, calendar_type:, depart_date: nil, trip_duration: nil, return_date: nil)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
airline_directions(airline_code:, limit: 10)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
countries_data()
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```ruby
|
|
81
|
+
cities_data()
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
airports_data()
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
```ruby
|
|
89
|
+
airlines_data()
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
airline_alliances_data()
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```ruby
|
|
97
|
+
planes_data()
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```ruby
|
|
101
|
+
routes_data()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```ruby
|
|
105
|
+
where_am_i(ip: nil, locale: nil)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Map API
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
map_of_supported_directions(origin_iata:, one_way: true, locale: nil)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
```ruby
|
|
115
|
+
map_of_prices(origin_iata:, period: :month, one_way: true, direct: false,
|
|
116
|
+
price: nil, no_visa: true, schengen: nil, need_visa: true, locale: nil,
|
|
117
|
+
min_trip_duration_in_days: nil, max_trip_duration_in_days: nil)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Flights API
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
flight_search(user_ip:,locale: nil, trip_class: 'Y', passengers: {}, segments: {}, know_english: true)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
```ruby
|
|
127
|
+
flight_search_link(search_id:, terms_url:)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
```ruby
|
|
131
|
+
flight_search_results(search_id:)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
```ruby
|
|
135
|
+
autocomplete_places(term:, locale: nil)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Hotels API
|
|
139
|
+
|
|
140
|
+
```ruby
|
|
141
|
+
hotel_lookup(query:, lang: nil, look_for: nil, limit: 10, convert_case: true)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
```ruby
|
|
145
|
+
hotel_prices(user_ip:, check_in:,check_out:,location:nil,location_id:nil,hotel_id:nil,hotel:nil,limit:10)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
```ruby
|
|
149
|
+
hotel_countries()
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
```ruby
|
|
153
|
+
hotel_locations()
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
```ruby
|
|
157
|
+
hotel_amenities()
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
```ruby
|
|
161
|
+
hotels_list(location_id:)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```ruby
|
|
165
|
+
hotel_room_types()
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
```ruby
|
|
169
|
+
hotel_types()
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
```ruby
|
|
173
|
+
hotel_search_start(city_id:nil,hotel_id:nil,iata:nil,check_in:,check_out:,adults_count:,user_ip:,
|
|
174
|
+
children_count:0,child_age1:0,child_age2:0,child_age3:0,lang:nil,currency:nil,wait_for_result:0,timeout:20)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
```ruby
|
|
178
|
+
hotel_search_result(search_id:,limit: 0,offset: 0,sort_by: :popularity, sort_asc: 1, rooms_count: 0)
|
|
179
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'rest_client'
|
|
2
|
+
require 'digest/md5'
|
|
3
|
+
|
|
4
|
+
require 'travelpayouts_api/request'
|
|
5
|
+
require 'travelpayouts_api/data_access'
|
|
6
|
+
require 'travelpayouts_api/map'
|
|
7
|
+
require 'travelpayouts_api/calendar'
|
|
8
|
+
require 'travelpayouts_api/flight'
|
|
9
|
+
require 'travelpayouts_api/hotel'
|
|
10
|
+
require 'travelpayouts_api/api'
|
|
11
|
+
require 'travelpayouts_api/error'
|
|
12
|
+
|
|
13
|
+
class Hash
|
|
14
|
+
def to_query(namespace = nil)
|
|
15
|
+
collect do |key, value|
|
|
16
|
+
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
|
|
17
|
+
end.sort * '&'
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
module TravelPayouts
|
|
22
|
+
class << self
|
|
23
|
+
|
|
24
|
+
def configure
|
|
25
|
+
yield config
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def config
|
|
29
|
+
@config ||= OpenStruct.new {}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def api(config = {})
|
|
33
|
+
TravelPayouts::Api.new(config)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module TravelPayouts
|
|
2
|
+
class Api
|
|
3
|
+
include TravelPayouts::Api::Request
|
|
4
|
+
include TravelPayouts::Api::DataAccess
|
|
5
|
+
include TravelPayouts::Api::Map
|
|
6
|
+
include TravelPayouts::Api::Calendar
|
|
7
|
+
include TravelPayouts::Api::Flight
|
|
8
|
+
include TravelPayouts::Api::Hotel
|
|
9
|
+
|
|
10
|
+
attr_reader :config
|
|
11
|
+
|
|
12
|
+
def initialize(config = {})
|
|
13
|
+
@config = TravelPayouts.config
|
|
14
|
+
for k,v in config
|
|
15
|
+
@config[k.to_sym] = v
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module TravelPayouts
|
|
2
|
+
class Api
|
|
3
|
+
module Calendar
|
|
4
|
+
def calendar_of_prices_url
|
|
5
|
+
'http://min-prices.aviasales.ru/calendar_preload'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def calendar_of_prices(origin:, destination:, depart_date:, one_way:true)
|
|
9
|
+
request calendar_of_prices_url, {
|
|
10
|
+
origin: origin,
|
|
11
|
+
destination: destination,
|
|
12
|
+
depart_date: depart_date,
|
|
13
|
+
one_way: one_way
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
module TravelPayouts
|
|
2
|
+
class Api
|
|
3
|
+
module DataAccess
|
|
4
|
+
def cheap_prices_url
|
|
5
|
+
'http://api.travelpayouts.com/v1/prices/cheap'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def direct_prices_url
|
|
9
|
+
'http://api.travelpayouts.com/v1/prices/direct'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def calendar_prices_url
|
|
13
|
+
'http://api.travelpayouts.com/v1/prices/calendar'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def airline_directions_url
|
|
17
|
+
'http://api.travelpayouts.com/v1/airline-directions'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def countries_data_url
|
|
21
|
+
'http://api.travelpayouts.com/data/countries.json'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def cities_data_url
|
|
25
|
+
'http://api.travelpayouts.com/data/cities.json'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def airports_data_url
|
|
29
|
+
'http://api.travelpayouts.com/data/airports.json'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def airlines_data_url
|
|
33
|
+
'http://api.travelpayouts.com/data/airlines.json'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def airline_alliances_data_url
|
|
37
|
+
'http://api.travelpayouts.com/data/airlines_alliances.json'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def planes_data_url
|
|
41
|
+
'http://api.travelpayouts.com/data/planes.json'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def routes_data_url
|
|
45
|
+
'http://api.travelpayouts.com/data/routes.json'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def where_am_i_url
|
|
49
|
+
'http://www.travelpayouts.com/whereami'
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def cheap_prices(origin:, destination:, depart_date: nil, return_date: nil)
|
|
53
|
+
request cheap_prices_url, {
|
|
54
|
+
origin: origin,
|
|
55
|
+
destination: destination,
|
|
56
|
+
depart_date: depart_date,
|
|
57
|
+
return_date: return_date
|
|
58
|
+
}
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def direct_prices(origin:, destination:, depart_date: nil, return_date: nil)
|
|
62
|
+
request direct_prices_url, {
|
|
63
|
+
origin: origin,
|
|
64
|
+
destination: destination,
|
|
65
|
+
depart_date: depart_date,
|
|
66
|
+
return_date: return_date
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def calendar_prices(origin:, destination:, calendar_type:, depart_date: nil, trip_duration: nil, return_date: nil)
|
|
71
|
+
request calendar_prices_url, {
|
|
72
|
+
origin: origin,
|
|
73
|
+
destination: destination,
|
|
74
|
+
depart_date: depart_date,
|
|
75
|
+
return_date: return_date,
|
|
76
|
+
calendar_type: calendar_type,
|
|
77
|
+
trip_duration: trip_duration
|
|
78
|
+
}
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def airline_directions(airline_code:, limit: 10)
|
|
82
|
+
request airline_directions_url, {
|
|
83
|
+
airline_code: airline_code,
|
|
84
|
+
limit: limit
|
|
85
|
+
}
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def countries_data
|
|
89
|
+
request countries_data_url, {}
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def cities_data
|
|
93
|
+
request cities_data_url, {}
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def airports_data
|
|
97
|
+
request airports_data_url, {}
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def airlines_data
|
|
101
|
+
request airlines_data_url, {}
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def airline_alliances_data
|
|
105
|
+
request airline_alliances_data_url, {}
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def planes_data
|
|
109
|
+
request planes_data_url, {}
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def routes_data
|
|
113
|
+
request routes_data_url, {}
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def where_am_i(ip:, locale: nil)
|
|
117
|
+
data = request where_am_i_url, {
|
|
118
|
+
callback: 'a',
|
|
119
|
+
ip: ip,
|
|
120
|
+
locale: locale
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
js = data.slice(2..-2)
|
|
124
|
+
respond(js)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module TravelPayouts
|
|
2
|
+
class Api
|
|
3
|
+
module Flight
|
|
4
|
+
def flight_search_url
|
|
5
|
+
'http://api.travelpayouts.com/v1/flight_search'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def flight_search_results_url
|
|
9
|
+
'http://api.travelpayouts.com/v1/flight_search_results'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def flight_search_link_url(search_id:, terms_url:)
|
|
13
|
+
"http://api.travelpayouts.com/v1/flight_searches/#{search_id}/clicks/#{terms_url}.json"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def autocomplete_places_url
|
|
17
|
+
'http://places.aviasales.ru'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def flight_search_link(search_id:, terms_url:)
|
|
21
|
+
request flight_search_link_url(search_id: search_id, terms_url: terms_url), {}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def flight_search(user_ip:,locale: nil, trip_class: 'Y', passengers: {}, segments: {}, know_english: true)
|
|
25
|
+
signed_flight_request :post, flight_search_url, {
|
|
26
|
+
user_ip: user_ip,
|
|
27
|
+
locale: locale,
|
|
28
|
+
trip_class: trip_class,
|
|
29
|
+
passengers: passengers,
|
|
30
|
+
segments: segments,
|
|
31
|
+
know_english: know_english.to_s
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def flight_search_results(search_id:)
|
|
36
|
+
request flight_search_results_url, { uuid: search_id }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def autocomplete_places(term:, locale: nil)
|
|
40
|
+
request autocomplete_places_url, {
|
|
41
|
+
term: term,
|
|
42
|
+
locale: locale
|
|
43
|
+
}
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
module TravelPayouts
|
|
2
|
+
class Api
|
|
3
|
+
module Hotel
|
|
4
|
+
def hotel_lookup_url
|
|
5
|
+
'http://engine.hotellook.com/api/v2/lookup.json'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def hotel_prices_url
|
|
9
|
+
'http://yasen.hotellook.com/api/v2/cache.json'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def hotel_countries_url
|
|
13
|
+
'http://engine.hotellook.com/api/v2/static/countries.json'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def hotel_locations_url
|
|
17
|
+
'http://engine.hotellook.com/api/v2/static/locations.json'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def hotel_amenities_url
|
|
21
|
+
'http://engine.hotellook.com/api/v2/static/amenities.json'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def hotels_list_url
|
|
25
|
+
'http://engine.hotellook.com/api/v2/static/hotels.json'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def hotel_room_types_url
|
|
29
|
+
'http://engine.hotellook.com/api/v2/static/roomTypes.json'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def hotel_types_url
|
|
33
|
+
'http://engine.hotellook.com/api/v2/static/hotelTypes.json'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def hotel_search_start_url
|
|
37
|
+
'http://engine.hotellook.com/api/v2/search/start.json'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def hotel_search_result_url
|
|
41
|
+
'http://engine.hotellook.com/api/v2/search/getResult.json'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def hotel_lookup(query:, lang: nil, look_for: nil, limit: 10, convert_case: true)
|
|
45
|
+
signed_hotel_request :get, hotel_lookup_url, {
|
|
46
|
+
query: query,
|
|
47
|
+
lang: lang,
|
|
48
|
+
lookFor: look_for,
|
|
49
|
+
limit: limit,
|
|
50
|
+
convertCase: convert_case.to_s
|
|
51
|
+
}
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def hotel_prices(user_ip:, check_in:,check_out:,location:nil,location_id:nil,hotel_id:nil,hotel:nil,limit:10)
|
|
55
|
+
signed_hotel_request :get, hotel_prices_url, {
|
|
56
|
+
customerIp: user_ip,
|
|
57
|
+
checkIn: check_in,
|
|
58
|
+
checkOut: check_out,
|
|
59
|
+
location: location,
|
|
60
|
+
locationId: location_id,
|
|
61
|
+
hotelId: hotel_id,
|
|
62
|
+
hotel: hotel,
|
|
63
|
+
limit: limit
|
|
64
|
+
}
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def hotel_countries
|
|
68
|
+
signed_hotel_request :get, hotel_countries_url, {}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def hotel_locations
|
|
72
|
+
signed_hotel_request :get, hotel_locations_url, {}
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def hotel_amenities
|
|
76
|
+
signed_hotel_request :get, hotel_amenities_url, {}
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def hotels_list(location_id:)
|
|
80
|
+
signed_hotel_request :get, hotels_list_url, {locationId: location_id}
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def hotel_room_types
|
|
84
|
+
signed_hotel_request :get, hotel_room_types_url, {}
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def hotel_types
|
|
88
|
+
signed_hotel_request :get, hotel_types_url, {}
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def hotel_search_start(city_id:nil,hotel_id:nil,iata:nil,check_in:,check_out:,adults_count:,user_ip:,
|
|
92
|
+
children_count:0,child_age1:0,child_age2:0,child_age3:0,lang:nil,currency:nil,wait_for_result:0,timeout:20)
|
|
93
|
+
signed_hotel_request :get, hotel_search_start_url, {
|
|
94
|
+
cityId: city_id,
|
|
95
|
+
hotelId: hotel_id,
|
|
96
|
+
iata: iata,
|
|
97
|
+
checkIn: check_in,
|
|
98
|
+
checkOut: check_out,
|
|
99
|
+
adultsCount: adults_count,
|
|
100
|
+
customerIp: user_ip,
|
|
101
|
+
childrenCount: children_count,
|
|
102
|
+
childAge1: child_age1,
|
|
103
|
+
childAge2: child_age2,
|
|
104
|
+
childAge3: child_age3,
|
|
105
|
+
lang: lang,
|
|
106
|
+
currency: currency,
|
|
107
|
+
waitForResult: wait_for_result,
|
|
108
|
+
timeout: timeout
|
|
109
|
+
}
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def hotel_search_result(search_id:,limit: 0,offset: 0,sort_by: :popularity, sort_asc: 1, rooms_count: 0)
|
|
113
|
+
signed_hotel_request :get, hotel_search_result_url, {
|
|
114
|
+
searchId: search_id,
|
|
115
|
+
limit: limit,
|
|
116
|
+
offset: offset,
|
|
117
|
+
sortBy: sort_by,
|
|
118
|
+
sortAsc: sort_asc,
|
|
119
|
+
roomsCount: rooms_count
|
|
120
|
+
}
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module TravelPayouts
|
|
2
|
+
class Api
|
|
3
|
+
module Map
|
|
4
|
+
def map_of_supported_directions_url
|
|
5
|
+
'http://map.aviasales.ru/supported_directions.json'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def map_of_prices_url
|
|
9
|
+
'http://map.aviasales.ru/prices.json'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def map_of_supported_directions(origin_iata:, one_way: true, locale: nil)
|
|
13
|
+
request map_of_supported_directions_url, {
|
|
14
|
+
origin_iata: origin_iata,
|
|
15
|
+
one_way: one_way,
|
|
16
|
+
locale: locale
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def map_of_prices(origin_iata:, period: :month, one_way: true, direct: false,
|
|
21
|
+
price: nil, no_visa: true, schengen: nil, need_visa: true, locale: nil,
|
|
22
|
+
min_trip_duration_in_days: nil, max_trip_duration_in_days: nil)
|
|
23
|
+
request map_of_prices_url, {
|
|
24
|
+
origin_iata: origin_iata,
|
|
25
|
+
period: period,
|
|
26
|
+
one_way: one_way,
|
|
27
|
+
direct: direct,
|
|
28
|
+
price: price,
|
|
29
|
+
no_visa: no_visa,
|
|
30
|
+
schengen: schengen,
|
|
31
|
+
need_visa: need_visa,
|
|
32
|
+
locale: locale,
|
|
33
|
+
min_trip_duration_in_days: min_trip_duration_in_days,
|
|
34
|
+
max_trip_duration_in_days: max_trip_duration_in_days
|
|
35
|
+
}
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
module TravelPayouts
|
|
2
|
+
class Api
|
|
3
|
+
module Request
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'hashie/mash'
|
|
6
|
+
|
|
7
|
+
def request(url, params, skip_parse: false)
|
|
8
|
+
token = config.token
|
|
9
|
+
params[:currency] ||= config.currency
|
|
10
|
+
params[:locale] ||= config.locale
|
|
11
|
+
|
|
12
|
+
params.delete_if{ |_, v| v == nil }
|
|
13
|
+
|
|
14
|
+
headers = {
|
|
15
|
+
x_access_token: token,
|
|
16
|
+
accept_encoding: 'gzip, deflate',
|
|
17
|
+
accept: :json
|
|
18
|
+
}
|
|
19
|
+
data = RestClient.get url, headers.merge(params: params)
|
|
20
|
+
skip_parse ? data : respond(data)
|
|
21
|
+
rescue RestClient::Exception => e
|
|
22
|
+
err = Error.new(e.response, e.http_code)
|
|
23
|
+
err.message = e.message
|
|
24
|
+
raise err
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def signed_flight_request(method, url, params)
|
|
28
|
+
token = config.token
|
|
29
|
+
params[:marker] = config.marker
|
|
30
|
+
params[:host] = config.host
|
|
31
|
+
params[:currency] ||= config.currency
|
|
32
|
+
params[:locale] ||= config.locale if params.has_key?(:locale)
|
|
33
|
+
|
|
34
|
+
params.delete_if{ |_, v| v == nil }
|
|
35
|
+
|
|
36
|
+
values = [token] + param_values(sort_params(params))
|
|
37
|
+
signature = Digest::MD5.hexdigest values.join(':')
|
|
38
|
+
params[:signature] = signature
|
|
39
|
+
|
|
40
|
+
headers = {
|
|
41
|
+
x_access_token: token,
|
|
42
|
+
accept_encoding: 'gzip, deflate',
|
|
43
|
+
accept: :json,
|
|
44
|
+
content_type: 'application/json'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return respond RestClient.post url, params.to_json, headers if method == :post
|
|
48
|
+
respond RestClient.get url, headers.merge(params: params)
|
|
49
|
+
rescue RestClient::Exception => e
|
|
50
|
+
err = Error.new(e.response, e.http_code)
|
|
51
|
+
err.message = e.message
|
|
52
|
+
raise err
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def signed_hotel_request(method, url, params)
|
|
56
|
+
params[:lang] ||= config.locale if params.has_key?(:lang)
|
|
57
|
+
params[:currency] ||= config.currency
|
|
58
|
+
|
|
59
|
+
params.delete_if{ |_, v| v == nil }
|
|
60
|
+
|
|
61
|
+
values = [config.token, config.marker] + param_values(sort_params(params))
|
|
62
|
+
signature = Digest::MD5.hexdigest values.join(':')
|
|
63
|
+
params[:signature] = signature
|
|
64
|
+
params[:marker] = config.marker
|
|
65
|
+
|
|
66
|
+
headers = {
|
|
67
|
+
x_access_token: config.token,
|
|
68
|
+
accept_encoding: 'gzip, deflate',
|
|
69
|
+
accept: :json,
|
|
70
|
+
content_type: 'application/json'
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return respond RestClient.post url, params.to_json, headers if method == :post
|
|
74
|
+
respond RestClient.get url, headers.merge(params: params)
|
|
75
|
+
|
|
76
|
+
rescue RestClient::Exception => e
|
|
77
|
+
err = Error.new(e.response, e.http_code)
|
|
78
|
+
err.message = e.message
|
|
79
|
+
raise err
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def sort_params(params)
|
|
83
|
+
return params unless params.is_a?(Hash) || params.is_a?(Array)
|
|
84
|
+
return Hash[params.sort.map{ |k,v| [k, sort_params(v)] }] if params.is_a?(Hash)
|
|
85
|
+
params.map{|p| sort_params(p)}
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def param_values(params)
|
|
89
|
+
return params unless params.is_a?(Hash) || params.is_a?(Array)
|
|
90
|
+
return params.values.map{|v| param_values(v)}.flatten if params.is_a?(Hash)
|
|
91
|
+
params.map{|p| param_values(p)}.flatten
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def respond(resp)
|
|
95
|
+
begin
|
|
96
|
+
hash = JSON.parse(resp)
|
|
97
|
+
rescue => _
|
|
98
|
+
return resp
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
convert_to_mash hash
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def convert_to_mash(hash)
|
|
105
|
+
return Hashie::Mash.new hash if hash.is_a? Hash
|
|
106
|
+
return hash unless hash.is_a? Array
|
|
107
|
+
hash.each{ |_,v| convert_to_mash v }
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
|
|
4
|
+
require 'travelpayouts_api/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = 'travelpayouts_api'
|
|
8
|
+
s.version = TravelPayouts::VERSION
|
|
9
|
+
s.date = '2015-02-25'
|
|
10
|
+
s.summary = 'Travelpayouts API'
|
|
11
|
+
s.description = 'Ruby gem for travelpayouts api'
|
|
12
|
+
s.authors = ['Vitaly Dyatlov']
|
|
13
|
+
s.email = 'vitaly@dyatlovprojects.com'
|
|
14
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.start_with?('spec/') }
|
|
15
|
+
s.homepage = 'http://github.com/dyatlov/travelpayouts_api'
|
|
16
|
+
s.license = 'MIT'
|
|
17
|
+
s.add_development_dependency 'rspec'
|
|
18
|
+
s.add_development_dependency 'webmock'
|
|
19
|
+
s.add_dependency 'rest-client'
|
|
20
|
+
s.add_dependency 'hashie'
|
|
21
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: travelpayouts_api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Vitaly Dyatlov
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: webmock
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rest-client
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :runtime
|
|
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: hashie
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
description: Ruby gem for travelpayouts api
|
|
70
|
+
email: vitaly@dyatlovprojects.com
|
|
71
|
+
executables: []
|
|
72
|
+
extensions: []
|
|
73
|
+
extra_rdoc_files: []
|
|
74
|
+
files:
|
|
75
|
+
- ".gitignore"
|
|
76
|
+
- Gemfile
|
|
77
|
+
- LICENSE.md
|
|
78
|
+
- README.md
|
|
79
|
+
- lib/travelpayouts_api.rb
|
|
80
|
+
- lib/travelpayouts_api/api.rb
|
|
81
|
+
- lib/travelpayouts_api/calendar.rb
|
|
82
|
+
- lib/travelpayouts_api/data_access.rb
|
|
83
|
+
- lib/travelpayouts_api/error.rb
|
|
84
|
+
- lib/travelpayouts_api/flight.rb
|
|
85
|
+
- lib/travelpayouts_api/hotel.rb
|
|
86
|
+
- lib/travelpayouts_api/map.rb
|
|
87
|
+
- lib/travelpayouts_api/request.rb
|
|
88
|
+
- lib/travelpayouts_api/version.rb
|
|
89
|
+
- travelpayouts_api.gemspec
|
|
90
|
+
homepage: http://github.com/dyatlov/travelpayouts_api
|
|
91
|
+
licenses:
|
|
92
|
+
- MIT
|
|
93
|
+
metadata: {}
|
|
94
|
+
post_install_message:
|
|
95
|
+
rdoc_options: []
|
|
96
|
+
require_paths:
|
|
97
|
+
- lib
|
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - ">="
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '0'
|
|
108
|
+
requirements: []
|
|
109
|
+
rubyforge_project:
|
|
110
|
+
rubygems_version: 2.2.2
|
|
111
|
+
signing_key:
|
|
112
|
+
specification_version: 4
|
|
113
|
+
summary: Travelpayouts API
|
|
114
|
+
test_files: []
|