wowzer 0.0.4 → 0.0.5

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.
Files changed (35) hide show
  1. data/fixtures/vcr_cassettes/application.yml +99 -0
  2. data/fixtures/vcr_cassettes/application_response.yml +99 -0
  3. data/fixtures/vcr_cassettes/candidate.yml +100 -0
  4. data/fixtures/vcr_cassettes/create_application.yml +249 -0
  5. data/fixtures/vcr_cassettes/create_notification.yml +97 -0
  6. data/fixtures/vcr_cassettes/delete_application.yml +143 -0
  7. data/fixtures/vcr_cassettes/delete_notification.yml +143 -0
  8. data/fixtures/vcr_cassettes/interview.yml +1 -1
  9. data/fixtures/vcr_cassettes/interview_applications.yml +204 -0
  10. data/fixtures/vcr_cassettes/interviews.yml +2 -2
  11. data/fixtures/vcr_cassettes/notification.yml +51 -0
  12. data/fixtures/vcr_cassettes/notifications.yml +99 -0
  13. data/fixtures/vcr_cassettes/resend_application.yml +143 -0
  14. data/fixtures/vcr_cassettes/resend_application_not_allowed.yml +99 -0
  15. data/fixtures/vcr_cassettes/update_notification.yml +47 -0
  16. data/lib/wowzer/application.rb +19 -13
  17. data/lib/wowzer/application_response.rb +32 -0
  18. data/lib/wowzer/candidate.rb +7 -0
  19. data/lib/wowzer/exception.rb +6 -0
  20. data/lib/wowzer/interview.rb +11 -15
  21. data/lib/wowzer/notification.rb +21 -0
  22. data/lib/wowzer/resource.rb +68 -0
  23. data/lib/wowzer/version.rb +1 -1
  24. data/lib/wowzer.rb +6 -1
  25. data/spec/lib/wowzer/application_response_spec.rb +17 -0
  26. data/spec/lib/wowzer/application_spec.rb +54 -0
  27. data/spec/lib/wowzer/candidate_spec.rb +13 -0
  28. data/spec/lib/wowzer/interview_spec.rb +46 -10
  29. data/spec/lib/wowzer/notifications_spec.rb +88 -0
  30. data/spec/spec_helper.rb +2 -2
  31. data/wowzer.gemspec +2 -3
  32. metadata +30 -9
  33. data/Gemfile.lock +0 -139
  34. data/spec/internal/config/database.yml +0 -3
  35. data/spec/internal/db/wowzer_test.sqlite +0 -0
@@ -0,0 +1,99 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://foo.bar%40foobar.com:12345@api.wowzerapp.com/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept:
13
+ - application/json
14
+ User-Agent:
15
+ - Faraday v0.8.7
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Wed, 03 Apr 2013 12:20:03 GMT
25
+ Server:
26
+ - Apache/2.2.17 (Ubuntu)
27
+ Strict-Transport-Security:
28
+ - max-age=31536000
29
+ X-Ua-Compatible:
30
+ - IE=Edge,chrome=1
31
+ Etag:
32
+ - ! '"3c8cad57a3f3b92deec5b055735843aa"'
33
+ Cache-Control:
34
+ - must-revalidate, private, max-age=0
35
+ X-Rack-Cache:
36
+ - miss
37
+ Set-Cookie:
38
+ - _novia_secure_session=8be9fa148e807511f47c210e67b5ac49; domain=wowzerapp.com;
39
+ path=/; HttpOnly; secure
40
+ Status:
41
+ - '200'
42
+ Content-Length:
43
+ - '520'
44
+ Content-Type:
45
+ - application/json; charset=utf-8
46
+ body:
47
+ encoding: US-ASCII
48
+ string: ! '{"_links":{"self":{"href":"https://api.wowzerapp.com"},"curie":{"name":"wowzer","templated":true,"href":"https://api.wowzerapp.com/docs/wowzer:{rel}"},"wowzer:interviews":{"href":"https://api.wowzerapp.com/hypermedia/interviews"},"wowzer:candidate":{"templated":true,"href":"https://api.wowzerapp.com/hypermedia/candidates{/id}"},"wowzer:application":{"templated":true,"href":"https://api.wowzerapp.com/hypermedia/applications{/id}"},"wowzer:notifications":{"href":"https://api.wowzerapp.com/hypermedia/notifications"}}}'
49
+ http_version: !!null
50
+ recorded_at: Wed, 03 Apr 2013 12:15:23 GMT
51
+ - request:
52
+ method: get
53
+ uri: https://foo.bar%40foobar.com:12345@api.wowzerapp.com/hypermedia/notifications
54
+ body:
55
+ encoding: US-ASCII
56
+ string: ''
57
+ headers:
58
+ Content-Type:
59
+ - application/json
60
+ Accept:
61
+ - application/json
62
+ User-Agent:
63
+ - Faraday v0.8.7
64
+ Accept-Encoding:
65
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
66
+ response:
67
+ status:
68
+ code: 200
69
+ message: OK
70
+ headers:
71
+ Date:
72
+ - Wed, 03 Apr 2013 12:20:04 GMT
73
+ Server:
74
+ - Apache/2.2.17 (Ubuntu)
75
+ Strict-Transport-Security:
76
+ - max-age=31536000
77
+ X-Ua-Compatible:
78
+ - IE=Edge,chrome=1
79
+ Etag:
80
+ - ! '"fe29d8341edc30e544bc29c90df82659"'
81
+ Cache-Control:
82
+ - must-revalidate, private, max-age=0
83
+ X-Rack-Cache:
84
+ - miss
85
+ Set-Cookie:
86
+ - _novia_secure_session=1e9d06fff2c34ac76d5cd1314ef33165; domain=wowzerapp.com;
87
+ path=/; HttpOnly; secure
88
+ Status:
89
+ - '200'
90
+ Content-Length:
91
+ - '397'
92
+ Content-Type:
93
+ - application/json; charset=utf-8
94
+ body:
95
+ encoding: US-ASCII
96
+ string: ! '{"_embedded":{"wowzer:notification":[{"id":"515c1d39572fc05e2306a170","username":"Bob","password":"Sinclair","callback_url":"https://sample.com/endpoint","target":"application_status","active":false,"_links":{"self":{"href":"https://api.wowzerapp.com/hypermedia/notifications/515c1d39572fc05e2306a170"}}}]},"count":1,"_links":{"self":{"href":"https://api.wowzerapp.com/hypermedia/notifications"}}}'
97
+ http_version: !!null
98
+ recorded_at: Wed, 03 Apr 2013 12:15:24 GMT
99
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,143 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://foo.bar%40foobar.com:12345@api.wowzerapp.com/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept:
13
+ - application/json
14
+ User-Agent:
15
+ - Faraday v0.8.7
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Fri, 05 Apr 2013 10:47:11 GMT
25
+ Server:
26
+ - Apache/2.2.17 (Ubuntu)
27
+ Strict-Transport-Security:
28
+ - max-age=31536000
29
+ X-Ua-Compatible:
30
+ - IE=Edge,chrome=1
31
+ Etag:
32
+ - ! '"3c8cad57a3f3b92deec5b055735843aa"'
33
+ Cache-Control:
34
+ - must-revalidate, private, max-age=0
35
+ X-Rack-Cache:
36
+ - miss
37
+ Set-Cookie:
38
+ - _novia_secure_session=ef5b821b5cb928e727f04f5c16bf41ee; domain=wowzerapp.com;
39
+ path=/; HttpOnly; secure
40
+ Status:
41
+ - '200'
42
+ Content-Length:
43
+ - '520'
44
+ Content-Type:
45
+ - application/json; charset=utf-8
46
+ body:
47
+ encoding: US-ASCII
48
+ string: ! '{"_links":{"self":{"href":"https://api.wowzerapp.com"},"curie":{"name":"wowzer","templated":true,"href":"https://api.wowzerapp.com/docs/wowzer:{rel}"},"wowzer:interviews":{"href":"https://api.wowzerapp.com/hypermedia/interviews"},"wowzer:candidate":{"templated":true,"href":"https://api.wowzerapp.com/hypermedia/candidates{/id}"},"wowzer:application":{"templated":true,"href":"https://api.wowzerapp.com/hypermedia/applications{/id}"},"wowzer:notifications":{"href":"https://api.wowzerapp.com/hypermedia/notifications"}}}'
49
+ http_version: !!null
50
+ recorded_at: Fri, 05 Apr 2013 10:44:32 GMT
51
+ - request:
52
+ method: get
53
+ uri: https://foo.bar%40foobar.com:12345@api.wowzerapp.com/hypermedia/applications/515d52d3572fc05e230a8328
54
+ body:
55
+ encoding: US-ASCII
56
+ string: ''
57
+ headers:
58
+ Content-Type:
59
+ - application/json
60
+ Accept:
61
+ - application/json
62
+ User-Agent:
63
+ - Faraday v0.8.7
64
+ Accept-Encoding:
65
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
66
+ response:
67
+ status:
68
+ code: 200
69
+ message: OK
70
+ headers:
71
+ Date:
72
+ - Fri, 05 Apr 2013 10:47:12 GMT
73
+ Server:
74
+ - Apache/2.2.17 (Ubuntu)
75
+ Strict-Transport-Security:
76
+ - max-age=31536000
77
+ X-Ua-Compatible:
78
+ - IE=Edge,chrome=1
79
+ Etag:
80
+ - ! '"6d224310c0d40af7064801686b8b971d"'
81
+ Cache-Control:
82
+ - must-revalidate, private, max-age=0
83
+ X-Rack-Cache:
84
+ - miss
85
+ Set-Cookie:
86
+ - _novia_secure_session=70ffa43d7a824864f24c12563c2ed328; domain=wowzerapp.com;
87
+ path=/; HttpOnly; secure
88
+ Status:
89
+ - '200'
90
+ Content-Length:
91
+ - '594'
92
+ Content-Type:
93
+ - application/json; charset=utf-8
94
+ body:
95
+ encoding: US-ASCII
96
+ string: ! '{"id":"515d52d3572fc05e230a8328","date_sent":"2013-04-05T10:36:24+00:00","date_updated":"2013-04-05T10:32:17Z","evaluation_status":"pending","status":"opened","_links":{"self":{"href":"https://api.wowzerapp.com/hypermedia/applications/515d52d3572fc05e230a8328"},"wowzer:interview":{"href":"https://api.wowzerapp.com/hypermedia/interviews/515d52a6572fc05e230a77a8"},"wowzer:candidate":{"href":"https://api.wowzerapp.com/hypermedia/candidates/515d52d3572fc05e230a8326"},"wowzer:application:invitation":{"href":"https://api.wowzerapp.com/hypermedia/applications/515d52d3572fc05e230a8328/resend"}}}'
97
+ http_version: !!null
98
+ recorded_at: Fri, 05 Apr 2013 10:44:33 GMT
99
+ - request:
100
+ method: post
101
+ uri: https://foo.bar%40foobar.com:12345@api.wowzerapp.com/hypermedia/applications/515d52d3572fc05e230a8328/resend
102
+ body:
103
+ encoding: UTF-8
104
+ string: ! '{}'
105
+ headers:
106
+ Content-Type:
107
+ - application/json
108
+ Accept:
109
+ - application/json
110
+ User-Agent:
111
+ - Faraday v0.8.7
112
+ response:
113
+ status:
114
+ code: 204
115
+ message: No Content
116
+ headers:
117
+ Date:
118
+ - Fri, 05 Apr 2013 10:47:13 GMT
119
+ Server:
120
+ - Apache/2.2.17 (Ubuntu)
121
+ Strict-Transport-Security:
122
+ - max-age=31536000
123
+ X-Ua-Compatible:
124
+ - IE=Edge,chrome=1
125
+ Cache-Control:
126
+ - no-cache
127
+ X-Rack-Cache:
128
+ - invalidate, pass
129
+ Set-Cookie:
130
+ - _novia_secure_session=2994328fa90159845abfcc3a5f5d58cc; domain=wowzerapp.com;
131
+ path=/; HttpOnly; secure
132
+ Status:
133
+ - '204'
134
+ Content-Length:
135
+ - '0'
136
+ Content-Type:
137
+ - text/plain
138
+ body:
139
+ encoding: US-ASCII
140
+ string: ''
141
+ http_version: !!null
142
+ recorded_at: Fri, 05 Apr 2013 10:44:35 GMT
143
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,99 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://foo.bar%40foobar.com:12345@api.wowzerapp.com/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept:
13
+ - application/json
14
+ User-Agent:
15
+ - Faraday v0.8.7
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Fri, 05 Apr 2013 10:12:15 GMT
25
+ Server:
26
+ - Apache/2.2.17 (Ubuntu)
27
+ Strict-Transport-Security:
28
+ - max-age=31536000
29
+ X-Ua-Compatible:
30
+ - IE=Edge,chrome=1
31
+ Etag:
32
+ - ! '"3c8cad57a3f3b92deec5b055735843aa"'
33
+ Cache-Control:
34
+ - must-revalidate, private, max-age=0
35
+ X-Rack-Cache:
36
+ - miss
37
+ Set-Cookie:
38
+ - _novia_secure_session=03d9840acdf48911f361cabbb3200009; domain=wowzerapp.com;
39
+ path=/; HttpOnly; secure
40
+ Status:
41
+ - '200'
42
+ Content-Length:
43
+ - '520'
44
+ Content-Type:
45
+ - application/json; charset=utf-8
46
+ body:
47
+ encoding: US-ASCII
48
+ string: ! '{"_links":{"self":{"href":"https://api.wowzerapp.com"},"curie":{"name":"wowzer","templated":true,"href":"https://api.wowzerapp.com/docs/wowzer:{rel}"},"wowzer:interviews":{"href":"https://api.wowzerapp.com/hypermedia/interviews"},"wowzer:candidate":{"templated":true,"href":"https://api.wowzerapp.com/hypermedia/candidates{/id}"},"wowzer:application":{"templated":true,"href":"https://api.wowzerapp.com/hypermedia/applications{/id}"},"wowzer:notifications":{"href":"https://api.wowzerapp.com/hypermedia/notifications"}}}'
49
+ http_version: !!null
50
+ recorded_at: Fri, 05 Apr 2013 10:07:34 GMT
51
+ - request:
52
+ method: get
53
+ uri: https://foo.bar%40foobar.com:12345@api.wowzerapp.com/hypermedia/applications/515d64a52478f64181000042
54
+ body:
55
+ encoding: US-ASCII
56
+ string: ''
57
+ headers:
58
+ Content-Type:
59
+ - application/json
60
+ Accept:
61
+ - application/json
62
+ User-Agent:
63
+ - Faraday v0.8.7
64
+ Accept-Encoding:
65
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
66
+ response:
67
+ status:
68
+ code: 200
69
+ message: OK
70
+ headers:
71
+ Date:
72
+ - Fri, 05 Apr 2013 10:12:16 GMT
73
+ Server:
74
+ - Apache/2.2.17 (Ubuntu)
75
+ Strict-Transport-Security:
76
+ - max-age=31536000
77
+ X-Ua-Compatible:
78
+ - IE=Edge,chrome=1
79
+ Etag:
80
+ - ! '"af205e033883a77fc364061181cedad2"'
81
+ Cache-Control:
82
+ - must-revalidate, private, max-age=0
83
+ X-Rack-Cache:
84
+ - miss
85
+ Set-Cookie:
86
+ - _novia_secure_session=cdab00e345b0575a337d27ab6a4763a3; domain=wowzerapp.com;
87
+ path=/; HttpOnly; secure
88
+ Status:
89
+ - '200'
90
+ Content-Length:
91
+ - '897'
92
+ Content-Type:
93
+ - application/json; charset=utf-8
94
+ body:
95
+ encoding: US-ASCII
96
+ string: ! '{"id":"515d64a52478f64181000042","date_sent":"2013-04-04T11:31:49+00:00","date_completed":"2013-04-04T11:41:35+00:00","date_updated":"2013-04-05T09:37:55Z","evaluation_status":"pending","status":"completed","_links":{"self":{"href":"https://api.wowzerapp.com/hypermedia/applications/515d64a52478f64181000042"},"wowzer:interview":{"href":"https://api.wowzerapp.com/hypermedia/interviews/515d52a6572fc05e230a77a8"},"wowzer:candidate":{"href":"https://api.wowzerapp.com/hypermedia/candidates/515d64a52478f64181000040"},"wowzer:application:response":[{"href":"https://foobar.com/en/interview_questionnaires/515d64a52478f64181000042/answers/515d65562478f64181000068","name":"standard"},{"href":"https://foobar.com/en/interview_questionnaires/515d64a52478f64181000042/answers/515d65562478f64181000068?auth_token=6a274bc84c5feba4b9bcdd4757799802&layout=iframe","name":"iframe"}]}}'
97
+ http_version: !!null
98
+ recorded_at: Fri, 05 Apr 2013 10:07:35 GMT
99
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: https://foo.bar%40foobar.com:12345@api.wowzerapp.com/hypermedia/notifications/515c1d39572fc05e2306a170
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"callback_url":"https://sample.com/endpoint2"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept:
13
+ - application/json
14
+ User-Agent:
15
+ - Faraday v0.8.7
16
+ response:
17
+ status:
18
+ code: 204
19
+ message: No Content
20
+ headers:
21
+ Date:
22
+ - Wed, 03 Apr 2013 13:59:10 GMT
23
+ Server:
24
+ - Apache/2.2.17 (Ubuntu)
25
+ Strict-Transport-Security:
26
+ - max-age=31536000
27
+ X-Ua-Compatible:
28
+ - IE=Edge,chrome=1
29
+ Cache-Control:
30
+ - no-cache
31
+ X-Rack-Cache:
32
+ - invalidate, pass
33
+ Set-Cookie:
34
+ - _novia_secure_session=e330b5b97f91dd40e804edeb8f25e47d; domain=wowzerapp.com;
35
+ path=/; HttpOnly; secure
36
+ Status:
37
+ - '204'
38
+ Content-Length:
39
+ - '0'
40
+ Content-Type:
41
+ - text/plain
42
+ body:
43
+ encoding: US-ASCII
44
+ string: ''
45
+ http_version: !!null
46
+ recorded_at: Wed, 03 Apr 2013 13:58:59 GMT
47
+ recorded_with: VCR 2.4.0
@@ -1,25 +1,31 @@
1
1
  module Wowzer
2
- class Application
2
+ class Application < Resource
3
3
 
4
- attr_accessor :attributes
4
+ def resend
5
+ if resource.links['wowzer:application:invitation']
6
+ response = resource.links['wowzer:application:invitation'].post({})
7
+ else
8
+ raise ActionNotAllowed
9
+ end
10
+
11
+ response.status == 204
12
+ end
5
13
 
6
- def initialize(attributes)
7
- self.attributes = attributes
14
+ def response?
15
+ !response.blank?
8
16
  end
9
17
 
10
- def self.all
11
- client.links['wowzer:interviews'].embedded['wowzer:interview'].map do |interview|
12
- new(interview.attributes)
13
- end
18
+ def response
19
+ ApplicationResponse.for(self)
14
20
  end
15
21
 
16
- def self.find(id)
17
- response = client.links['wowzer:interviews'].links['wowzer:interview'].expand(id: id).get
18
- new(response.body)
22
+ def self.absolute_resource_link
23
+ client.links["wowzer:#{resource_name}"]
19
24
  end
20
25
 
21
- def self.client
22
- @@client ||= Client.new
26
+ def delete
27
+ response = resource.links['self'].delete
28
+ response.status == 204
23
29
  end
24
30
 
25
31
  end
@@ -0,0 +1,32 @@
1
+ module Wowzer
2
+ class ApplicationResponse < Resource
3
+
4
+ attr_accessor :data
5
+
6
+ def initialize(data)
7
+ self.data = data
8
+ end
9
+
10
+ def self.for(application)
11
+ data = application.resource.links['wowzer:application:response'].instance_variable_get("@link")
12
+ data.blank? ? nil : new(data)
13
+ end
14
+
15
+ def iframe_response
16
+ data.select{|t| t["name"] == "iframe"}.first
17
+ end
18
+
19
+ def standard_response
20
+ data.select{|t| t["name"] == "standard"}.first
21
+ end
22
+
23
+ def iframe_response_url
24
+ iframe_response["href"] if iframe_response
25
+ end
26
+
27
+ def standard_response_url
28
+ standard_response["href"] if standard_response
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ module Wowzer
2
+ class Candidate < Resource
3
+ def self.absolute_resource_link
4
+ client.links["wowzer:#{resource_name}"]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module Wowzer
2
+
3
+ class ResourceNotFound < Exception; end
4
+ class ActionNotAllowed < Exception; end
5
+
6
+ end
@@ -1,25 +1,21 @@
1
1
  module Wowzer
2
- class Interview
2
+ class Interview < Resource
3
3
 
4
- attr_accessor :attributes
5
-
6
- def initialize(attributes)
7
- self.attributes = attributes
8
- end
9
-
10
- def self.all
11
- client.links['wowzer:interviews'].embedded['wowzer:interview'].map do |interview|
12
- new(interview.attributes)
4
+ def applications
5
+ applications_link.embedded['wowzer:application'].map do |application_resource|
6
+ Application.new(application_resource)
13
7
  end
14
8
  end
15
9
 
16
- def self.find(id)
17
- response = client.links['wowzer:interviews'].links['wowzer:interview'].expand(id: id).get
18
- new(response.body)
10
+ def applications_link
11
+ resource.links['wowzer:applications']
19
12
  end
20
13
 
21
- def self.client
22
- Wowzer::client
14
+ def create_application(options={})
15
+ response = applications_link.post(options)
16
+ resource = ::Hyperclient::Resource.new(response.body, self.class.client)
17
+
18
+ Application.new(resource)
23
19
  end
24
20
 
25
21
  end
@@ -0,0 +1,21 @@
1
+ module Wowzer
2
+ class Notification < Resource
3
+
4
+ def self.create(options={})
5
+ response = client.links['wowzer:notifications'].post(options)
6
+ resource = ::Hyperclient::Resource.new(response.body, self.client)
7
+
8
+ new(resource)
9
+ end
10
+
11
+ def update(params = {})
12
+ response = resource.links['self'].put(params)
13
+ end
14
+
15
+ def delete
16
+ response = resource.links['self'].delete
17
+ response.status == 204
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,68 @@
1
+ module Wowzer
2
+ class Resource
3
+
4
+ attr_accessor :resource
5
+
6
+ def initialize(resource)
7
+ self.resource = resource
8
+ end
9
+
10
+ def self.client
11
+ Wowzer::client
12
+ end
13
+
14
+ def self.all
15
+ absolute_resource_embedded.map{|resource| new(resource)}
16
+ end
17
+
18
+ def self.find(id)
19
+ resource = find_by_embedded(id) || find_by_link(id)
20
+ raise ResourceNotFound unless resource
21
+ resource
22
+ end
23
+
24
+ def method_missing(method, *args, &block)
25
+ if resource.attributes.respond_to?(method)
26
+ resource.attributes.send(method, *args, &block)
27
+ else
28
+ super
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def self.find_by_embedded(id)
35
+ return nil if client.links["wowzer:#{resources_name}"].blank?
36
+ embedded = absolute_resource_embedded.map{|r| new(r)}
37
+
38
+ if embedded.any?
39
+ embedded.select{|e| e.id == id}.first
40
+ end
41
+ end
42
+
43
+ def self.find_by_link(id)
44
+ if link = absolute_resource_link
45
+ resource = link.expand(id: id).resource
46
+ new(resource)
47
+ end
48
+ end
49
+
50
+ def self.resource_name
51
+ self.to_s.demodulize.underscore
52
+ end
53
+
54
+ def self.resources_name
55
+ self.to_s.demodulize.pluralize.underscore
56
+ end
57
+
58
+ def self.absolute_resource_link
59
+ return nil if client.links["wowzer:#{resources_name}"].blank?
60
+ client.links["wowzer:#{resources_name}"].links["wowzer:#{resource_name}"]
61
+ end
62
+
63
+ def self.absolute_resource_embedded
64
+ client.links["wowzer:#{resources_name}"].embedded["wowzer:#{resource_name}"]
65
+ end
66
+
67
+ end
68
+ end
@@ -1,3 +1,3 @@
1
1
  module Wowzer
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/wowzer.rb CHANGED
@@ -18,5 +18,10 @@ end
18
18
 
19
19
  require 'wowzer/version'
20
20
  require 'wowzer/client'
21
+ require 'wowzer/resource'
21
22
  require 'wowzer/interview'
22
- #require 'wowzer/application'
23
+ require 'wowzer/application'
24
+ require 'wowzer/application_response'
25
+ require 'wowzer/notification'
26
+ require 'wowzer/exception'
27
+ require 'wowzer/candidate'
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wowzer::ApplicationResponse do
4
+
5
+ it "should retrieve the response for an application" do
6
+ response = nil
7
+
8
+ VCR.use_cassette('application_response') do
9
+ application = Wowzer::Application.find('515d64a52478f64181000042')
10
+ response = application.response
11
+ end
12
+
13
+ response.iframe_response_url.should == "https://foobar.com/en/interview_questionnaires/515d64a52478f64181000042/answers/515d65562478f64181000068?auth_token=115486f877a541e844b3ecc98b0152ea&layout=iframe"
14
+ response.standard_response_url.should == "https://foobar.com/en/interview_questionnaires/515d64a52478f64181000042/answers/515d65562478f64181000068"
15
+ end
16
+
17
+ end