credly-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +49 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +98 -0
- data/LICENSE +21 -0
- data/README.md +58 -0
- data/Rakefile +12 -0
- data/lib/credly/actions/badge_templates.rb +15 -0
- data/lib/credly/actions/badges.rb +31 -0
- data/lib/credly/actions/issuer_authorizations.rb +19 -0
- data/lib/credly/actions/obi.rb +19 -0
- data/lib/credly/actions/organizations.rb +31 -0
- data/lib/credly/actions/workforce.rb +35 -0
- data/lib/credly/client.rb +39 -0
- data/lib/credly/connection.rb +46 -0
- data/lib/credly/error.rb +49 -0
- data/lib/credly/version.rb +5 -0
- data/lib/credly_ruby.rb +12 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f5d96c6baa44e620c2e44bc279d9bcdd8d58e71db589b1f07e97f82c2ccf0899
|
4
|
+
data.tar.gz: '0778f0d6e8085ae348a428756a3dbad3488386c60ab33e7f99263fdd20b9605a'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 50faa5e49656e64d0f29177595121932a978fc16a2220bd56fcba9fdf2832757be9ced0890cee793143f260e28d391583e855458004c08510af04de41f875493
|
7
|
+
data.tar.gz: fdfb11f1616d5ecf3d5b126e837c458314bde7f101778076b35cf10cc0fc746626ee7efd36b01f175938d1dfefd693376ec6a580ad7d39f8fdd72b7a977285b9
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rspec
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
NewCops: enable
|
6
|
+
SuggestExtensions: false
|
7
|
+
TargetRubyVersion: 2.6
|
8
|
+
|
9
|
+
Metrics/BlockLength:
|
10
|
+
Enabled: true
|
11
|
+
Exclude:
|
12
|
+
- spec/**/*
|
13
|
+
|
14
|
+
Naming/FileName:
|
15
|
+
Enabled: true
|
16
|
+
Exclude:
|
17
|
+
- lib/credly-ruby.rb
|
18
|
+
|
19
|
+
RSpec/ExampleLength:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
RSpec/FilePath:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
RSpec/InstanceVariable:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
RSpec/MultipleMemoizedHelpers:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
RSpec/SubjectStub:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
RSpec/VerifiedDoubles:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/Documentation:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Style/StringLiterals:
|
41
|
+
Enabled: true
|
42
|
+
EnforcedStyle: single_quotes
|
43
|
+
|
44
|
+
Style/StringLiteralsInInterpolation:
|
45
|
+
Enabled: true
|
46
|
+
EnforcedStyle: double_quotes
|
47
|
+
|
48
|
+
Layout/LineLength:
|
49
|
+
Max: 150
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gemspec
|
6
|
+
|
7
|
+
gem 'faraday', '~> 2.7', '>= 2.7.11'
|
8
|
+
|
9
|
+
group :development, :test do
|
10
|
+
gem 'rspec', '~> 3.12.0'
|
11
|
+
gem 'rspec_junit_formatter', '~> 0.6.0'
|
12
|
+
gem 'rubocop', '~> 1.52.1'
|
13
|
+
gem 'rubocop-rspec', '~> 2.22.0'
|
14
|
+
gem 'simplecov'
|
15
|
+
gem 'webmock', '~> 3.18.1'
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
credly-ruby (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.8.5)
|
10
|
+
public_suffix (>= 2.0.2, < 6.0)
|
11
|
+
ast (2.4.2)
|
12
|
+
base64 (0.1.1)
|
13
|
+
crack (0.4.5)
|
14
|
+
rexml
|
15
|
+
diff-lcs (1.5.0)
|
16
|
+
docile (1.4.0)
|
17
|
+
faraday (2.7.11)
|
18
|
+
base64
|
19
|
+
faraday-net_http (>= 2.0, < 3.1)
|
20
|
+
ruby2_keywords (>= 0.0.4)
|
21
|
+
faraday-net_http (3.0.2)
|
22
|
+
hashdiff (1.0.1)
|
23
|
+
json (2.6.3)
|
24
|
+
parallel (1.23.0)
|
25
|
+
parser (3.2.2.3)
|
26
|
+
ast (~> 2.4.1)
|
27
|
+
racc
|
28
|
+
public_suffix (5.0.3)
|
29
|
+
racc (1.7.1)
|
30
|
+
rainbow (3.1.1)
|
31
|
+
regexp_parser (2.8.1)
|
32
|
+
rexml (3.2.6)
|
33
|
+
rspec (3.12.0)
|
34
|
+
rspec-core (~> 3.12.0)
|
35
|
+
rspec-expectations (~> 3.12.0)
|
36
|
+
rspec-mocks (~> 3.12.0)
|
37
|
+
rspec-core (3.12.2)
|
38
|
+
rspec-support (~> 3.12.0)
|
39
|
+
rspec-expectations (3.12.3)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.12.0)
|
42
|
+
rspec-mocks (3.12.6)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.12.0)
|
45
|
+
rspec-support (3.12.1)
|
46
|
+
rspec_junit_formatter (0.6.0)
|
47
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
48
|
+
rubocop (1.52.1)
|
49
|
+
json (~> 2.3)
|
50
|
+
parallel (~> 1.10)
|
51
|
+
parser (>= 3.2.2.3)
|
52
|
+
rainbow (>= 2.2.2, < 4.0)
|
53
|
+
regexp_parser (>= 1.8, < 3.0)
|
54
|
+
rexml (>= 3.2.5, < 4.0)
|
55
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
56
|
+
ruby-progressbar (~> 1.7)
|
57
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
58
|
+
rubocop-ast (1.29.0)
|
59
|
+
parser (>= 3.2.1.0)
|
60
|
+
rubocop-capybara (2.18.0)
|
61
|
+
rubocop (~> 1.41)
|
62
|
+
rubocop-factory_bot (2.23.1)
|
63
|
+
rubocop (~> 1.33)
|
64
|
+
rubocop-rspec (2.22.0)
|
65
|
+
rubocop (~> 1.33)
|
66
|
+
rubocop-capybara (~> 2.17)
|
67
|
+
rubocop-factory_bot (~> 2.22)
|
68
|
+
ruby-progressbar (1.13.0)
|
69
|
+
ruby2_keywords (0.0.5)
|
70
|
+
simplecov (0.22.0)
|
71
|
+
docile (~> 1.1)
|
72
|
+
simplecov-html (~> 0.11)
|
73
|
+
simplecov_json_formatter (~> 0.1)
|
74
|
+
simplecov-html (0.12.3)
|
75
|
+
simplecov_json_formatter (0.1.4)
|
76
|
+
unicode-display_width (2.4.2)
|
77
|
+
webmock (3.18.1)
|
78
|
+
addressable (>= 2.8.0)
|
79
|
+
crack (>= 0.3.2)
|
80
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
81
|
+
|
82
|
+
PLATFORMS
|
83
|
+
x64-mingw-ucrt
|
84
|
+
x86_64-darwin-21
|
85
|
+
x86_64-linux
|
86
|
+
|
87
|
+
DEPENDENCIES
|
88
|
+
credly-ruby!
|
89
|
+
faraday (~> 2.7, >= 2.7.11)
|
90
|
+
rspec (~> 3.12.0)
|
91
|
+
rspec_junit_formatter (~> 0.6.0)
|
92
|
+
rubocop (~> 1.52.1)
|
93
|
+
rubocop-rspec (~> 2.22.0)
|
94
|
+
simplecov
|
95
|
+
webmock (~> 3.18.1)
|
96
|
+
|
97
|
+
BUNDLED WITH
|
98
|
+
2.4.10
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Riipen
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/riipen/credly-ruby/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/riipen/credly-ruby/tree/main)
|
2
|
+
|
3
|
+
# Credly Ruby
|
4
|
+
|
5
|
+
An API client for the Credly REST API in ruby.
|
6
|
+
|
7
|
+
Credly API documentation can be found here:
|
8
|
+
|
9
|
+
https://www.credly.com/docs/
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add to your `Gemfile`:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'credly-ruby'
|
17
|
+
```
|
18
|
+
|
19
|
+
Then `bundle install`.
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Quick Start
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
client = Credly::Client.new(auth_token: 'my_organization_token')
|
27
|
+
|
28
|
+
client.badge_list(organization_id)
|
29
|
+
```
|
30
|
+
|
31
|
+
The `Client` class also accepts the following options:
|
32
|
+
|
33
|
+
|Option|Type|Description|Default|
|
34
|
+
|------|----|-----------|-------|
|
35
|
+
|sandbox|boolean|Whether to use the sandbox environment.|false|
|
36
|
+
|version|string|The API version to use.|v1|
|
37
|
+
|
38
|
+
Additional request examples can be found in https://github.com/riipen/credly-ruby/blob/main/spec/credly-ruby/actions
|
39
|
+
|
40
|
+
### Errors
|
41
|
+
|
42
|
+
Any error code returned by the Credly API will result in one of the following expections
|
43
|
+
|
44
|
+
|Code|Exception|
|
45
|
+
|----|---------|
|
46
|
+
|400| Credly::BadRequest|
|
47
|
+
|401| Credly::Unauthorized|
|
48
|
+
|403| Credly::Forbidden|
|
49
|
+
|404| Credly::NotFound|
|
50
|
+
|410| Credly::Gone|
|
51
|
+
|4xx| Credly::ClientError|
|
52
|
+
|500| Credly::InternalServerError|
|
53
|
+
|503| Credly::ServiceUnavailable|
|
54
|
+
|5xx| Credly::ServerError|
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
Copyright (C) 2023 Riipen. See [LICENSE](https://github.com/riipen/credly-ruby/blob/master/LICENSE.md) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Credly
|
4
|
+
module Actions
|
5
|
+
module BadgeTemplates
|
6
|
+
def badge_templates_list(organization_id, query_params = {})
|
7
|
+
connection.get("organizations/#{organization_id}/badge_templates", query_params)
|
8
|
+
end
|
9
|
+
|
10
|
+
def badge_template_get(organization_id, badge_template_id)
|
11
|
+
connection.get("organizations/#{organization_id}/badge_templates/#{badge_template_id}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Credly
|
4
|
+
module Actions
|
5
|
+
module Badges
|
6
|
+
def badge_list(organization_id, query_params = {})
|
7
|
+
connection.get("organizations/#{organization_id}/badges", query_params)
|
8
|
+
end
|
9
|
+
|
10
|
+
def badge_issue(organization_id, body_params)
|
11
|
+
connection.post("organizations/#{organization_id}/badges", body_params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def badge_delete(organization_id, badge_id)
|
15
|
+
connection.delete("organizations/#{organization_id}/badges/#{badge_id}")
|
16
|
+
end
|
17
|
+
|
18
|
+
def badge_list_bulk(organization_id, query_params = {})
|
19
|
+
connection.get("organizations/#{organization_id}/high_volume_issued_badge_search", query_params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def badge_revoke(organization_id, badge_id, body_params)
|
23
|
+
connection.put("organizations/#{organization_id}/badges/#{badge_id}/revoke", body_params)
|
24
|
+
end
|
25
|
+
|
26
|
+
def badge_replace(organization_id, badge_id, body_params)
|
27
|
+
connection.post("organizations/#{organization_id}/badges/#{badge_id}/replace", body_params)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Credly
|
4
|
+
module Actions
|
5
|
+
module IssuerAuthorizations
|
6
|
+
def issuer_list(organization_id)
|
7
|
+
connection.get("organizations/#{organization_id}/issuers")
|
8
|
+
end
|
9
|
+
|
10
|
+
def grantor_list(organization_id)
|
11
|
+
connection.get("organizations/#{organization_id}/grantors")
|
12
|
+
end
|
13
|
+
|
14
|
+
def issuer_deauthorize(organization_id, issuer_id)
|
15
|
+
connection.delete("organizations/#{organization_id}/issuers/#{issuer_id}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Credly
|
4
|
+
module Actions
|
5
|
+
module OBI
|
6
|
+
def obi_badge_assertion_get(badge_id)
|
7
|
+
connection.get("obi/v2/badge_assertions/#{badge_id}")
|
8
|
+
end
|
9
|
+
|
10
|
+
def obi_badge_class_get(badge_class_id)
|
11
|
+
connection.get("obi/v2/badge_classes/#{badge_class_id}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def obi_issuer_get(issuer_id)
|
15
|
+
connection.get("obi/v2/issuers/#{issuer_id}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Credly
|
4
|
+
module Actions
|
5
|
+
module Organizations
|
6
|
+
def organizations_list
|
7
|
+
connection.get('organizations')
|
8
|
+
end
|
9
|
+
|
10
|
+
def organization_get(organization_id)
|
11
|
+
connection.get("organizations/#{organization_id}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def organization_update(organization_id, body_params)
|
15
|
+
connection.put("organizations/#{organization_id}", body_params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def organization_event_get(organization_id, event_id)
|
19
|
+
connection.get("organizations/#{organization_id}/events/#{event_id}")
|
20
|
+
end
|
21
|
+
|
22
|
+
def organization_tokens_list(organization_id)
|
23
|
+
connection.get("organizations/#{organization_id}/authorization_tokens")
|
24
|
+
end
|
25
|
+
|
26
|
+
def organization_event_list(organization_id, query_params = {})
|
27
|
+
connection.get("organizations/#{organization_id}/events", query_params)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Credly
|
4
|
+
module Actions
|
5
|
+
module Workforce
|
6
|
+
def employee_list(organization_id, query_params = {})
|
7
|
+
connection.get("organizations/#{organization_id}/employees", query_params)
|
8
|
+
end
|
9
|
+
|
10
|
+
def employee_get(organization_id, employee_id)
|
11
|
+
connection.get("organizations/#{organization_id}/employees/#{employee_id}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def employee_update(organization_id, employee_id, body_params)
|
15
|
+
connection.put("organizations/#{organization_id}/employees/#{employee_id}", body_params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def employee_create(organization_id, body_params)
|
19
|
+
connection.post("organizations/#{organization_id}/employees", body_params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def employee_invite(organization_id, body_params)
|
23
|
+
connection.post("organizations/#{organization_id}/employees/send_invitations", body_params)
|
24
|
+
end
|
25
|
+
|
26
|
+
def employee_delete(organization_id, employee_id)
|
27
|
+
connection.delete("organizations/#{organization_id}/employees/#{employee_id}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def employee_data_api_get(organization_id, employee_id)
|
31
|
+
connection.get("organizations/#{organization_id}/employees/#{employee_id}/data")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Credly
|
4
|
+
class Client
|
5
|
+
include Credly::Actions::Badges
|
6
|
+
include Credly::Actions::BadgeTemplates
|
7
|
+
include Credly::Actions::Organizations
|
8
|
+
include Credly::Actions::OBI
|
9
|
+
include Credly::Actions::IssuerAuthorizations
|
10
|
+
include Credly::Actions::Workforce
|
11
|
+
attr_reader :url, :auth_token
|
12
|
+
attr_accessor :sandbox
|
13
|
+
|
14
|
+
BASE_URL_P = 'https://api.credly.com'
|
15
|
+
BASE_URL_S = 'https://sandbox-api.credly.com'
|
16
|
+
|
17
|
+
def initialize(auth_token:, version: 'v1', sandbox: false)
|
18
|
+
@base_url = sandbox ? BASE_URL_S : BASE_URL_P
|
19
|
+
@url = [@base_url, version].join('/')
|
20
|
+
@version = version
|
21
|
+
@auth_token = auth_token
|
22
|
+
@sandbox = sandbox
|
23
|
+
@connection = Connection.new(@url, @auth_token)
|
24
|
+
end
|
25
|
+
|
26
|
+
def connection
|
27
|
+
@connection ||= Connection.new(@url, @auth_token)
|
28
|
+
end
|
29
|
+
|
30
|
+
def auth_token=(auth_token)
|
31
|
+
@auth_token = auth_token
|
32
|
+
@connection.auth_token = auth_token
|
33
|
+
end
|
34
|
+
|
35
|
+
def base_url
|
36
|
+
@sandbox ? BASE_URL_S : BASE_URL_P
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
|
5
|
+
module Credly
|
6
|
+
class Connection
|
7
|
+
def initialize(url, auth_token)
|
8
|
+
@connection = Faraday.new(url: url) do |builder|
|
9
|
+
builder.request :json
|
10
|
+
builder.headers[:accept] = 'application/json'
|
11
|
+
builder.response :json
|
12
|
+
builder.request :authorization, :basic, auth_token, ''
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def auth_token=(auth_token)
|
17
|
+
@connection.set_basic_auth(auth_token, '')
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(path, params = {})
|
21
|
+
request(:delete, path, params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get(path, params = {})
|
25
|
+
request(:get, path, params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def post(path, params = {})
|
29
|
+
request(:post, path, params)
|
30
|
+
end
|
31
|
+
|
32
|
+
def put(path, params = {})
|
33
|
+
request(:put, path, params)
|
34
|
+
end
|
35
|
+
|
36
|
+
def request(method, path, params)
|
37
|
+
response = @connection.send(method, path, params)
|
38
|
+
|
39
|
+
error = Error.from_response(response)
|
40
|
+
|
41
|
+
raise error if error
|
42
|
+
|
43
|
+
response.body
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/credly/error.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Credly
|
4
|
+
class Error < StandardError
|
5
|
+
attr_reader :response
|
6
|
+
|
7
|
+
def self.from_response(response) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength:
|
8
|
+
klass =
|
9
|
+
case response.status
|
10
|
+
when 400 then BadRequest
|
11
|
+
when 401 then Unauthorized
|
12
|
+
when 403 then Forbidden
|
13
|
+
when 404 then NotFound
|
14
|
+
when 410 then Gone
|
15
|
+
when 422 then UnprocessableEntity
|
16
|
+
when 400..499 then ClientError
|
17
|
+
when 500 then InternalServerError
|
18
|
+
when 503 then ServiceUnavailable
|
19
|
+
when 500..599 then ServerError
|
20
|
+
end
|
21
|
+
|
22
|
+
klass&.new(response)
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(response = nil)
|
26
|
+
@response = response
|
27
|
+
super(build_error_message)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def build_error_message
|
33
|
+
return nil if @response.nil?
|
34
|
+
|
35
|
+
@response.body
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class ClientError < Error; end
|
40
|
+
class BadRequest < Error; end
|
41
|
+
class Unauthorized < Error; end
|
42
|
+
class Forbidden < Error; end
|
43
|
+
class NotFound < Error; end
|
44
|
+
class ServerError < Error; end
|
45
|
+
class InternalServerError < Error; end
|
46
|
+
class ServiceUnavailable < Error; end
|
47
|
+
class UnprocessableEntity < Error; end
|
48
|
+
class Gone < Error; end
|
49
|
+
end
|
data/lib/credly_ruby.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'credly/connection'
|
4
|
+
require 'credly/actions/badges'
|
5
|
+
require 'credly/actions/badge_templates'
|
6
|
+
require 'credly/actions/organizations'
|
7
|
+
require 'credly/actions/obi'
|
8
|
+
require 'credly/actions/issuer_authorizations'
|
9
|
+
require 'credly/actions/workforce'
|
10
|
+
require 'credly/client'
|
11
|
+
require 'credly/error'
|
12
|
+
require 'credly/version'
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: credly-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Ogilvie
|
8
|
+
- Elijah Almacen
|
9
|
+
- ChanSokphanavy Plean
|
10
|
+
- Yahui Qin
|
11
|
+
- Shuning Xu
|
12
|
+
autorequire:
|
13
|
+
bindir: exe
|
14
|
+
cert_chain: []
|
15
|
+
date: 2023-10-12 00:00:00.000000000 Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: faraday
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - "~>"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '1.0'
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
27
|
+
type: :runtime
|
28
|
+
prerelease: false
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.0.0
|
37
|
+
description: Access the Credly REST API.
|
38
|
+
email:
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- ".rubocop.yml"
|
44
|
+
- CHANGELOG.md
|
45
|
+
- Gemfile
|
46
|
+
- Gemfile.lock
|
47
|
+
- LICENSE
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- lib/credly/actions/badge_templates.rb
|
51
|
+
- lib/credly/actions/badges.rb
|
52
|
+
- lib/credly/actions/issuer_authorizations.rb
|
53
|
+
- lib/credly/actions/obi.rb
|
54
|
+
- lib/credly/actions/organizations.rb
|
55
|
+
- lib/credly/actions/workforce.rb
|
56
|
+
- lib/credly/client.rb
|
57
|
+
- lib/credly/connection.rb
|
58
|
+
- lib/credly/error.rb
|
59
|
+
- lib/credly/version.rb
|
60
|
+
- lib/credly_ruby.rb
|
61
|
+
homepage: https://github.com/riipen/credly-ruby
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata:
|
65
|
+
homepage_uri: https://github.com/riipen/credly-ruby
|
66
|
+
source_code_uri: https://github.com/riipen/credly-ruby
|
67
|
+
changelog_uri: https://github.com/riipen/credly-ruby/blob/master/CHANGELOG.md
|
68
|
+
rubygems_mfa_required: 'true'
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.6.0
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubygems_version: 3.3.7
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: An API client for Credly in ruby.
|
88
|
+
test_files: []
|