cloudally 0.2.1 → 0.3.0

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: f2f46745c7981091945d40c86bd68e6004dff4ea39ecaa436225c9d5df00a535
4
- data.tar.gz: 2bf09895b3b8df0b1741f87b41c1f8d2a16c4b5fbb53c0047b9eaa5adcc7e399
3
+ metadata.gz: 3e29633647fb8984a79c99fcd163a8ec7a394aee08e70fa9b769841ac8a2f0b4
4
+ data.tar.gz: 6231ffb138601eb3719500f778758b9824a83a3e51032d25d4420ef9bbe605f2
5
5
  SHA512:
6
- metadata.gz: '068f074ab511b4f91073553debfb77f96a81a0e7e82f1c3f02d02618be89c50217acb19fa18f964ee73270e9cb740654b426a159d60d84b846bed9eadceabc2e'
7
- data.tar.gz: 78b7f883e82d2e0bd2e25654d74223c3409ace9bc1f64d6f374b3ca8e5b565bfece1de7bd822e3ec6d0891ec4102939358d56e91c270380288461d120dd0735a
6
+ metadata.gz: bf7fb20897ffd7c2c443824dab575b922458ffb1c12f55e15ab220412d174b44a90744a1c764537e3a44d3f5a496c72ef207f352c49bb569d189c6a56957aaa1
7
+ data.tar.gz: 2ba40d29f87ead154cf16f18ba26080fd4469de2b96d7c4cf9c02d7bd1b84ae999df2caed48dd95511eda0102b23ca7c6394fe46c0c15fd43aebae07f4828c3e
data/CHANGELOG.md CHANGED
@@ -17,3 +17,10 @@
17
17
 
18
18
  ## [0.2.1] - 2024-01-30
19
19
  - use wrapi gem
20
+
21
+ ## [0.2.2] - 2024-02-08
22
+ - updated wrapi pagination
23
+
24
+ ## [0.3.0] - 2024-02-21
25
+ - Harmonization exceptions
26
+
data/Gemfile CHANGED
@@ -7,3 +7,4 @@ gemspec
7
7
 
8
8
  gem "rake", "~> 13.0"
9
9
  gem "rubocop", "~> 1.7"
10
+ gem 'simplecov', require: false, group: :test
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # Cloudally API
2
+ [![Version](https://img.shields.io/gem/v/cloudally.svg)](https://rubygems.org/gems/cloudally)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/fc344d88ac45777b3168/maintainability)](https://codeclimate.com/github/jancotanis/cloudally/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/fc344d88ac45777b3168/test_coverage)](https://codeclimate.com/github/jancotanis/cloudally/test_coverage)
2
5
 
3
6
 
4
7
  This is a wrapper for the CloudAlly portal API v1. You can see the API endpoints here https://api.cloudally.com/documentation
data/Rakefile CHANGED
@@ -1,14 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
3
+ require 'bundler/gem_tasks'
4
+ require 'dotenv'
5
+ require 'rake/testtask'
6
+
7
+ Dotenv.load
8
+
9
+ system './bin/cc-test-reporter before-build'
5
10
 
6
11
  Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/*_test.rb"]
12
+ t.libs << 'test'
13
+ t.libs << 'lib'
14
+ t.test_files = FileList['test/**/*_test.rb']
15
+ at_exit do
16
+ system './bin/cc-test-reporter after-build'
17
+ end
10
18
  end
11
19
 
12
- require "rubocop/rake_task"
20
+ require 'rubocop/rake_task'
13
21
  RuboCop::RakeTask.new
14
22
  task default: %i[test rubocop]
Binary file
data/cloudally.gemspec CHANGED
@@ -29,8 +29,9 @@ Gem::Specification.new do |s|
29
29
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
30
30
  s.platform = Gem::Platform::RUBY
31
31
  s.add_runtime_dependency 'faraday'
32
- s.add_runtime_dependency 'wrapi', ">= 0.1.3"
32
+ s.add_runtime_dependency 'wrapi', ">= 0.2.0"
33
33
  s.add_development_dependency 'dotenv'
34
34
  s.add_development_dependency 'minitest'
35
35
  s.add_development_dependency 'rubocop'
36
+ s.add_development_dependency 'simplecov'
36
37
  end
@@ -1,25 +1,36 @@
1
+ require 'faraday'
2
+ require File.expand_path('error', __dir__)
1
3
 
2
4
  module CloudAlly
3
5
  # Deals with authentication flow and stores it within global configuration
4
6
  module Authentication
5
7
  # Authorize to the CloudAlly portal and return access_token
6
8
  def auth(options = {})
9
+ raise raise ConfigurationError.new "client_id and/or client_secret empty" unless client_id && client_secret
7
10
  api_auth('/auth', options)
11
+ rescue Faraday::UnauthorizedError => e
12
+ raise AuthenticationError.new e.to_s
8
13
  end
9
14
  alias login auth
10
15
 
11
16
  # Return an access token from authorization
12
17
  def auth_refresh(token)
13
18
  api_refresh('/auth/refresh', token)
19
+ rescue Faraday::UnauthorizedError => e
20
+ raise AuthenticationError.new e.to_s
14
21
  end
15
22
 
16
23
  # Authorize to the partner portal and return access_token
17
24
  def auth_partner(options = {})
25
+ raise raise ConfigurationError.new "client_id and/or client_secret empty" unless client_id && client_secret
18
26
  api_auth('/auth/partner', options)
27
+ rescue Faraday::ServerError, Faraday::UnauthorizedError => e
28
+ raise AuthenticationError.new e.to_s
19
29
  end
20
30
  alias partner_login auth_partner
21
31
  private
22
32
  def api_access_token_params
33
+ raise raise ConfigurationError.new "username and/or password empty" unless username && password
23
34
  {
24
35
  email: username,
25
36
  password: password
@@ -0,0 +1,11 @@
1
+ module CloudAlly
2
+
3
+ # Generic error to be able to rescue all CloudAlly errors
4
+ class CloudAllyError < StandardError; end
5
+
6
+ # Error when configuration not sufficient
7
+ class ConfigurationError < CloudAllyError; end
8
+
9
+ # Error when authentication fails
10
+ class AuthenticationError < CloudAllyError; end
11
+ end
@@ -0,0 +1,37 @@
1
+ require 'uri'
2
+ require 'json'
3
+
4
+ module CloudAlly
5
+ # Defines HTTP request methods
6
+ # required attributes format
7
+ module RequestPagination
8
+
9
+ class Pager
10
+ def initialize(page_size)
11
+ @page = 1
12
+ @page_size = page_size
13
+ @total = @page + 1
14
+ @next_page = ''
15
+ end
16
+ def page_options
17
+ following_page = { pageSize: @page_size }
18
+ unless @next_page.empty?
19
+ following_page.merge!({ page: @page, nextPageToken: @next_page })
20
+ else
21
+ following_page
22
+ end
23
+ end
24
+ def next_page!(data)
25
+ @page += 1
26
+ @total = data['totalPages'].to_i
27
+ @next_page = data['nextPageToken']
28
+ end
29
+ def self.data(body)
30
+ body['data'] ? body['data'] : body
31
+ end
32
+ def more_pages?
33
+ @page < @total
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudAlly
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/cloudally.rb CHANGED
@@ -3,6 +3,7 @@ require "wrapi"
3
3
  require File.expand_path('cloudally/api', __dir__)
4
4
  require File.expand_path('cloudally/client', __dir__)
5
5
  require File.expand_path('cloudally/version', __dir__)
6
+ require File.expand_path('cloudally/pagination', __dir__)
6
7
 
7
8
  module CloudAlly
8
9
  extend WrAPI::Configuration
@@ -10,6 +11,7 @@ module CloudAlly
10
11
 
11
12
  DEFAULT_ENDPOINT = 'https://api.cloudally.com/v1/'.freeze
12
13
  DEFAULT_USERAGENT = "CloudAlly Ruby API wrapper #{CloudAlly::VERSION}".freeze
14
+ DEFAULT_PAGINATION = CloudAlly::RequestPagination::Pager
13
15
 
14
16
  # Alias for CloudAlly::Client.new
15
17
  #
@@ -17,7 +19,8 @@ module CloudAlly
17
19
  def self.client(options = {})
18
20
  CloudAlly::Client.new({
19
21
  endpoint: DEFAULT_ENDPOINT,
20
- user_agent: DEFAULT_USERAGENT
22
+ user_agent: DEFAULT_USERAGENT,
23
+ pagination_class: DEFAULT_PAGINATION
21
24
  }.merge(options))
22
25
  end
23
26
 
@@ -25,5 +28,6 @@ module CloudAlly
25
28
  super
26
29
  self.endpoint = DEFAULT_ENDPOINT
27
30
  self.user_agent = DEFAULT_USERAGENT
31
+ self.pagination_class = DEFAULT_PAGINATION
28
32
  end
29
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudally
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janco Tanis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-05 00:00:00.000000000 Z
11
+ date: 2024-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.3
33
+ version: 0.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.1.3
40
+ version: 0.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dotenv
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description:
84
98
  email: gems@jancology.com
85
99
  executables: []
@@ -92,12 +106,15 @@ files:
92
106
  - Gemfile
93
107
  - README.md
94
108
  - Rakefile
109
+ - bin/cc-test-reporter.exe
95
110
  - cloudally.gemspec
96
111
  - lib/cloudally.rb
97
112
  - lib/cloudally/api.rb
98
113
  - lib/cloudally/authentication.rb
99
114
  - lib/cloudally/client.rb
100
115
  - lib/cloudally/client/partners.rb
116
+ - lib/cloudally/error.rb
117
+ - lib/cloudally/pagination.rb
101
118
  - lib/cloudally/version.rb
102
119
  homepage: https://rubygems.org/gems/cloudally
103
120
  licenses: