citrix 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +12 -4
  3. data/CHANGELOG.md +8 -0
  4. data/README.md +5 -5
  5. data/Rakefile +7 -4
  6. data/citrix.gemspec +17 -15
  7. data/lib/citrix.rb +2 -2
  8. data/lib/citrix/training.rb +15 -15
  9. data/lib/citrix/training/helpers/http_client.rb +5 -5
  10. data/lib/citrix/training/namespace/registrants.rb +8 -8
  11. data/lib/citrix/training/namespace/trainings.rb +9 -9
  12. data/lib/citrix/training/serializer/registrant.rb +7 -7
  13. data/lib/citrix/training/serializer/training.rb +9 -9
  14. data/lib/citrix/version.rb +1 -1
  15. data/test/citrix/training/client_test.rb +18 -0
  16. data/test/citrix/training/credentials_test.rb +27 -0
  17. data/test/citrix/training/helpers/http_client_test.rb +45 -0
  18. data/test/citrix/training/helpers/initializer_test.rb +15 -0
  19. data/test/citrix/training/namespace/registrants_test.rb +95 -0
  20. data/test/citrix/training/namespace/trainings_test.rb +111 -0
  21. data/test/citrix/training/resource/registrant_test.rb +23 -0
  22. data/test/citrix/training/resource/training_test.rb +25 -0
  23. data/test/citrix/training/serializer/registrant_test.rb +53 -0
  24. data/test/citrix/training/serializer/training_date_test.rb +21 -0
  25. data/test/citrix/training/serializer/training_test.rb +82 -0
  26. data/{spec → test}/fixtures/register.json +0 -0
  27. data/{spec → test}/fixtures/registrant.json +1 -1
  28. data/{spec → test}/fixtures/registrants.json +0 -0
  29. data/{spec → test}/fixtures/training.json +0 -0
  30. data/{spec → test}/fixtures/trainings.json +0 -0
  31. data/{spec/spec_helper.rb → test/test_helper.rb} +24 -37
  32. metadata +67 -40
  33. data/.rspec +0 -1
  34. data/spec/citrix/training/client_spec.rb +0 -22
  35. data/spec/citrix/training/credentials_spec.rb +0 -31
  36. data/spec/citrix/training/helpers/http_client_spec.rb +0 -54
  37. data/spec/citrix/training/helpers/initializer_spec.rb +0 -15
  38. data/spec/citrix/training/namespace/registrants_spec.rb +0 -94
  39. data/spec/citrix/training/namespace/trainings_spec.rb +0 -109
  40. data/spec/citrix/training/resource/registrant_spec.rb +0 -11
  41. data/spec/citrix/training/resource/training_spec.rb +0 -11
  42. data/spec/citrix/training/serializer/registrant_spec.rb +0 -50
  43. data/spec/citrix/training/serializer/training_date_spec.rb +0 -21
  44. 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: 202698e1982c4eef3b771e757d37ce8f4e759b3e
4
- data.tar.gz: a9feb13e4be7315947e8842af036a2f992ab8fbc
3
+ metadata.gz: 7109ce3e2498799d2c4da324d633c8ba0e72fd01
4
+ data.tar.gz: 996f1d6711209f2ed53f3c618cb24ddfe0bfeb40
5
5
  SHA512:
6
- metadata.gz: 0d682457accf3034894bc1927a46ea7262af587f796c78bf1b8d7999e406332984b22429b609941603e1dfc108b59a03a3a10d3c82a822b7ee2df48cf88c4035
7
- data.tar.gz: 8baf578f08483877dec153cdd70f0da6293bfc671e5d05266d25e77f6d4988ed41b6ef36fefed9fd99bcd64a8cc67fc5ecdea060a209f729aee570ccba6ff7e6
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 rspec
3
-
2
+ script: bundle exec rake
3
+ sudo: false
4
+ cache: bundler
4
5
  rvm:
5
- - 2.1.5
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: 36d1b2992ebb12fef1167de97f900d332f01e75f0b2bc90b3159621585a9ed1e
19
+ repo_token:
20
+ secure: "MJuQnvBt4+7QucNh3YWIur3AcDMsIEaIaEkT+tWbE/153lLdyNWP78hBZFN5Ktbq156O05cop6jeXxL8skHJsBaCedx1Qp/agDwO4CX4Ia7pQh9WN4ouYGFkFvrEc4h0hDbo8fgO0lZcZg6PCTMItBXJxqF3URH+zzfvGDOOi9w="
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.2.1
4
+
5
+ - Depend on specific version of Aitch.
6
+
7
+ ## v0.2.0
8
+
9
+ - Add method to find training by its key.
10
+
3
11
  ## v0.1.0
4
12
 
5
13
  - Initial release
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.json
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.json
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.json
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.json
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.json
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 "rspec/core/rake_task"
2
+ require "rake/testtask"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
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 './lib/citrix/version'
1
+ require "./lib/citrix/version"
2
2
 
3
3
  Gem::Specification.new do |spec|
4
- spec.name = 'citrix'
4
+ spec.name = "citrix"
5
5
  spec.version = Citrix::VERSION
6
- spec.authors = ['Nando Vieira']
7
- spec.email = ['fnando.vieira@gmail.com']
8
- spec.summary = 'API wrappers for Citrix services like GoToTraining.'
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 = 'https://github.com/fnando/citrix'
11
- spec.license = 'MIT'
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 = ['lib']
16
+ spec.require_paths = ["lib"]
17
17
 
18
- spec.add_dependency 'aitch'
18
+ spec.add_dependency "aitch", ">= 1.0.1"
19
19
 
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 'codeclimate-test-reporter'
24
- spec.add_development_dependency 'webmock'
25
- spec.add_development_dependency 'pry-meta'
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 'citrix/version'
2
- require 'citrix/training'
1
+ require "citrix/version"
2
+ require "citrix/training"
@@ -1,22 +1,22 @@
1
- require 'time'
1
+ require "time"
2
2
 
3
- require 'aitch'
3
+ require "aitch"
4
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'
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 = 'https://api.citrixonline.com/G2T/rest'
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
- http_client.configuration.json_parser
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 'logger'
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
- 'Authorization' => -> { "OAuth oauth_token=#{credentials.oauth_token}" },
24
- 'Accept' => 'application/json',
25
- 'Content-Type' => 'application/json'
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: 'John',
26
- # last_name: 'Doe',
27
- # email: 'john@example.com'
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('organizers', credentials.organizer_key, 'trainings', training.key, 'registrants')
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.json).deserialize
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('organizers', credentials.organizer_key, 'trainings', training.key, 'registrants')
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.json.map do |attrs|
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('organizers', credentials.organizer_key, 'trainings', training.key, 'registrants', registrant.key)
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: 'Ruby on Rails',
15
- # description: 'Getting started with Ruby on Rails',
16
- # timezone: 'America/Sao_Paulo',
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('organizers', credentials.organizer_key, 'trainings')
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('organizers', credentials.organizer_key, 'trainings')
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.json.map do |attrs|
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('organizers', credentials.organizer_key, 'trainings', key)
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.json)
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('organizers', credentials.organizer_key, 'trainings', training.key)
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['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
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['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']
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['startDate']),
42
- Time.parse(date['endDate'])
41
+ Time.parse(date["startDate"]),
42
+ Time.parse(date["endDate"])
43
43
  )
44
44
  end
45
45
  end
@@ -1,3 +1,3 @@
1
1
  module Citrix
2
- VERSION = '0.2.0'
2
+ VERSION = "0.2.1"
3
3
  end
@@ -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