This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from TheJumpCloud/ts-updates-2018-10-13
API v1 and v2 updates 2018-10-13
- Loading branch information
Showing
27 changed files
with
129 additions
and
583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Ruby artifacts | ||
*.gem | ||
|
||
# input and output directories | ||
input | ||
output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,167 +1,190 @@ | ||
## JCAPI-Ruby | ||
|
||
### Description ### | ||
### Description | ||
|
||
This repository contains the Ruby client code for the JumpCloud API v1 and v2. | ||
It also provides the tools to generate the client code from the API yaml files, using swagger-codegen. | ||
For detailed instructions on how to generate the code, see the [Contributing](CONTRIBUTING.md) section. | ||
This repository contains the Ruby client code for the JumpCloud API v1 and | ||
v2. It also provides the tools to generate the client code from the API YAML | ||
files, using Swagger Codegen. For detailed instructions on how to generate the | ||
code, see the [Contributing](CONTRIBUTING.md) section. | ||
|
||
### Installing the Ruby Client | ||
|
||
#### Installing from github with Bundler | ||
#### Installing from GitHub with Bundler | ||
|
||
Add the following line(s) to your Gemfile: | ||
|
||
`gem 'jcapiv1', :git => 'https://github.com/TheJumpCloud/jcapi-ruby.git'` for the jcapiv1 gem | ||
`gem 'jcapiv1', :git => 'https://github.com/TheJumpCloud/jcapi-ruby.git'` for the jcapiv1 gem. | ||
|
||
`gem 'jcapiv2', :git => 'https://github.com/TheJumpCloud/jcapi-ruby.git'` for the jcapiv2 gem | ||
`gem 'jcapiv2', :git => 'https://github.com/TheJumpCloud/jcapi-ruby.git'` for the jcapiv2 gem. | ||
|
||
And run: `bundle install` | ||
And run: `bundle install`. | ||
|
||
#### Manual install | ||
#### Manual Install | ||
|
||
Change to the appropriate directory (jcapiv1 or jcapiv2) and then run the following | ||
commands to build/install the Ruby Client API package: | ||
commands to build/install the Ruby client API package: | ||
|
||
To build the Ruby code into a gem: | ||
|
||
```shell | ||
gem build jcapiv1.gemspec | ||
``` | ||
|
||
Then either install the gem locally: | ||
|
||
```shell | ||
gem install --user-install ./jcapiv1-1.0.0.gem | ||
``` | ||
|
||
Or for all users: | ||
|
||
```shell | ||
$ sudo gem install ./jcapiv1-1.0.0.gem | ||
sudo gem install ./jcapiv1-1.0.0.gem | ||
``` | ||
|
||
### Authentication and Authorization | ||
|
||
All endpoints support authentication via API key: see the [Authentication and Authorization](https://docs.jumpcloud.com/2.0/authentication-and-authorization/authentication-and-authorization-overview) | ||
section in our API docs. | ||
|
||
Some Systems endpoints (in both API v1 and v2) also support the [System Context authorization](https://docs.jumpcloud.com/2.0/authentication-and-authorization/system-context) | ||
which allows an individual system to manage its information and resource associations. | ||
All endpoints support authentication via API key: see the | ||
[Authentication & Authorization](https://docs.jumpcloud.com/2.0/authentication-and-authorization/authentication-and-authorization-overview) | ||
section in our API documentation. | ||
|
||
Some systems endpoints (in both API v1 and v2) also support | ||
[System Context Authorization](https://docs.jumpcloud.com/2.0/authentication-and-authorization/system-context) | ||
which allows an individual system to manage its information and resource | ||
associations. | ||
|
||
### Usage Examples | ||
|
||
For more detailed instructions, refer to each API's respective README file | ||
([README for API v1](jcapiv1/README.md) and [README for API v2](jcapiv2/README.md)) | ||
and the generated docs under each folder. | ||
For more detailed instructions, refer to each API version's respective README | ||
file ([README for API v1](jcapiv1/README.md) and | ||
[README for API v2](jcapiv2/README.md)) and the generated documentation under | ||
each folder. | ||
|
||
#### API v1 Example | ||
|
||
#### API v1 example: | ||
```ruby | ||
#!/usr/bin/env ruby | ||
|
||
# Load the gem | ||
require 'jcapiv1' | ||
|
||
# Setup API key: | ||
JCAPIv1.configure do |config| | ||
# Configure API key authorization: x-api-key | ||
config.api_key['x-api-key'] = '<YOUR_JUMPCLOUD_API_KEY>' | ||
end | ||
|
||
# instantiate the Systemusers API object: | ||
api_instance = JCAPIv1::SystemusersApi.new | ||
api_key = 'YOUR_API_KEY' | ||
system_user_id = 'YOUR_SYSTEM_USER_ID' | ||
|
||
content_type = 'application/json' | ||
accept = 'application/json' | ||
|
||
# Set up the configuration object with your API key for authorization. | ||
JCAPIv1.configure do |config| | ||
config.api_key['x-api-key'] = api_key | ||
end | ||
|
||
# Instantiate the API object for the group of endpoints you need to use, | ||
# for instance the system users API. | ||
system_users_api = JCAPIv1::SystemusersApi.new | ||
|
||
# Example 1: print all users: | ||
# Example 1: Make an API call to retrieve system users. | ||
|
||
opts = { | ||
limit: 100, # The number of records to return at once. | ||
sort: 'username' # sort by username | ||
sort: 'username' | ||
} | ||
|
||
begin | ||
res = api_instance.systemusers_list(content_type, accept, opts) | ||
puts res.total_count | ||
puts res.results | ||
response = system_users_api.systemusers_list(content_type, accept, opts) | ||
puts response | ||
rescue JCAPIv1::ApiError => e | ||
puts 'Exception when calling SystemusersApi->systemusers_list: #{e}' | ||
puts "Exception when calling SystemusersApi->systemusers_list: #{e}" | ||
end | ||
|
||
# Example 2: Make an API call to update a system user. | ||
|
||
# Example 2: modify the lastname of a specific user: | ||
|
||
# create a put request with the updated last name: | ||
put_request = JCAPIv1::Systemuserputpost.new | ||
put_request.lastname = 'updated last name' | ||
# pass the request in the optional parameters: | ||
opts = { | ||
body: put_request | ||
} | ||
put_request = JCAPIv1::Systemuserput.new | ||
put_request.lastname = 'Updated Last Name' | ||
opts = { body: put_request } | ||
|
||
begin | ||
res = api_instance.systemusers_put('<YOUR_USER_ID>', content_type, accept, opts) | ||
puts res | ||
response = system_users_api.systemusers_put( | ||
system_user_id, content_type, accept, opts | ||
) | ||
puts response | ||
rescue JCAPIv1::ApiError => e | ||
puts 'Exception when calling SystemusersApi->systemusers_get: #{e}' | ||
puts "Exception when calling SystemusersApi->systemusers_put: #{e}" | ||
end | ||
|
||
``` | ||
|
||
|
||
#### API v2 example: | ||
#### API v2 Example | ||
|
||
```ruby | ||
#!/usr/bin/env ruby | ||
|
||
# Load the gem | ||
require 'jcapiv2' | ||
|
||
# Setup API key: | ||
api_key = 'YOUR_API_KEY' | ||
|
||
content_type = 'application/json' | ||
accept = 'application/json' | ||
|
||
# Set up the configuration object with your API key for authorization | ||
JCAPIv2.configure do |config| | ||
# Configure API key authorization: x-api-key | ||
config.api_key['x-api-key'] = '<YOUR_JUMPCLOUD_API_KEY>' | ||
config.api_key['x-api-key'] = api_key | ||
end | ||
|
||
# instantiate the UserGroups API object: | ||
api_instance = JCAPIv2::UserGroupsApi.new | ||
# Instantiate the API object for the group of endpoints you need to use, | ||
# for instance the user groups API. | ||
user_groups_api = JCAPIv2::UserGroupsApi.new | ||
|
||
content_type = 'application/json' | ||
accept = 'application/json' | ||
# Make an API call to retrieve user groups. | ||
|
||
# print all user groups: | ||
begin | ||
res = api_instance.groups_user_list(content_type, accept) | ||
puts res | ||
response = user_groups_api.groups_user_list(content_type, accept) | ||
puts response | ||
rescue JCAPIv2::ApiError => e | ||
puts 'Exception when calling UserGroupsApi->groups_user_list: #{e}' | ||
puts "Exception when calling UserGroupsApi->groups_user_list: #{e}" | ||
end | ||
|
||
``` | ||
|
||
|
||
#### System Context API example: | ||
#### System Context Authorization Example | ||
|
||
```ruby | ||
#!/usr/bin/env ruby | ||
|
||
# Load the gem | ||
require 'jcapiv2' | ||
|
||
# instantiate the Systems API object: | ||
api_instance = JCAPIv2::SystemsApi.new | ||
# Set headers for System Context Authorization. For detailed instructions on | ||
# how to generate these headers, refer to: | ||
# https://docs.jumpcloud.com/2.0/authentication-and-authorization/system-context | ||
system_id = 'YOUR_SYSTEM_ID' | ||
# The current date on the system, e.g. 'Fri, 16 Jan 1998 12:13:05 GMT' | ||
system_date = 'YOUR_SYSTEM_DATE' | ||
system_signature = 'YOUR_SYSTEM_SIGNATURE' | ||
system_context_auth = \ | ||
"Signature keyId=\"system/#{system_id}\","\ | ||
'headers="request-line date",'\ | ||
'algorithm="rsa-sha256",'\ | ||
"signature=\"#{system_signature}\"" | ||
|
||
content_type = 'application/json' | ||
accept = 'application/json' | ||
system_id = '<YOUR_SYSTEM_ID>' | ||
# set headers for the System Context Authorization: | ||
# for detailed instructions on how to generate these headers, | ||
# refer to: https://docs.jumpcloud.com/2.0/authentication-and-authorization/system-context | ||
opts = { | ||
authorization: 'Signature keyId="system/<YOUR_SYSTEM_ID>",headers="request-line date",algorithm="rsa-sha256",signature="<YOUR_SYSTEM_SIGNATURE>"', | ||
date: 'Thu, 19 Oct 2017 17:27:57 GMT' # the current date on the system | ||
} | ||
|
||
# Instantiate the API object for the group of endpoints you need to use, | ||
# for instance the user groups API. | ||
systems_api = JCAPIv2::SystemsApi.new | ||
|
||
# Make an API call to retrieve all system groups this system is a member of. | ||
|
||
opts = { authorization: system_context_auth, date: system_date } | ||
|
||
begin | ||
# list the system groups this system is a member of: | ||
res = api_instance.graph_system_member_of(system_id, content_type, accept, opts) | ||
puts res | ||
response = systems_api.graph_system_member_of( | ||
system_id, content_type, accept, opts | ||
) | ||
puts response | ||
rescue JCAPIv2::ApiError => e | ||
puts 'Exception when calling systemsAPI->graph_system_member_of: #{e}' | ||
puts "Exception when calling systemsAPI->graph_system_member_of: #{e}" | ||
end | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"gemName": "jcapiv1", | ||
"moduleName": "JCAPIv1", | ||
"gemVersion": "1.1.0" | ||
"gemVersion": "1.2.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"gemName": "jcapiv2", | ||
"moduleName": "JCAPIv2", | ||
"gemVersion": "1.1.0" | ||
"gemVersion": "1.2.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.