sacs_ruby 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.travis.yml +4 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +196 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +7 -0
  12. data/lib/sacs_ruby.rb +56 -0
  13. data/lib/sacs_ruby/api/advanced_calendar_search.rb +13 -0
  14. data/lib/sacs_ruby/api/aircraft_equipment_lookup.rb +14 -0
  15. data/lib/sacs_ruby/api/airline_alliance_lookup.rb +15 -0
  16. data/lib/sacs_ruby/api/airline_lookup.rb +14 -0
  17. data/lib/sacs_ruby/api/airports_at_cities_lookup.rb +19 -0
  18. data/lib/sacs_ruby/api/alternate_airport_shop.rb +15 -0
  19. data/lib/sacs_ruby/api/alternate_date.rb +13 -0
  20. data/lib/sacs_ruby/api/bargain_finder_max.rb +15 -0
  21. data/lib/sacs_ruby/api/car_availability.rb +13 -0
  22. data/lib/sacs_ruby/api/city_pairs_lookup.rb +17 -0
  23. data/lib/sacs_ruby/api/countries_lookup.rb +15 -0
  24. data/lib/sacs_ruby/api/destination_finder.rb +17 -0
  25. data/lib/sacs_ruby/api/fare_range.rb +25 -0
  26. data/lib/sacs_ruby/api/flights_to.rb +17 -0
  27. data/lib/sacs_ruby/api/geo_autocomplete.rb +17 -0
  28. data/lib/sacs_ruby/api/geo_code.rb +12 -0
  29. data/lib/sacs_ruby/api/geo_search.rb +12 -0
  30. data/lib/sacs_ruby/api/insta_flights_search.rb +17 -0
  31. data/lib/sacs_ruby/api/lead_price_calendar.rb +17 -0
  32. data/lib/sacs_ruby/api/low_fare_forecast.rb +19 -0
  33. data/lib/sacs_ruby/api/low_fare_history.rb +17 -0
  34. data/lib/sacs_ruby/api/multi_airport_city_lookup.rb +20 -0
  35. data/lib/sacs_ruby/api/point_of_sale_country_code_lookup.rb +17 -0
  36. data/lib/sacs_ruby/api/seat_map.rb +13 -0
  37. data/lib/sacs_ruby/api/top_destinations.rb +19 -0
  38. data/lib/sacs_ruby/api/travel_seasonality.rb +23 -0
  39. data/lib/sacs_ruby/api/travel_seasonality_airports_lookup.rb +13 -0
  40. data/lib/sacs_ruby/api/travel_theme_lookup.rb +15 -0
  41. data/lib/sacs_ruby/base.rb +47 -0
  42. data/lib/sacs_ruby/base_post.rb +27 -0
  43. data/lib/sacs_ruby/client.rb +124 -0
  44. data/lib/sacs_ruby/configuration.rb +23 -0
  45. data/lib/sacs_ruby/credentials.rb +35 -0
  46. data/lib/sacs_ruby/error.rb +55 -0
  47. data/lib/sacs_ruby/json.rb +16 -0
  48. data/lib/sacs_ruby/version.rb +3 -0
  49. data/sacs_ruby.gemspec +28 -0
  50. metadata +189 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 75d94307e3961345367091ae837f1eaa43585ad5
4
+ data.tar.gz: 17fa57d319d3a0e795ed7b9e4b1ad29d7f7f7c29
5
+ SHA512:
6
+ metadata.gz: 9216b138e08cba97fe16e77df0bd0f31b77e24b698aeb3d1b2113f8f94c5c91576de0f9e4727ed8829132993a9f37aa2e9614c9e02507503bcccbe71ee9cf0a0
7
+ data.tar.gz: 147e6fd9812b5ff9e28d6d3232ac1222bbd8902320f17675c9431ffb9eae6228851b4d5a30a527bd2c97e8dc4427b32d6de1515c0e929f9622840ee5f57f33b9
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ sabre
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sacs_ruby.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Sabre Corp
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,196 @@
1
+ # Ruby Sabre API Client
2
+
3
+ This library implements [Sabre REST API](https://developer.sabre.com/docs/read/REST_APIs)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'sacs_ruby'
11
+ ```
12
+
13
+ If you are not using JRuby please consider using [Oj gem](https://github.com/ohler55/oj) for JSON serialization.
14
+ To install Oj add this line to your Gemfile:
15
+
16
+ ```ruby
17
+ gem 'oj'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install sacs_ruby
27
+
28
+ ## Configuration
29
+
30
+ To get API keys please register on [developer.sabre.com](https://developer.sabre.com/member/register)
31
+
32
+ Initialize gem with configuration file. If using Rails add it to `config/initializers/sacs_ruby.rb`
33
+
34
+ ```ruby
35
+ SacsRuby.configure do |config|
36
+ config.user_id = '' # User ID
37
+ config.group = '' # Group
38
+ config.domain = 'EXT' # Domain
39
+ config.client_secret = '' # Client Secret
40
+ config.environment = 'https://api.test.sabre.com' # Environment
41
+ config.token_strategy = :single # or :shared - see Token paragraph
42
+ end
43
+ ```
44
+
45
+ #### Use environment variables to store API keys. Never commit it for security reasons.
46
+
47
+ ### Access Token
48
+
49
+ For single server configuration you can use default token strategy:
50
+ ```ruby
51
+ config.token_strategy = :single
52
+ ```
53
+ Token will be obtained with first request, then stored and auto renewed through life of the server.
54
+ Be aware that there is a limit of tokens issued for given API keys.
55
+
56
+ For multi server configuration (or development when a lot of restarts happen) please
57
+ use shared token strategy:
58
+ ```ruby
59
+ config.token_strategy = :shared
60
+ ```
61
+
62
+ To request token use:
63
+ ```ruby
64
+ token = SacsRuby.client.fetch_token
65
+ token.access_token
66
+ token.expires_on
67
+ ```
68
+ Please store it and implement token refresh in to your workflow.
69
+
70
+ Expired token will raise `SacsRuby::AuthorizationError`.
71
+
72
+ To use shared token add it as argument, ie:
73
+ ```ruby
74
+ results = SacsRuby::API::BargainFinderMax.get(payload: payload, token: received_access_token)
75
+ ```
76
+
77
+ ### Environment
78
+
79
+ When using `https://api.test.sabre.com`, Sabre TEST API will be used.
80
+
81
+ When you will be ready, you can request access to PROD servers and change to
82
+ `https://api.sabre.com`
83
+
84
+ ## Usage
85
+
86
+ For detailed documentation regarding required params and possible response, please refer to [Sabre REST API documentation](https://developer.sabre.com/docs/read/REST_APIs)
87
+
88
+ ### Basic usage
89
+
90
+ Each API endpoint listed in documentation can be requested following this pattern:
91
+ ```ruby
92
+ SacsRuby::API::NameOfTheApi.get(*args)
93
+ ```
94
+
95
+ Example:
96
+
97
+ ```ruby
98
+ results = SacsRuby::API::InstaFlightsSearch.get(origin: 'LAX', destination: 'JFK', departuredate: '2015-12-01', returndate: '2015-12-06') # add `token: token_string` if needed
99
+ ```
100
+
101
+ or:
102
+
103
+ ```ruby
104
+ ifs = SacsRuby::API::InstaFlightsSearch.new(origin: 'LAX', destination: 'JFK', departuredate: '2015-12-04', returndate: '2015-12-06')
105
+
106
+ ifs.opts # => {:origin=>"LAX", :destination=>"JFK", :departuredate=>"2015-12-04", :returndate=>"2015-12-06"}
107
+
108
+ ifs.get # gets data from api
109
+
110
+ ifs.results # prints response hash
111
+ ```
112
+
113
+ If required params are missed during endpoint initialization `SacsRuby::ApiArgumentError` will be raised.
114
+
115
+ Sometimes additional argument requires another argument to be present.
116
+ If it is missing, `SacsRuby::BadRequestError` will be raised with error description provided by the API.
117
+
118
+
119
+ ### Advanced usage
120
+
121
+ Sabre API is very powerful tool. Some of the endpoints cannot accept single arguments,
122
+ due to complexity of request.
123
+
124
+ For those endpoints you need to build JSON payload.
125
+
126
+ We recomend to create method which will build hash and then converts it to JSON.
127
+
128
+ Ie:
129
+ ```ruby
130
+ class BargainFinderMax
131
+ def self.build_json(params)
132
+ {
133
+ 'OTA_AirLowFareSearchRQ' => {
134
+ 'OriginDestinationInformation' => [{
135
+ 'DepartureDateTime' => departure_date_helper(params),
136
+ 'DestinationLocation' => {
137
+ 'LocationCode' => params['destination']
138
+ },
139
+ 'OriginLocation' => {
140
+ 'LocationCode' => params['origin']
141
+ },
142
+ 'RPH' => params['rph']
143
+ }],
144
+ 'POS' => {
145
+ 'Source' => [{
146
+ 'RequestorID' => {
147
+ 'CompanyName' => {
148
+ 'Code' => params['pos_company_code']
149
+ }, 'ID' => params['pos_id'], 'Type' => params['pos_type']
150
+ }
151
+ }]
152
+ },
153
+ 'TPA_Extensions' => {
154
+ 'IntelliSellTransaction' => {
155
+ 'RequestType' => {
156
+ 'Name' => params['request_type']
157
+ }
158
+ }
159
+ },
160
+ 'TravelPreferences' => {
161
+ 'TPA_Extensions' => {
162
+ 'NumTrips' => {
163
+ 'Number' => 1
164
+ }
165
+ }
166
+ },
167
+ 'TravelerInfoSummary' => {
168
+ 'AirTravelerAvail' => [{
169
+ 'PassengerTypeQuantity' => [{
170
+ 'Code' => params['passenger_code'],
171
+ 'Quantity' => params['passenger_qnt'].to_i
172
+ }]
173
+ }]
174
+ }
175
+ }
176
+ }.to_json
177
+ end
178
+
179
+ def self.departure_date_helper(params)
180
+ DateTime.strptime(params['departure_date'], '%m/%d/%Y').strftime('%FT%T')
181
+ end
182
+ end
183
+
184
+ payload = BargainFinderMax.build_json(params)
185
+ results = SacsRuby::API::BargainFinderMax.get(payload: payload)
186
+ ```
187
+ Pay attention to the format of required arguments.
188
+
189
+ ### Support
190
+
191
+ - [Stack Overflow](http://stackoverflow.com/questions/tagged/sabre)
192
+ - Need to report an issue/improvement? Use the built-in [issues](https://github.com/SabreDevStudio/SACS-Ruby/issues) section.
193
+ - [Sabre Dev Studio](https://developer.sabre.com/)
194
+
195
+ ### Disclaimer of Warranty and Limitation of Liability
196
+ This software and any compiled programs created using this software are furnished “as is” without warranty of any kind, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. No oral or written information or advice given by Sabre, its agents or employees shall create a warranty or in any way increase the scope of this warranty, and you may not rely on any such information or advice. Sabre does not warrant, guarantee, or make any representations regarding the use, or the results of the use, of this software, compiled programs created using this software, or written materials in terms of correctness, accuracy, reliability, currentness, or otherwise. The entire risk as to the results and performance of this software and any compiled applications created using this software is assumed by you. Neither Sabre nor anyone else who has been involved in the creation, production or delivery of this software shall be liable for any direct, indirect, consequential, or incidental damages (including damages for loss of business profits, business interruption, loss of business information, and the like) arising out of the use of or inability to use such product even if Sabre has been advised of the possibility of such damages.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sabre"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,56 @@
1
+ require 'sacs_ruby/version'
2
+ require 'sacs_ruby/error'
3
+ require 'rest-client'
4
+
5
+ module SacsRuby
6
+ autoload :Configuration, 'sacs_ruby/configuration'
7
+ autoload :Credentials, 'sacs_ruby/credentials'
8
+ autoload :Client, 'sacs_ruby/client'
9
+ autoload :Base, 'sacs_ruby/base'
10
+ autoload :JSON, 'sacs_ruby/json'
11
+ autoload :BasePost, 'sacs_ruby/base_post'
12
+
13
+ module API
14
+ autoload :InstaFlightsSearch, 'sacs_ruby/api/insta_flights_search'
15
+ autoload :LeadPriceCalendar,'sacs_ruby/api/lead_price_calendar'
16
+ autoload :DestinationFinder, 'sacs_ruby/api/destination_finder'
17
+ autoload :FlightsTo, 'sacs_ruby/api/flights_to'
18
+ autoload :LowFareForecast, 'sacs_ruby/api/low_fare_forecast'
19
+ autoload :FareRange, 'sacs_ruby/api/fare_range'
20
+ autoload :TravelSeasonality, 'sacs_ruby/api/travel_seasonality'
21
+ autoload :TopDestinations, 'sacs_ruby/api/top_destinations'
22
+ autoload :LowFareHistory, 'sacs_ruby/api/low_fare_history'
23
+ autoload :PointOfSaleCountryCodeLookup, 'sacs_ruby/api/point_of_sale_country_code_lookup'
24
+ autoload :TravelSeasonalityAirportsLookup, 'sacs_ruby/api/travel_seasonality_airports_lookup'
25
+ autoload :CountriesLookup, 'sacs_ruby/api/countries_lookup'
26
+ autoload :CityPairsLookup, 'sacs_ruby/api/city_pairs_lookup'
27
+ autoload :TravelThemeLookup, 'sacs_ruby/api/travel_theme_lookup'
28
+ autoload :MultiAirportCityLookup, 'sacs_ruby/api/multi_airport_city_lookup'
29
+ autoload :AirportsAtCitiesLookup, 'sacs_ruby/api/airports_at_cities_lookup'
30
+ autoload :AirlineAllianceLookup, 'sacs_ruby/api/airline_alliance_lookup'
31
+ autoload :AircraftEquipmentLookup, 'sacs_ruby/api/aircraft_equipment_lookup'
32
+ autoload :AirlineLookup, 'sacs_ruby/api/airline_lookup'
33
+ autoload :GeoAutocomplete, 'sacs_ruby/api/geo_autocomplete'
34
+ autoload :BargainFinderMax, 'sacs_ruby/api/bargain_finder_max'
35
+ autoload :AlternateAirportShop, 'sacs_ruby/api/alternate_airport_shop'
36
+ autoload :AlternateDate, 'sacs_ruby/api/alternate_date'
37
+ autoload :AdvancedCalendarSearch, 'sacs_ruby/api/advanced_calendar_search'
38
+ autoload :SeatMap, 'sacs_ruby/api/seat_map'
39
+ autoload :CarAvailability, 'sacs_ruby/api/car_availability'
40
+ autoload :GeoCode, 'sacs_ruby/api/geo_code'
41
+ autoload :GeoSearch, 'sacs_ruby/api/geo_search'
42
+ end
43
+
44
+ class << self
45
+ attr_accessor :configuration
46
+ end
47
+
48
+ def self.configure
49
+ self.configuration ||= Configuration.new
50
+ yield(configuration)
51
+ end
52
+
53
+ def self.client
54
+ @client ||= Client.new
55
+ end
56
+ end
@@ -0,0 +1,13 @@
1
+ module SacsRuby
2
+ module API
3
+ # The Advanced Calendar Search API returns the lowest published fares and
4
+ # flight itineraries for a given city pair.
5
+ class AdvancedCalendarSearch < SacsRuby::Base
6
+ include BasePost
7
+
8
+ def endpoint_url
9
+ '/v1.9.0/shop/calendar/flights?mode=live'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module SacsRuby
2
+ module API
3
+ # The Aircraft Equipment Lookup API returns the aircraft name associated
4
+ # with a specified IATA aircraft equipment code. If no code is specified,
5
+ # the API returns all codes and their corresponding names.
6
+ # @see https://developer.sabre.com/docs/rest_apis/utility/aircraft_equipment_lookup API Documentation
7
+ # @see Base Base class for documentation
8
+ class AircraftEquipmentLookup < SacsRuby::Base
9
+ def endpoint_url
10
+ '/v1/lists/utilities/aircraft/equipment'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module SacsRuby
2
+ module API
3
+ # The Airline Alliance Lookup API returns the airline alliance member
4
+ # information associated with a specified airline alliance group code.
5
+ # If no code is specified, the API returns all airline alliance groups and
6
+ # their corresponding member information.
7
+ # @see https://developer.sabre.com/docs/rest_apis/utility/airline_alliance_lookup API Documentation
8
+ # @see Base Base class for documentation
9
+ class AirlineAllianceLookup < SacsRuby::Base
10
+ def endpoint_url
11
+ '/v1/lists/utilities/airlines/alliances'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module SacsRuby
2
+ module API
3
+ # The Airline Lookup API returns the airline name associated with a
4
+ # specified IATA airline code. If no code is specified, the API returns all
5
+ # codes and their corresponding names.
6
+ # @see https://developer.sabre.com/docs/read/rest_apis/utility/airline_lookup API Documentation
7
+ # @see Base Base class for documentation
8
+ class AirlineLookup < SacsRuby::Base
9
+ def endpoint_url
10
+ '/v1/lists/utilities/airlines'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ module SacsRuby
2
+ module API
3
+ # The Airports at Cities Lookup API returns the major airport, rail station
4
+ # and other codes that are associated with a single a multi-airport city
5
+ # (MAC) code. An example multi-airport city code is CHI, and the
6
+ # corresponding city name is Chicago.
7
+ # @see https://developer.sabre.com/docs/read/rest_apis/air/utility/airports_at_cities_lookup API Documentation
8
+ # @see Base Base class for documentation
9
+ class AirportsAtCitiesLookup < SacsRuby::Base
10
+ def required_vars
11
+ %i(city)
12
+ end
13
+
14
+ def endpoint_url
15
+ "/v1/lists/supported/cities/#{opts.delete(:city)}/airports"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ module SacsRuby
2
+ module API
3
+ # The Alternate Airport Shop API allows you to define up to 20 airports per
4
+ # origin and/or destination. The API returns the lead fare (either nonstop
5
+ # or overall, whichever is lowest) with the corresponding flight itinerary
6
+ # and fare breakdown for each lead fare.
7
+ class AlternateAirportShop < SacsRuby::Base
8
+ include BasePost
9
+
10
+ def endpoint_url
11
+ '/v1.9.0/shop/altairports/flights?mode=live'
12
+ end
13
+ end
14
+ end
15
+ end