api_connect_client 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/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +57 -0
- data/LICENSE.txt +21 -0
- data/README.md +179 -0
- data/Rakefile +6 -0
- data/api_connect_client.gemspec +30 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/api_connect_client/application.rb +45 -0
- data/lib/api_connect_client/base.rb +59 -0
- data/lib/api_connect_client/config.rb +35 -0
- data/lib/api_connect_client/developer.rb +84 -0
- data/lib/api_connect_client/manager.rb +30 -0
- data/lib/api_connect_client/product.rb +17 -0
- data/lib/api_connect_client/user.rb +16 -0
- data/lib/api_connect_client/version.rb +3 -0
- data/lib/api_connect_client.rb +11 -0
- metadata +163 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7ae8ab6ea8f955373a02e828ef8e608b5b425afa
|
4
|
+
data.tar.gz: 4adbbc5896a5480193d8729ff79ce49995e4ce0d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: baa2ed02fd9d60f1c0c16b6ade5e88594ec2c4c03113f6cc25f10f6acb3fba567d040694984771afb2f530fdf245af88fc77f96d968c24009f0ae395073b9888
|
7
|
+
data.tar.gz: 409d4bfe874ff28cadf3c13470fac7e03d3f0dd263726526615ae613ae1f6979a321f8576f17fb62525eadb0ebd12dcd165482983bb19badb63621d3b88052e1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
api_connect_client (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.5.2)
|
10
|
+
public_suffix (>= 2.0.2, < 4.0)
|
11
|
+
coderay (1.1.2)
|
12
|
+
crack (0.4.3)
|
13
|
+
safe_yaml (~> 1.0.0)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
dotenv (2.2.1)
|
16
|
+
hashdiff (0.3.7)
|
17
|
+
method_source (0.9.0)
|
18
|
+
pry (0.11.3)
|
19
|
+
coderay (~> 1.1.0)
|
20
|
+
method_source (~> 0.9.0)
|
21
|
+
public_suffix (3.0.1)
|
22
|
+
rake (10.5.0)
|
23
|
+
rspec (3.7.0)
|
24
|
+
rspec-core (~> 3.7.0)
|
25
|
+
rspec-expectations (~> 3.7.0)
|
26
|
+
rspec-mocks (~> 3.7.0)
|
27
|
+
rspec-core (3.7.0)
|
28
|
+
rspec-support (~> 3.7.0)
|
29
|
+
rspec-expectations (3.7.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.7.0)
|
32
|
+
rspec-mocks (3.7.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.7.0)
|
35
|
+
rspec-support (3.7.0)
|
36
|
+
safe_yaml (1.0.4)
|
37
|
+
vcr (3.0.3)
|
38
|
+
webmock (3.1.0)
|
39
|
+
addressable (>= 2.3.6)
|
40
|
+
crack (>= 0.3.2)
|
41
|
+
hashdiff
|
42
|
+
|
43
|
+
PLATFORMS
|
44
|
+
ruby
|
45
|
+
|
46
|
+
DEPENDENCIES
|
47
|
+
api_connect_client!
|
48
|
+
bundler (~> 1.16)
|
49
|
+
dotenv (~> 2.2)
|
50
|
+
pry (~> 0.11.3)
|
51
|
+
rake (~> 10.0)
|
52
|
+
rspec (~> 3.0)
|
53
|
+
vcr (~> 3.0)
|
54
|
+
webmock (~> 3.1)
|
55
|
+
|
56
|
+
BUNDLED WITH
|
57
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Carlos Fiebig
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
# Api Connect Client
|
2
|
+
|
3
|
+
This gem is used to interact with the [Developer Portal REST APIs](https://www.ibm.com/support/knowledgecenter/en/SSFS6T/com.ibm.apic.apirest.doc/dev_portal_apis.html)
|
4
|
+
to perform some of the operations that are normally carried out in the Developer Portal UI.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'api_connect_client'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install api_connect_client
|
21
|
+
|
22
|
+
## Configuration
|
23
|
+
|
24
|
+
The Developer Portal REST APIs requires you to define a context with the form of `organization.space` where lives the catalog you are trying to interact with. In order to configure this gem you need to register the context:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
ApiConnectClient::Config.register_context("your_bluemix_context")
|
28
|
+
```
|
29
|
+
|
30
|
+
In rails you can create an initializer in config/initializers (e.g. api_connect_client.rb) and define your context.
|
31
|
+
|
32
|
+
The endpoint used to interact with this APIs is `https://us.apiconnect.ibmcloud.com/v1/portal` You can also register a custom endpoint like this:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
ApiConnectClient::Config.register_endpoint("your_custom_endpoint")
|
36
|
+
```
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
Once you have configured your context you can interact with the APIs in two different ways:
|
41
|
+
|
42
|
+
* Manager:
|
43
|
+
* Create users
|
44
|
+
* List public products
|
45
|
+
* Show an specific product
|
46
|
+
|
47
|
+
* Developer:
|
48
|
+
* Create applications
|
49
|
+
* List applications
|
50
|
+
* Show an specific application
|
51
|
+
* Update application information
|
52
|
+
* Update application credentials
|
53
|
+
* Subscribe application to a plan
|
54
|
+
|
55
|
+
### Initialize manager
|
56
|
+
|
57
|
+
To interact as a manager you need to initialize it like this:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
manager = ApiConnectClient::Manager.new('manager_email', 'manager_password')
|
61
|
+
```
|
62
|
+
|
63
|
+
#### Create user
|
64
|
+
|
65
|
+
Then with the `manager` you can create a new user:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
manager.create_user(first_name, last_name, organization_name, username, password)
|
69
|
+
```
|
70
|
+
|
71
|
+
#### List public products
|
72
|
+
|
73
|
+
To list public products:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
manager.list_products
|
77
|
+
```
|
78
|
+
|
79
|
+
Which will return an array with the public products of your catalog with the following structure:
|
80
|
+
|
81
|
+
```json
|
82
|
+
[
|
83
|
+
{
|
84
|
+
"id": "5a0333569cf1b5ba87c1fd2f",
|
85
|
+
"info": {
|
86
|
+
"name": "product_name",
|
87
|
+
"title": "Product Title",
|
88
|
+
"version": "1.0.1",
|
89
|
+
"description": "Product description"
|
90
|
+
},
|
91
|
+
"url": "https://us.apiconnect.ibmcloud.com/v1/portal/products/5a0333569cf1b5ba87c1fd2f",
|
92
|
+
"status": "published"
|
93
|
+
},
|
94
|
+
{
|
95
|
+
"id": "5a0333569cf1b5ba87c1fd2a",
|
96
|
+
"info": {
|
97
|
+
"name": "product_name",
|
98
|
+
"title": "Product Title",
|
99
|
+
"version": "1.0.1",
|
100
|
+
"description": "Product description",
|
101
|
+
"categories": [
|
102
|
+
"mock"
|
103
|
+
]
|
104
|
+
},
|
105
|
+
"url": "https://us.apiconnect.ibmcloud.com/v1/portal/products/5a0333569cf1b5ba87c1fd2a",
|
106
|
+
"status": "published"
|
107
|
+
}
|
108
|
+
]
|
109
|
+
```
|
110
|
+
|
111
|
+
#### Show a product
|
112
|
+
|
113
|
+
If you want to retrieve an specific product you can call:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
manager.show_product(product_id)
|
117
|
+
```
|
118
|
+
|
119
|
+
### Initialize Developer
|
120
|
+
|
121
|
+
To interact as a developer you need to initialize it like this:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
developer = ApiConnectClient::Developer.new('developer_email', 'developer_password', 'organization_id')
|
125
|
+
```
|
126
|
+
|
127
|
+
#### Create applications
|
128
|
+
|
129
|
+
Then with the `developer` you can create a new application:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
developer.create_application(name, description, oauth_redirect_url, public_app = false)
|
133
|
+
```
|
134
|
+
|
135
|
+
#### List applications
|
136
|
+
|
137
|
+
List the applications owned by the developer:
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
developer.list_applications
|
141
|
+
```
|
142
|
+
|
143
|
+
#### Show an specific application
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
developer.show_application(app_id)
|
147
|
+
```
|
148
|
+
|
149
|
+
#### Update application information
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
developer.update_application(app_id, name, description, oauth_redirect_uri, public_app)
|
153
|
+
```
|
154
|
+
|
155
|
+
#### Update application credentials
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
developer.update_application_credentials(app_id, client_id, client_secret)
|
159
|
+
```
|
160
|
+
|
161
|
+
#### Subscribe application to a plan
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
developer.subscribe_application(app_id, product_id, plan = 'default')
|
165
|
+
```
|
166
|
+
|
167
|
+
## Development
|
168
|
+
|
169
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
170
|
+
|
171
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
172
|
+
|
173
|
+
## Contributing
|
174
|
+
|
175
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/api-connect-client.
|
176
|
+
|
177
|
+
## License
|
178
|
+
|
179
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "api_connect_client"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "api_connect_client"
|
8
|
+
spec.version = ApiConnectClient::VERSION
|
9
|
+
spec.authors = ["Carlos Fiebig"]
|
10
|
+
spec.email = ["cffiebigc@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = 'Client to interact with IBM Api Connect'
|
13
|
+
spec.description = 'Manager and Developer from IBM Api Connect to interact with te developer portal REST APIs'
|
14
|
+
spec.homepage = "https://github.com/cffiebigc/api-connect-client"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "pry", '~> 0.11.3'
|
27
|
+
spec.add_development_dependency "webmock", '~> 3.1'
|
28
|
+
spec.add_development_dependency "vcr", '~> 3.0'
|
29
|
+
spec.add_development_dependency "dotenv", '~> 2.2'
|
30
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "api_connect_client"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module ApiConnectClient
|
2
|
+
class Application < Base
|
3
|
+
def initialize(org_id, user, pass)
|
4
|
+
super()
|
5
|
+
@headers = { 'X-IBM-APIManagement-Context': ApiConnectClient::Config.context }
|
6
|
+
@owner = { id: org_id, username: user, password: pass }
|
7
|
+
end
|
8
|
+
|
9
|
+
def all
|
10
|
+
get("/orgs/#{@owner[:id]}/apps", @owner[:username], @owner[:password])
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(body)
|
14
|
+
post("/orgs/#{@owner[:id]}/apps", body, @owner[:username], @owner[:password])
|
15
|
+
end
|
16
|
+
|
17
|
+
def show(app_id)
|
18
|
+
get("/orgs/#{@owner[:id]}/apps/#{app_id}", @owner[:username], @owner[:password])
|
19
|
+
end
|
20
|
+
|
21
|
+
def remove(app_id)
|
22
|
+
delete("/orgs/#{@owner[:id]}/apps/#{app_id}", @owner[:username], @owner[:password])
|
23
|
+
end
|
24
|
+
|
25
|
+
def update(app_id, body)
|
26
|
+
put("/orgs/#{@owner[:id]}/apps/#{app_id}", body, @owner[:username], @owner[:password])
|
27
|
+
end
|
28
|
+
|
29
|
+
def update_credentials(app_id, body)
|
30
|
+
put("/orgs/#{@owner[:id]}/apps/#{app_id}/credentials", body, @owner[:username], @owner[:password])
|
31
|
+
end
|
32
|
+
|
33
|
+
def subscribe(app_id, body)
|
34
|
+
post("/orgs/#{@owner[:id]}/apps/#{app_id}/subscriptions", body, @owner[:username], @owner[:password])
|
35
|
+
end
|
36
|
+
|
37
|
+
def list_subscriptions(app_id)
|
38
|
+
get("/orgs/#{@owner[:id]}/apps/#{app_id}/subscriptions", @owner[:username], @owner[:password])
|
39
|
+
end
|
40
|
+
|
41
|
+
def unsubscribe(app_id, subscription_id)
|
42
|
+
delete("/orgs/#{@owner[:id]}/apps/#{app_id}/subscriptions/#{subscription_id}", @owner[:username], @owner[:password])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module ApiConnectClient
|
5
|
+
class Base
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@endpoint = ApiConnectClient::Config.endpoint
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def get(path, user = nil, pass = nil, params = {})
|
14
|
+
uri = URI("#{@endpoint}#{path}?#{URI.encode_www_form(params)}")
|
15
|
+
req = Net::HTTP::Get.new(uri)
|
16
|
+
req.basic_auth(user, pass) unless user.nil? || pass.nil?
|
17
|
+
headers_for(req)
|
18
|
+
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
|
19
|
+
JSON.parse(res.body)
|
20
|
+
end
|
21
|
+
|
22
|
+
def post(path, body, user = nil, pass = nil, params = {})
|
23
|
+
uri = URI("#{@endpoint}#{path}?#{URI.encode_www_form(params)}")
|
24
|
+
req = Net::HTTP::Post.new(uri)
|
25
|
+
req.basic_auth(user, pass) unless user.nil? || pass.nil?
|
26
|
+
headers_for(req)
|
27
|
+
req.content_type = 'application/json'
|
28
|
+
req.body = body
|
29
|
+
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
|
30
|
+
JSON.parse(res.body)
|
31
|
+
end
|
32
|
+
|
33
|
+
def put(path, body, user = nil, pass = nil, params = {})
|
34
|
+
uri = URI("#{@endpoint}#{path}?#{URI.encode_www_form(params)}")
|
35
|
+
req = Net::HTTP::Put.new(uri)
|
36
|
+
req.basic_auth(user, pass) unless user.nil? || pass.nil?
|
37
|
+
headers_for(req)
|
38
|
+
req.content_type = 'application/json'
|
39
|
+
req.body = body
|
40
|
+
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
|
41
|
+
JSON.parse(res.body)
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete(path, user = nil, pass = nil, params = {})
|
45
|
+
uri = URI("#{@endpoint}#{path}?#{URI.encode_www_form(params)}")
|
46
|
+
req = Net::HTTP::Delete.new(uri)
|
47
|
+
req.basic_auth(user, pass) unless user.nil? || pass.nil?
|
48
|
+
headers_for(req)
|
49
|
+
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
|
50
|
+
JSON.parse(res.body) unless res.body.nil?
|
51
|
+
end
|
52
|
+
|
53
|
+
def headers_for(request)
|
54
|
+
@headers.to_a.each do |header|
|
55
|
+
request[header[0]] = header[1]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ApiConnectClient
|
2
|
+
class Config
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def register_context(context)
|
6
|
+
@context = context
|
7
|
+
end
|
8
|
+
|
9
|
+
def context
|
10
|
+
@context ||= ''
|
11
|
+
end
|
12
|
+
|
13
|
+
def register_endpoint(endpoint)
|
14
|
+
@endpoint = endpoint
|
15
|
+
end
|
16
|
+
|
17
|
+
def endpoint
|
18
|
+
@endpoint ||= 'https://us.apiconnect.ibmcloud.com/v1/portal'
|
19
|
+
end
|
20
|
+
|
21
|
+
def register_manager_credentials(username, password)
|
22
|
+
@manager_username = username
|
23
|
+
@manager_password = password
|
24
|
+
end
|
25
|
+
|
26
|
+
def manager_username
|
27
|
+
@manager_username ||= ''
|
28
|
+
end
|
29
|
+
|
30
|
+
def manager_password
|
31
|
+
@manager_password ||= ''
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module ApiConnectClient
|
2
|
+
class Developer
|
3
|
+
def initialize(username, password, organization_id)
|
4
|
+
@headers = {
|
5
|
+
'X-IBM-APIManagement-Context': ApiConnectClient::Config.context
|
6
|
+
}
|
7
|
+
@username = username
|
8
|
+
@password = password
|
9
|
+
@@organization_id = organization_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_application(name, description, oauth_redirect_url, public_app = false)
|
13
|
+
body = {
|
14
|
+
"name" => name,
|
15
|
+
"credentials" => {
|
16
|
+
"clientID" => true,
|
17
|
+
"clientSecret" => true
|
18
|
+
},
|
19
|
+
"description" => description || '',
|
20
|
+
"oauthRedirectURI" => oauth_redirect_url,
|
21
|
+
"public" => public_app
|
22
|
+
}
|
23
|
+
app = ApiConnectClient::Application.new(@@organization_id, @username, @password)
|
24
|
+
app.create(body.to_json)
|
25
|
+
end
|
26
|
+
|
27
|
+
def list_applications
|
28
|
+
app = ApiConnectClient::Application.new(@@organization_id, @username, @password)
|
29
|
+
app.all
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete_application(app_id)
|
33
|
+
app = ApiConnectClient::Application.new(@@organization_id, @username, @password)
|
34
|
+
app.remove(app_id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def show_application(app_id)
|
38
|
+
app = ApiConnectClient::Application.new(@@organization_id, @username, @password)
|
39
|
+
app.show(app_id)
|
40
|
+
end
|
41
|
+
|
42
|
+
def update_application(app_id, name, description, oauth_redirect_uri, public_app)
|
43
|
+
body = {
|
44
|
+
"name" => name,
|
45
|
+
"appImageURL" => "https://something.com/empty.jpg",
|
46
|
+
"description" => description,
|
47
|
+
"oauthRedirectURI" => oauth_redirect_uri,
|
48
|
+
"public" => public_app
|
49
|
+
}
|
50
|
+
app = ApiConnectClient::Application.new(@@organization_id, @username, @password)
|
51
|
+
app.update(app_id, body.to_json)
|
52
|
+
end
|
53
|
+
|
54
|
+
def update_application_credentials(app_id, client_id, client_secret)
|
55
|
+
body = {
|
56
|
+
"clientID" => client_id,
|
57
|
+
"clientSecret" => client_secret
|
58
|
+
}
|
59
|
+
app = ApiConnectClient::Application.new(@@organization_id, @username, @password)
|
60
|
+
app.update_credentials(app_id, body.to_json)
|
61
|
+
end
|
62
|
+
|
63
|
+
def subscribe_application(app_id, product_id, plan = 'default')
|
64
|
+
body = {
|
65
|
+
"plan" => plan,
|
66
|
+
"product" => {
|
67
|
+
"id" => product_id
|
68
|
+
}
|
69
|
+
}
|
70
|
+
app = ApiConnectClient::Application.new(@@organization_id, @username, @password)
|
71
|
+
app.subscribe(app_id, body.to_json)
|
72
|
+
end
|
73
|
+
|
74
|
+
def list_application_subscriptions(app_id)
|
75
|
+
app = ApiConnectClient::Application.new(@@organization_id, @username, @password)
|
76
|
+
app.list_subscriptions(app_id)
|
77
|
+
end
|
78
|
+
|
79
|
+
def unsubscribe_application(app_id, subscription_id)
|
80
|
+
app = ApiConnectClient::Application.new(@@organization_id, @username, @password)
|
81
|
+
app.unsubscribe(app_id, subscription_id)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ApiConnectClient
|
2
|
+
class Manager
|
3
|
+
def initialize(admin_user = nil , admin_pass = nil)
|
4
|
+
@admin_user = "apimanager/#{admin_user || ApiConnectClient::Config.manager_username }"
|
5
|
+
@admin_pass = admin_pass || ApiConnectClient::Config.manager_password
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_developer(username, password, first_name = '', last_name = '', organization_name = '')
|
9
|
+
body = {
|
10
|
+
"firstName" => first_name,
|
11
|
+
"lastName" => last_name,
|
12
|
+
"organization" => organization_name,
|
13
|
+
"password" => password,
|
14
|
+
"username" => username
|
15
|
+
}
|
16
|
+
user = ApiConnectClient::User.new(@admin_user, @admin_pass)
|
17
|
+
user.create(body.to_json)
|
18
|
+
end
|
19
|
+
|
20
|
+
def list_products
|
21
|
+
product = ApiConnectClient::Product.new
|
22
|
+
product.all
|
23
|
+
end
|
24
|
+
|
25
|
+
def show_product(product_id)
|
26
|
+
product = ApiConnectClient::Product.new
|
27
|
+
product.show(product_id)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ApiConnectClient
|
2
|
+
class Product < Base
|
3
|
+
def initialize
|
4
|
+
super()
|
5
|
+
@headers = { 'X-IBM-APIManagement-Context': ApiConnectClient::Config.context }
|
6
|
+
end
|
7
|
+
|
8
|
+
def all
|
9
|
+
get("/products")
|
10
|
+
end
|
11
|
+
|
12
|
+
def show(product_id)
|
13
|
+
@headers['Accept'] = 'application/vnd.ibm-apim.product+json'
|
14
|
+
get("/products/#{product_id}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ApiConnectClient
|
2
|
+
class User < Base
|
3
|
+
def initialize(admin_user, admin_pass)
|
4
|
+
super()
|
5
|
+
@headers = {
|
6
|
+
'X-IBM-APIManagement-Context': ApiConnectClient::Config.context
|
7
|
+
}
|
8
|
+
@admin_user = admin_user
|
9
|
+
@admin_pass = admin_pass
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(body)
|
13
|
+
post('/users/register', body, @admin_user, @admin_pass)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "api_connect_client/version"
|
2
|
+
|
3
|
+
module ApiConnectClient
|
4
|
+
require_relative './api_connect_client/base'
|
5
|
+
require_relative './api_connect_client/product'
|
6
|
+
require_relative './api_connect_client/user'
|
7
|
+
require_relative './api_connect_client/application'
|
8
|
+
require_relative './api_connect_client/manager'
|
9
|
+
require_relative './api_connect_client/developer'
|
10
|
+
require_relative './api_connect_client/config'
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: api_connect_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carlos Fiebig
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-23 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.11.3
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.11.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dotenv
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.2'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.2'
|
111
|
+
description: Manager and Developer from IBM Api Connect to interact with te developer
|
112
|
+
portal REST APIs
|
113
|
+
email:
|
114
|
+
- cffiebigc@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- api_connect_client.gemspec
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- lib/api_connect_client.rb
|
131
|
+
- lib/api_connect_client/application.rb
|
132
|
+
- lib/api_connect_client/base.rb
|
133
|
+
- lib/api_connect_client/config.rb
|
134
|
+
- lib/api_connect_client/developer.rb
|
135
|
+
- lib/api_connect_client/manager.rb
|
136
|
+
- lib/api_connect_client/product.rb
|
137
|
+
- lib/api_connect_client/user.rb
|
138
|
+
- lib/api_connect_client/version.rb
|
139
|
+
homepage: https://github.com/cffiebigc/api-connect-client
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.5.2
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Client to interact with IBM Api Connect
|
163
|
+
test_files: []
|