citrix 0.0.0 → 0.1.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 +4 -4
- data/.travis.yml +4 -0
- data/CHANGELOG.md +5 -0
- data/CONTRIBUITING.md +40 -0
- data/README.md +106 -1
- data/citrix.gemspec +5 -0
- data/lib/citrix.rb +1 -0
- data/lib/citrix/training.rb +22 -0
- data/lib/citrix/training/client.rb +38 -0
- data/lib/citrix/training/credentials.rb +27 -0
- data/lib/citrix/training/helpers/http_client.rb +33 -0
- data/lib/citrix/training/helpers/initializer.rb +13 -0
- data/lib/citrix/training/namespace/registrants.rb +107 -0
- data/lib/citrix/training/namespace/trainings.rb +91 -0
- data/lib/citrix/training/resource/registrant.rb +60 -0
- data/lib/citrix/training/resource/training.rb +67 -0
- data/lib/citrix/training/resource/training_date.rb +25 -0
- data/lib/citrix/training/serializer/registrant.rb +32 -0
- data/lib/citrix/training/serializer/training.rb +49 -0
- data/lib/citrix/training/serializer/training_date.rb +19 -0
- data/lib/citrix/version.rb +1 -1
- data/spec/citrix/training/client_spec.rb +22 -0
- data/spec/citrix/training/credentials_spec.rb +31 -0
- data/spec/citrix/training/helpers/http_client_spec.rb +54 -0
- data/spec/citrix/training/helpers/initializer_spec.rb +15 -0
- data/spec/citrix/training/namespace/registrants_spec.rb +94 -0
- data/spec/citrix/training/namespace/trainings_spec.rb +85 -0
- data/spec/citrix/training/resource/registrant_spec.rb +11 -0
- data/spec/citrix/training/resource/training_spec.rb +11 -0
- data/spec/citrix/training/serializer/registrant_spec.rb +50 -0
- data/spec/citrix/training/serializer/training_date_spec.rb +21 -0
- data/spec/citrix/training/serializer/training_spec.rb +79 -0
- data/spec/fixtures/register.json +5 -0
- data/spec/fixtures/registrant.json +10 -0
- data/spec/fixtures/registrants.json +31 -0
- data/spec/fixtures/training.json +24 -0
- data/spec/fixtures/trainings.json +26 -0
- data/spec/spec_helper.rb +94 -0
- metadata +103 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5a06b3c6f0dc327a0bcbcd906dd5348a55dd998
|
4
|
+
data.tar.gz: 32d47b27842f60d00284619696f908da9df02e9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3406b08706191fde2506c2fd55d95fcb59111627ea91031fa82190b59a44a5a1a7b776a43a8f27edcdda47eb0188378e937b4ba560876012d6b1079d90e2204f
|
7
|
+
data.tar.gz: a42202ff1e877baea7d5da52558eaf54184da3524d595865f12e197a14d3c019415c69a119137544256461e7a8de0afbb476a7e1ef860a5826d10c13b863671c
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/CONTRIBUITING.md
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
## Issues
|
4
|
+
|
5
|
+
If you want to request a feature or report a bug, please use the following template.
|
6
|
+
|
7
|
+
```markdown
|
8
|
+
## Description
|
9
|
+
|
10
|
+
[Add feature/bug description here]
|
11
|
+
|
12
|
+
## How to reproduce
|
13
|
+
|
14
|
+
[Add steps on how to reproduce this issue]
|
15
|
+
|
16
|
+
## What do you expect
|
17
|
+
|
18
|
+
[Describe what do you expect to happen]
|
19
|
+
|
20
|
+
## What happened instead
|
21
|
+
|
22
|
+
[Describe the actual results]
|
23
|
+
|
24
|
+
## Gem version:
|
25
|
+
|
26
|
+
Citrix version: [Add citrix gem version here]
|
27
|
+
```
|
28
|
+
|
29
|
+
## Writing code
|
30
|
+
|
31
|
+
Once you've made your great commits (include tests, please):
|
32
|
+
|
33
|
+
1. [Fork](http://help.github.com/forking/) citrix
|
34
|
+
2. Create a topic branch - `git checkout -b my_branch`
|
35
|
+
3. Push to your branch - `git push origin my_branch`
|
36
|
+
4. [Create an Issue](http://github.com/fnando/citrix/issues) with a link to your branch
|
37
|
+
5. That's it!
|
38
|
+
|
39
|
+
Please respect the indentation rules and code style.
|
40
|
+
And don't touch the versioning thing.
|
data/README.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Citrix
|
2
2
|
|
3
|
+
[](https://travis-ci.org/fnando/citrix)
|
4
|
+
[](https://codeclimate.com/github/fnando/citrix)
|
5
|
+
[](https://codeclimate.com/github/fnando/citrix)
|
6
|
+
|
7
|
+
API wrappers for Citrix services like GoToTraining. It includes partial API mapping for GoToTraining.
|
8
|
+
|
3
9
|
## Installation
|
4
10
|
|
5
11
|
Add this line to your application's Gemfile:
|
@@ -16,7 +22,106 @@ Or install it yourself as:
|
|
16
22
|
|
17
23
|
## Usage
|
18
24
|
|
19
|
-
|
25
|
+
### GoToTraining
|
26
|
+
|
27
|
+
#### Create client
|
28
|
+
|
29
|
+
Initialize a client with provided credentials.
|
30
|
+
The credentials must be a instance of or
|
31
|
+
a Hash accepted by `Citrix::Training::Credentials`.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
client = Citrix::Training::Client.build(
|
35
|
+
oauth_token: ENV.fetch('CITRIX_OAUTH_TOKEN'),
|
36
|
+
organizer_key: ENV.fetch('CITRIX_ORGANIZER_KEY'),
|
37
|
+
account_key: ENV.fetch('CITRIX_ACCOUNT_KEY')
|
38
|
+
)
|
39
|
+
```
|
40
|
+
|
41
|
+
#### Create training
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
response, training = client.trainings.create({
|
45
|
+
name: 'Ruby on Rails',
|
46
|
+
description: 'Getting started with Ruby on Rails',
|
47
|
+
timezone: 'America/Sao_Paulo',
|
48
|
+
dates: [date],
|
49
|
+
web_registration: false,
|
50
|
+
confirmation_email: false,
|
51
|
+
organizers: [organizer]
|
52
|
+
})
|
53
|
+
|
54
|
+
if response.ok?
|
55
|
+
# Training successfully created!
|
56
|
+
else
|
57
|
+
p response.json
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
#### Get all trainings
|
62
|
+
|
63
|
+
Retrieve information on all scheduled trainings for a given organizer.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
response, trainings = client.trainings.all
|
67
|
+
|
68
|
+
if trainings
|
69
|
+
# Retrieved all trainings
|
70
|
+
else
|
71
|
+
p response.json
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
#### Remove a training
|
76
|
+
|
77
|
+
Deletes a scheduled or completed training.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
response = client.trainings.remove(training)
|
81
|
+
response.ok? #=> successfully removed
|
82
|
+
```
|
83
|
+
|
84
|
+
#### Add registrant
|
85
|
+
|
86
|
+
Register one person, identified by a unique email address, for a training.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
response, registrant = client.registrants(training).create({
|
90
|
+
first_name: 'John',
|
91
|
+
last_name: 'Doe',
|
92
|
+
email: 'john@example.com'
|
93
|
+
})
|
94
|
+
|
95
|
+
if response.ok?
|
96
|
+
# Do something with registrant
|
97
|
+
else
|
98
|
+
p response.json
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
#### Get all registrants
|
103
|
+
|
104
|
+
Retrieve details on all registrants for a specific training.
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
response, registrants = client.registrants(training).all
|
108
|
+
|
109
|
+
if response.ok?
|
110
|
+
# Do something with registrants
|
111
|
+
else
|
112
|
+
p response.json
|
113
|
+
end
|
114
|
+
```
|
115
|
+
|
116
|
+
#### Remove registrant
|
117
|
+
|
118
|
+
This call cancels a registration in a scheduled training for a
|
119
|
+
specific registrant.
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
response = client.registrants(training).remove(registrant)
|
123
|
+
response.ok? #=> successfully removed
|
124
|
+
```
|
20
125
|
|
21
126
|
## Contributing
|
22
127
|
|
data/citrix.gemspec
CHANGED
@@ -15,7 +15,12 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
16
|
spec.require_paths = ['lib']
|
17
17
|
|
18
|
+
spec.add_dependency 'aitch'
|
19
|
+
|
18
20
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
19
21
|
spec.add_development_dependency 'rake'
|
20
22
|
spec.add_development_dependency 'rspec'
|
23
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
24
|
+
spec.add_development_dependency 'webmock'
|
25
|
+
spec.add_development_dependency 'pry-meta'
|
21
26
|
end
|
data/lib/citrix.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
require 'aitch'
|
4
|
+
|
5
|
+
require 'citrix/training/helpers/initializer'
|
6
|
+
require 'citrix/training/helpers/http_client'
|
7
|
+
require 'citrix/training/credentials'
|
8
|
+
require 'citrix/training/client'
|
9
|
+
require 'citrix/training/namespace/trainings'
|
10
|
+
require 'citrix/training/namespace/registrants'
|
11
|
+
require 'citrix/training/resource/training'
|
12
|
+
require 'citrix/training/resource/registrant'
|
13
|
+
require 'citrix/training/serializer/training'
|
14
|
+
require 'citrix/training/serializer/registrant'
|
15
|
+
require 'citrix/training/resource/training_date'
|
16
|
+
require 'citrix/training/serializer/training_date'
|
17
|
+
|
18
|
+
module Citrix
|
19
|
+
module Training
|
20
|
+
API_ENDPOINT = 'https://api.citrixonline.com/G2T/rest'
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Citrix
|
2
|
+
module Training
|
3
|
+
class Client
|
4
|
+
include Helpers::Initializer
|
5
|
+
|
6
|
+
# Set credentials.
|
7
|
+
attr_accessor :credentials
|
8
|
+
|
9
|
+
# Initialize a client with provided credentials.
|
10
|
+
# The credentials must be a instance of or
|
11
|
+
# a Hash accepted by `Citrix::Training::Credentials`.
|
12
|
+
#
|
13
|
+
# client = Citrix::Training::Client.build(
|
14
|
+
# oauth_token: ENV.fetch('CITRIX_OAUTH_TOKEN'),
|
15
|
+
# organizer_key: ENV.fetch('CITRIX_ORGANIZER_KEY'),
|
16
|
+
# account_key: ENV.fetch('CITRIX_ACCOUNT_KEY')
|
17
|
+
# )
|
18
|
+
#
|
19
|
+
def self.build(credentials)
|
20
|
+
new(credentials: Credentials.build(credentials))
|
21
|
+
end
|
22
|
+
|
23
|
+
# Return the training namespace, which include methods for creating and
|
24
|
+
# finding trainings. For additional info, check
|
25
|
+
# `Citrix::Training::Namespace::Trainings`.
|
26
|
+
def trainings
|
27
|
+
Namespace::Trainings.new(credentials: credentials)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Return the registrants namespace, which include methods for creating
|
31
|
+
# registrants. It requires an existing training.
|
32
|
+
# For additional info, check `Citrix::Training::Namespace::Registrants`.
|
33
|
+
def registrants(training)
|
34
|
+
Namespace::Registrants.new(credentials: credentials, training: training)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Citrix
|
2
|
+
module Training
|
3
|
+
class Credentials
|
4
|
+
include Helpers::Initializer
|
5
|
+
|
6
|
+
# Set the OAuth token.
|
7
|
+
# You can use the [Omniauth::Citrix](http://github.com/fnando/omniauth-citrix)
|
8
|
+
# for OAuth2 authentication on Rack-based applications.
|
9
|
+
attr_accessor :oauth_token
|
10
|
+
|
11
|
+
# Set the organizer key.
|
12
|
+
attr_accessor :organizer_key
|
13
|
+
|
14
|
+
# Set the account key.
|
15
|
+
attr_accessor :account_key
|
16
|
+
|
17
|
+
# Initialize a `Citrix::Training::Credentials` instance.
|
18
|
+
def self.build(credentials)
|
19
|
+
if credentials.kind_of?(self)
|
20
|
+
credentials
|
21
|
+
else
|
22
|
+
new(credentials)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Citrix
|
2
|
+
module Training
|
3
|
+
module Helpers
|
4
|
+
module HttpClient
|
5
|
+
def json_parser
|
6
|
+
http_client.configuration.json_parser
|
7
|
+
end
|
8
|
+
|
9
|
+
def url_for(*args)
|
10
|
+
File.join(API_ENDPOINT, *args.map(&:to_s))
|
11
|
+
end
|
12
|
+
|
13
|
+
def http_client
|
14
|
+
@http_client ||= Aitch::Namespace.new.tap do |ns|
|
15
|
+
ns.configure do |config|
|
16
|
+
if $DEBUG
|
17
|
+
require 'logger'
|
18
|
+
config.logger = Logger.new($stdout)
|
19
|
+
end
|
20
|
+
|
21
|
+
config.user_agent = "Citrix::Rubygems/#{Citrix::VERSION}"
|
22
|
+
config.default_headers = {
|
23
|
+
'Authorization' => -> { "OAuth oauth_token=#{credentials.oauth_token}" },
|
24
|
+
'Accept' => 'application/json',
|
25
|
+
'Content-Type' => 'application/json'
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module Citrix
|
2
|
+
module Training
|
3
|
+
module Namespace
|
4
|
+
class Registrants
|
5
|
+
include Helpers::Initializer
|
6
|
+
include Helpers::HttpClient
|
7
|
+
|
8
|
+
# Set the credentials.
|
9
|
+
attr_accessor :credentials
|
10
|
+
|
11
|
+
# Set the training.
|
12
|
+
attr_accessor :training
|
13
|
+
|
14
|
+
# Register one person, identified by a unique email address, for a training.
|
15
|
+
#
|
16
|
+
# Approval is automatic unless payment or approval is required. The
|
17
|
+
# response contains the Confirmation page URL and Join URL for the
|
18
|
+
# registrant.
|
19
|
+
#
|
20
|
+
# NOTE: If some registrants do not receive a confirmation email, the
|
21
|
+
# emails could be getting blocked by their email server due to spam
|
22
|
+
# filtering or a grey-listing setting.
|
23
|
+
#
|
24
|
+
# response, registrant = client.registrants(training).create({
|
25
|
+
# first_name: 'John',
|
26
|
+
# last_name: 'Doe',
|
27
|
+
# email: 'john@example.com'
|
28
|
+
# })
|
29
|
+
#
|
30
|
+
# if response.ok?
|
31
|
+
# # Do something with registrant
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# Options:
|
35
|
+
#
|
36
|
+
# - `first_name`: First name of user. Required.
|
37
|
+
# - `last_name`: Last name of user. Required.
|
38
|
+
# - `email`: Email of registrant. Required.
|
39
|
+
#
|
40
|
+
# Endpoint: https://developer.citrixonline.com/api/gototraining-rest-api/apimethod/register-training-0
|
41
|
+
#
|
42
|
+
def create(attributes)
|
43
|
+
registrant = Resource::Registrant.new(attributes)
|
44
|
+
|
45
|
+
url = url_for('organizers', credentials.organizer_key, 'trainings', training.key, 'registrants')
|
46
|
+
response = http_client.post(url, registrant.serialize)
|
47
|
+
|
48
|
+
if response.ok?
|
49
|
+
additional_attributes = Serializer::Registrant.new(attributes: response.json).deserialize
|
50
|
+
additional_attributes.each do |key, value|
|
51
|
+
registrant.public_send("#{key}=", value) if value
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
[response, registrant]
|
56
|
+
end
|
57
|
+
|
58
|
+
# Retrieve details on all registrants for a specific training.
|
59
|
+
#
|
60
|
+
# Registrants can be:
|
61
|
+
#
|
62
|
+
# - UNREGISTERED: registrant withdrew their registration but didn't
|
63
|
+
# opt-out of receiving more training or webinar information
|
64
|
+
# - DELETED: registrant withdrew their registration and opted-out of
|
65
|
+
# receiving more information about the training or webinar
|
66
|
+
# - WAITING: registrant registered and is awaiting approval (where
|
67
|
+
# organizer has required approval)
|
68
|
+
# - APPROVED: registrant registered and is approved
|
69
|
+
# - DENIED - registrant registered and was not approved.
|
70
|
+
#
|
71
|
+
# IMPORTANT: The registrant data caches are typically updated
|
72
|
+
# immediately and the data will be returned in the response. However,
|
73
|
+
# the update can take as long as two hours.
|
74
|
+
#
|
75
|
+
# Endpoint: https://developer.citrixonline.com/api/gototraining-rest-api/apimethod/get-training-registrants-0
|
76
|
+
#
|
77
|
+
def all
|
78
|
+
url = url_for('organizers', credentials.organizer_key, 'trainings', training.key, 'registrants')
|
79
|
+
response = http_client.get(url)
|
80
|
+
|
81
|
+
if response.ok?
|
82
|
+
registrants = response.json.map do |attrs|
|
83
|
+
Resource::Registrant.new Resource::Registrant.deserialize(attrs)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
[response, registrants]
|
88
|
+
end
|
89
|
+
|
90
|
+
# This call cancels a registration in a scheduled training for a
|
91
|
+
# specific registrant.
|
92
|
+
#
|
93
|
+
# If the registrant has paid for the training, a cancellation cannot be
|
94
|
+
# completed with this method; it must be completed on the Citrix
|
95
|
+
# external admin site. No notification is sent to the registrant or
|
96
|
+
# the organizer by default. The registrant can re-register if needed.
|
97
|
+
#
|
98
|
+
# Endpoint: https://developer.citrixonline.com/api/gototraining-rest-api/apimethod/cancel-registration-0
|
99
|
+
#
|
100
|
+
def remove(registrant)
|
101
|
+
url = url_for('organizers', credentials.organizer_key, 'trainings', training.key, 'registrants', registrant.key)
|
102
|
+
http_client.delete(url)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|