amadeus-discover 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 86b96af49d6a66a81452f973c8d85d212c8e0e39ff18cf1ae28c11961da6fb74
4
+ data.tar.gz: 0d9a10033a10c722d5f7e3c8d88feb91fc9910fe26f792ea045493a7d602c107
5
+ SHA512:
6
+ metadata.gz: c7b475bf35f1a947e4a9b5139dae9417fb4ffef171e3717b0b8d62ac791c366519f4d6e66638060c011aeac4ba6fb781da3b05511ebadbf31f7dbf8cbfd3f257
7
+ data.tar.gz: 3a402a58ae75756aaf65982fdc7811aea479593c4cab7bd949d57062197fd3767d4e71b7368a0c73cecc8a917fd850f2f4d6e79b07ab57d020ee5a050ffff145
data/.env.example ADDED
@@ -0,0 +1,14 @@
1
+
2
+ # Entrypoint to the Amadeus Discover API instance you want to target.
3
+ AMADEUS_DISCOVER_HOST="https://api-test.amadeus-discover.com"
4
+
5
+ # Credentials
6
+ # You need a valid account to identify your self on the Amadeus Discover API.
7
+ # To create an account, please get in touch with API instance administrators.
8
+ AMADEUS_DISCOVER_USERNAME="{username}"
9
+ AMADEUS_DISCOVER_PASSWORD="{password}"
10
+
11
+ # To create products (as in integration tests), you need a booking engine to
12
+ # identify your organisation. You should have got this when you got your
13
+ # credentials.
14
+ AMADEUS_DISCOVER_BOOKING_ENGINE="{BOOKING ENGINE}"
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ /.env
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
14
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --force-color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Metrics/BlockLength:
7
+ Exclude:
8
+ - 'amadeus-discover.gemspec'
9
+ - 'spec/**/*.rb'
10
+
11
+ Naming/FileName:
12
+ Exclude:
13
+ - 'lib/amadeus-discover.rb'
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in amadeus-discover.gemspec
6
+ gemspec
7
+
8
+ gem 'awesome_print', '~> 1.9.2'
9
+ gem 'byebug', '~> 11.1'
data/Gemfile.lock ADDED
@@ -0,0 +1,105 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ amadeus-discover (1.0.0)
5
+ faraday (~> 1.9)
6
+ faraday_middleware (~> 1.2)
7
+ hashie (~> 5.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.4.2)
13
+ awesome_print (1.9.2)
14
+ byebug (11.1.3)
15
+ diff-lcs (1.5.0)
16
+ dotenv (2.7.6)
17
+ ethon (0.15.0)
18
+ ffi (>= 1.15.0)
19
+ faraday (1.10.0)
20
+ faraday-em_http (~> 1.0)
21
+ faraday-em_synchrony (~> 1.0)
22
+ faraday-excon (~> 1.1)
23
+ faraday-httpclient (~> 1.0)
24
+ faraday-multipart (~> 1.0)
25
+ faraday-net_http (~> 1.0)
26
+ faraday-net_http_persistent (~> 1.0)
27
+ faraday-patron (~> 1.0)
28
+ faraday-rack (~> 1.0)
29
+ faraday-retry (~> 1.0)
30
+ ruby2_keywords (>= 0.0.4)
31
+ faraday-em_http (1.0.0)
32
+ faraday-em_synchrony (1.0.0)
33
+ faraday-excon (1.1.0)
34
+ faraday-httpclient (1.0.1)
35
+ faraday-multipart (1.0.3)
36
+ multipart-post (>= 1.2, < 3)
37
+ faraday-net_http (1.0.1)
38
+ faraday-net_http_persistent (1.2.0)
39
+ faraday-patron (1.0.0)
40
+ faraday-rack (1.0.0)
41
+ faraday-retry (1.0.3)
42
+ faraday_middleware (1.2.0)
43
+ faraday (~> 1.0)
44
+ ffaker (2.20.0)
45
+ ffi (1.15.5)
46
+ hashie (5.0.0)
47
+ multipart-post (2.1.1)
48
+ parallel (1.22.1)
49
+ parser (3.1.1.0)
50
+ ast (~> 2.4.1)
51
+ rainbow (3.1.1)
52
+ rake (13.0.6)
53
+ regexp_parser (2.2.1)
54
+ rexml (3.2.5)
55
+ rspec (3.11.0)
56
+ rspec-core (~> 3.11.0)
57
+ rspec-expectations (~> 3.11.0)
58
+ rspec-mocks (~> 3.11.0)
59
+ rspec-core (3.11.0)
60
+ rspec-support (~> 3.11.0)
61
+ rspec-expectations (3.11.0)
62
+ diff-lcs (>= 1.2.0, < 2.0)
63
+ rspec-support (~> 3.11.0)
64
+ rspec-mocks (3.11.0)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.11.0)
67
+ rspec-support (3.11.0)
68
+ rubocop (1.26.1)
69
+ parallel (~> 1.10)
70
+ parser (>= 3.1.0.0)
71
+ rainbow (>= 2.2.2, < 4.0)
72
+ regexp_parser (>= 1.8, < 3.0)
73
+ rexml
74
+ rubocop-ast (>= 1.16.0, < 2.0)
75
+ ruby-progressbar (~> 1.7)
76
+ unicode-display_width (>= 1.4.0, < 3.0)
77
+ rubocop-ast (1.16.0)
78
+ parser (>= 3.1.1.0)
79
+ rubocop-rspec (2.9.0)
80
+ rubocop (~> 1.19)
81
+ ruby-progressbar (1.11.0)
82
+ ruby2_keywords (0.0.5)
83
+ timecop (0.9.5)
84
+ typhoeus (1.4.0)
85
+ ethon (>= 0.9.0)
86
+ unicode-display_width (2.1.0)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ amadeus-discover!
93
+ awesome_print (~> 1.9.2)
94
+ byebug (~> 11.1)
95
+ dotenv (~> 2.7.6)
96
+ ffaker (~> 2.20)
97
+ rake (~> 13.0)
98
+ rspec (~> 3.9)
99
+ rubocop
100
+ rubocop-rspec
101
+ timecop (~> 0.9.5)
102
+ typhoeus (~> 1.4.0)
103
+
104
+ BUNDLED WITH
105
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2022 Vaolo
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # AmadeusDiscover
2
+
3
+ Faraday based Ruby client for the Amadeus Discover API for content partners use.
4
+
5
+ ## Installation
6
+
7
+ `AmadeusDiscover` is distributed as a gem and available on rubygems.org so you can add it to your Gemfile or install it manually with:
8
+
9
+ ````shell
10
+ $ gem install amadeus-discover
11
+ ````
12
+
13
+ ## Usage
14
+
15
+ ### Initializing a new client instance
16
+
17
+ The client can be initialized directly:
18
+
19
+ ````ruby
20
+ connection = Faraday::Connection.new('https://api-test.amadeus-discover.com') do |builder|
21
+ # Add middlewares, a logger or specify an adapter
22
+ end
23
+
24
+ credentials = {
25
+ username: '{username}',
26
+ password: '{password}',
27
+ client_id: 'content-partner-api',
28
+ grant_type: 'password'
29
+ }
30
+
31
+ client = AmadeusDiscover::Client.new(connection, credentials)
32
+ ````
33
+
34
+ Alternatively, you can configure `AmadeusDiscover` to use default connection and credentials for every client instances:
35
+
36
+ ````ruby
37
+ # In <config/initializers/amadeus_discover.rb>
38
+ AmadeusDiscover.configure do |config|
39
+ config.connection = Faraday::Connection.new(ENV['AMADEUS_DISCOVER_HOST']) do |builder|
40
+ builder.response :logger, Rails.logger
41
+ builder.adapter :typhoeus
42
+ end
43
+
44
+ config.credentials = {
45
+ username: ENV['AMADEUS_DISCOVER_USERNAME'],
46
+ password: ENV['AMADEUS_DISCOVER_PASSWORD'],
47
+ client_id: 'content-partner-api',
48
+ grant_type: 'password'
49
+ }
50
+ end
51
+
52
+ # Anywhere in yout application
53
+ client = AmadeusDiscover::Client.new
54
+ ````
55
+
56
+ ### Using a client
57
+
58
+ Once created, a client gives you access to Amadeus Discover API methods:
59
+
60
+ ````ruby
61
+ client = AmadeusDiscover::Client.new
62
+
63
+ # Get all suppliers - Not available at this time
64
+ # suppliers = client.suppliers.list
65
+
66
+ # Create a supplier
67
+ s = client.suppliers.create(name: 'My supplier')
68
+
69
+ client.suppliers(s['id']).tap do |supplier|
70
+ # Get supplier informations
71
+ supplier.get
72
+
73
+ # Update supplier
74
+ supplier.update(more_data)
75
+
76
+ # Delete supplier
77
+ supplier.delete
78
+
79
+ # Get all products for a supplier
80
+ products = supplier.products.list
81
+
82
+ # Create a new product for a supplier
83
+ p = supplier.products.create(title: { en: "Let's have some fun!" })
84
+
85
+ supplier.products(p['id']).tap do |product|
86
+ # Get product informations - Not available at this time
87
+ # supplier.get
88
+
89
+ # Update product
90
+ product.update(more_data)
91
+
92
+ # Delete supplier
93
+ product.delete
94
+ end
95
+ end
96
+ ````
97
+
98
+ If an error occured, a `Faraday::Error` will be raised. The exact type of that exception will depend on the encountered error type (authentication error, client error, server error…). See <https://lostisland.github.io/faraday/middleware/raise-error> for details.
99
+
100
+ ## Contributing
101
+
102
+ Bug reports and pull requests are welcome on Gitlab at <https://gitlab.com/vaolo-public/ruby/amadeus-discover>.
103
+
104
+ ### Development
105
+
106
+ After checking out the repo, run `bundle install` to install development dependencies.
107
+
108
+ Running tests require a bunch of environment variables to be declared, to identify where is hosted the instance of the Amadeus Discover API you'll target and credentials you'll use for authentication. Development tools integrate [dotenv](https://github.com/bkeepers/dotenv) so you can do it in a `.env` file and a `.env.example` is available to list and document all required variables.
109
+
110
+ Once your `.env` file is ready, run `bundle exec rake spec` to run the tests.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+ RuboCop::RakeTask.new
10
+
11
+ task default: %i[spec rubocop]
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/amadeus_discover/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'amadeus-discover'
7
+ spec.version = AmadeusDiscover::VERSION
8
+ spec.licenses = ['Apache-2.0']
9
+ spec.authors = ['Vaolo']
10
+ spec.email = ['techservices@vaolo.com']
11
+
12
+ spec.summary = 'Ruby wrapper around Amadeus Discover API'
13
+ spec.description = 'Ruby wrapper around Amadeus Discover API'
14
+ spec.homepage = 'https://gitlab.com/vaolo-public/ruby/amadeus-discover'
15
+
16
+ # spec.metadata['allowed_push_host'] = 'TODO: Set to 'http://mygemserver.com''
17
+ spec.metadata['rubygems_mfa_required'] = 'true'
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = spec.homepage
20
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/-/blob/master/CHANGELOG.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
30
+
31
+ spec.add_dependency 'faraday', '~> 1.9'
32
+ spec.add_dependency 'faraday_middleware', '~> 1.2'
33
+ spec.add_dependency 'hashie', '~> 5.0'
34
+
35
+ spec.add_development_dependency 'dotenv', '~> 2.7.6'
36
+ spec.add_development_dependency 'ffaker', '~> 2.20'
37
+ spec.add_development_dependency 'rake', '~> 13.0'
38
+ spec.add_development_dependency 'rspec', '~> 3.9'
39
+ spec.add_development_dependency 'timecop', '~> 0.9.5'
40
+ spec.add_development_dependency 'typhoeus', '~> 1.4.0'
41
+
42
+ spec.add_development_dependency 'rubocop'
43
+ spec.add_development_dependency 'rubocop-rspec'
44
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require './lib/amadeus-discover'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'amadeus_discover'
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'hashie'
4
+
5
+ module AmadeusDiscover
6
+ class Authenticator
7
+ # Store and validate credentials that will be used for authentication.
8
+ #
9
+ # @!visibility private
10
+ class Credentials < Hashie::Dash
11
+ include Hashie::Extensions::IndifferentAccess
12
+ include Hashie::Extensions::IgnoreUndeclared
13
+
14
+ property :username, required: true
15
+ property :password, required: true
16
+ property :client_id, required: true
17
+ property :grant_type, required: true
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'hashie'
4
+
5
+ module AmadeusDiscover
6
+ class Authenticator
7
+ # Store and validate an authentication response, as delivered by the
8
+ # authentication API endpoint.
9
+ #
10
+ # @!visibility private
11
+ class Response < Hashie::Dash
12
+ include Hashie::Extensions::IndifferentAccess
13
+ include Hashie::Extensions::IgnoreUndeclared
14
+
15
+ property :access_token, required: true
16
+ property :expires_in, required: true
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module AmadeusDiscover
6
+ class Authenticator
7
+ # Handle an authentication token
8
+ #
9
+ # @!visibility private
10
+ class Token
11
+ extend Forwardable
12
+
13
+ attr_reader :issued_at
14
+
15
+ def_delegators :@response, :access_token, :expires_in
16
+ alias value access_token
17
+
18
+ def initialize(response, issued_at = Time.now)
19
+ @response = Response.new(response)
20
+ @issued_at = issued_at
21
+ end
22
+
23
+ def valid?
24
+ (issued_at + expires_in) > Time.now
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AmadeusDiscover
4
+ # Authenticator to be used with Faraday's Authentication Middleware
5
+ #
6
+ # Authentication Middleware and this are automatically injected into your
7
+ # connection stack so you don't need to configure them.
8
+ class Authenticator
9
+ autoload :Credentials, 'amadeus_discover/authenticator/credentials'
10
+ autoload :Token, 'amadeus_discover/authenticator/token'
11
+ autoload :Response, 'amadeus_discover/authenticator/response'
12
+
13
+ ENDPOINT = '/auth/realms/amadeus-discover/protocol/openid-connect/token'
14
+
15
+ def initialize(connection, credentials = {})
16
+ @connection = reconfigure(connection)
17
+ @credentials = Credentials.new(credentials)
18
+ end
19
+
20
+ def bearer_token
21
+ @token = nil unless token.valid?
22
+ token.value
23
+ end
24
+
25
+ protected
26
+
27
+ attr_reader :connection, :credentials
28
+
29
+ def token
30
+ @token ||= fetch_token
31
+ end
32
+
33
+ def fetch_token
34
+ response = connection.post(ENDPOINT, credentials.to_hash)
35
+
36
+ begin
37
+ Token.new(response.body)
38
+ rescue ArgumentError => e
39
+ raise Faraday::ParsingError.new(e, response)
40
+ end
41
+ end
42
+
43
+ # Ensure given connection is always configured with at least what we know we need internally.
44
+ def reconfigure(connection)
45
+ connection.builder.tap do |builder|
46
+ builder.request :url_encoded
47
+
48
+ builder.response :json
49
+ builder.response :raise_error
50
+ end
51
+
52
+ connection
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AmadeusDiscover
4
+ # The Amadeus Discover API client
5
+ class Client
6
+ autoload :Decorator, 'amadeus_discover/client/decorator'
7
+
8
+ include Namespaces
9
+
10
+ attr_reader :connection
11
+
12
+ def initialize(connection = AmadeusDiscover::Config.connection, credentials = AmadeusDiscover::Config.credentials)
13
+ conn = appropriate(connection)
14
+ @connection = reconfigure(conn, AmadeusDiscover::Authenticator.new(clone_connection(conn), credentials))
15
+ end
16
+
17
+ protected
18
+
19
+ def appropriate(connection)
20
+ conn = clone_connection(connection)
21
+ conn.headers.update(user_agent: user_agent_string(conn.headers[:user_agent]))
22
+ conn
23
+ end
24
+
25
+ # Workaround a glitch in Faraday: cloning a Faraday::Connection with only an
26
+ # adapter set but will reset clone builder to Faraday's default middlewares
27
+ # **and adapter**. We must set the adapter again and remove default handlers.
28
+ def clone_connection(original)
29
+ dup = original.dup
30
+ return dup unless original.builder.handlers.empty?
31
+
32
+ dup.builder.tap do |builder|
33
+ builder.handlers.each { |handler| builder.delete handler }
34
+ builder.adapter original.builder.adapter.klass
35
+ end
36
+
37
+ dup
38
+ end
39
+
40
+ # Ensure given connection is always configured with at least what we know we need internally.
41
+ def reconfigure(connection, authenticator)
42
+ connection.builder.tap do |builder|
43
+ builder.request :authorization, 'Bearer', -> { authenticator.bearer_token }
44
+ builder.request :json
45
+
46
+ builder.response :json
47
+ builder.response :raise_error
48
+ end
49
+
50
+ connection
51
+ end
52
+
53
+ def user_agent_string(base)
54
+ [base, "AmadeusDiscover/#{AmadeusDiscover::VERSION}", "Ruby/#{RUBY_VERSION}"].join(' ')
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Class variables are fine here as this configuration module is not to be used
4
+ # in any inheritance or composition chain.
5
+ # rubocop:disable Style/ClassVars
6
+ module AmadeusDiscover
7
+ # Global configuration for {AmadeusDiscover::Client}s.
8
+ module Config
9
+ # Credentials to be used by default to authenticate client requests.
10
+ #
11
+ # Must be a Hash with valid credentials, client ID and grant type. Ex:
12
+ #
13
+ # {
14
+ # username: '{username}',
15
+ # password: '{password}',
16
+ # client_id: 'content-partner-api',
17
+ # grant_type: 'password'
18
+ # }
19
+ @@credentials = {}
20
+
21
+ # A Faraday::Connection to be used by default to query the API.
22
+ #
23
+ # Will be reconfigured on client's initialization to use the correct request
24
+ # and response middlewares, depending on the queried endpoint. Use this to
25
+ # specify API host you want to query, a Faraday adapter, or logger or
26
+ # instrumentation middleware to integrate Amadeus Discover in your
27
+ # application.
28
+ @@connection = nil
29
+
30
+ class << self
31
+ def credentials
32
+ @@credentials
33
+ end
34
+
35
+ def credentials=(credentials)
36
+ @@credentials = credentials
37
+ end
38
+
39
+ def connection
40
+ @@connection
41
+ end
42
+
43
+ def connection=(connection)
44
+ @@connection = connection
45
+ end
46
+ end
47
+ end
48
+ end
49
+ # rubocop:enable Style/ClassVars
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AmadeusDiscover
4
+ # Parent class for all action namespaces
5
+ #
6
+ # @!visibility private
7
+ class Namespace
8
+ extend Forwardable
9
+
10
+ # The API client
11
+ # @return [AmadeusDiscover::Client]
12
+ attr_reader :client
13
+
14
+ def_delegators :@client, :connection
15
+
16
+ # Initialize the namespaced client with an {AmadeusDiscover::Client}
17
+ # instance.
18
+ # @param [AmadeusDiscover::Client] client
19
+ def initialize(client)
20
+ @client = client
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AmadeusDiscover
4
+ module Namespaces
5
+ module Suppliers
6
+ # An action namespace for the +/api/supplier/:id/product+ endpoints.
7
+ module Products
8
+ # Namespace for actions on a supplier's products collection.
9
+ class Collection < AmadeusDiscover::Namespace
10
+ # Returns the list of products for supplier.
11
+ def list
12
+ connection.get(path).body
13
+ end
14
+
15
+ # Create a new product
16
+ def create(product_data)
17
+ # WARN: Can not use path here because URLs do not follow REST conventions.
18
+ connection.post("/api/supplier/#{client.supplier_id}/product", product_data).body
19
+ end
20
+
21
+ protected
22
+
23
+ def path
24
+ "/api/supplier/#{client.supplier_id}/products"
25
+ end
26
+ end
27
+
28
+ # Namespace for actions on a supplier's product.
29
+ class Member < AmadeusDiscover::Namespace
30
+ attr_reader :product_id
31
+
32
+ def initialize(client, product_id)
33
+ @product_id = product_id
34
+ super(client)
35
+ end
36
+
37
+ # Retrieve product information
38
+ def get
39
+ connection.get(path).body
40
+ end
41
+
42
+ # Udpate product
43
+ def update(product_data)
44
+ connection.post(path, product_data).body
45
+ end
46
+
47
+ # Delete product
48
+ def delete
49
+ connection.delete(path).body
50
+ end
51
+
52
+ protected
53
+
54
+ def path
55
+ "/api/supplier/#{client.supplier_id}/product/#{product_id}"
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AmadeusDiscover
4
+ module Namespaces
5
+ # An action namespace for the +/api/supplier+ endpoints.
6
+ module Suppliers
7
+ autoload :Products, 'amadeus_discover/namespaces/suppliers/products'
8
+
9
+ # Namespace for actions on suppliers collection.
10
+ class Collection < AmadeusDiscover::Namespace
11
+ # Create a new supplier
12
+ def create(supplier_data)
13
+ connection.post(path, supplier_data).body
14
+ end
15
+
16
+ protected
17
+
18
+ def path
19
+ '/api/supplier'
20
+ end
21
+ end
22
+
23
+ # Namespace for actions on a supplier.
24
+ class Member < AmadeusDiscover::Namespace
25
+ attr_reader :supplier_id
26
+
27
+ def initialize(client, supplier_id)
28
+ @supplier_id = supplier_id
29
+ super(client)
30
+ end
31
+
32
+ # Retrieve supplier information
33
+ def get
34
+ connection.get(path).body
35
+ end
36
+
37
+ # Udpate supplier
38
+ def update(supplier_data)
39
+ connection.post(path, supplier_data).body
40
+ end
41
+
42
+ # Delete supplier
43
+ def delete
44
+ connection.delete(path).body
45
+ end
46
+
47
+ # Get access to supplier's products
48
+ def products(product_id = nil)
49
+ return Products::Collection.new(self) if product_id.nil?
50
+
51
+ Products::Member.new(self, product_id)
52
+ end
53
+
54
+ protected
55
+
56
+ def path
57
+ "/api/supplier/#{supplier_id}"
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AmadeusDiscover
4
+ # Top-level action namespaces, available on instances of
5
+ # AmadeusDiscover::Client.
6
+ module Namespaces
7
+ autoload :Suppliers, 'amadeus_discover/namespaces/suppliers'
8
+
9
+ # Get access to suppliers
10
+ def suppliers(supplier_id = nil)
11
+ return Suppliers::Collection.new(self) if supplier_id.nil?
12
+
13
+ Suppliers::Member.new(self, supplier_id)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AmadeusDiscover
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'amadeus_discover/version'
4
+
5
+ # Amadeus Discover API client global namespace
6
+ module AmadeusDiscover
7
+ autoload :Authenticator, 'amadeus_discover/authenticator'
8
+ autoload :Config, 'amadeus_discover/config'
9
+ autoload :Client, 'amadeus_discover/client'
10
+ autoload :Namespace, 'amadeus_discover/namespace'
11
+ autoload :Namespaces, 'amadeus_discover/namespaces'
12
+
13
+ class << self
14
+ # Shortcut to globally configure AmadeusDiscover clients
15
+ #
16
+ # Yield the AmadeusDiscover configuration object to a block.
17
+ # See {AmadeusDiscover::Config} for available configurations.
18
+ def configure
19
+ yield AmadeusDiscover::Config
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,226 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amadeus-discover
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Vaolo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashie
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.7.6
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.7.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: ffaker
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.20'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.20'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '13.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '13.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.9'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.9'
111
+ - !ruby/object:Gem::Dependency
112
+ name: timecop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.5
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.9.5
125
+ - !ruby/object:Gem::Dependency
126
+ name: typhoeus
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.4.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.4.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Ruby wrapper around Amadeus Discover API
168
+ email:
169
+ - techservices@vaolo.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".env.example"
175
+ - ".gitignore"
176
+ - ".rspec"
177
+ - ".rubocop.yml"
178
+ - Gemfile
179
+ - Gemfile.lock
180
+ - LICENSE
181
+ - README.md
182
+ - Rakefile
183
+ - amadeus-discover.gemspec
184
+ - bin/console
185
+ - bin/setup
186
+ - lib/amadeus-discover.rb
187
+ - lib/amadeus_discover.rb
188
+ - lib/amadeus_discover/authenticator.rb
189
+ - lib/amadeus_discover/authenticator/credentials.rb
190
+ - lib/amadeus_discover/authenticator/response.rb
191
+ - lib/amadeus_discover/authenticator/token.rb
192
+ - lib/amadeus_discover/client.rb
193
+ - lib/amadeus_discover/config.rb
194
+ - lib/amadeus_discover/namespace.rb
195
+ - lib/amadeus_discover/namespaces.rb
196
+ - lib/amadeus_discover/namespaces/suppliers.rb
197
+ - lib/amadeus_discover/namespaces/suppliers/products.rb
198
+ - lib/amadeus_discover/version.rb
199
+ homepage: https://gitlab.com/vaolo-public/ruby/amadeus-discover
200
+ licenses:
201
+ - Apache-2.0
202
+ metadata:
203
+ rubygems_mfa_required: 'true'
204
+ homepage_uri: https://gitlab.com/vaolo-public/ruby/amadeus-discover
205
+ source_code_uri: https://gitlab.com/vaolo-public/ruby/amadeus-discover
206
+ changelog_uri: https://gitlab.com/vaolo-public/ruby/amadeus-discover/-/blob/master/CHANGELOG.md
207
+ post_install_message:
208
+ rdoc_options: []
209
+ require_paths:
210
+ - lib
211
+ required_ruby_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: 2.7.0
216
+ required_rubygems_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ requirements: []
222
+ rubygems_version: 3.1.6
223
+ signing_key:
224
+ specification_version: 4
225
+ summary: Ruby wrapper around Amadeus Discover API
226
+ test_files: []