citrix 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +12 -4
- data/CHANGELOG.md +8 -0
- data/README.md +5 -5
- data/Rakefile +7 -4
- data/citrix.gemspec +17 -15
- data/lib/citrix.rb +2 -2
- data/lib/citrix/training.rb +15 -15
- data/lib/citrix/training/helpers/http_client.rb +5 -5
- data/lib/citrix/training/namespace/registrants.rb +8 -8
- data/lib/citrix/training/namespace/trainings.rb +9 -9
- data/lib/citrix/training/serializer/registrant.rb +7 -7
- data/lib/citrix/training/serializer/training.rb +9 -9
- data/lib/citrix/version.rb +1 -1
- data/test/citrix/training/client_test.rb +18 -0
- data/test/citrix/training/credentials_test.rb +27 -0
- data/test/citrix/training/helpers/http_client_test.rb +45 -0
- data/test/citrix/training/helpers/initializer_test.rb +15 -0
- data/test/citrix/training/namespace/registrants_test.rb +95 -0
- data/test/citrix/training/namespace/trainings_test.rb +111 -0
- data/test/citrix/training/resource/registrant_test.rb +23 -0
- data/test/citrix/training/resource/training_test.rb +25 -0
- data/test/citrix/training/serializer/registrant_test.rb +53 -0
- data/test/citrix/training/serializer/training_date_test.rb +21 -0
- data/test/citrix/training/serializer/training_test.rb +82 -0
- data/{spec → test}/fixtures/register.json +0 -0
- data/{spec → test}/fixtures/registrant.json +1 -1
- data/{spec → test}/fixtures/registrants.json +0 -0
- data/{spec → test}/fixtures/training.json +0 -0
- data/{spec → test}/fixtures/trainings.json +0 -0
- data/{spec/spec_helper.rb → test/test_helper.rb} +24 -37
- metadata +67 -40
- data/.rspec +0 -1
- data/spec/citrix/training/client_spec.rb +0 -22
- data/spec/citrix/training/credentials_spec.rb +0 -31
- data/spec/citrix/training/helpers/http_client_spec.rb +0 -54
- data/spec/citrix/training/helpers/initializer_spec.rb +0 -15
- data/spec/citrix/training/namespace/registrants_spec.rb +0 -94
- data/spec/citrix/training/namespace/trainings_spec.rb +0 -109
- data/spec/citrix/training/resource/registrant_spec.rb +0 -11
- data/spec/citrix/training/resource/training_spec.rb +0 -11
- data/spec/citrix/training/serializer/registrant_spec.rb +0 -50
- data/spec/citrix/training/serializer/training_date_spec.rb +0 -21
- data/spec/citrix/training/serializer/training_spec.rb +0 -79
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7109ce3e2498799d2c4da324d633c8ba0e72fd01
|
4
|
+
data.tar.gz: 996f1d6711209f2ed53f3c618cb24ddfe0bfeb40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4ad01c7ba733da8aa9a42e9c9c34f773df5952475cb05ac364528ac2f57761654725a1fa0ba8c9aa74b906fe5130e00e9921055e225d0e447380256cda2d31f
|
7
|
+
data.tar.gz: 296844f93c20d33c323bb7635dba14b79da3c5cd3ed8a28a5c925be6c1453e9cb0c442bc2758757c9982815113a16743b474d84cebde22a00a99a915bcfbf650
|
data/.travis.yml
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
language: ruby
|
2
|
-
script: bundle exec
|
3
|
-
|
2
|
+
script: bundle exec rake
|
3
|
+
sudo: false
|
4
|
+
cache: bundler
|
4
5
|
rvm:
|
5
|
-
- 2.
|
6
|
+
- '2.3.0'
|
7
|
+
- '2.2'
|
8
|
+
- '2.1'
|
9
|
+
- '2.0'
|
6
10
|
|
7
11
|
gemfile:
|
8
12
|
- Gemfile
|
9
13
|
|
14
|
+
notifications:
|
15
|
+
email: false
|
16
|
+
|
10
17
|
addons:
|
11
18
|
code_climate:
|
12
|
-
repo_token:
|
19
|
+
repo_token:
|
20
|
+
secure: "MJuQnvBt4+7QucNh3YWIur3AcDMsIEaIaEkT+tWbE/153lLdyNWP78hBZFN5Ktbq156O05cop6jeXxL8skHJsBaCedx1Qp/agDwO4CX4Ia7pQh9WN4ouYGFkFvrEc4h0hDbo8fgO0lZcZg6PCTMItBXJxqF3URH+zzfvGDOOi9w="
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -56,7 +56,7 @@ response, training = client.trainings.create({
|
|
56
56
|
if response.ok?
|
57
57
|
# Training successfully created!
|
58
58
|
else
|
59
|
-
p response.
|
59
|
+
p response.data
|
60
60
|
end
|
61
61
|
```
|
62
62
|
|
@@ -70,7 +70,7 @@ response, trainings = client.trainings.all
|
|
70
70
|
if trainings
|
71
71
|
# Retrieved all trainings
|
72
72
|
else
|
73
|
-
p response.
|
73
|
+
p response.data
|
74
74
|
end
|
75
75
|
```
|
76
76
|
|
@@ -84,7 +84,7 @@ response, training = client.trainings.find(training_key)
|
|
84
84
|
if training
|
85
85
|
# Do something with training
|
86
86
|
else
|
87
|
-
p response.
|
87
|
+
p response.data
|
88
88
|
end
|
89
89
|
```
|
90
90
|
|
@@ -111,7 +111,7 @@ response, registrant = client.registrants(training).create({
|
|
111
111
|
if response.ok?
|
112
112
|
# Do something with registrant
|
113
113
|
else
|
114
|
-
p response.
|
114
|
+
p response.data
|
115
115
|
end
|
116
116
|
```
|
117
117
|
|
@@ -125,7 +125,7 @@ response, registrants = client.registrants(training).all
|
|
125
125
|
if response.ok?
|
126
126
|
# Do something with registrants
|
127
127
|
else
|
128
|
-
p response.
|
128
|
+
p response.data
|
129
129
|
end
|
130
130
|
```
|
131
131
|
|
data/Rakefile
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
-
require "
|
2
|
+
require "rake/testtask"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
7
|
+
t.warning = false
|
8
|
+
end
|
7
9
|
|
10
|
+
task default: :test
|
data/citrix.gemspec
CHANGED
@@ -1,26 +1,28 @@
|
|
1
|
-
require
|
1
|
+
require "./lib/citrix/version"
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name =
|
4
|
+
spec.name = "citrix"
|
5
5
|
spec.version = Citrix::VERSION
|
6
|
-
spec.authors = [
|
7
|
-
spec.email = [
|
8
|
-
spec.summary =
|
6
|
+
spec.authors = ["Nando Vieira"]
|
7
|
+
spec.email = ["fnando.vieira@gmail.com"]
|
8
|
+
spec.summary = "API wrappers for Citrix services like GoToTraining."
|
9
9
|
spec.description = spec.summary
|
10
|
-
spec.homepage =
|
11
|
-
spec.license =
|
10
|
+
spec.homepage = "https://github.com/fnando/citrix"
|
11
|
+
spec.license = "MIT"
|
12
12
|
|
13
13
|
spec.files = `git ls-files -z`.split("\x0")
|
14
14
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
15
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
-
spec.require_paths = [
|
16
|
+
spec.require_paths = ["lib"]
|
17
17
|
|
18
|
-
spec.add_dependency
|
18
|
+
spec.add_dependency "aitch", ">= 1.0.1"
|
19
19
|
|
20
|
-
spec.add_development_dependency
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
spec.add_development_dependency "minitest-utils"
|
24
|
+
spec.add_development_dependency "mocha"
|
25
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
26
|
+
spec.add_development_dependency "webmock"
|
27
|
+
spec.add_development_dependency "pry-meta"
|
26
28
|
end
|
data/lib/citrix.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "citrix/version"
|
2
|
+
require "citrix/training"
|
data/lib/citrix/training.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require
|
1
|
+
require "time"
|
2
2
|
|
3
|
-
require
|
3
|
+
require "aitch"
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
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
17
|
|
18
18
|
module Citrix
|
19
19
|
module Training
|
20
|
-
API_ENDPOINT =
|
20
|
+
API_ENDPOINT = "https://api.citrixonline.com/G2T/rest".freeze
|
21
21
|
end
|
22
22
|
end
|
@@ -3,7 +3,7 @@ module Citrix
|
|
3
3
|
module Helpers
|
4
4
|
module HttpClient
|
5
5
|
def json_parser
|
6
|
-
|
6
|
+
Aitch::ResponseParser::JSONParser.engine
|
7
7
|
end
|
8
8
|
|
9
9
|
def url_for(*args)
|
@@ -14,15 +14,15 @@ module Citrix
|
|
14
14
|
@http_client ||= Aitch::Namespace.new.tap do |ns|
|
15
15
|
ns.configure do |config|
|
16
16
|
if $DEBUG
|
17
|
-
require
|
17
|
+
require "logger"
|
18
18
|
config.logger = Logger.new($stdout)
|
19
19
|
end
|
20
20
|
|
21
21
|
config.user_agent = "Citrix::Rubygems/#{Citrix::VERSION}"
|
22
22
|
config.default_headers = {
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
"Authorization" => -> { "OAuth oauth_token=#{credentials.oauth_token}" },
|
24
|
+
"Accept" => "application/json",
|
25
|
+
"Content-Type" => "application/json"
|
26
26
|
}
|
27
27
|
end
|
28
28
|
end
|
@@ -22,9 +22,9 @@ module Citrix
|
|
22
22
|
# filtering or a grey-listing setting.
|
23
23
|
#
|
24
24
|
# response, registrant = client.registrants(training).create({
|
25
|
-
# first_name:
|
26
|
-
# last_name:
|
27
|
-
# email:
|
25
|
+
# first_name: "John",
|
26
|
+
# last_name: "Doe",
|
27
|
+
# email: "john@example.com"
|
28
28
|
# })
|
29
29
|
#
|
30
30
|
# if response.ok?
|
@@ -42,11 +42,11 @@ module Citrix
|
|
42
42
|
def create(attributes)
|
43
43
|
registrant = Resource::Registrant.new(attributes)
|
44
44
|
|
45
|
-
url = url_for(
|
45
|
+
url = url_for("organizers", credentials.organizer_key, "trainings", training.key, "registrants")
|
46
46
|
response = http_client.post(url, registrant.serialize)
|
47
47
|
|
48
48
|
if response.ok?
|
49
|
-
additional_attributes = Serializer::Registrant.new(attributes: response.
|
49
|
+
additional_attributes = Serializer::Registrant.new(attributes: response.data).deserialize
|
50
50
|
additional_attributes.each do |key, value|
|
51
51
|
registrant.public_send("#{key}=", value) if value
|
52
52
|
end
|
@@ -75,11 +75,11 @@ module Citrix
|
|
75
75
|
# Endpoint: https://developer.citrixonline.com/api/gototraining-rest-api/apimethod/get-training-registrants-0
|
76
76
|
#
|
77
77
|
def all
|
78
|
-
url = url_for(
|
78
|
+
url = url_for("organizers", credentials.organizer_key, "trainings", training.key, "registrants")
|
79
79
|
response = http_client.get(url)
|
80
80
|
|
81
81
|
if response.ok?
|
82
|
-
registrants = response.
|
82
|
+
registrants = response.data.map do |attrs|
|
83
83
|
Resource::Registrant.new Resource::Registrant.deserialize(attrs)
|
84
84
|
end
|
85
85
|
end
|
@@ -98,7 +98,7 @@ module Citrix
|
|
98
98
|
# Endpoint: https://developer.citrixonline.com/api/gototraining-rest-api/apimethod/cancel-registration-0
|
99
99
|
#
|
100
100
|
def remove(registrant)
|
101
|
-
url = url_for(
|
101
|
+
url = url_for("organizers", credentials.organizer_key, "trainings", training.key, "registrants", registrant.key)
|
102
102
|
http_client.delete(url)
|
103
103
|
end
|
104
104
|
end
|
@@ -11,9 +11,9 @@ module Citrix
|
|
11
11
|
# Create a new training.
|
12
12
|
#
|
13
13
|
# response, training = client.trainings.create({
|
14
|
-
# name:
|
15
|
-
# description:
|
16
|
-
# timezone:
|
14
|
+
# name: "Ruby on Rails",
|
15
|
+
# description: "Getting started with Ruby on Rails",
|
16
|
+
# timezone: "America/Sao_Paulo",
|
17
17
|
# dates: [date],
|
18
18
|
# web_registration: false,
|
19
19
|
# confirmation_email: false,
|
@@ -39,7 +39,7 @@ module Citrix
|
|
39
39
|
def create(attributes)
|
40
40
|
training = Resource::Training.new(attributes)
|
41
41
|
|
42
|
-
url = url_for(
|
42
|
+
url = url_for("organizers", credentials.organizer_key, "trainings")
|
43
43
|
response = http_client.post(url, training.serialize)
|
44
44
|
|
45
45
|
training.key = json_parser.load(response.body) if response.ok?
|
@@ -57,11 +57,11 @@ module Citrix
|
|
57
57
|
# Endpoint: https://developer.citrixonline.com/api/gototraining-rest-api/apimethod/get-trainings
|
58
58
|
#
|
59
59
|
def all
|
60
|
-
url = url_for(
|
60
|
+
url = url_for("organizers", credentials.organizer_key, "trainings")
|
61
61
|
response = http_client.get(url)
|
62
62
|
|
63
63
|
if response.ok?
|
64
|
-
trainings = response.
|
64
|
+
trainings = response.data.map do |attrs|
|
65
65
|
Resource::Training.new Resource::Training.deserialize(attrs)
|
66
66
|
end
|
67
67
|
end
|
@@ -71,11 +71,11 @@ module Citrix
|
|
71
71
|
|
72
72
|
# Find a scheduled or completed training by its key.
|
73
73
|
def find(key)
|
74
|
-
url = url_for(
|
74
|
+
url = url_for("organizers", credentials.organizer_key, "trainings", key)
|
75
75
|
response = http_client.get(url)
|
76
76
|
|
77
77
|
if response.ok?
|
78
|
-
training = Resource::Training.new Resource::Training.deserialize(response.
|
78
|
+
training = Resource::Training.new Resource::Training.deserialize(response.data)
|
79
79
|
end
|
80
80
|
|
81
81
|
[response, training]
|
@@ -94,7 +94,7 @@ module Citrix
|
|
94
94
|
# response.ok? #=> successfully removed
|
95
95
|
#
|
96
96
|
def remove(training)
|
97
|
-
url = url_for(
|
97
|
+
url = url_for("organizers", credentials.organizer_key, "trainings", training.key)
|
98
98
|
http_client.delete(url)
|
99
99
|
end
|
100
100
|
end
|
@@ -17,13 +17,13 @@ module Citrix
|
|
17
17
|
|
18
18
|
def deserialize
|
19
19
|
{
|
20
|
-
first_name: attributes[
|
21
|
-
last_name: attributes[
|
22
|
-
email: attributes[
|
23
|
-
join_url: attributes[
|
24
|
-
confirmation_url: attributes[
|
25
|
-
key: attributes[
|
26
|
-
status: attributes[
|
20
|
+
first_name: attributes["givenName"],
|
21
|
+
last_name: attributes["surname"],
|
22
|
+
email: attributes["email"],
|
23
|
+
join_url: attributes["joinUrl"],
|
24
|
+
confirmation_url: attributes["confirmationUrl"],
|
25
|
+
key: attributes["registrantKey"],
|
26
|
+
status: attributes["status"] ? attributes["status"].downcase : nil
|
27
27
|
}
|
28
28
|
end
|
29
29
|
end
|
@@ -23,13 +23,13 @@ module Citrix
|
|
23
23
|
|
24
24
|
def deserialize
|
25
25
|
{
|
26
|
-
key: attributes[
|
27
|
-
name: attributes[
|
28
|
-
description: attributes[
|
29
|
-
timezone: attributes[
|
30
|
-
dates: deserialize_dates(attributes[
|
31
|
-
web_registration: !attributes[
|
32
|
-
confirmation_email: !attributes[
|
26
|
+
key: attributes["trainingKey"],
|
27
|
+
name: attributes["name"],
|
28
|
+
description: attributes["description"],
|
29
|
+
timezone: attributes["timeZone"],
|
30
|
+
dates: deserialize_dates(attributes["times"] || []),
|
31
|
+
web_registration: !attributes["registrationSettings"]["disableWebRegistration"],
|
32
|
+
confirmation_email: !attributes["registrationSettings"]["disableConfirmationEmail"]
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
@@ -38,8 +38,8 @@ module Citrix
|
|
38
38
|
def deserialize_dates(dates)
|
39
39
|
dates.map do |date|
|
40
40
|
Resource::TrainingDate.new(
|
41
|
-
Time.parse(date[
|
42
|
-
Time.parse(date[
|
41
|
+
Time.parse(date["startDate"]),
|
42
|
+
Time.parse(date["endDate"])
|
43
43
|
)
|
44
44
|
end
|
45
45
|
end
|
data/lib/citrix/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ClientTest < Minitest::Test
|
4
|
+
test "returns client" do
|
5
|
+
client = Citrix::Training::Client.build({})
|
6
|
+
assert_kind_of Citrix::Training::Client, client
|
7
|
+
end
|
8
|
+
|
9
|
+
test "sets credentials" do
|
10
|
+
client = Citrix::Training::Client.build({})
|
11
|
+
assert_kind_of Citrix::Training::Credentials, client.credentials
|
12
|
+
end
|
13
|
+
|
14
|
+
test "returns namespace" do
|
15
|
+
client = Citrix::Training::Client.build({})
|
16
|
+
assert_kind_of Citrix::Training::Namespace::Trainings, client.trainings
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CredentialsTest < Minitest::Test
|
4
|
+
test "initializes credentials" do
|
5
|
+
credentials = Citrix::Training::Credentials.new(
|
6
|
+
oauth_token: "OAUTH_TOKEN",
|
7
|
+
organizer_key: "ORGANIZER_KEY",
|
8
|
+
account_key: "ACCOUNT_KEY"
|
9
|
+
)
|
10
|
+
|
11
|
+
assert_equal "OAUTH_TOKEN", credentials.oauth_token
|
12
|
+
assert_equal "ORGANIZER_KEY", credentials.organizer_key
|
13
|
+
assert_equal "ACCOUNT_KEY", credentials.account_key
|
14
|
+
end
|
15
|
+
|
16
|
+
test "builds a new instance" do
|
17
|
+
credentials = Citrix::Training::Credentials.build({})
|
18
|
+
assert_kind_of Citrix::Training::Credentials, credentials
|
19
|
+
end
|
20
|
+
|
21
|
+
test "builds a new credentials instance" do
|
22
|
+
credentials = Citrix::Training::Credentials.new
|
23
|
+
new_credentials = Citrix::Training::Credentials.build(credentials)
|
24
|
+
|
25
|
+
assert_equal credentials, new_credentials
|
26
|
+
end
|
27
|
+
end
|