clever-ruby 0.0.3 → 0.0.4

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.
data/lib/clever-ruby.rb CHANGED
@@ -19,6 +19,7 @@ require 'clever-ruby/school'
19
19
  require 'clever-ruby/student'
20
20
  require 'clever-ruby/section'
21
21
  require 'clever-ruby/teacher'
22
+ require 'clever-ruby/event'
22
23
 
23
24
  # Errors
24
25
  require 'clever-ruby/errors/clever_error'
@@ -23,6 +23,10 @@ module Clever
23
23
  get_linked_resources 'students', filters
24
24
  end
25
25
 
26
+ def events(filters={})
27
+ get_linked_resources 'events', filters
28
+ end
29
+
26
30
  private
27
31
 
28
32
  def get_linked_resources(resource_type, filters={})
@@ -0,0 +1,25 @@
1
+ module Clever
2
+ class Event < APIResource
3
+ include Clever::APIOperations::List
4
+
5
+ def optional_attributes
6
+ [:previous_attributes]
7
+ end
8
+
9
+ def object
10
+ klass = Util.types_to_clever_class(type_pieces[0])
11
+ klass ||= CleverObject
12
+ klass.construct_from(data[:object])
13
+ end
14
+
15
+ def action
16
+ type_pieces[1]
17
+ end
18
+
19
+ private
20
+
21
+ def type_pieces
22
+ type.split(".")
23
+ end
24
+ end
25
+ end
@@ -15,14 +15,19 @@ module Clever
15
15
  end
16
16
  end
17
17
 
18
- def self.convert_to_clever_object(resp)
18
+ def self.types_to_clever_class(type)
19
19
  types = {
20
- 'students' => Student,
21
- 'sections' => Section,
22
- 'teachers' => Teacher,
23
- 'districts' => District,
24
- 'schools' => School
20
+ 'students' => Student,
21
+ 'sections' => Section,
22
+ 'teachers' => Teacher,
23
+ 'districts' => District,
24
+ 'schools' => School,
25
+ 'push' => Event
25
26
  }
27
+ types.fetch(type)
28
+ end
29
+
30
+ def self.convert_to_clever_object(resp)
26
31
  case resp
27
32
  when Array
28
33
  resp.map { |i| convert_to_clever_object(i) }
@@ -31,7 +36,7 @@ module Clever
31
36
  # match = /\/v1.1\/([a-z]+)\/\S+$/.match(resp[:uri])
32
37
  # puts match[1].inspect
33
38
  if klass_name = /\/v1.1\/([a-z]+)\/\S+$/.match(resp[:uri])[1]
34
- klass = types[klass_name]
39
+ klass = types_to_clever_class(klass_name)
35
40
  end
36
41
  klass ||= CleverObject
37
42
  klass.construct_from(resp[:data])
@@ -1,3 +1,3 @@
1
1
  module Clever
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,138 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://DEMO_KEY:@api.getclever.com/v1.1/districts?
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Access-Control-Allow-Headers:
22
+ - Content-Type,Authorization,X-Requested-With,Accept,Origin,Referer,User-Agent
23
+ Access-Control-Allow-Methods:
24
+ - GET,PUT,POST,DELETE
25
+ Access-Control-Allow-Origin:
26
+ - ! '*'
27
+ Cache-Control:
28
+ - no-cache="set-cookie"
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Date:
32
+ - Wed, 13 Mar 2013 13:50:06 GMT
33
+ Server:
34
+ - nginx/1.2.7
35
+ Set-Cookie:
36
+ - AWSELB=A91137730E0ED0C3FE64858C01B7DE99906AE563A8E925E576645DC25B200EBF95B82D57D3F5C679B21661A8DECDD5707A5ACD5D114CAD14B5229AFB824566522F545F7D62;PATH=/;MAX-AGE=300
37
+ X-Powered-By:
38
+ - Express
39
+ Content-Length:
40
+ - '174'
41
+ Connection:
42
+ - keep-alive
43
+ body:
44
+ encoding: US-ASCII
45
+ string: ! '{"data":[{"data":{"name":"Demo District","id":"4fd43cc56d11340000000005"},"uri":"/v1.1/districts/4fd43cc56d11340000000005"}],"links":[{"rel":"self","uri":"/v1.1/districts"}]}'
46
+ http_version:
47
+ recorded_at: Wed, 13 Mar 2013 13:50:11 GMT
48
+ - request:
49
+ method: get
50
+ uri: https://DEMO_KEY:@api.getclever.com/v1.1/districts/4fd43cc56d11340000000005
51
+ body:
52
+ encoding: US-ASCII
53
+ string: ''
54
+ headers:
55
+ Accept:
56
+ - ! '*/*; q=0.5, application/xml'
57
+ Accept-Encoding:
58
+ - gzip, deflate
59
+ User-Agent:
60
+ - Ruby
61
+ response:
62
+ status:
63
+ code: 200
64
+ message: OK
65
+ headers:
66
+ Access-Control-Allow-Headers:
67
+ - Content-Type,Authorization,X-Requested-With,Accept,Origin,Referer,User-Agent
68
+ Access-Control-Allow-Methods:
69
+ - GET,PUT,POST,DELETE
70
+ Access-Control-Allow-Origin:
71
+ - ! '*'
72
+ Cache-Control:
73
+ - no-cache="set-cookie"
74
+ Content-Type:
75
+ - application/json; charset=utf-8
76
+ Date:
77
+ - Wed, 13 Mar 2013 13:50:07 GMT
78
+ Server:
79
+ - nginx/1.2.7
80
+ Set-Cookie:
81
+ - AWSELB=A91137730E0ED0C3FE64858C01B7DE99906AE563A8E925E576645DC25B200EBF95B82D57D3F5C679B21661A8DECDD5707A5ACD5D114CAD14B5229AFB824566522F545F7D62;PATH=/;MAX-AGE=300
82
+ X-Powered-By:
83
+ - Express
84
+ Content-Length:
85
+ - '599'
86
+ Connection:
87
+ - keep-alive
88
+ body:
89
+ encoding: US-ASCII
90
+ string: ! '{"data":{"name":"Demo District","id":"4fd43cc56d11340000000005"},"links":[{"rel":"self","uri":"/v1.1/districts/4fd43cc56d11340000000005"},{"rel":"schools","uri":"/v1.1/districts/4fd43cc56d11340000000005/schools"},{"rel":"teachers","uri":"/v1.1/districts/4fd43cc56d11340000000005/teachers"},{"rel":"students","uri":"/v1.1/districts/4fd43cc56d11340000000005/students"},{"rel":"sections","uri":"/v1.1/districts/4fd43cc56d11340000000005/sections"},{"rel":"properties","uri":"/v1.1/districts/4fd43cc56d11340000000005/properties"},{"rel":"events","uri":"/v1.1/districts/4fd43cc56d11340000000005/events"}]}'
91
+ http_version:
92
+ recorded_at: Wed, 13 Mar 2013 13:50:11 GMT
93
+ - request:
94
+ method: get
95
+ uri: https://DEMO_KEY:@api.getclever.com//v1.1/districts/4fd43cc56d11340000000005/events?
96
+ body:
97
+ encoding: US-ASCII
98
+ string: ''
99
+ headers:
100
+ Accept:
101
+ - ! '*/*; q=0.5, application/xml'
102
+ Accept-Encoding:
103
+ - gzip, deflate
104
+ User-Agent:
105
+ - Ruby
106
+ response:
107
+ status:
108
+ code: 200
109
+ message: OK
110
+ headers:
111
+ Access-Control-Allow-Headers:
112
+ - Content-Type,Authorization,X-Requested-With,Accept,Origin,Referer,User-Agent
113
+ Access-Control-Allow-Methods:
114
+ - GET,PUT,POST,DELETE
115
+ Access-Control-Allow-Origin:
116
+ - ! '*'
117
+ Cache-Control:
118
+ - no-cache="set-cookie"
119
+ Content-Type:
120
+ - application/json; charset=utf-8
121
+ Date:
122
+ - Wed, 13 Mar 2013 13:50:08 GMT
123
+ Server:
124
+ - nginx/1.2.7
125
+ Set-Cookie:
126
+ - AWSELB=A91137730E0ED0C3FE64858C01B7DE99906AE563A8E925E576645DC25B200EBF95B82D57D3F5C679B21661A8DECDD5707A5ACD5D114CAD14B5229AFB824566522F545F7D62;PATH=/;MAX-AGE=300
127
+ X-Powered-By:
128
+ - Express
129
+ Content-Length:
130
+ - '92'
131
+ Connection:
132
+ - keep-alive
133
+ body:
134
+ encoding: US-ASCII
135
+ string: ! '{"data":[{"data": {"type": "sections.created","data": {"object": {"school": "51278c814f766d0765015e2a","teacher": "510980a5923bcbba1f0cb4f0","sis_id": "1034","grade": "8","course_name": "Calculus I","course_number": "801","name": "Gregs class of math","subject": "math","district": "510976d3a0f6dd9842000006","students": ["512bb9ccca5e6fa77505fe7f"],"last_modified": "2013-02-25T19:22:26.624Z","created": "2013-02-25T19:22:26.624Z","id": "512bb9f2ca5e6fa77506133f"}},"created": "2013-02-25T19:22:26.706Z","id": "512bb9f2ca5e6fa775061340"},"uri": "/v1.1/push/events/512bb9f2ca5e6fa775061340"}],"links":[{"rel":"self","uri":"/v1.1/districts/4fd43cc56d11340000000005/events"}]}'
136
+ http_version:
137
+ recorded_at: Tue, 12 Mar 2013 15:38:16 GMT
138
+ recorded_with: VCR 2.4.0
@@ -41,4 +41,13 @@ class ListTest < Test::Unit::TestCase
41
41
  @district.students({limit: 2}).size.must_equal 2
42
42
  end
43
43
  end
44
+
45
+ should "retrieve a district's events" do
46
+ VCR.use_cassette("districts_events", :allow_playback_repeats => true) do
47
+ @district = Clever::District.all.first
48
+ @district.events.size.must_equal 1
49
+ event = @district.events.first
50
+ event.must_be_instance_of Clever::Event
51
+ end
52
+ end
44
53
  end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ class EventTest < Test::Unit::TestCase
4
+ def setup
5
+ @event = Clever::Event.construct_from({
6
+ type: "sections.created",
7
+ data: {
8
+ object: {
9
+ id: "512bb9f2ca5e6fa77506133f"
10
+ }
11
+ },
12
+ id: "512bb9f2ca5e6fa775061340"
13
+ })
14
+ end
15
+
16
+ should "create a clever object for the object the event is about" do
17
+ @event.object.must_be_instance_of Clever::Section
18
+ end
19
+
20
+ should "know what action the event is about (created/updated/deleted)" do
21
+ @event.action.must_equal "created"
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clever-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -166,6 +166,7 @@ files:
166
166
  - lib/clever-ruby/errors/authentication_error.rb
167
167
  - lib/clever-ruby/errors/clever_error.rb
168
168
  - lib/clever-ruby/errors/invalid_request_error.rb
169
+ - lib/clever-ruby/event.rb
169
170
  - lib/clever-ruby/json.rb
170
171
  - lib/clever-ruby/school.rb
171
172
  - lib/clever-ruby/section.rb
@@ -174,6 +175,7 @@ files:
174
175
  - lib/clever-ruby/util.rb
175
176
  - lib/clever-ruby/version.rb
176
177
  - test/data/vcr_cassettes/districts.yml
178
+ - test/data/vcr_cassettes/districts_events.yml
177
179
  - test/data/vcr_cassettes/districts_schools.yml
178
180
  - test/data/vcr_cassettes/districts_sections.yml
179
181
  - test/data/vcr_cassettes/districts_students.yml
@@ -189,6 +191,7 @@ files:
189
191
  - test/test_helper.rb
190
192
  - test/unit/clever_test.rb
191
193
  - test/unit/configuration_test.rb
194
+ - test/unit/event_test.rb
192
195
  - test/unit/optional_attributes_test.rb
193
196
  homepage: http://github.com/Clever/clever-ruby
194
197
  licenses: []
@@ -216,6 +219,7 @@ specification_version: 3
216
219
  summary: Ruby bindings to the Clever API.
217
220
  test_files:
218
221
  - test/data/vcr_cassettes/districts.yml
222
+ - test/data/vcr_cassettes/districts_events.yml
219
223
  - test/data/vcr_cassettes/districts_schools.yml
220
224
  - test/data/vcr_cassettes/districts_sections.yml
221
225
  - test/data/vcr_cassettes/districts_students.yml
@@ -231,4 +235,5 @@ test_files:
231
235
  - test/test_helper.rb
232
236
  - test/unit/clever_test.rb
233
237
  - test/unit/configuration_test.rb
238
+ - test/unit/event_test.rb
234
239
  - test/unit/optional_attributes_test.rb