canvas_oauth_engine 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aeea7a018d9223514938324eca406c1a3bfaa531
4
- data.tar.gz: 5b5d1f62203b995e933f66bacbc7a0800fe134f3
3
+ metadata.gz: bd71940eac39f52a99da306965eb23fba309c976
4
+ data.tar.gz: 97c14ba4e0722765bdd5882fb21ca6b8a4718166
5
5
  SHA512:
6
- metadata.gz: 83f2c5aab79984582c12852bff31389482717058c83b08f2d0e5bca32496cfed3fcb03b4553e4097074b8f36e7a91dbbf1291b2fec3e9db0610643adea27275f
7
- data.tar.gz: 989c4018501d5c5663dce76f0d0af68098227b9e10859d17051075b1da7cb9ccd001e4c5934a9e06a7c275e13dd799399f70c217afaf4a2e4a125845ebbf7bd8
6
+ metadata.gz: d3d6fa87ad02ac0a56d1841502f61f2222e8ef322cc4f3d3533858fde597e9cd16e327960f8846f67266c495bd7e34286bd29aae6e45ca1fef63ae790213e7f2
7
+ data.tar.gz: 652903cb90ff4453d540079deaf9c43ede5d4491e963c4d3c1fe9f07c438cfd13222fd3ebb3ac0f65481b451b04931454300271bb57067a8aaa8d10d7265f2f9
@@ -46,22 +46,18 @@ module CanvasOauth
46
46
  end
47
47
  end
48
48
 
49
- def paginated_get(*params)
50
- params[1] ||= {}
51
- params[1][:query] ||= {}
52
- params[1][:query][:per_page] = PER_PAGE
49
+ def paginated_get(url, params = {})
50
+ params[:query] ||= {}
51
+ params[:query][:per_page] = PER_PAGE
53
52
 
54
53
  all_pages = []
55
54
 
56
- while params[0] do
57
- if current_page = authenticated_get(*params)
58
- all_pages += current_page if valid_page?(current_page)
55
+ while url && current_page = authenticated_get(url, params) do
56
+ all_pages.concat(current_page) if valid_page?(current_page)
59
57
 
60
- links = LinkHeader.parse(current_page.headers['link'])
61
- params[0] = links.find_link(["rel", "next"]).try(:href)
62
- else
63
- params[0] = nil
64
- end
58
+ links = LinkHeader.parse(current_page.headers['link'])
59
+ url = links.find_link(["rel", "next"]).try(:href)
60
+ params[:query] = nil if params[:query]
65
61
  end
66
62
 
67
63
  all_pages
@@ -203,6 +199,10 @@ module CanvasOauth
203
199
  authenticated_put "/api/v1/courses/#{course_id}/assignments/#{assignment_id}/submissions/#{user_id}", { body: params }
204
200
  end
205
201
 
202
+ def get_submission(course_id, assignment_id, user_id)
203
+ authenticated_get "/api/v1/courses/#{course_id}/assignments/#{assignment_id}/submissions/#{user_id}"
204
+ end
205
+
206
206
  def course_account_id(course_id)
207
207
  course = get_course(course_id)
208
208
  course['account_id'] if course
@@ -1,3 +1,3 @@
1
1
  module CanvasOauth
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -165,6 +165,13 @@ describe CanvasOauth::CanvasApi do
165
165
  canvas.grade_assignment('1', '2', '3', percentage: "80%")
166
166
  end
167
167
  end
168
+
169
+ describe 'get_submission' do
170
+ it 'queries /api/v1/courses/:course_id/assignments/:assignment_id/submissions/:user_id' do
171
+ expect(canvas).to receive(:authenticated_get).with('/api/v1/courses/1/assignments/2/submissions/3')
172
+ canvas.get_submission(1, 2, 3)
173
+ end
174
+ end
168
175
  end
169
176
 
170
177
  describe "pagination" do
@@ -179,6 +186,10 @@ describe CanvasOauth::CanvasApi do
179
186
  end
180
187
 
181
188
  describe "paginated_get" do
189
+
190
+ let(:first_response_link) { {'link' => "<https://foobar.com/some/address?taco=tuesday&per_page=50&page=2>; rel=\"next\", <https://foobar.com/some/address?taco=tuesday&per_page=50&page=2>; rel=\"last\""} }
191
+ let(:query) { { query: { taco: 'tuesday' } } }
192
+
182
193
  it "adds per_page parameters to the request query" do
183
194
  expect(canvas).to receive(:authenticated_get).with("/some/address", query: { per_page: 50 })
184
195
  canvas.paginated_get "/some/address"
@@ -188,11 +199,28 @@ describe CanvasOauth::CanvasApi do
188
199
  allow(canvas).to receive(:valid_page?) { true }
189
200
  first_response = []
190
201
  second_response = []
191
- allow(first_response).to receive(:headers).and_return({'link' => "<https://foobar.com/some/address?page=2>; rel=\"next\", <https://foobar.com/some/address?page=2>; rel=\"last\""})
202
+ allow(first_response).to receive(:headers).and_return(first_response_link)
192
203
  allow(second_response).to receive(:headers).and_return({})
193
204
  expect(canvas).to receive(:authenticated_get).
194
205
  exactly(2).times.and_return(first_response,second_response)
195
- canvas.paginated_get "/some/address"
206
+ canvas.paginated_get "/some/address", query
207
+ end
208
+
209
+ it "requests the next link without repeating query elements" do
210
+ query_expected = query.dup
211
+ query_expected[:query][:per_page] = 50
212
+
213
+ allow(canvas).to receive(:valid_page?) { true }
214
+
215
+ first_response = []
216
+ second_response = []
217
+ allow(first_response).to receive(:headers).and_return(first_response_link)
218
+ allow(second_response).to receive(:headers).and_return({})
219
+
220
+ expect(canvas).to receive(:authenticated_get).with("/some/address", query_expected).and_return(first_response)
221
+ expect(canvas).to receive(:authenticated_get).with('https://foobar.com/some/address?taco=tuesday&per_page=50&page=2', {query: nil}).and_return(second_response)
222
+
223
+ canvas.paginated_get "/some/address", query
196
224
  end
197
225
 
198
226
  it "sends only one request when no next link is in the response Link header" do
data/spec/spec_helper.rb CHANGED
@@ -22,6 +22,13 @@ module CanvasOauth
22
22
  end
23
23
  end
24
24
 
25
+ Shoulda::Matchers.configure do |config|
26
+ config.integrate do |with|
27
+ with.test_framework :rspec
28
+ with.library :rails
29
+ end
30
+ end
31
+
25
32
  RSpec.configure do |config|
26
33
  # ## Mock Framework
27
34
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas_oauth_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Donahue
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-09-02 00:00:00.000000000 Z
13
+ date: 2016-05-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -134,16 +134,16 @@ dependencies:
134
134
  name: shoulda-matchers
135
135
  requirement: !ruby/object:Gem::Requirement
136
136
  requirements:
137
- - - ">="
137
+ - - "~>"
138
138
  - !ruby/object:Gem::Version
139
- version: '0'
139
+ version: 3.1.1
140
140
  type: :development
141
141
  prerelease: false
142
142
  version_requirements: !ruby/object:Gem::Requirement
143
143
  requirements:
144
- - - ">="
144
+ - - "~>"
145
145
  - !ruby/object:Gem::Version
146
- version: '0'
146
+ version: 3.1.1
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: webmock
149
149
  requirement: !ruby/object:Gem::Requirement
@@ -162,16 +162,30 @@ dependencies:
162
162
  name: guard-rspec
163
163
  requirement: !ruby/object:Gem::Requirement
164
164
  requirements:
165
- - - ">="
165
+ - - '='
166
166
  - !ruby/object:Gem::Version
167
- version: '0'
167
+ version: 4.6.4
168
168
  type: :development
169
169
  prerelease: false
170
170
  version_requirements: !ruby/object:Gem::Requirement
171
171
  requirements:
172
- - - ">="
172
+ - - '='
173
173
  - !ruby/object:Gem::Version
174
- version: '0'
174
+ version: 4.6.4
175
+ - !ruby/object:Gem::Dependency
176
+ name: listen
177
+ requirement: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: 3.0.6
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: 3.0.6
175
189
  - !ruby/object:Gem::Dependency
176
190
  name: rb-fsevent
177
191
  requirement: !ruby/object:Gem::Requirement
@@ -267,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
281
  version: '0'
268
282
  requirements: []
269
283
  rubyforge_project:
270
- rubygems_version: 2.4.8
284
+ rubygems_version: 2.5.1
271
285
  signing_key:
272
286
  specification_version: 4
273
287
  summary: CanvasOauth is a mountable engine for handling the oauth workflow with canvas