citrix 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -0
  3. data/CHANGELOG.md +5 -0
  4. data/CONTRIBUITING.md +40 -0
  5. data/README.md +106 -1
  6. data/citrix.gemspec +5 -0
  7. data/lib/citrix.rb +1 -0
  8. data/lib/citrix/training.rb +22 -0
  9. data/lib/citrix/training/client.rb +38 -0
  10. data/lib/citrix/training/credentials.rb +27 -0
  11. data/lib/citrix/training/helpers/http_client.rb +33 -0
  12. data/lib/citrix/training/helpers/initializer.rb +13 -0
  13. data/lib/citrix/training/namespace/registrants.rb +107 -0
  14. data/lib/citrix/training/namespace/trainings.rb +91 -0
  15. data/lib/citrix/training/resource/registrant.rb +60 -0
  16. data/lib/citrix/training/resource/training.rb +67 -0
  17. data/lib/citrix/training/resource/training_date.rb +25 -0
  18. data/lib/citrix/training/serializer/registrant.rb +32 -0
  19. data/lib/citrix/training/serializer/training.rb +49 -0
  20. data/lib/citrix/training/serializer/training_date.rb +19 -0
  21. data/lib/citrix/version.rb +1 -1
  22. data/spec/citrix/training/client_spec.rb +22 -0
  23. data/spec/citrix/training/credentials_spec.rb +31 -0
  24. data/spec/citrix/training/helpers/http_client_spec.rb +54 -0
  25. data/spec/citrix/training/helpers/initializer_spec.rb +15 -0
  26. data/spec/citrix/training/namespace/registrants_spec.rb +94 -0
  27. data/spec/citrix/training/namespace/trainings_spec.rb +85 -0
  28. data/spec/citrix/training/resource/registrant_spec.rb +11 -0
  29. data/spec/citrix/training/resource/training_spec.rb +11 -0
  30. data/spec/citrix/training/serializer/registrant_spec.rb +50 -0
  31. data/spec/citrix/training/serializer/training_date_spec.rb +21 -0
  32. data/spec/citrix/training/serializer/training_spec.rb +79 -0
  33. data/spec/fixtures/register.json +5 -0
  34. data/spec/fixtures/registrant.json +10 -0
  35. data/spec/fixtures/registrants.json +31 -0
  36. data/spec/fixtures/training.json +24 -0
  37. data/spec/fixtures/trainings.json +26 -0
  38. data/spec/spec_helper.rb +94 -0
  39. metadata +103 -2
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Citrix::Training::Helpers::Initializer do
4
+ it 'assigns properties' do
5
+ klass = Class.new do
6
+ include Citrix::Training::Helpers::Initializer
7
+ attr_accessor :name, :email
8
+ end
9
+
10
+ instance = klass.new(name: 'John', email: 'john@example.com')
11
+
12
+ expect(instance.name).to eq('John')
13
+ expect(instance.email).to eq('john@example.com')
14
+ end
15
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe Citrix::Training::Namespace::Registrants do
4
+ describe '#create' do
5
+ let(:client) { build_client }
6
+ let(:training) { build_training }
7
+
8
+ it 'performs request' do
9
+ stub_request(:post, /.+/).to_return(
10
+ body: '{}',
11
+ headers: {'Content-Type' => 'application/json'}
12
+ )
13
+
14
+ url = url_for('organizers', client.credentials.organizer_key, 'trainings', training.key, 'registrants')
15
+ attrs = build_registrant_attributes
16
+ serialized_attrs = serialize(attrs, Citrix::Training::Serializer::Registrant)
17
+ client.registrants(training).create(attrs)
18
+
19
+ expect(last_request.method).to eq(:post)
20
+ expect(last_request.uri.normalize.to_s).to eq(url)
21
+ expect(last_request.body).to eq(JSON.dump(serialized_attrs))
22
+ end
23
+
24
+ it 'updates registrant with additional attributes' do
25
+ attrs = JSON.load(fixtures.join('register.json').read)
26
+
27
+ stub_request(:post, /.+/).to_return(
28
+ body: JSON.dump(attrs),
29
+ headers: {'Content-Type' => 'application/json'}
30
+ )
31
+
32
+ response, registrant = client.registrants(training).create({first_name: 'John'})
33
+
34
+ expect(registrant.first_name).to eq('John')
35
+ expect(registrant.join_url).to eq(attrs['joinUrl'])
36
+ expect(registrant.confirmation_url).to eq(attrs['confirmationUrl'])
37
+ expect(registrant.key).to eq(attrs['registrantKey'])
38
+ end
39
+ end
40
+
41
+ describe '#all' do
42
+ let(:client) { build_client }
43
+ let(:training) { build_training }
44
+
45
+ it 'performs request' do
46
+ stub_request(:get, /.+/).to_return(
47
+ body: '[]',
48
+ headers: {'Content-Type' => 'application/json'}
49
+ )
50
+
51
+ url = url_for('organizers', client.credentials.organizer_key, 'trainings', training.key, 'registrants')
52
+ client.registrants(training).all
53
+
54
+ expect(last_request.method).to eq(:get)
55
+ expect(last_request.uri.normalize.to_s).to eq(url)
56
+ end
57
+
58
+ it 'returns registrants' do
59
+ stub_request(:get, /.+/).to_return(
60
+ status: 200,
61
+ body: fixtures.join('registrants.json').read,
62
+ headers: {'Content-Type' => 'application/json'}
63
+ )
64
+
65
+ response, registrants = client.registrants(training).all
66
+
67
+ expect(registrants.size).to eq(3)
68
+ expect(registrants.first).to be_a(Citrix::Training::Resource::Registrant)
69
+ end
70
+ end
71
+
72
+ describe '#remove' do
73
+ let(:client) { build_client }
74
+ let(:training) { build_training }
75
+ let(:registrant) { build_registrant }
76
+
77
+ it 'performs request' do
78
+ stub_request(:delete, /.+/)
79
+
80
+ url = url_for('organizers', client.credentials.organizer_key, 'trainings', training.key, 'registrants', registrant.key)
81
+ client.registrants(training).remove(registrant)
82
+
83
+ expect(last_request.method).to eq(:delete)
84
+ expect(last_request.uri.normalize.to_s).to eq(url)
85
+ end
86
+
87
+ it 'returns response' do
88
+ stub_request(:delete, /.+/)
89
+ response = client.registrants(training).remove(registrant)
90
+
91
+ expect(response).to be_a(Aitch::Response)
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe Citrix::Training::Namespace::Trainings do
4
+ describe '#create' do
5
+ let(:client) { build_client }
6
+
7
+ it 'performs request' do
8
+ stub_request(:post, /.+/)
9
+
10
+ url = url_for('organizers', client.credentials.organizer_key, 'trainings')
11
+ attrs = build_training_attributes
12
+ serialized_attrs = serialize(attrs, Citrix::Training::Serializer::Training)
13
+ client.trainings.create(attrs)
14
+
15
+ expect(last_request.method).to eq(:post)
16
+ expect(last_request.uri.normalize.to_s).to eq(url)
17
+ expect(last_request.body).to eq(JSON.dump(serialized_attrs))
18
+ end
19
+
20
+ it 'returns response' do
21
+ stub_request(:post, /.+/)
22
+ response, training = client.trainings.create({})
23
+ expect(response).to be_a(Aitch::Response)
24
+ end
25
+
26
+ it 'returns training instance' do
27
+ stub_request(:post, /.+/)
28
+ response, training = client.trainings.create({})
29
+ expect(training).to be_a(Citrix::Training::Resource::Training)
30
+ end
31
+
32
+ it 'sets training key' do
33
+ stub_request(:post, /.+/).to_return(body: '"1234"', status: 201)
34
+ response, training = client.trainings.create({})
35
+ expect(training.key).to eq('1234')
36
+ end
37
+ end
38
+
39
+ describe '#all' do
40
+ let(:client) { build_client }
41
+
42
+ it 'performs request' do
43
+ stub_request(:get, /.+/).to_return(body: '[]', headers: {'Content-Type' => 'application/json'})
44
+
45
+ url = url_for('organizers', client.credentials.organizer_key, 'trainings')
46
+ client.trainings.all
47
+
48
+ expect(last_request.method).to eq(:get)
49
+ expect(last_request.uri.normalize.to_s).to eq(url)
50
+ end
51
+
52
+ it 'returns trainings' do
53
+ stub_request(:get, /.+/)
54
+ .to_return(status: 200, body: fixtures.join('trainings.json').read, headers: {'Content-Type' => 'application/json'})
55
+
56
+ response, trainings = client.trainings.all
57
+
58
+ expect(trainings.size).to eq(1)
59
+ expect(trainings.first).to be_a(Citrix::Training::Resource::Training)
60
+ end
61
+ end
62
+
63
+ describe '#remove' do
64
+ let(:client) { build_client }
65
+
66
+ it 'performs request' do
67
+ stub_request(:delete, /.+/)
68
+
69
+ training = build_training
70
+ url = url_for('organizers', client.credentials.organizer_key, 'trainings', training.key)
71
+ client.trainings.remove(training)
72
+
73
+ expect(last_request.method).to eq(:delete)
74
+ expect(last_request.uri.normalize.to_s).to eq(url)
75
+ end
76
+
77
+ it 'returns response' do
78
+ stub_request(:delete, /.+/)
79
+ training = build_training
80
+ response = client.trainings.remove(training)
81
+
82
+ expect(response).to be_a(Aitch::Response)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Citrix::Training::Resource::Registrant do
4
+ let(:attributes) {
5
+ JSON.load(fixtures.join('registrant.json').read)
6
+ }
7
+
8
+ it 'loads all attributes' do
9
+ described_class.new described_class.deserialize(attributes)
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Citrix::Training::Resource::Training do
4
+ let(:attributes) {
5
+ JSON.load(fixtures.join('training.json').read)
6
+ }
7
+
8
+ it 'loads all attributes' do
9
+ described_class.new described_class.deserialize(attributes)
10
+ end
11
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Citrix::Training::Serializer::Registrant do
4
+ describe '#serialize' do
5
+ it 'returns first name' do
6
+ expect(serialize(first_name: 'NAME')).to include(givenName: 'NAME')
7
+ end
8
+
9
+ it 'returns last name' do
10
+ expect(serialize(last_name: 'NAME')).to include(surname: 'NAME')
11
+ end
12
+
13
+ it 'returns email' do
14
+ expect(serialize(email: 'EMAIL')).to include(email: 'EMAIL')
15
+ end
16
+ end
17
+
18
+ describe '#deserialize' do
19
+ let(:raw_attrs) { JSON.load(fixtures.join('registrant.json').read) }
20
+ let(:attrs) { deserialize(raw_attrs) }
21
+
22
+ it 'returns first name' do
23
+ expect(attrs).to include(first_name: raw_attrs['givenName'])
24
+ end
25
+
26
+ it 'returns last name' do
27
+ expect(attrs).to include(last_name: raw_attrs['surname'])
28
+ end
29
+
30
+ it 'returns email' do
31
+ expect(attrs).to include(email: raw_attrs['email'])
32
+ end
33
+
34
+ it 'returns join url' do
35
+ expect(attrs).to include(join_url: raw_attrs['joinUrl'])
36
+ end
37
+
38
+ it 'returns confirmation url' do
39
+ expect(attrs).to include(confirmation_url: raw_attrs['confirmationUrl'])
40
+ end
41
+
42
+ it 'returns registrant key' do
43
+ expect(attrs).to include(key: raw_attrs['registrantKey'])
44
+ end
45
+
46
+ it 'returns status' do
47
+ expect(attrs).to include(status: raw_attrs['status'].downcase)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Citrix::Training::Serializer::TrainingDate do
4
+ describe '#serialize' do
5
+ it 'returns starting date' do
6
+ starting = Time.now
7
+ ending = starting + 3600
8
+ params = serialize(starts_at: starting, ends_at: ending)
9
+
10
+ expect(params).to include(startDate: starting.iso8601)
11
+ end
12
+
13
+ it 'returns ending date' do
14
+ starting = Time.now
15
+ ending = starting + 3600
16
+ params = serialize(starts_at: starting, ends_at: ending)
17
+
18
+ expect(params).to include(endDate: ending.iso8601)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Citrix::Training::Serializer::Training do
4
+ describe '#serialize' do
5
+ it 'returns name' do
6
+ expect(serialize(name: 'NAME')).to include(name: 'NAME')
7
+ end
8
+
9
+ it 'returns description' do
10
+ expect(serialize(description: 'DESCRIPTION')).to include(description: 'DESCRIPTION')
11
+ end
12
+
13
+ it 'returns time zone' do
14
+ expect(serialize(timezone: 'TZ')).to include(timeZone: 'TZ')
15
+ end
16
+
17
+ it 'returns registration settings (web registration)' do
18
+ params = serialize(web_registration: true)
19
+ expect(params[:registrationSettings]).to include(disableWebRegistration: false)
20
+ end
21
+
22
+ it 'returns registration settings (confirmation email)' do
23
+ params = serialize(confirmation_email: true)
24
+ expect(params[:registrationSettings]).to include(disableConfirmationEmail: false)
25
+ end
26
+
27
+ it 'returns dates' do
28
+ date = Citrix::Training::Resource::TrainingDate.new(Time.now, Time.now + 3600)
29
+ params = serialize(dates: [date])
30
+
31
+ expect(params[:times].size).to eq(1)
32
+ expect(params[:times].first).to include(startDate: date.starts_at.iso8601)
33
+ expect(params[:times].first).to include(endDate: date.ends_at.iso8601)
34
+ end
35
+ end
36
+
37
+ describe '#deserialize' do
38
+ let(:attrs) {
39
+ JSON.load(fixtures.join('training.json').read)
40
+ }
41
+
42
+ it 'returns name' do
43
+ expect(deserialize(attrs)).to include(name: attrs['name'])
44
+ end
45
+
46
+ it 'returns description' do
47
+ expect(deserialize(attrs)).to include(description: attrs['description'])
48
+ end
49
+
50
+ it 'returns time zone' do
51
+ expect(deserialize(attrs)).to include(timezone: attrs['timeZone'])
52
+ end
53
+
54
+ it 'returns key' do
55
+ expect(deserialize(attrs)).to include(key: attrs['trainingKey'])
56
+ end
57
+
58
+ it 'returns dates' do
59
+ params = deserialize(attrs)
60
+
61
+ starts_at = Time.parse(attrs['times'][0]['startDate'])
62
+ ends_at = Time.parse(attrs['times'][0]['endDate'])
63
+
64
+ expect(params[:dates].size).to eq(1)
65
+ expect(params[:dates].first.starts_at.to_i).to eq(starts_at.to_i)
66
+ expect(params[:dates].first.ends_at.to_i).to eq(ends_at.to_i)
67
+ end
68
+
69
+ it 'returns web registration' do
70
+ params = deserialize(attrs)
71
+ expect(params).to include(web_registration: true)
72
+ end
73
+
74
+ it 'returns confirmation e-mail' do
75
+ params = deserialize(attrs)
76
+ expect(params).to include(confirmation_email: true)
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,5 @@
1
+ {
2
+ "joinUrl": "https://global.gototraining.com/join/training/3480581380460709633/107019724",
3
+ "confirmationUrl": "https://attendee.gototraining.com/registration/confirmation.tmpl?registrant=2121396992126760705&training=3480581380460709633",
4
+ "registrantKey": 2121396992126760705
5
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "email": " c.waters@test.com ",
3
+ "givenName": "Charley",
4
+ "surname": "Waters",
5
+ "status": "APPROVED",
6
+ "registrationDate": "2014-03-07T22:48:19Z",
7
+ "joinUrl": "https://global.gototraining.com/join/training/3480581380460709633/107445004",
8
+ "confirmationUrl": "https://attendee.gototraining.com/registration/confirmation.tmpl?registrant=5646167387902096129&training=3480581380460709633",
9
+ "registrantKey": "5646167387902096129"
10
+ }
@@ -0,0 +1,31 @@
1
+ [
2
+ {
3
+ "email": " c.waters@test.com ",
4
+ "givenName": "Charley",
5
+ "surname": "Waters",
6
+ "status": "APPROVED",
7
+ "registrationDate": "2014-03-07T22:48:19Z",
8
+ "joinUrl": "https://global.gototraining.com/join/training/3480581380460709633/107445004",
9
+ "confirmationUrl": "https://attendee.gototraining.com/registration/confirmation.tmpl?registrant=5646167387902096129&training=3480581380460709633",
10
+ "registrantKey": "5646167387902096129"
11
+ },
12
+ {
13
+ "email": "john.smith@test.com",
14
+ "givenName": "John",
15
+ "surname": "Smith",
16
+ "status": "UNREGISTERED",
17
+ "registrationDate": "2014-03-08T13:21:52Z",
18
+ "joinUrl": "https://global.gototraining.com/join/training/3480581380460709633/107019724",
19
+ "confirmationUrl": "https://attendee.gototraining.com/registration/confirmation.tmpl?registrant=2121396992126760705&training=3480581380460709633",
20
+ "registrantKey": "2121396992126760705"
21
+ },
22
+ {
23
+ "email": "jane.jones@test.com",
24
+ "givenName": "Jane",
25
+ "surname": "Jones",
26
+ "registrationDate": "2014-03-07T18:13:31Z",
27
+ "joinUrl": "https://global.gototraining.com/join/training/3480581380460709633/107245649",
28
+ "confirmationUrl": "https://attendee.gototraining.com/registration/confirmation.tmpl?registrant=5012777222131839489&training=3480581380460709633",
29
+ "registrantKey": "5012777222131839489"
30
+ }
31
+ ]
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "Intro to HTML, CSS and JavaScript",
3
+ "description": "Create basic webpages and sites using HTML 5, CSS3 and basic JavaScript.",
4
+ "timeZone": "America/New_York",
5
+ "times": [
6
+ {
7
+ "startDate": "2014-03-26T15:00:00Z",
8
+ "endDate": "2014-03-26T23:00:00Z"
9
+ }
10
+ ],
11
+ "organizers": [
12
+ {
13
+ "givenName": "Charley",
14
+ "surname": "Waters",
15
+ "email": "c.waters@test.com",
16
+ "organizerKey": "8439885694023994630"
17
+ }
18
+ ],
19
+ "registrationSettings": {
20
+ "disableConfirmationEmail": false,
21
+ "disableWebRegistration": false
22
+ },
23
+ "trainingKey": "8178251407424893697"
24
+ }