idcf-ilb 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.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +93 -0
  5. data/.travis.yml +9 -0
  6. data/CODE_OF_CONDUCT.md +49 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +111 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/idcf-ilb.gemspec +29 -0
  14. data/lib/idcf/ilb.rb +13 -0
  15. data/lib/idcf/ilb/client.rb +180 -0
  16. data/lib/idcf/ilb/client_extensions.rb +24 -0
  17. data/lib/idcf/ilb/client_extensions/config.rb +97 -0
  18. data/lib/idcf/ilb/client_extensions/fwgroup.rb +57 -0
  19. data/lib/idcf/ilb/client_extensions/job.rb +75 -0
  20. data/lib/idcf/ilb/client_extensions/limit.rb +24 -0
  21. data/lib/idcf/ilb/client_extensions/loadbalancer.rb +79 -0
  22. data/lib/idcf/ilb/client_extensions/log.rb +30 -0
  23. data/lib/idcf/ilb/client_extensions/network.rb +26 -0
  24. data/lib/idcf/ilb/client_extensions/server.rb +46 -0
  25. data/lib/idcf/ilb/client_extensions/sslalgorithm.rb +43 -0
  26. data/lib/idcf/ilb/client_extensions/sslcert.rb +79 -0
  27. data/lib/idcf/ilb/client_extensions/sslpolicy.rb +58 -0
  28. data/lib/idcf/ilb/client_extensions/traffic.rb +35 -0
  29. data/lib/idcf/ilb/client_extensions/virtualmachine.rb +29 -0
  30. data/lib/idcf/ilb/errors.rb +10 -0
  31. data/lib/idcf/ilb/request.rb +97 -0
  32. data/lib/idcf/ilb/resources.rb +22 -0
  33. data/lib/idcf/ilb/resources/base.rb +60 -0
  34. data/lib/idcf/ilb/resources/config.rb +21 -0
  35. data/lib/idcf/ilb/resources/fwgroup.rb +16 -0
  36. data/lib/idcf/ilb/resources/job.rb +16 -0
  37. data/lib/idcf/ilb/resources/limit.rb +13 -0
  38. data/lib/idcf/ilb/resources/loadbalancer.rb +16 -0
  39. data/lib/idcf/ilb/resources/log.rb +13 -0
  40. data/lib/idcf/ilb/resources/network.rb +9 -0
  41. data/lib/idcf/ilb/resources/nic.rb +13 -0
  42. data/lib/idcf/ilb/resources/server.rb +9 -0
  43. data/lib/idcf/ilb/resources/sslalgorithm.rb +21 -0
  44. data/lib/idcf/ilb/resources/sslcert.rb +16 -0
  45. data/lib/idcf/ilb/resources/sslpolicy.rb +23 -0
  46. data/lib/idcf/ilb/resources/traffic.rb +9 -0
  47. data/lib/idcf/ilb/resources/virtualmachine.rb +13 -0
  48. data/lib/idcf/ilb/response.rb +84 -0
  49. data/lib/idcf/ilb/validators.rb +22 -0
  50. data/lib/idcf/ilb/validators/base.rb +105 -0
  51. data/lib/idcf/ilb/validators/config.rb +27 -0
  52. data/lib/idcf/ilb/validators/fwgroup.rb +17 -0
  53. data/lib/idcf/ilb/validators/job.rb +18 -0
  54. data/lib/idcf/ilb/validators/limit.rb +17 -0
  55. data/lib/idcf/ilb/validators/loadbalancer.rb +26 -0
  56. data/lib/idcf/ilb/validators/log.rb +22 -0
  57. data/lib/idcf/ilb/validators/network.rb +25 -0
  58. data/lib/idcf/ilb/validators/server.rb +13 -0
  59. data/lib/idcf/ilb/validators/sslalgorithm.rb +14 -0
  60. data/lib/idcf/ilb/validators/sslcert.rb +24 -0
  61. data/lib/idcf/ilb/validators/sslpolicy.rb +17 -0
  62. data/lib/idcf/ilb/validators/traffic.rb +14 -0
  63. data/lib/idcf/ilb/validators/virtualmachine.rb +26 -0
  64. data/lib/idcf/ilb/version.rb +5 -0
  65. metadata +232 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f6d85d4223388f0a809843489c8ffeea35560105
4
+ data.tar.gz: cda181912eba70f0942c51ff34ff9b94d6706946
5
+ SHA512:
6
+ metadata.gz: e4d2dfb9bbc52a8fef13380ffe21a33723cca1075b7f93ce17567b59c9da78b459090a7e98a4df875389796cf89456deac3b08135b81e3586bfd383eecaac994
7
+ data.tar.gz: 084ddad1e7b25140d6805610b12aed379f1f2d7dde9cad1243bc2c1887272008dcdbc0d031df2c737ff89a328c027a1964ea041f5a1f789e7451f87b23e2ffb2
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /.env
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,93 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Exclude:
4
+ - "Gemfile"
5
+ - "*.gemspec"
6
+ DisplayCopNames: true
7
+
8
+ Documentation:
9
+ Enabled: false
10
+
11
+ Lint/AssignmentInCondition:
12
+ Enabled: false
13
+
14
+ Lint/HandleExceptions:
15
+ Enabled: false
16
+
17
+ Lint/UnderscorePrefixedVariableName:
18
+ Enabled: false
19
+
20
+ Lint/UnusedBlockArgument:
21
+ Enabled: false
22
+
23
+ Lint/UnusedMethodArgument:
24
+ Enabled: false
25
+
26
+ Metrics/AbcSize:
27
+ Max: 20
28
+
29
+ Metrics/CyclomaticComplexity:
30
+ Max: 6
31
+
32
+ Metrics/LineLength:
33
+ Max: 100
34
+
35
+ Metrics/MethodLength:
36
+ Max: 20
37
+
38
+ Metrics/PerceivedComplexity:
39
+ Max: 7
40
+
41
+ Style/FrozenStringLiteralComment:
42
+ Enabled: false
43
+
44
+ Style/AccessorMethodName:
45
+ Enabled: false
46
+
47
+ Style/AsciiComments:
48
+ Enabled: false
49
+
50
+ Style/Documentation:
51
+ Enabled: false
52
+
53
+ Style/DoubleNegation:
54
+ Enabled: false
55
+
56
+ Style/FormatString:
57
+ EnforcedStyle: percent
58
+
59
+ Style/GuardClause:
60
+ MinBodyLength: 4
61
+
62
+ Style/IfUnlessModifier:
63
+ Enabled: false
64
+
65
+ Style/MultilineBlockChain:
66
+ Enabled: false
67
+
68
+ Style/NumericLiterals:
69
+ MinDigits: 7
70
+
71
+ Style/PredicateName:
72
+ NamePrefixBlacklist:
73
+ - "is_"
74
+ - "have_"
75
+
76
+ Style/SignalException:
77
+ EnforcedStyle: only_raise
78
+
79
+ Style/SingleLineBlockParams:
80
+ Enabled: false
81
+
82
+ Style/SpaceAroundOperators:
83
+ AllowForAlignment: true
84
+
85
+ Style/SpaceBeforeComma:
86
+ Enabled: false
87
+
88
+ Style/StringLiterals:
89
+ EnforcedStyle: double_quotes
90
+
91
+ Style/TrailingCommaInLiteral:
92
+ Enabled: false
93
+
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1
4
+ - 2.2
5
+ before_install: gem install bundler -v 1.11.2
6
+ env:
7
+ global:
8
+ - secure: "GYnbgGX4ELD31qLfeXmaVAcEZeLSXV4VmQPi7GHBSLckrEfUlc2jJrdwcYY0t4+kfL1HPHkCVb61u7/KizD3fbjo9B+RjIKDCzOnRt0qf4TMnieJDLLaWhGvEPQZpqSSX9skvqbY1eMipFn+PgN9CEFRqnnVANp8PxY3TxGh5zi0hTaxZIh918/FxH0gCiTQOGpkjInSadY8bI9tDlKAV8g+EDolAerWz7WDq3+d/GM/VhpQyprqQkd76cyQ2HkBEvngJYAm1RpsJfnSPuqE0rP6C82onV4kVoREI0l0YZGVV1octXrucHqxLRnqAr3yb0pua8vLYVlSEn0Xf44B2XBQURsOkCmMCbbwwT8jhNP/dcy9pASQY1wpcyUQ/HVDISKU807E5S2iW1Y2iXLtg6aIE19QqQxQPOBAfn68dXY5ZaOkxl+scc4O3oFl1YQtsgD+9AF09hVsKTSfNFrejTrzWhVEQypg0LGyUs0d5jZLXzpJuD9lNb2FMuD56iual1UaJZTS4kpnuoDxYiIKfDDVgXXZLA0UZ4GXQ/Y4xJ2ZASwX4oWnV/MEmNS1ghifLAE/dex9i6xHYO6T6VNPgPOTBvZ2n1BW3UBk+xoBBMId3pCT159LD/Mg95yxi1d0ypYG/y/3bkc/WGX0PJGMPY96MQouWj/1RTBGelyfvHE="
9
+ - secure: "JRXadTSkoBWqvwW/K7eJ25Yq6CXMrUyhuAU1u/McnmYIz4htK1Txw54hhy8UnV+LgFMOSJf7eMFeQwrkUcGxvG/1Nl0OMizrPaVWDac7BVuYPc4EwyUQQ5rO7no8un8XJtIIxImXNMqHzbXcH0tBvfHZtckWq2x29caK+noe5X8y6eu3RTHaDeLKcPD42owOBaahCNY/R8qPSDD1p3YjB0ZteeBeeGBtEnzxHTCgzV3pYBoA/Bh1crSgjBAqDYRdY8Z3WCW0UCCw6exFq/ZeXLdiLtC2S0BAk/Z3HAlF7IvG14D7BKpSG3ytQNr9HfiGWNwU2GN1EcM3CbGArz45J2LyW/GuYWpt80ckobYTmb51RgTdlelfciKgsQrPdkZu4gFrWlw05OIlps3AekmlpUyku6VTnvs8/F1QN60TtKk5hJrNVH26q4jjUbucXQk5c2FE8Nc7aQAfPlFGhUwnHJmJ9JBahz/B/VrObk5+ibAyI1a3ENvXq7t1Tyu0X7x+Edlkft322u+tScHTk7+D+2R2mYzbOqPH1l4U0cqdlGFevg/ytwiTGi0wI6pu/B3B0hImJ+RCs9dO5pHmupFUUSjXT3mtsf0QC9Af88LUP/dCjAD9MfbOF2py3JNgyuorzYJUJHVvyaAxg1gplAedQ7lZwX0Jdz4iEJV/aaQb44I="
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at kasugai@dropsystem.co.jp. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in idcf-ilb.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 IDC Frontier Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,111 @@
1
+ # Idcf::Ilb
2
+ [![Gem Version](https://badge.fury.io/rb/idcf-ilb.svg)](http://badge.fury.io/rb/idcf-ilb)
3
+ [![Build Status](https://travis-ci.org/idcf/idcf-ilb-ruby.svg?branch=master)](https://travis-ci.org/idcf/idcf-ilb-ruby)
4
+ [![Code Climate](https://codeclimate.com/github/idcf/idcf-ilb-ruby/badges/gpa.svg)](https://codeclimate.com/github/idcf/idcf-ilb-ruby)
5
+ [![Test Coverage](https://codeclimate.com/github/idcf/idcf-ilb-ruby/badges/coverage.svg)](https://codeclimate.com/github/idcf/idcf-ilb-ruby/coverage)
6
+
7
+ A Ruby client for [IDCF Cloud ILB service](https://console.jp-east.idcfcloud.com/ilb/).
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'idcf-ilb'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install idcf-ilb
24
+
25
+ ## Usage
26
+ ### Basic usage
27
+ #### Client
28
+ You can create a instance of client by specifying API_KEY and SECRET_KEY.
29
+ You can get API_KEY and SECRET_KEY in [IDCF Cloud](https://console.idcfcloud.com/user/apikey).
30
+
31
+ ```ruby
32
+ require "idcf/ilb"
33
+
34
+ client =
35
+ Idcf::Ilb::Client.new(
36
+ api_key: ENV["IDCF_API_KEY"],
37
+ secret_key: ENV["IDCF_SECRET_KEY"]
38
+ )
39
+
40
+ # Call GET request directly
41
+ # returns Response object
42
+ response = client.get("loadbalancers")
43
+ response.success? #=> true
44
+ response.status #=> 200
45
+
46
+ # Response#body returns HTTP response body as a hash or an array
47
+ response.body #=> [loadbalancer1, loadbalancer2, ...]
48
+ response.body[0] #=> loadbalancer1
49
+
50
+ # Response#[] is alias to Response#body[]
51
+ response[0] #=> loadbalancer1
52
+ ```
53
+
54
+ #### Servers
55
+ ##### Add server
56
+ ```ruby
57
+ # Get target config of loadbalancer
58
+ config = client.list_loadbalancers.body.first["configs"].first
59
+
60
+ # Specify of the adding target server IP address and port
61
+ adding_server =
62
+ {
63
+ ipaddress: "xxx.xxx.xxx.xxx",
64
+ port: 80
65
+ }
66
+
67
+ # Add server to config
68
+ response =
69
+ client.add_server(
70
+ config["loadbalancer_id"],
71
+ config["id"],
72
+ adding_server
73
+ )
74
+
75
+ response #=> server array
76
+ ```
77
+
78
+ ##### Get servers
79
+ ```ruby
80
+ loadbalancer = client.loadbalancers.body.first # Get one of the loadbalancer
81
+ config = loadbalancer["configs"].first # Get one of the loadbalancer's config hash
82
+ response = client.list_servers(loadbalancer["id"], config["id"])
83
+
84
+ response #=> server array
85
+ ```
86
+
87
+ ##### Delete server
88
+ ```ruby
89
+ # Get one of the loadbalancer's config hash
90
+ config = client.list_loadbalancers.body.first["configs"].first
91
+
92
+ # Specify of the deletion target server IP address and port
93
+ deletion_server = config["servers"].first
94
+
95
+ response =
96
+ client.delete_server(
97
+ config["loadbalancer_id"],
98
+ config["id"],
99
+ deletion_server["id"]
100
+ )
101
+
102
+ response #=> server array
103
+ ```
104
+
105
+ ## Contributing
106
+
107
+ 1. Fork it ( https://github.com/idcf/idcf-ilb-ruby/fork )
108
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
109
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
110
+ 4. Push to the branch (`git push origin my-new-feature`)
111
+ 5. Create a new Pull Request
@@ -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 "idcf/ilb/ruby"
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,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,29 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'idcf/ilb/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "idcf-ilb"
7
+ spec.version = Idcf::Ilb::VERSION
8
+ spec.authors = ["Akito Ueno"]
9
+ spec.email = ["aueno@idcf.jp"]
10
+
11
+ spec.summary = %q{A Ruby client for IDCF Cloud ILB Service.}
12
+ spec.homepage = "http://www.idcf.jp/cloud/"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.bindir = "exe"
16
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.11"
20
+ spec.add_development_dependency "codeclimate-test-reporter"
21
+ spec.add_development_dependency "dotenv"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "simplecov"
25
+
26
+ spec.add_dependency "activesupport", "~> 4.2.3"
27
+ spec.add_dependency "faraday", "~> 0.9.1"
28
+ spec.add_dependency "faraday_middleware", "~> 0.10.0"
29
+ end
@@ -0,0 +1,13 @@
1
+ require "idcf/ilb/errors"
2
+
3
+ # IDCF Cloud SDK
4
+ module Idcf
5
+ module Ilb
6
+ autoload :Client , "idcf/ilb/client"
7
+ autoload :ClientExtensions, "idcf/ilb/client_extensions"
8
+ autoload :Request , "idcf/ilb/request"
9
+ autoload :Resources , "idcf/ilb/resources"
10
+ autoload :Response , "idcf/ilb/response"
11
+ autoload :Validators , "idcf/ilb/validators"
12
+ end
13
+ end
@@ -0,0 +1,180 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+
4
+ module Idcf
5
+ module Ilb
6
+ # Client for IDCF ILB service
7
+ class Client
8
+ include ClientExtensions::Loadbalancer
9
+ include ClientExtensions::Config
10
+ include ClientExtensions::Server
11
+ include ClientExtensions::Job
12
+ include ClientExtensions::Sslcert
13
+ include ClientExtensions::Sslalgorithm
14
+ include ClientExtensions::Sslpolicy
15
+ include ClientExtensions::Fwgroup
16
+ include ClientExtensions::Network
17
+ include ClientExtensions::Virtualmachine
18
+ include ClientExtensions::Limit
19
+ include ClientExtensions::Log
20
+ include ClientExtensions::Traffic
21
+
22
+ attr_reader :api_key, :secret_key, :host, :endpoint
23
+
24
+ # The constructor of Ilb::Client uses keyword arguments.
25
+ #
26
+ # @param [String] api_key API key for IDCF Cloud
27
+ # @param [String] secret_key Secret key for IDCF Cloud
28
+ def initialize(api_key:,
29
+ secret_key:,
30
+ host: "ilb.jp-east.idcfcloud.com",
31
+ endpoint: "/api/v1",
32
+ verify_ssl: true
33
+ )
34
+
35
+ @api_key = api_key
36
+ @secret_key = secret_key
37
+ @host = host
38
+ @endpoint = endpoint
39
+ @verify_ssl = verify_ssl
40
+ end
41
+
42
+ # @private
43
+ def connection
44
+ @connection ||=
45
+ Faraday.new(url: url_prefix, ssl: ssl_options) do |connection|
46
+ connection.request :json
47
+ connection.response :json
48
+ connection.adapter Faraday.default_adapter
49
+ end
50
+ end
51
+
52
+ # Send DELETE request.
53
+ #
54
+ # @param resource [String] resource name
55
+ # @param parameters [Hash] request parameters
56
+ # @param headers [Hash] HTTP request headers
57
+ # @return [Response] Response object
58
+ def delete(resource, parameters = {}, headers = {})
59
+ send(:delete, resource, parameters, headers)
60
+ end
61
+
62
+ # Send DELETE request with handling error
63
+ #
64
+ # @param resource [String] resource name
65
+ # @param parameters [Hash] request parameters
66
+ # @param headers [Hash] HTTP request headers
67
+ # @return [Response] Response object
68
+ def delete!(resource, parameters = {}, headers = {})
69
+ send!(:delete, resource, parameters, headers)
70
+ end
71
+
72
+ # Send GET request
73
+ #
74
+ # @param resource [String] Resource name
75
+ # @param parameters [Hash] Parameters
76
+ # @param headers [Hash] HTTP request headers
77
+ # @return [Response] Response object
78
+ def get(resource, parameters = {}, headers = {})
79
+ send(:get, resource, parameters, headers)
80
+ end
81
+
82
+ # Send GET request with handling error
83
+ #
84
+ # @param resource [String] resource name
85
+ # @param parameters [Hash] request parameters
86
+ # @param headers [Hash] HTTP request headers
87
+ # @return [Response] Response object
88
+ def get!(resource, parameters = {}, headers = {})
89
+ send!(:get, resource, parameters, headers)
90
+ end
91
+
92
+ # Send POST request
93
+ #
94
+ # @param resource [String] resource name
95
+ # @param parameters [Hash] request parameters
96
+ # @param headers [Hash] HTTP request headers
97
+ # @return [Response] Response object
98
+ def post(resource, parameters = {}, headers = {})
99
+ send(:post, resource, parameters, headers)
100
+ end
101
+
102
+ # Send POST request with handling error
103
+ #
104
+ # @param resource [String] resource name
105
+ # @param parameters [Hash] request parameters
106
+ # @param headers [Hash] HTTP request headers
107
+ # @return [Response] Response object
108
+ def post!(resource, parameters = {}, headers = {})
109
+ send!(:post, resource, parameters, headers)
110
+ end
111
+
112
+ # Send PUT request
113
+ #
114
+ # @param resource [String] resource name
115
+ # @param parameters [Hash] request parameters
116
+ # @param headers [Hash] HTTP request headers
117
+ # @return [Response] Response object
118
+ def put(resource, parameters = {}, headers = {})
119
+ send(:put, resource, parameters, headers)
120
+ end
121
+
122
+ # Send PUT request with handling error
123
+ #
124
+ # @param resource [String] resource name
125
+ # @param parameters [Hash] request parameters
126
+ # @param headers [Hash] HTTP request headers
127
+ # @return [Response] Response object
128
+ def put!(resource, parameters = {}, headers = {})
129
+ send!(:put, resource, parameters, headers)
130
+ end
131
+
132
+ # Send PATCH request
133
+ #
134
+ # @param resource [String] resource name
135
+ # @param parameters [Hash] request parameters
136
+ # @param headers [Hash] HTTP request headers
137
+ # @return [Response] Response object
138
+ def patch(resource, parameters = {}, headers = {})
139
+ send(:patch, resource, parameters, headers)
140
+ end
141
+
142
+ # Send PATCH request with handling error
143
+ #
144
+ # @param resource [String] resource name
145
+ # @param parameters [Hash] request parameters
146
+ # @param headers [Hash] HTTP request headers
147
+ # @return [Response] Response object
148
+ def patch!(resource, parameters = {}, headers = {})
149
+ send!(:patch, resource, parameters, headers)
150
+ end
151
+
152
+ private
153
+
154
+ def send(method, resource, parameters = {}, headers = {})
155
+ Request.new(self, method, resource, parameters, headers).send
156
+ end
157
+
158
+ def send!(method, resource, parameters = {}, headers = {})
159
+ response = send(method, resource, parameters, headers)
160
+ unless response.success?
161
+ raise(
162
+ ApiError,
163
+ "HTTP status code: #{response.status}, " \
164
+ "Error message: #{response.message}, " \
165
+ "Reference: #{response.reference}"
166
+ )
167
+ end
168
+ response
169
+ end
170
+
171
+ def ssl_options
172
+ { verify: @verify_ssl }
173
+ end
174
+
175
+ def url_prefix
176
+ "https://#{host}"
177
+ end
178
+ end
179
+ end
180
+ end