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
File without changes
@@ -1,5 +1,5 @@
1
1
  {
2
- "email": " c.waters@test.com ",
2
+ "email": "c.waters@test.com",
3
3
  "givenName": "Charley",
4
4
  "surname": "Waters",
5
5
  "status": "APPROVED",
File without changes
File without changes
File without changes
@@ -1,43 +1,30 @@
1
- require 'codeclimate-test-reporter'
1
+ require "codeclimate-test-reporter"
2
2
  CodeClimate::TestReporter.start
3
3
 
4
- require 'bundler/setup'
5
- require 'citrix'
6
- require 'webmock/rspec'
4
+ require "bundler/setup"
5
+ require "citrix"
7
6
 
8
- require 'ostruct'
9
- require 'pathname'
7
+ require "ostruct"
8
+ require "pathname"
10
9
 
11
- WebMock.disable_net_connect!(allow: %w{codeclimate.com})
10
+ require "minitest/utils"
11
+ require "minitest/autorun"
12
12
 
13
- def WebMock.requests
14
- @requests ||= []
15
- end
16
-
17
- WebMock.after_request do |request, response|
18
- WebMock.requests << request
19
- end
20
-
21
- RSpec.configure do |config|
22
- config.before do
23
- WebMock.requests.clear
24
- $DEBUG = false
25
- end
26
-
27
- config.include Module.new {
28
- def serialize(attributes, serializer = described_class)
13
+ module Minitest
14
+ class Test
15
+ def serialize(attributes)
29
16
  serializer.new(attributes: attributes).serialize
30
17
  end
31
18
 
32
- def deserialize(attributes, serializer = described_class)
19
+ def deserialize(attributes)
33
20
  serializer.new(attributes: attributes).deserialize
34
21
  end
35
22
 
36
23
  def build_credentials(credentials = {})
37
24
  Citrix::Training::Credentials.build({
38
- oauth_token: credentials.fetch(:oauth_token, 'OAUTH_TOKEN'),
39
- organizer_key: credentials.fetch(:organizer_key, 'ORGANIZER_KEY'),
40
- account_key: credentials.fetch(:account_key, 'ACCOUNT_KEY')
25
+ oauth_token: credentials.fetch(:oauth_token, "OAUTH_TOKEN"),
26
+ organizer_key: credentials.fetch(:organizer_key, "ORGANIZER_KEY"),
27
+ account_key: credentials.fetch(:account_key, "ACCOUNT_KEY")
41
28
  })
42
29
  end
43
30
 
@@ -47,9 +34,9 @@ RSpec.configure do |config|
47
34
 
48
35
  def build_training_attributes(attributes = {})
49
36
  {
50
- name: 'NAME',
51
- description: 'DESCRIPTION',
52
- timezone: 'TIMEZONE',
37
+ name: "NAME",
38
+ description: "DESCRIPTION",
39
+ timezone: "TIMEZONE",
53
40
  web_registration: false,
54
41
  confirmation_email: false,
55
42
  organizers: [],
@@ -63,21 +50,21 @@ RSpec.configure do |config|
63
50
 
64
51
  def build_training(attributes = {})
65
52
  Citrix::Training::Resource::Training.new(
66
- build_training_attributes.merge(key: '1234').merge(attributes)
53
+ build_training_attributes.merge(key: "1234").merge(attributes)
67
54
  )
68
55
  end
69
56
 
70
57
  def build_registrant_attributes(attributes = {})
71
58
  {
72
- first_name: 'John',
73
- last_name: 'Doe',
74
- email: 'john@example.com'
59
+ first_name: "John",
60
+ last_name: "Doe",
61
+ email: "john@example.com"
75
62
  }.merge(attributes)
76
63
  end
77
64
 
78
65
  def build_registrant(attributes = {})
79
66
  Citrix::Training::Resource::Registrant.new(
80
- build_registrant_attributes.merge(key: '1234').merge(attributes)
67
+ build_registrant_attributes.merge(key: "1234").merge(attributes)
81
68
  )
82
69
  end
83
70
 
@@ -90,7 +77,7 @@ RSpec.configure do |config|
90
77
  end
91
78
 
92
79
  def fixtures
93
- Pathname.new(File.expand_path('../fixtures', __FILE__))
80
+ Pathname.new(File.expand_path("../fixtures", __FILE__))
94
81
  end
95
- }
82
+ end
96
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: citrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-16 00:00:00.000000000 Z
11
+ date: 2016-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aitch
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.0.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-utils
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: codeclimate-test-reporter
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -116,7 +144,6 @@ extensions: []
116
144
  extra_rdoc_files: []
117
145
  files:
118
146
  - ".gitignore"
119
- - ".rspec"
120
147
  - ".travis.yml"
121
148
  - CHANGELOG.md
122
149
  - CONTRIBUTING.md
@@ -140,23 +167,23 @@ files:
140
167
  - lib/citrix/training/serializer/training.rb
141
168
  - lib/citrix/training/serializer/training_date.rb
142
169
  - lib/citrix/version.rb
143
- - spec/citrix/training/client_spec.rb
144
- - spec/citrix/training/credentials_spec.rb
145
- - spec/citrix/training/helpers/http_client_spec.rb
146
- - spec/citrix/training/helpers/initializer_spec.rb
147
- - spec/citrix/training/namespace/registrants_spec.rb
148
- - spec/citrix/training/namespace/trainings_spec.rb
149
- - spec/citrix/training/resource/registrant_spec.rb
150
- - spec/citrix/training/resource/training_spec.rb
151
- - spec/citrix/training/serializer/registrant_spec.rb
152
- - spec/citrix/training/serializer/training_date_spec.rb
153
- - spec/citrix/training/serializer/training_spec.rb
154
- - spec/fixtures/register.json
155
- - spec/fixtures/registrant.json
156
- - spec/fixtures/registrants.json
157
- - spec/fixtures/training.json
158
- - spec/fixtures/trainings.json
159
- - spec/spec_helper.rb
170
+ - test/citrix/training/client_test.rb
171
+ - test/citrix/training/credentials_test.rb
172
+ - test/citrix/training/helpers/http_client_test.rb
173
+ - test/citrix/training/helpers/initializer_test.rb
174
+ - test/citrix/training/namespace/registrants_test.rb
175
+ - test/citrix/training/namespace/trainings_test.rb
176
+ - test/citrix/training/resource/registrant_test.rb
177
+ - test/citrix/training/resource/training_test.rb
178
+ - test/citrix/training/serializer/registrant_test.rb
179
+ - test/citrix/training/serializer/training_date_test.rb
180
+ - test/citrix/training/serializer/training_test.rb
181
+ - test/fixtures/register.json
182
+ - test/fixtures/registrant.json
183
+ - test/fixtures/registrants.json
184
+ - test/fixtures/training.json
185
+ - test/fixtures/trainings.json
186
+ - test/test_helper.rb
160
187
  homepage: https://github.com/fnando/citrix
161
188
  licenses:
162
189
  - MIT
@@ -177,25 +204,25 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
204
  version: '0'
178
205
  requirements: []
179
206
  rubyforge_project:
180
- rubygems_version: 2.4.5
207
+ rubygems_version: 2.5.1
181
208
  signing_key:
182
209
  specification_version: 4
183
210
  summary: API wrappers for Citrix services like GoToTraining.
184
211
  test_files:
185
- - spec/citrix/training/client_spec.rb
186
- - spec/citrix/training/credentials_spec.rb
187
- - spec/citrix/training/helpers/http_client_spec.rb
188
- - spec/citrix/training/helpers/initializer_spec.rb
189
- - spec/citrix/training/namespace/registrants_spec.rb
190
- - spec/citrix/training/namespace/trainings_spec.rb
191
- - spec/citrix/training/resource/registrant_spec.rb
192
- - spec/citrix/training/resource/training_spec.rb
193
- - spec/citrix/training/serializer/registrant_spec.rb
194
- - spec/citrix/training/serializer/training_date_spec.rb
195
- - spec/citrix/training/serializer/training_spec.rb
196
- - spec/fixtures/register.json
197
- - spec/fixtures/registrant.json
198
- - spec/fixtures/registrants.json
199
- - spec/fixtures/training.json
200
- - spec/fixtures/trainings.json
201
- - spec/spec_helper.rb
212
+ - test/citrix/training/client_test.rb
213
+ - test/citrix/training/credentials_test.rb
214
+ - test/citrix/training/helpers/http_client_test.rb
215
+ - test/citrix/training/helpers/initializer_test.rb
216
+ - test/citrix/training/namespace/registrants_test.rb
217
+ - test/citrix/training/namespace/trainings_test.rb
218
+ - test/citrix/training/resource/registrant_test.rb
219
+ - test/citrix/training/resource/training_test.rb
220
+ - test/citrix/training/serializer/registrant_test.rb
221
+ - test/citrix/training/serializer/training_date_test.rb
222
+ - test/citrix/training/serializer/training_test.rb
223
+ - test/fixtures/register.json
224
+ - test/fixtures/registrant.json
225
+ - test/fixtures/registrants.json
226
+ - test/fixtures/training.json
227
+ - test/fixtures/trainings.json
228
+ - test/test_helper.rb
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Citrix::Training::Client do
4
- describe '.build' do
5
- it 'returns client' do
6
- client = Citrix::Training::Client.build({})
7
- expect(client).to be_a(Citrix::Training::Client)
8
- end
9
-
10
- it 'sets credentials' do
11
- client = Citrix::Training::Client.build({})
12
- expect(client.credentials).to be_a(Citrix::Training::Credentials)
13
- end
14
- end
15
-
16
- describe '#trainings' do
17
- it 'returns namespace' do
18
- client = Citrix::Training::Client.build({})
19
- expect(client.trainings).to be_a(Citrix::Training::Namespace::Trainings)
20
- end
21
- end
22
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Citrix::Training::Credentials do
4
- describe '#initialize' do
5
- subject(:credentials) {
6
- Citrix::Training::Credentials.new(
7
- oauth_token: 'OAUTH_TOKEN',
8
- organizer_key: 'ORGANIZER_KEY',
9
- account_key: 'ACCOUNT_KEY'
10
- )
11
- }
12
-
13
- it { expect(credentials.oauth_token).to eq('OAUTH_TOKEN') }
14
- it { expect(credentials.organizer_key).to eq('ORGANIZER_KEY') }
15
- it { expect(credentials.account_key).to eq('ACCOUNT_KEY') }
16
- end
17
-
18
- describe '.build' do
19
- it 'returns new instance' do
20
- credentials = Citrix::Training::Credentials.build({})
21
- expect(credentials).to be_a(Citrix::Training::Credentials)
22
- end
23
-
24
- it 'returns credentials' do
25
- credentials = Citrix::Training::Credentials.new
26
- new_credentials = Citrix::Training::Credentials.build(credentials)
27
-
28
- expect(new_credentials).to eq(credentials)
29
- end
30
- end
31
- end
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Citrix::Training::Helpers::HttpClient do
4
- let(:helper) { Object.new.extend(described_class) }
5
-
6
- describe '#json_parser' do
7
- it 'returns parser' do
8
- expect(helper.json_parser).to eq(helper.http_client.configuration.json_parser)
9
- end
10
- end
11
-
12
- describe '#url_for' do
13
- it 'returns url' do
14
- url = helper.url_for('trainings', 1234)
15
- expect(url).to eq(File.join(Citrix::Training::API_ENDPOINT, 'trainings', '1234'))
16
- end
17
- end
18
-
19
- describe '#http_client' do
20
- let(:config) { helper.http_client.configuration }
21
-
22
- it 'enabled debug mode' do
23
- $DEBUG = true
24
- expect(config.logger).to be_a(Logger)
25
- end
26
-
27
- it 'skips debug mode' do
28
- $DEBUG = false
29
- expect(config.logger).to be_falsy
30
- end
31
-
32
- it 'sets user agent' do
33
- expect(config.user_agent).to eq("Citrix::Rubygems/#{Citrix::VERSION}")
34
- end
35
-
36
- context 'default headers' do
37
- it 'sets content type' do
38
- expect(config.default_headers['Content-Type']).to eq('application/json')
39
- end
40
-
41
- it 'sets accept' do
42
- expect(config.default_headers['Accept']).to eq('application/json')
43
- end
44
-
45
- it 'sets authorization' do
46
- credentials = double(oauth_token: 'OAUTH_TOKEN')
47
- allow(helper).to receive(:credentials).and_return(credentials)
48
- auth_header = config.default_headers['Authorization'].call
49
-
50
- expect(auth_header).to eq('OAuth oauth_token=OAUTH_TOKEN')
51
- end
52
- end
53
- end
54
- end
@@ -1,15 +0,0 @@
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
@@ -1,94 +0,0 @@
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