amadeus 1.0.0.beta5 → 1.0.0.beta6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 791529954c105956f49fc4fb7501fcbde20c6e315a63b5b458e26cc55fe69ec1
4
- data.tar.gz: 8d9809a62d730f91031edef5a45eb8ce37efcdb96949ded22c0197390aa0f7c5
3
+ metadata.gz: 317bd9d6cad6d73e64e60eeb11a7c20c2f858af4d19ed911ec01272b4276e89b
4
+ data.tar.gz: 4a3f55ab0b9a58ae32ab392257131956428450b433fd45114526cfa045908607
5
5
  SHA512:
6
- metadata.gz: c861dfa5193329f99c90d059f5b44d6ea6942ad5df3cffb7ada477fe728b557db4e4652892a5d0d0e04358646eedb42caf0c680166acd3328ebd44136e5cf519
7
- data.tar.gz: 830555fa850108f7e9e085450f99b3204ac978b60d16a576a687aaf69b77954239a08c5421cf45922682004a9b0598dfeb75bba21bfcb44ebcd972dc90817a7c
6
+ metadata.gz: 1499acbe2d880c597424df6e06d06849cb71b4b61a16ccf55bdaf4ed442ecdc578a4dd16df0eb82e12e45acac90b50fdf1a6818c8956ea447cffd28b091009b7
7
+ data.tar.gz: 89379f8c00da7c677e66f1eff6904fb4da6a02ee0c9e2d731a4252801d571648c1cf8fff6ce0b72873e034821dc28ca9410230b52461054940f00c3d707e456f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.0.beta6 - 2018-04-05
4
+
5
+ Adds easier to read error messages
6
+
3
7
  ## 1.0.0.beta5 - 2018-03-28
4
8
 
5
9
  Add support for Amadeus's specific `Accept` request header.
data/README.md CHANGED
@@ -8,14 +8,14 @@
8
8
 
9
9
  Amadeus provides a set of APIs for the travel industry. Flights, Hotels, Locations and more.
10
10
 
11
- For more details see the [Ruby documentation](https://developer.amadeus.com/docs/ruby) on [Amadeus.com](https://developer.amadeus.com).
11
+ For more details see the [Ruby documentation](https://developer.amadeus.com/docs/ruby) on [Amadeus.com](https://developer.amadeus.com) and the [class reference](https://amadeus4dev.github.io/amadeus-ruby) here on GitHub.
12
12
 
13
13
  ## Installation
14
14
 
15
15
  This gem requires Ruby 2.2+. You can install install it directly or via bundler.
16
16
 
17
17
  ```rb
18
- gem 'amadeus', '~> 1.0.0.beta5'
18
+ gem 'amadeus', '~> 1.0.0.beta6'
19
19
  ```
20
20
 
21
21
  __Next__: [Get Started with the Ruby SDK.](https://developer.amadeus.com/docs/ruby/get_started/initialize)
@@ -161,7 +161,7 @@ require 'logger'
161
161
  amadeus = Amadeus::Client.new(
162
162
  client_id: '...',
163
163
  client_secret: '...',
164
- log_level: 'debug'
164
+ log_level: 'debug' # or "warn" or "silent", defaults to "silent"
165
165
  )
166
166
  ```
167
167
 
@@ -41,7 +41,7 @@ module Amadeus
41
41
  # The available hosts for this API
42
42
  HOSTS = {
43
43
  test: 'test.api.amadeus.com',
44
- production: 'production.api.amadeus.com'
44
+ production: 'api.amadeus.com'
45
45
  }.freeze
46
46
 
47
47
  # Initialize using your credentials:
@@ -63,8 +63,8 @@ module Amadeus
63
63
  # the API
64
64
  # @option options [Object] :logger ('Logger') a `Logger`-compatible logger
65
65
  # that accepts a debug call
66
- # @option options [string] :log_level ('warn') if this client is running in
67
- # debug, warn, or silent mode
66
+ # @option options [string] :log_level ('silent') if this client is running
67
+ # in debug, warn, or silent mode
68
68
  # @option options [string] :hostname ('production') the name of the server
69
69
  # API calls are made to (`production` or `test`)
70
70
  # @option options [string] :custom_app_id (null) a custom App ID to be
@@ -18,11 +18,6 @@ module Amadeus
18
18
  # @return [String]
19
19
  attr_reader :code
20
20
 
21
- # The content of the response that describes the error
22
- #
23
- # @return [Hash]
24
- attr_reader :description
25
-
26
21
  # Initializes an error by storing the {Amadeus::Response} object
27
22
  # that raised this error. The continues to determien the custom
28
23
  # error message
@@ -31,9 +26,9 @@ module Amadeus
31
26
  # @!visibility private
32
27
  def initialize(response)
33
28
  @response = response
34
- @description = determine_description
35
- super(@description)
36
29
  @code = determine_code
30
+
31
+ super(description)
37
32
  end
38
33
 
39
34
  # PROTECTED
@@ -49,13 +44,52 @@ module Amadeus
49
44
 
50
45
  private
51
46
 
52
- def determine_description
53
- return nil unless response && response.parsed
54
- result = response.result
55
- return result['errors'] if result['errors']
56
- return result if result['error_description']
47
+ # Determines the description for this error, as used in in the error output
48
+ def description
49
+ description = short_description
50
+ description += long_description
51
+ description
52
+ end
53
+
54
+ # Determines the short description, printed after on the same line as the
55
+ # error class name
56
+ def short_description
57
+ if response.respond_to?(:status_code) && response.status_code
58
+ "[#{response.status_code}]"
59
+ else
60
+ '[---]'
61
+ end
62
+ end
63
+
64
+ # Determines the longer description, printed after the initial error
65
+ def long_description
66
+ return '' unless response && response.parsed
67
+ message = ''
68
+ message += error_description if response.result['error_description']
69
+ message += errors_description if response.result['errors']
70
+ message
71
+ end
72
+
73
+ # Returns the description of a single error
74
+ def error_description
75
+ message = ''
76
+ message += "\n#{response.result['error']}" if response.result['error']
77
+ message += "\n#{response.result['error_description']}"
78
+ message
79
+ end
80
+
81
+ # Returns the description of multiple errors
82
+ def errors_description
83
+ response.result['errors'].map do |error|
84
+ message = "\n"
85
+ if error['source'] && error['source']['parameter']
86
+ message += "[#{error['source']['parameter']}] "
87
+ end
88
+ message + error['detail'] if error['detail']
89
+ end.join
57
90
  end
58
91
 
92
+ # Determines the code for this error
59
93
  def determine_code
60
94
  self.class.to_s.split('::').last
61
95
  end
@@ -58,6 +58,8 @@ module Amadeus
58
58
  http_request
59
59
  end
60
60
 
61
+ # PROTECTED
62
+
61
63
  # Builds the request object
62
64
  def http_request
63
65
  @http_request ||= begin
@@ -130,8 +132,9 @@ module Amadeus
130
132
  end
131
133
 
132
134
  def uri
133
- url = "#{@scheme}://#{@host}#{@path}"
135
+ url = "#{@scheme}://#{@host}"
134
136
  url += ":#{@port}" unless port_matches_scheme
137
+ url += @path.to_s
135
138
  uri = URI(url)
136
139
  params = flatten_keys(@params)
137
140
  uri.query = URI.encode_www_form(params) if @verb == :GET
@@ -19,7 +19,7 @@ module Amadeus
19
19
  # @!visibility private
20
20
  def initialize_logger(options)
21
21
  @logger = init_optional(:logger, options, Logger.new(STDOUT))
22
- @log_level = init_optional(:log_level, options, 'warn')
22
+ @log_level = init_optional(:log_level, options, 'silent')
23
23
  end
24
24
 
25
25
  # Initializes the port, hostname, and use of SSL
@@ -32,7 +32,7 @@ module Amadeus
32
32
  # @return [Amadeus::Response] a parsed response
33
33
  # @raise [Amadeus::Base] an exception if the call failed
34
34
  # @example Search for hotels in London
35
- # amadeus.shopping.hotels('SMPARCOL').hotel_offers.get
35
+ # amadeus.shopping.hotel('SMPARCOL').hotel_offers.get
36
36
  #
37
37
  def get(params = {})
38
38
  client.get("/v1/shopping/hotels/#{@hotel_id}/hotel-offers", params)
@@ -36,7 +36,7 @@ module Amadeus
36
36
  # @return [Amadeus::Response] a parsed response
37
37
  # @raise [Amadeus::Base] an exception if the call failed
38
38
  # @example Search for hotels in London
39
- # amadeus.shopping.hotels('SMPARCOL')
39
+ # amadeus.shopping.hotel('SMPARCOL')
40
40
  # .offers('AC7D4DA2C322A73AF0824318A4965DA2805A3FC2').get
41
41
  #
42
42
  def get(params = {})
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Amadeus
4
4
  # The current client version
5
- VERSION = '1.0.0.beta5'.freeze
5
+ VERSION = '1.0.0.beta6'.freeze
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amadeus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta5
4
+ version: 1.0.0.beta6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amadeus
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-03-28 00:00:00.000000000 Z
12
+ date: 2018-04-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: awesome_print