companion_cube 0.2.3
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 +7 -0
- data/CHANGELOG.md +43 -0
- data/LICENSE +21 -0
- data/README.md +114 -0
- data/bin/console +22 -0
- data/bin/setup +8 -0
- data/lib/companion_cube.rb +2 -0
- data/lib/companion_cube/client.rb +71 -0
- data/lib/companion_cube/version.rb +3 -0
- metadata +163 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d266227d5728df0bfbd1e3bab171a1d5117bc646601ed0418edc9e36a161a58a
|
4
|
+
data.tar.gz: 6073315fc04b331975683919ab3050c403d656a540d740867197017d9ee0eaaa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d0686ba10b830b3a75afcd7c99713701c79db3b2d8bcb36af2ea5f6d0502f3c3f1820a3ce9dc85071fd0928aa5dd6fcb634b7e9b6459c210b5f63a54ab08e6d1
|
7
|
+
data.tar.gz: e7f47865bff4e98ad9a2989c7cb590c2cfc011ae6e5444604c6b6e5a4992b3b5d06837de40ae162910de12b63ed0255f0fdfc243abf8ea895788556e00b6181b
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
5
|
+
and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
|
+
|
7
|
+
## [0.2.3][] - 2020-01-31
|
8
|
+
### Added
|
9
|
+
- Feature to delete courses
|
10
|
+
|
11
|
+
## [0.2.0][] - 2017-05-11
|
12
|
+
### Added
|
13
|
+
- Support for `/reports/completions` and `/reports/enrollments`
|
14
|
+
- Build instructions
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
- Fixed test coverage measurement in `coverage/index.html`
|
18
|
+
|
19
|
+
## [0.1.2][] - 2017-04-25
|
20
|
+
### Fixed
|
21
|
+
- Bug in parsing responses.
|
22
|
+
|
23
|
+
## [0.1.1][] - 2017-04-17
|
24
|
+
### Added
|
25
|
+
- SimpleCov for test coverage.
|
26
|
+
|
27
|
+
### Changed
|
28
|
+
- Remove Rails things from RuboCop config.
|
29
|
+
- Git-less gem specification.
|
30
|
+
|
31
|
+
### Removed
|
32
|
+
- Custom exceptions.
|
33
|
+
|
34
|
+
### Fixed
|
35
|
+
- Send multipart request for create/update course.
|
36
|
+
|
37
|
+
## 0.1.0 - 2017-04-07
|
38
|
+
### Added
|
39
|
+
- Implement all APIs
|
40
|
+
|
41
|
+
[Unreleased]: https://github.ibm.com/bdu/companion-cube-ruby/compare/0.1.2...HEAD
|
42
|
+
[0.1.2]: https://github.ibm.com/bdu/companion-cube-ruby/compare/0.1.1...0.1.2
|
43
|
+
[0.1.1]: https://github.ibm.com/bdu/companion-cube-ruby/compare/0.1.0...0.1.1
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 International Business Machines
|
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,114 @@
|
|
1
|
+
[](https://travis.ibm.com/bdu/companion-cube-ruby)
|
2
|
+
|
3
|
+
# Companion Cube
|
4
|
+
|
5
|
+
Ruby client for [Companion Cube](https://github.ibm.com/bdu/companion-cube).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's `Gemfile`:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem "companion_cube"
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```sh
|
18
|
+
bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```sh
|
24
|
+
gem install companion_cube
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# To start, create a client
|
31
|
+
cc = CompanionCube::Client.new(url: "https://cc.example.com")
|
32
|
+
|
33
|
+
# Retrieve all existing courses
|
34
|
+
courses = cc.courses
|
35
|
+
|
36
|
+
# Create a new course
|
37
|
+
params = {
|
38
|
+
run: "...",
|
39
|
+
archive_file: File.new("...")
|
40
|
+
}
|
41
|
+
new_course = cc.create_course(params)
|
42
|
+
|
43
|
+
# Retrieve an existing course
|
44
|
+
course = cc.course(new_course["id"])
|
45
|
+
|
46
|
+
# Update a course
|
47
|
+
params = {
|
48
|
+
archive_file: File.new("...")
|
49
|
+
}
|
50
|
+
updated_course = cc.update_course(course["id"], params)
|
51
|
+
```
|
52
|
+
|
53
|
+
## Development
|
54
|
+
|
55
|
+
To run the tests, run:
|
56
|
+
|
57
|
+
```sh
|
58
|
+
docker-compose run --rm cc rake spec
|
59
|
+
```
|
60
|
+
|
61
|
+
You can also run the following command for an interactive prompt that will
|
62
|
+
allow you to experiment.
|
63
|
+
|
64
|
+
```sh
|
65
|
+
docker-compose run --rm cc bin/console
|
66
|
+
```
|
67
|
+
|
68
|
+
For added flexibility, you can use Bash.
|
69
|
+
|
70
|
+
```sh
|
71
|
+
docker-compose run --rm cc bash
|
72
|
+
```
|
73
|
+
|
74
|
+
## Build
|
75
|
+
|
76
|
+
Add the gem repo to your configuration:
|
77
|
+
|
78
|
+
```sh
|
79
|
+
# replace @ with %40 in your username
|
80
|
+
gem source -a \
|
81
|
+
https://<USERNAME>:<PASSWORD>@na.artifactory.swg-devops.com/artifactory/api/gems/apset-ruby/
|
82
|
+
|
83
|
+
# keep @ AS IS
|
84
|
+
curl -u<USERNAME>:<PASSWORD> \
|
85
|
+
https://na.artifactory.swg-devops.com/artifactory/api/gems/apset-ruby/api/v1/api_key.yaml \
|
86
|
+
> ~/.gem/credentials
|
87
|
+
```
|
88
|
+
|
89
|
+
Build the gem:
|
90
|
+
|
91
|
+
```sh
|
92
|
+
gem build companion_cube.gemspec
|
93
|
+
```
|
94
|
+
|
95
|
+
Install the gem locally: (optional)
|
96
|
+
|
97
|
+
```sh
|
98
|
+
gem install companion_cube-*.gem
|
99
|
+
```
|
100
|
+
|
101
|
+
Push the gem:
|
102
|
+
|
103
|
+
```sh
|
104
|
+
gem push companion_cube-*.gem
|
105
|
+
rm companion_cube-*.gem
|
106
|
+
```
|
107
|
+
|
108
|
+
## License
|
109
|
+
|
110
|
+
Please refer to [LICENSE](LICENSE).
|
111
|
+
|
112
|
+
## Authors
|
113
|
+
|
114
|
+
* Partner Ecosystem Team, IBM Digital Business Group <mailto:imcloud@ca.ibm.com>
|
data/bin/console
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "json"
|
5
|
+
require "companion_cube"
|
6
|
+
|
7
|
+
cc = nil
|
8
|
+
|
9
|
+
begin
|
10
|
+
cc = CompanionCube::Client.new(
|
11
|
+
url: ENV.fetch("COMPANION_CUBE_URL"),
|
12
|
+
access_key: ENV.fetch("COMPANION_CUBE_ACCESS_KEY"),
|
13
|
+
secret_key: ENV.fetch("COMPANION_CUBE_SECRET_KEY")
|
14
|
+
)
|
15
|
+
rescue
|
16
|
+
puts "Set Companion Cube env variables to automatically load the client"
|
17
|
+
end
|
18
|
+
|
19
|
+
instance_variable_set(:@companion_cube, cc)
|
20
|
+
|
21
|
+
require "irb"
|
22
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require "rest-client"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module CompanionCube
|
5
|
+
class Client
|
6
|
+
API_HEADERS = { "Accept" => "application/json" }.freeze
|
7
|
+
|
8
|
+
def initialize(url:, access_key: nil, secret_key: nil)
|
9
|
+
raise "Missing required parameter 'url'" if url.nil? || url.empty?
|
10
|
+
|
11
|
+
keys_empty = !access_key.nil? && access_key.empty?
|
12
|
+
keys_empty ||= !secret_key.nil? && secret_key.empty?
|
13
|
+
raise "Access/secret key cannot be blank" if keys_empty
|
14
|
+
|
15
|
+
self.resource = RestClient::Resource.new(url, access_key, secret_key)
|
16
|
+
end
|
17
|
+
|
18
|
+
def courses
|
19
|
+
JSON.parse(send_request(:get, "/courses"))
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_course(params)
|
23
|
+
params[:multipart] = true
|
24
|
+
|
25
|
+
send_request(:post, "/courses", body: params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete_course(id)
|
29
|
+
send_request(:delete, "/courses/#{id}")
|
30
|
+
end
|
31
|
+
|
32
|
+
def course(id)
|
33
|
+
raise "Missing required parameter 'id'" if id.nil?
|
34
|
+
|
35
|
+
JSON.parse(send_request(:get, "/courses/#{id}"))
|
36
|
+
end
|
37
|
+
|
38
|
+
def update_course(id, params)
|
39
|
+
params[:multipart] = true
|
40
|
+
|
41
|
+
send_request(:put, "/courses/#{id}", body: params)
|
42
|
+
end
|
43
|
+
|
44
|
+
def reports(type, params = {})
|
45
|
+
raise "Missing required parameter 'type'" if type.nil?
|
46
|
+
format = params.fetch(:format, :json).to_sym
|
47
|
+
|
48
|
+
response = send_request(:get, "/reports/#{type}", params: params, accept: format)
|
49
|
+
return JSON.parse(response) if format == :json
|
50
|
+
# csv, etc.
|
51
|
+
response
|
52
|
+
end
|
53
|
+
|
54
|
+
protected
|
55
|
+
|
56
|
+
attr_accessor :resource
|
57
|
+
|
58
|
+
def send_request(method, path, opts = {})
|
59
|
+
body = opts.fetch(:body, {})
|
60
|
+
headers = opts.fetch(:headers, {}).merge(API_HEADERS)
|
61
|
+
|
62
|
+
response = if %i[get delete].include?(method)
|
63
|
+
resource[path].send(method, opts)
|
64
|
+
else
|
65
|
+
resource[path].send(method, body, headers)
|
66
|
+
end
|
67
|
+
|
68
|
+
response.body
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: companion_cube
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Partner Ecosystem Team, IBM Digital Business Group
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.48'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.48'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler-audit
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.5'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.5'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.12'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.12'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rest-client
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.0'
|
125
|
+
description: Companion Cube client
|
126
|
+
email:
|
127
|
+
- imcloud@ca.ibm.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- CHANGELOG.md
|
133
|
+
- LICENSE
|
134
|
+
- README.md
|
135
|
+
- bin/console
|
136
|
+
- bin/setup
|
137
|
+
- lib/companion_cube.rb
|
138
|
+
- lib/companion_cube/client.rb
|
139
|
+
- lib/companion_cube/version.rb
|
140
|
+
homepage: https://github.com/IBM/companion-cube-ruby
|
141
|
+
licenses:
|
142
|
+
- All rights reserved.
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubygems_version: 3.0.3
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Companion Cube client
|
163
|
+
test_files: []
|