cloud_party 0.1.1.pre.alpha.1 → 0.1.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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +1 -1
  4. data/.rubocop_config.yml +2 -1
  5. data/.travis.yml +11 -6
  6. data/README.md +17 -8
  7. data/Rakefile +1 -1
  8. data/cloud_party.gemspec +27 -25
  9. data/lib/cloud_party/context.rb +5 -7
  10. data/lib/cloud_party/exception.rb +28 -54
  11. data/lib/cloud_party/exceptions/request_errors/bad_request_error.rb +26 -0
  12. data/lib/cloud_party/exceptions/request_errors/forbidden_error.rb +26 -0
  13. data/lib/cloud_party/exceptions/request_errors/method_not_allowed_error.rb +27 -0
  14. data/lib/cloud_party/exceptions/request_errors/not_found_error.rb +26 -0
  15. data/lib/cloud_party/exceptions/request_errors/too_many_requests_error.rb +27 -0
  16. data/lib/cloud_party/exceptions/request_errors/unauthorized_error.rb +26 -0
  17. data/lib/cloud_party/exceptions/request_errors/unsupported_media_type_error.rb +27 -0
  18. data/lib/cloud_party/exceptions/request_errors.rb +25 -0
  19. data/lib/cloud_party/exceptions/un_recognized_endpoint_error.rb +20 -0
  20. data/lib/cloud_party/exceptions/un_recognized_result_type_error.rb +14 -0
  21. data/lib/cloud_party/exceptions.rb +42 -1
  22. data/lib/cloud_party/nodes/accounts.rb +26 -0
  23. data/lib/cloud_party/nodes/ips.rb +5 -3
  24. data/lib/cloud_party/nodes/memberships.rb +6 -6
  25. data/lib/cloud_party/nodes/zones.rb +30 -0
  26. data/lib/cloud_party/nodes.rb +2 -0
  27. data/lib/cloud_party/response.rb +17 -3
  28. data/lib/cloud_party/responses/accounts.rb +148 -0
  29. data/lib/cloud_party/responses/ips.rb +3 -6
  30. data/lib/cloud_party/responses/memberships.rb +1 -0
  31. data/lib/cloud_party/responses/nodes/accounts.rb +3 -0
  32. data/lib/cloud_party/responses/nodes/zones/account.rb +30 -0
  33. data/lib/cloud_party/responses/nodes/zones/permissions.rb +33 -0
  34. data/lib/cloud_party/responses/nodes/zones/plan.rb +25 -0
  35. data/lib/cloud_party/responses/nodes/zones/plan_pending.rb +27 -0
  36. data/lib/cloud_party/responses/nodes/zones.rb +6 -0
  37. data/lib/cloud_party/responses/nodes.rb +7 -2
  38. data/lib/cloud_party/responses/zones.rb +150 -0
  39. data/lib/cloud_party/responses.rb +11 -0
  40. data/lib/cloud_party/version.rb +1 -1
  41. data/lib/cloud_party.rb +5 -1
  42. data/sonar-project.properties +9 -0
  43. metadata +55 -37
  44. data/lib/cloud_party/exceptions/bad_request_400.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 601dd1b5d58468c8aad061cee2f8d18a5b84e6d323c774e1ef6a8b74d8be4b5e
4
- data.tar.gz: 8df613162612d6265b1bc4a6cbdad2fffcfc4cf8c8f5bca43af66f575374ab02
3
+ metadata.gz: c9d6d0080a0cd0c540c77091058416c7356ec427394dbdbad571fecae55d2b96
4
+ data.tar.gz: e2ff2b1c423f6d11bcdbb2cf573c26423b9d64da0cba9dafad3a42c8b2b3154a
5
5
  SHA512:
6
- metadata.gz: 2cdae24dee8725545e482666bae4b6c7c38ae58afde1810ba7f8d7d954d3edfe3820ccd10dcd12f769c37d757f2a03b60489a8c8f71ac7a56ef67cd294a2cac1
7
- data.tar.gz: fbf2b47382b7906807cecea53d1318692e28325cbf487295f198bf851ee81b9c85cd8134e85454829b6d1cdbde3a5a9f09417d92f1b11caad37cf2bef0162540
6
+ metadata.gz: 8977fd0128fb51169959e3ec22dadcc87bfa48ae6cd22e57b3a93d57d1d24e0f804cca2ed6e9834d116692eca0c49a297966d1c375cae9137f8cc8f3445728e9
7
+ data.tar.gz: dac649d63809a0fff7269c10763428ba297c45f2277b1268b7b01a9ec199e343ea31f7c94343672e084e92b862748e1a2a6bf29ea4fe38082bf3125949dd2d4d
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  /.vscode/
14
14
 
15
15
  /Deskfile
16
+ /.scannerwork/
data/.rubocop.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  inherit_from: .rubocop_config.yml
2
2
  AllCops:
3
- TargetRubyVersion: 2.5.1
3
+ TargetRubyVersion: 2.3
4
4
 
5
5
  Metrics/AbcSize:
6
6
  Max: 23
data/.rubocop_config.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  # Available cops (428) + config for /home/ken/everygit/cloudflare_cli:
2
+ # Available cops (428) + config for /home/ken/everygit/cloudflare_cli:
2
3
  # Department 'Bundler' (4):
3
4
  Bundler/DuplicatedGem:
4
5
  Description: Checks for duplicate gem entries in Gemfile.
@@ -866,7 +867,7 @@ Lint/FormatParameterMismatch:
866
867
  Lint/HandleExceptions:
867
868
  Description: Don't suppress exception.
868
869
  StyleGuide: "#dont-hide-exceptions"
869
- Enabled: true
870
+ Enabled: false
870
871
 
871
872
  Lint/ImplicitStringConcatenation:
872
873
  Description: Checks for adjacent string literals on the same line, which could better
data/.travis.yml CHANGED
@@ -1,10 +1,15 @@
1
1
  language: ruby
2
- bundler_args: --jobs=6 --retry=3 --standalone
2
+ bundler_args: "--jobs=6 --retry=3 --standalone"
3
3
  script:
4
- - echo "Running tests against $(ruby -v) ..."
5
- - bundle exec rake -t
4
+ - echo "Running tests against $(ruby -v) ..."
5
+ - bundle exec rake -t
6
6
  rvm:
7
- - 2.3
8
- - 2.4
9
- - 2.5
7
+ - 2.3
8
+ - 2.4
9
+ - 2.5
10
+ addons:
11
+ sonarcloud:
12
+ organization: iotaspencer-github
13
+ token:
14
+ secure: LmYxRG98giIzDDwNdOcgiTK0b5+f+M92672qWhbsXQD9hWQUnPWJpbzRk7+ApjulxIIi28HYqTkS32K4VIPvP8N425idqqoPg98kpjkaG7kqKmj6zXARZSOhW7Qs7c3E0kmGEe10YQi88u75x9caR/aKoL/RmJq2wPCjOqJfVaQczEJb18ULFjLOpdO5AulHNbN3VByjf+miuIM7mztlyPwhH/tXiMxKR5TgTe5L0s2XwCblvxjYD+wQTz538m2CPTqgktlv2FqFxEsjTuZORzALlvBlaFTS/gxYnQhsMUEIE5SfxQ/xuQo1Zg07j8JjTLcTNr9tOBi5Q2mk9sgiLSbJowT/zkQGN6rWizu5NUhJJiVK1IN/B2vnuLCB9XvyeYYrfksxYS36vb2mFLOEt1b/BTjcjVuagc5/3krGR4K16xlyZYoOaAKfYGjmeYKAoNorSWBryZJqZtZA50SroK+2lwEfEokcogz+hbitWWSgUGbIBUowvZP7Sr/J8lWH3887rfANaVziXjmS3G3Dimv12AIdsx5sw3w8Lo7XgZt/P5W+dV6hKpwZvE2NoU8Y7JQyjdHBs6DTrOiIpIk4kgsgeXzgT1ti9VNMZrdlzEbgJKi1CrgvHa7tL9/EjxVBQDJBOBeq5VcoFJRVi/u63FJRlk7QXbrqOXvyDwU4O4Y=
10
15
 
data/README.md CHANGED
@@ -1,28 +1,34 @@
1
+ # CloudParty
2
+ HTTParty based library for Cloudflare
3
+
4
+ ### SonarCloud
5
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=iotaspencer_gem_cloud_party&metric=alert_status)](https://sonarcloud.io/dashboard?id=cloud_party)
6
+ [![Code Smell](https://sonarcloud.io/api/project_badges/measure?project=iotaspencer_gem_cloud_party&metric=code_smells)](https://sonarcloud.io/dashboard?id=cloud_party)
7
+
8
+ ### Badges
1
9
  [![Gem Version](https://badge.fury.io/rb/cloud_party.svg)](https://badge.fury.io/rb/cloud_party)
2
10
  [![Code Climate](https://codeclimate.com/github/IotaSpencer/cloud_party/badges/gpa.svg)](https://codeclimate.com/github/IotaSpencer/cloud_party)
3
11
  [![Test Coverage](https://codeclimate.com/github/IotaSpencer/cloud_party/badges/coverage.svg)](https://codeclimate.com/github/IotaSpencer/cloud_party/coverage)
4
12
  [![Build Status](https://travis-ci.org/IotaSpencer/cloud_party.svg?branch=master)](https://travis-ci.org/IotaSpencer/cloud_party)
5
- # CloudParty
6
13
 
7
- Super thin Ruby wrapper for Cloudflare's V4 API.
8
14
 
9
15
  ## Installation
10
16
 
11
17
  Add this line to your application's Gemfile:
12
18
 
13
- ```ruby
19
+ ```
14
20
  gem 'cloud_party'
15
21
  ```
16
22
 
17
23
  And then execute:
18
24
 
19
- ```shell
25
+ ```
20
26
  $ bundle
21
27
  ```
22
28
 
23
29
  Or install it yourself as:
24
30
 
25
- ```shell
31
+ ```
26
32
  $ gem install cloud_party
27
33
  ```
28
34
 
@@ -98,7 +104,7 @@ p zone.result
98
104
  #### Add(POST) an A Record to the zone
99
105
 
100
106
  ```ruby
101
- dns_record = connection.post('zones/{#zone.result[:id]}/dns_records', {
107
+ dns_record = connection.post('zones/#!{#zone.result[:id]}/dns_records', {
102
108
  type: 'A',
103
109
  name: 'supercooldomain.com',
104
110
  content: '127.0.0.1'
@@ -111,7 +117,7 @@ p dns_record.result
111
117
  #### DELETE a zone
112
118
 
113
119
  ```ruby
114
- deleted_zone = connection.delete('zones/#{zone.result[:id]}')
120
+ deleted_zone = connection.delete('zones/#!{zone.result[:id]}')
115
121
 
116
122
  # Check out the response
117
123
  p deleted_zone
@@ -123,7 +129,7 @@ p deleted_zone
123
129
  begin
124
130
  connection.get('user')
125
131
  rescue => e
126
- # Inspect e.reponse for more details
132
+ # Inspect e.response for more details
127
133
  p e.response
128
134
  end
129
135
  ```
@@ -138,7 +144,10 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
138
144
 
139
145
  Bug reports and pull requests are welcome on GitHub at https://github.com/trev/rubyflare. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
140
146
 
147
+ ## Legal
141
148
 
149
+ cloud_party, its developers, and other collaborators are not affiliated with nor endorsed by Cloudflare unless explicitly
150
+ noted
142
151
  ## License
143
152
 
144
153
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
- task default: :test
5
+ task default: :spec
data/cloud_party.gemspec CHANGED
@@ -4,33 +4,35 @@ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'cloud_party/version'
6
6
 
7
- Gem::Specification.new do |spec|
8
- spec.name = 'cloud_party'
9
- spec.version = CloudParty::VERSION
10
- spec.authors = ['Ken Spencer', 'Trevor Wistaff']
11
- spec.email = ['me+gems@iotaspencer.me', 'trev@a07.com.au']
7
+ spec = Gem::Specification.new do |s|
8
+ s.name = 'cloud_party'
9
+ s.version = CloudParty::VERSION
10
+ s.authors = ['Ken Spencer']
11
+ s.email = ['me+gems@iotaspencer.me']
12
12
 
13
- spec.summary = "Thin Ruby wrapper around Cloudflare's V4 API. Based on https://github.com/trev/rubyflare"
14
- spec.description = "Thin Ruby wrapper around Cloudflare's V4 API for good measure!"
15
- spec.homepage = 'https://github.com/IotaSpencer/cloud_party'
16
- spec.license = 'MIT'
13
+ s.summary = "Thin Ruby wrapper around Cloudflare's V4 API. Based on https://github.com/trev/rubyflare"
14
+ s.description = "Thin Ruby wrapper around Cloudflare's V4 API for good measure!"
15
+ s.homepage = 'https://github.com/IotaSpencer/cloud_party'
16
+ s.license = 'MIT'
17
17
 
18
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- spec.bindir = 'bin'
20
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
- spec.require_paths = %w[lib]
18
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ s.bindir = 'bin'
20
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ s.require_paths = %w[lib]
22
22
 
23
- # spec.required_ruby_version = '>= 2.3'
24
- spec.add_development_dependency 'bundler', '~> 1.17.2'
25
- spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.6.0'
26
- spec.add_development_dependency 'debase'
27
- spec.add_development_dependency 'pry', '~> 0.11.3'
28
- spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.1'
29
- spec.add_development_dependency 'rspec', '~> 3.5'
30
- spec.add_development_dependency 'ruby-debug-ide', '~> 0.7.0.beta7'
31
- spec.add_development_dependency 'webmock', '~> 2.1'
23
+ s.required_ruby_version = '>= 2.3'
32
24
 
33
- spec.add_runtime_dependency 'app_configuration'
34
- spec.add_runtime_dependency 'httparty', '~> 0.16.2'
35
- spec.add_runtime_dependency 'rubyflare'
25
+ s.add_development_dependency 'bundler', '~> 1.17.2'
26
+ s.add_development_dependency 'codeclimate-test-reporter', '~> 0.6.0'
27
+ s.add_development_dependency 'debase'
28
+ s.add_development_dependency 'minitest'
29
+ s.add_development_dependency 'minitest-reporters', '>= 0.5.0'
30
+ s.add_development_dependency 'pry', '~> 0.11.3'
31
+ s.add_development_dependency 'rake', '~> 12.3', '>= 12.3.1'
32
+ s.add_development_dependency 'ruby-debug-ide', '~> 0.7.0.beta7'
33
+ s.add_development_dependency 'webmock', '~> 2.1'
34
+
35
+ s.add_runtime_dependency 'app_configuration'
36
+ s.add_runtime_dependency 'httparty', '~> 0.16.2'
36
37
  end
38
+ # spec
@@ -3,13 +3,11 @@
3
3
  require 'httparty'
4
4
  require 'cloud_party/config'
5
5
  module CloudParty
6
- class Context
7
- attr_reader :cfg
8
- define_singleton_method(:cfg) do
9
- CloudParty::Config.new
10
- end
11
- def self.inherited(subclass)
12
- # I don't know yet
6
+ module Context
7
+ def self.included(base)
8
+ base.define_singleton_method(:cfg) do
9
+ CloudParty::Config.new
10
+ end
13
11
  end
14
12
  end
15
13
  end
@@ -1,61 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudParty
4
- class ConnectionError < StandardError
5
- attr_reader :response
6
-
7
- def initialize(message, response)
8
- super(message)
9
- @response = response
10
- end
11
- end
12
-
13
- class APIError < StandardError
14
- attr_reader(:response)
15
- def initialize(message, response)
16
- super(message)
17
- @response = response
18
- end
19
- end
20
- class RequestError < StandardError
21
- def initialize(obj:, method:, code:, response:, endpoint:)
22
- @obj = obj
23
- @method = method
24
- @endpoint = endpoint
25
- @code = code
26
- @response = response
27
- end
28
-
29
- def to_s
30
- [error_string.squish, extra_string].join("\n")
4
+ module Errors
5
+ class APIError < StandardError
6
+ attr_reader(:response)
7
+ def initialize(message, response)
8
+ super(message)
9
+ @response = response
10
+ end
31
11
  end
32
-
33
- def self.extra_string; end
34
-
35
- def self.error_string; end
36
- end
37
- class UnknownError < RequestError
38
- def initialize(obj:, method:, response:, endpoint: nil, code:)
39
- super
40
- end
41
-
42
- def self.error_string
43
- <<~HEREDOC
44
- An error with the request has occurred, please make
45
- sure the method verb, endpoint, and credentials are
46
- correct for this request.
47
- HEREDOC
48
- end
49
-
50
- def self.extra_string
51
- <<~HEREDOC
52
- Credentials Context: #{@obj&.class&.cfg}
53
-
54
- Method Verb: #{@method}
55
- Endpoint: #{@endpoint}
56
- HTTP Status Code: #{@code}
57
- Response Body: #{@response.body}
58
- HEREDOC
12
+ class RequestError < StandardError
13
+ def initialize(obj:, method:, code:, response:, endpoint:)
14
+ @obj = obj
15
+ @method = method
16
+ @endpoint = endpoint
17
+ @code = code
18
+ @response = response
19
+ end
20
+
21
+ def to_s
22
+ [error_string.squish, extra_string].join("\n")
23
+ end
24
+
25
+ def self.extra_string
26
+ # This method should be overridden
27
+ end
28
+
29
+ # override error_string to provide your own error_string
30
+ def self.error_string
31
+ # This method should be overridden
32
+ end
59
33
  end
60
34
  end
61
35
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cloud_party/exception'
4
+ module CloudParty
5
+ module Errors
6
+ # Request was invalid
7
+ class BadRequestError < RequestError
8
+ def initialize(obj:, method:, response:, endpoint: nil, code: 400)
9
+ super
10
+ end
11
+
12
+ def self.error_string
13
+ <<~HEREDOC
14
+ There was a '400 -- Bad Request' error.
15
+ HEREDOC
16
+ end
17
+
18
+ def self.extra_string
19
+ <<~HEREDOC
20
+ VERB: #{@method}
21
+
22
+ HEREDOC
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cloud_party/exception'
4
+ module CloudParty
5
+ module Errors
6
+ # Page/Endpoint doesn't exist
7
+ class ForbiddenError < RequestError
8
+ def initialize(obj:, method:, response:, endpoint: nil, code: 403)
9
+ super
10
+ end
11
+
12
+ def self.error_string
13
+ <<~HEREDOC
14
+ There was a '401 -- Unauthorized' error.
15
+ HEREDOC
16
+ end
17
+
18
+ def self.extra_string
19
+ <<~HEREDOC
20
+ VERB: #{@method}
21
+
22
+ HEREDOC
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cloud_party/exception'
4
+ module CloudParty
5
+ module Errors
6
+ # Page/Endpoint doesn't exist
7
+ class MethodNotAllowedError < RequestError
8
+ def initialize(obj:, method:, response:, endpoint: nil, code: 405)
9
+ super
10
+ end
11
+
12
+ def self.error_string
13
+ <<~HEREDOC
14
+ There was a '429 -- Too many requests' error.
15
+ You've hit the rate limit of Cloudflare
16
+ HEREDOC
17
+ end
18
+
19
+ def self.extra_string
20
+ <<~HEREDOC
21
+ VERB: #{@method}
22
+
23
+ HEREDOC
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cloud_party/exception'
4
+ module CloudParty
5
+ module Errors
6
+ # Page/Endpoint doesn't exist
7
+ class NotFoundError < RequestError
8
+ def initialize(obj:, method:, response:, endpoint: nil, code: 404)
9
+ super
10
+ end
11
+
12
+ def self.error_string
13
+ <<~HEREDOC
14
+ There was a '404 -- Not Found' error.
15
+ HEREDOC
16
+ end
17
+
18
+ def self.extra_string
19
+ <<~HEREDOC
20
+ VERB: #{@method}
21
+
22
+ HEREDOC
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cloud_party/exception'
4
+ module CloudParty
5
+ module Errors
6
+ # Page/Endpoint doesn't exist
7
+ class TooManyRequestsError < RequestError
8
+ def initialize(obj:, method:, response:, endpoint: nil, code: 429)
9
+ super
10
+ end
11
+
12
+ def self.error_string
13
+ <<~HEREDOC
14
+ There was a '429 -- Too many requests' error.
15
+ You've hit the rate limit of Cloudflare
16
+ HEREDOC
17
+ end
18
+
19
+ def self.extra_string
20
+ <<~HEREDOC
21
+ VERB: #{@method}
22
+
23
+ HEREDOC
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cloud_party/exception'
4
+ module CloudParty
5
+ module Errors
6
+ # Page/Endpoint doesn't exist
7
+ class UnauthorizedError < RequestError
8
+ def initialize(obj:, method:, response:, endpoint: nil, code: 401)
9
+ super
10
+ end
11
+
12
+ def self.error_string
13
+ <<~HEREDOC
14
+ There was a '401 -- Unauthorized' error.
15
+ HEREDOC
16
+ end
17
+
18
+ def self.extra_string
19
+ <<~HEREDOC
20
+ VERB: #{@method}
21
+
22
+ HEREDOC
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cloud_party/exception'
4
+ module CloudParty
5
+ module Errors
6
+ # Page/Endpoint doesn't exist
7
+ class UnsupportedMediaTypeError < RequestError
8
+ def initialize(obj:, method:, response:, endpoint: nil, code: 415)
9
+ super
10
+ end
11
+
12
+ def self.error_string
13
+ <<~HEREDOC
14
+ There was a '429 -- Too many requests' error.
15
+ You've hit the rate limit of Cloudflare
16
+ HEREDOC
17
+ end
18
+
19
+ def self.extra_string
20
+ <<~HEREDOC
21
+ VERB: #{@method}
22
+
23
+ HEREDOC
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ module CloudParty
2
+ module Errors
3
+ ##
4
+ # 400
5
+ autoload :BadRequestError, 'cloud_party/exceptions/request_errors/bad_request_error'
6
+ ##
7
+ # 401
8
+ autoload :UnauthorizedError, 'cloud_party/exceptions/request_errors/unauthorized_error'
9
+ ##
10
+ # 403
11
+ autoload :ForbiddenError, 'cloud_party/exceptions/request_errors/forbidden_error'
12
+ ##
13
+ # 404
14
+ autoload :NotFoundError, 'cloud_party/exceptions/request_errors/not_found_error'
15
+ ##
16
+ # 405
17
+ autoload :MethodNotAllowedError, 'cloud_party/exceptions/request_errors/method_not_allowed_error'
18
+ ##
19
+ # 415
20
+ autoload :UnsupportedMediaTypeError, 'cloud_party/exceptions/request_errors/unsupported_media_type_error'
21
+ ##
22
+ # 429
23
+ autoload :TooManyRequestsError, 'cloud_party/exceptions/request_errors/too_many_requests_error'
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CloudParty
4
+ module Errors
5
+ ##
6
+ # UnRecognizedEndpointError
7
+ #
8
+ # When an endpoint is not recognized by the gem logic
9
+ class UnRecognizedEndpointError < StandardError
10
+ attr_reader :endpoint, :klass
11
+
12
+ def initialize(endpoint, klass)
13
+ super("'#{endpoint}' is not a recognized endpoint for class #{klass}")
14
+ @endpoint = endpoint
15
+ @klass = klass
16
+ end
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,14 @@
1
+
2
+ ##
3
+ # Raised when the result's `body` is not a recognized class
4
+ module CloudParty
5
+ module Errors
6
+ class UnRecognizedResultTypeError < StandardError
7
+ attr_reader :result_class
8
+
9
+ def initialize(result_object)
10
+ @result_class = result_object.class
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,6 +1,47 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'cloud_party/exception'
4
+ require 'cloud_party/exceptions/request_errors'
4
5
  module CloudParty
5
- autoload :BadRequestError, 'cloud_party/exceptions/bad_request_400'
6
+ module Errors
7
+
8
+ ##
9
+ # ### ConnectionError
10
+ class ConnectionError < StandardError
11
+ attr_reader :response
12
+
13
+ def initialize(message, response)
14
+ super(message)
15
+ @response = response
16
+ end
17
+ end
18
+
19
+ class UnknownError < RequestError
20
+ def initialize(obj:, method:, response:, endpoint: nil, code:)
21
+ super
22
+ end
23
+
24
+ def self.error_string
25
+ <<~HEREDOC
26
+ An error with the request has occurred, please make
27
+ sure the method verb, endpoint, and credentials are
28
+ correct for this request.
29
+ HEREDOC
30
+ end
31
+
32
+ def self.extra_string
33
+ <<~HEREDOC
34
+ Credentials Context: #{@obj&.class&.cfg}
35
+
36
+ Method Verb: #{@method}
37
+ Endpoint: #{@endpoint}
38
+ HTTP Status Code: #{@code}
39
+ Response Body: #{@response.body}
40
+ HEREDOC
41
+ end
42
+ end
43
+ autoload :UnRecognizedResultTypeError, 'cloud_party/exceptions/un_recognized_result_type_error'
44
+ autoload :UnRecognizedEndpointError, 'cloud_party/exceptions/un_recognized_endpoint_error'
45
+
46
+ end
6
47
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cloud_party/context'
4
+ require 'cloud_party/responses'
5
+ module CloudParty
6
+ module Nodes
7
+ class Accounts
8
+ include CloudParty::Context
9
+ include HTTParty
10
+ base_uri 'api.cloudflare.com:443/client/v4'
11
+ headers 'X-Auth-Email' => cfg.email,
12
+ 'X-Auth-Key' => cfg.api_key,
13
+ 'Content-Type' => 'application/json',
14
+ 'User-Agent' => "CloudParty/#{CloudParty::VERSION}"
15
+
16
+ def initialize(options = nil)
17
+ super()
18
+ @options = options
19
+ end
20
+
21
+ def list
22
+ CloudParty::Responses::Accounts.new(:get, '/accounts', self.class.get('/accounts'), @options)
23
+ end
24
+ end
25
+ end
26
+ end