clever-ruby 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/clever-ruby.rb +1 -0
- data/lib/clever-ruby/api_operations/list.rb +24 -0
- data/lib/clever-ruby/api_operations/pagelist.rb +6 -2
- data/lib/clever-ruby/api_operations/results_list.rb +20 -0
- data/lib/clever-ruby/util.rb +4 -0
- data/lib/clever-ruby/version.rb +1 -1
- data/test/data/vcr_cassettes/district_count.yml +44 -0
- data/test/data/vcr_cassettes/district_find_by_page.yml +85 -0
- data/test/data/vcr_cassettes/district_find_multiple.yml +85 -0
- data/test/data/vcr_cassettes/district_find_one.yml +85 -0
- data/test/data/vcr_cassettes/districts.yml +46 -5
- data/test/data/vcr_cassettes/districts_event_pages.yml +134 -134
- data/test/data/vcr_cassettes/districts_events.yml +44 -44
- data/test/data/vcr_cassettes/districts_school_pages.yml +50 -50
- data/test/data/vcr_cassettes/districts_schools.yml +44 -44
- data/test/data/vcr_cassettes/districts_section_pages.yml +303 -303
- data/test/data/vcr_cassettes/districts_sections.yml +44 -44
- data/test/data/vcr_cassettes/districts_student_pages.yml +184 -184
- data/test/data/vcr_cassettes/districts_students.yml +44 -44
- data/test/data/vcr_cassettes/districts_students_filtered.yml +25 -25
- data/test/data/vcr_cassettes/districts_teacher_pages.yml +100 -100
- data/test/data/vcr_cassettes/districts_teachers.yml +44 -44
- data/test/data/vcr_cassettes/error_handling.yml +24 -24
- data/test/data/vcr_cassettes/event_count.yml +44 -0
- data/test/data/vcr_cassettes/event_find_by_page.yml +110 -0
- data/test/data/vcr_cassettes/event_find_multiple.yml +124 -0
- data/test/data/vcr_cassettes/event_find_one.yml +114 -0
- data/test/data/vcr_cassettes/events.yml +110 -0
- data/test/data/vcr_cassettes/school_count.yml +44 -0
- data/test/data/vcr_cassettes/school_find_by_page.yml +96 -0
- data/test/data/vcr_cassettes/school_find_multiple.yml +104 -0
- data/test/data/vcr_cassettes/school_find_one.yml +99 -0
- data/test/data/vcr_cassettes/schools.yml +48 -7
- data/test/data/vcr_cassettes/schools_optional_attributes.yml +7 -7
- data/test/data/vcr_cassettes/section_count.yml +44 -0
- data/test/data/vcr_cassettes/section_find_by_page.yml +1146 -0
- data/test/data/vcr_cassettes/section_find_multiple.yml +147 -0
- data/test/data/vcr_cassettes/section_find_one.yml +352 -0
- data/test/data/vcr_cassettes/sections.yml +69 -28
- data/test/data/vcr_cassettes/student_count.yml +44 -0
- data/test/data/vcr_cassettes/student_find_by_page.yml +1171 -0
- data/test/data/vcr_cassettes/student_find_multiple.yml +111 -0
- data/test/data/vcr_cassettes/student_find_one.yml +160 -0
- data/test/data/vcr_cassettes/students.yml +118 -77
- data/test/data/vcr_cassettes/teacher_count.yml +44 -0
- data/test/data/vcr_cassettes/teacher_find_by_page.yml +176 -0
- data/test/data/vcr_cassettes/teacher_find_multiple.yml +119 -0
- data/test/data/vcr_cassettes/teacher_find_one.yml +177 -0
- data/test/data/vcr_cassettes/teachers.yml +15 -3712
- data/test/integration/api_operations/list_test.rb +84 -28
- metadata +82 -30
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MTI0OGY0NTY3MDg0ODc1NGE0OTJlNmE1NGQxMjVmZGJlNGFjMzFlMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTJjNGFhNTlkZTMxYWM0NjMxNjVjOGZmNmI1NjUyMTg4ZjIwZWI0YQ==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NGNiNGM5OGM3ZjYwNjYyZGIyMmZlM2VjZmFmNWQxNjdhMjBmY2M1ZDBlMDY0
|
10
|
+
NWZhZTM4MTE3MmIyOTkxNTQ0ODdhODAxODVhNGI0N2U1OGY3NjdhMWM1Njc3
|
11
|
+
ZTlmZTY0NjQxZjUyNTliNGRiZjI1MTIzZDllYzRiNDU2MjVjOWM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NGZjMjNkYjgxNGQxYWE0NWY2MGZkNjgzNzZmMThlZDIyZGI5MTk3OTcwMzI2
|
14
|
+
OTJlZGMwZjQwZjI1NDMyNjVjZGZjN2E3ZTVhMDMyNzg3OWVjOGM1NGViNTBk
|
15
|
+
MzdkNWE3ODhkZGExZGVlNzk4NWMyZGYwMDQwOGE5NjlkMDUyOTY=
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -60,6 +60,6 @@ end
|
|
60
60
|
|
61
61
|
1. Fork it
|
62
62
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
|
-
3. Commit your changes (`git commit -
|
63
|
+
3. Commit your changes (`git add -p ./path/to/files; git commit -m 'Add some feature'`)
|
64
64
|
4. Push to the branch (`git push origin my-new-feature`)
|
65
65
|
5. Create new Pull Request
|
data/lib/clever-ruby.rb
CHANGED
@@ -11,6 +11,30 @@ module Clever
|
|
11
11
|
end
|
12
12
|
accum
|
13
13
|
end
|
14
|
+
|
15
|
+
def find(id = nil, filters = {})
|
16
|
+
if id.is_a? Array
|
17
|
+
unless id.select { |e| !Clever::Util.valid_id? e }.empty?
|
18
|
+
fail ArgumentError, 'Array of IDs must only contain valid ObjectIDs'
|
19
|
+
end
|
20
|
+
|
21
|
+
filters[:where] = JSON.dump(_id: { :'$in' => id })
|
22
|
+
end
|
23
|
+
|
24
|
+
if id.nil? || id.is_a?(Array)
|
25
|
+
Clever::APIOperations::PageList.new(url, filters).to_results_list
|
26
|
+
elsif Clever::Util.valid_id? id
|
27
|
+
retrieve id
|
28
|
+
else
|
29
|
+
fail ArgumentError, 'id must be a valid ObjectID, an array of them, or nil.'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def count(filters = {})
|
34
|
+
filters[:count] = true
|
35
|
+
response = Clever.request :get, url, filters
|
36
|
+
response[:count]
|
37
|
+
end
|
14
38
|
end
|
15
39
|
|
16
40
|
def self.included(base)
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Clever
|
2
2
|
module APIOperations
|
3
3
|
# Handles paginated requests.
|
4
|
-
# TODO: use rel links
|
5
|
-
# TODO: build functionality elsewhere
|
6
4
|
class PageList
|
5
|
+
include Enumerable
|
6
|
+
|
7
7
|
def initialize(uri, filters = {})
|
8
8
|
@uri = uri
|
9
9
|
@filters = filters
|
@@ -16,6 +16,10 @@ module Clever
|
|
16
16
|
page = page.next
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
def to_results_list
|
21
|
+
Clever::APIOperations::ResultsList.new self
|
22
|
+
end
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Clever
|
2
|
+
module APIOperations
|
3
|
+
# Represents a list of results for a paged request.
|
4
|
+
class ResultsList
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize(pagelist)
|
8
|
+
@pages = pagelist
|
9
|
+
end
|
10
|
+
|
11
|
+
def each
|
12
|
+
@pages.each do |page|
|
13
|
+
page.each do |elem|
|
14
|
+
yield elem
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/clever-ruby/util.rb
CHANGED
data/lib/clever-ruby/version.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://DEMO_KEY:@api.clever.com/v1.1/districts?count=true
|
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,PATCH,POST,DELETE
|
25
|
+
Access-Control-Allow-Origin:
|
26
|
+
- "*"
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
Date:
|
30
|
+
- Tue, 09 Sep 2014 21:48:49 GMT
|
31
|
+
Server:
|
32
|
+
- nginx/1.4.7
|
33
|
+
X-Powered-By:
|
34
|
+
- Express
|
35
|
+
Content-Length:
|
36
|
+
- '71'
|
37
|
+
Connection:
|
38
|
+
- keep-alive
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: '{"count":1,"links":[{"rel":"self","uri":"/v1.1/districts?count=true"}]}'
|
42
|
+
http_version:
|
43
|
+
recorded_at: Tue, 09 Sep 2014 21:48:49 GMT
|
44
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,85 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://DEMO_KEY:@api.clever.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,PATCH,POST,DELETE
|
25
|
+
Access-Control-Allow-Origin:
|
26
|
+
- "*"
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
Date:
|
30
|
+
- Tue, 09 Sep 2014 21:48:53 GMT
|
31
|
+
Server:
|
32
|
+
- nginx/1.4.7
|
33
|
+
X-Powered-By:
|
34
|
+
- Express
|
35
|
+
Content-Length:
|
36
|
+
- '217'
|
37
|
+
Connection:
|
38
|
+
- keep-alive
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: '{"data":[{"data":{"name":"Demo District","id":"4fd43cc56d11340000000005"},"uri":"/v1.1/districts/4fd43cc56d11340000000005"}],"paging":{"current":1,"total":1,"count":1},"links":[{"rel":"self","uri":"/v1.1/districts"}]}'
|
42
|
+
http_version:
|
43
|
+
recorded_at: Tue, 09 Sep 2014 21:48:53 GMT
|
44
|
+
- request:
|
45
|
+
method: get
|
46
|
+
uri: https://DEMO_KEY:@api.clever.com/v1.1/districts?count=true
|
47
|
+
body:
|
48
|
+
encoding: US-ASCII
|
49
|
+
string: ''
|
50
|
+
headers:
|
51
|
+
Accept:
|
52
|
+
- "*/*; q=0.5, application/xml"
|
53
|
+
Accept-Encoding:
|
54
|
+
- gzip, deflate
|
55
|
+
User-Agent:
|
56
|
+
- Ruby
|
57
|
+
response:
|
58
|
+
status:
|
59
|
+
code: 200
|
60
|
+
message: OK
|
61
|
+
headers:
|
62
|
+
Access-Control-Allow-Headers:
|
63
|
+
- Content-Type,Authorization,X-Requested-With,Accept,Origin,Referer,User-Agent
|
64
|
+
Access-Control-Allow-Methods:
|
65
|
+
- GET,PATCH,POST,DELETE
|
66
|
+
Access-Control-Allow-Origin:
|
67
|
+
- "*"
|
68
|
+
Content-Type:
|
69
|
+
- application/json; charset=utf-8
|
70
|
+
Date:
|
71
|
+
- Tue, 09 Sep 2014 21:48:53 GMT
|
72
|
+
Server:
|
73
|
+
- nginx/1.4.7
|
74
|
+
X-Powered-By:
|
75
|
+
- Express
|
76
|
+
Content-Length:
|
77
|
+
- '71'
|
78
|
+
Connection:
|
79
|
+
- keep-alive
|
80
|
+
body:
|
81
|
+
encoding: UTF-8
|
82
|
+
string: '{"count":1,"links":[{"rel":"self","uri":"/v1.1/districts?count=true"}]}'
|
83
|
+
http_version:
|
84
|
+
recorded_at: Tue, 09 Sep 2014 21:48:53 GMT
|
85
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,85 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://DEMO_KEY:@api.clever.com/v1.1/districts?limit=20
|
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,PATCH,POST,DELETE
|
25
|
+
Access-Control-Allow-Origin:
|
26
|
+
- "*"
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
Date:
|
30
|
+
- Tue, 09 Sep 2014 21:48:53 GMT
|
31
|
+
Server:
|
32
|
+
- nginx/1.4.7
|
33
|
+
X-Powered-By:
|
34
|
+
- Express
|
35
|
+
Content-Length:
|
36
|
+
- '226'
|
37
|
+
Connection:
|
38
|
+
- keep-alive
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: '{"data":[{"data":{"name":"Demo District","id":"4fd43cc56d11340000000005"},"uri":"/v1.1/districts/4fd43cc56d11340000000005"}],"paging":{"current":1,"total":1,"count":1},"links":[{"rel":"self","uri":"/v1.1/districts?limit=20"}]}'
|
42
|
+
http_version:
|
43
|
+
recorded_at: Tue, 09 Sep 2014 21:48:53 GMT
|
44
|
+
- request:
|
45
|
+
method: get
|
46
|
+
uri: https://DEMO_KEY:@api.clever.com/v1.1/districts?where=%7B%22_id%22:%7B%22$in%22:%5B%224fd43cc56d11340000000005%22%5D%7D%7D
|
47
|
+
body:
|
48
|
+
encoding: US-ASCII
|
49
|
+
string: ''
|
50
|
+
headers:
|
51
|
+
Accept:
|
52
|
+
- "*/*; q=0.5, application/xml"
|
53
|
+
Accept-Encoding:
|
54
|
+
- gzip, deflate
|
55
|
+
User-Agent:
|
56
|
+
- Ruby
|
57
|
+
response:
|
58
|
+
status:
|
59
|
+
code: 200
|
60
|
+
message: OK
|
61
|
+
headers:
|
62
|
+
Access-Control-Allow-Headers:
|
63
|
+
- Content-Type,Authorization,X-Requested-With,Accept,Origin,Referer,User-Agent
|
64
|
+
Access-Control-Allow-Methods:
|
65
|
+
- GET,PATCH,POST,DELETE
|
66
|
+
Access-Control-Allow-Origin:
|
67
|
+
- "*"
|
68
|
+
Content-Type:
|
69
|
+
- application/json; charset=utf-8
|
70
|
+
Date:
|
71
|
+
- Tue, 09 Sep 2014 21:48:53 GMT
|
72
|
+
Server:
|
73
|
+
- nginx/1.4.7
|
74
|
+
X-Powered-By:
|
75
|
+
- Express
|
76
|
+
Content-Length:
|
77
|
+
- '288'
|
78
|
+
Connection:
|
79
|
+
- keep-alive
|
80
|
+
body:
|
81
|
+
encoding: UTF-8
|
82
|
+
string: '{"data":[{"data":{"name":"Demo District","id":"4fd43cc56d11340000000005"},"uri":"/v1.1/districts/4fd43cc56d11340000000005"}],"paging":{"current":1,"total":1,"count":1},"links":[{"rel":"self","uri":"/v1.1/districts?where=%7B%22_id%22:%7B%22$in%22:[%224fd43cc56d11340000000005%22]%7D%7D"}]}'
|
83
|
+
http_version:
|
84
|
+
recorded_at: Tue, 09 Sep 2014 21:48:53 GMT
|
85
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,85 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://DEMO_KEY:@api.clever.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,PATCH,POST,DELETE
|
25
|
+
Access-Control-Allow-Origin:
|
26
|
+
- "*"
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
Date:
|
30
|
+
- Tue, 09 Sep 2014 21:48:51 GMT
|
31
|
+
Server:
|
32
|
+
- nginx/1.4.7
|
33
|
+
X-Powered-By:
|
34
|
+
- Express
|
35
|
+
Content-Length:
|
36
|
+
- '217'
|
37
|
+
Connection:
|
38
|
+
- keep-alive
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: '{"data":[{"data":{"name":"Demo District","id":"4fd43cc56d11340000000005"},"uri":"/v1.1/districts/4fd43cc56d11340000000005"}],"paging":{"current":1,"total":1,"count":1},"links":[{"rel":"self","uri":"/v1.1/districts"}]}'
|
42
|
+
http_version:
|
43
|
+
recorded_at: Tue, 09 Sep 2014 21:48:51 GMT
|
44
|
+
- request:
|
45
|
+
method: get
|
46
|
+
uri: https://DEMO_KEY:@api.clever.com/v1.1/districts/4fd43cc56d11340000000005
|
47
|
+
body:
|
48
|
+
encoding: US-ASCII
|
49
|
+
string: ''
|
50
|
+
headers:
|
51
|
+
Accept:
|
52
|
+
- "*/*; q=0.5, application/xml"
|
53
|
+
Accept-Encoding:
|
54
|
+
- gzip, deflate
|
55
|
+
User-Agent:
|
56
|
+
- Ruby
|
57
|
+
response:
|
58
|
+
status:
|
59
|
+
code: 200
|
60
|
+
message: OK
|
61
|
+
headers:
|
62
|
+
Access-Control-Allow-Headers:
|
63
|
+
- Content-Type,Authorization,X-Requested-With,Accept,Origin,Referer,User-Agent
|
64
|
+
Access-Control-Allow-Methods:
|
65
|
+
- GET,PATCH,POST,DELETE
|
66
|
+
Access-Control-Allow-Origin:
|
67
|
+
- "*"
|
68
|
+
Content-Type:
|
69
|
+
- application/json; charset=utf-8
|
70
|
+
Date:
|
71
|
+
- Tue, 09 Sep 2014 21:48:51 GMT
|
72
|
+
Server:
|
73
|
+
- nginx/1.4.7
|
74
|
+
X-Powered-By:
|
75
|
+
- Express
|
76
|
+
Content-Length:
|
77
|
+
- '518'
|
78
|
+
Connection:
|
79
|
+
- keep-alive
|
80
|
+
body:
|
81
|
+
encoding: UTF-8
|
82
|
+
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":"events","uri":"/v1.1/districts/4fd43cc56d11340000000005/events"}]}'
|
83
|
+
http_version:
|
84
|
+
recorded_at: Tue, 09 Sep 2014 21:48:51 GMT
|
85
|
+
recorded_with: VCR 2.4.0
|