bearcat 1.3.10 → 1.3.11

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2638ba0d30fa85c6877d987310f9bf59e7661f2c
4
- data.tar.gz: d7538f4a870fe635eb6bd68bd8b3b204c8e5da91
3
+ metadata.gz: 867a8c613b078d0b370d683d195f09f9664771e3
4
+ data.tar.gz: 6b3dcbf10b3d5af0086080adb1a06659c9e6a7d2
5
5
  SHA512:
6
- metadata.gz: d9c8ca2a6573b456018a826791c5d8051c05bd74c2a7654ef172c57e018f8c536dccf0542efc9208df1dd165e5c5f9fb1fa4528fce42b637bf635f955eab6a6d
7
- data.tar.gz: e1ca459229b2f15d92d3b3e564c2fc5f429a7c9c4e0133d8818a0c132fa3be41559df13d55d17e8f3c7064c622f175ebd8924417207eee91b2759d670de61a24
6
+ metadata.gz: 9e0c02e8102651d70fdc2f514178e3f93646b37c32487b3e701e8a54178ffb55a5f0feb9d5f1b622377d5d235a95093e0dc9d6db3977ffd090e96044074aaad8
7
+ data.tar.gz: 0637013e221c6655a499db41df3b31235d604b281acf56b7e4b87e4b97d58aaa6a4b4b60dd3b6ae2a405df9c54cb67233445d0a294472a710c0f97809cbdae4f
@@ -114,11 +114,18 @@ module Bearcat
114
114
  end
115
115
 
116
116
  def get_page(url, params = {})
117
- params['per_page'] = @page_count unless params.has_key? 'per_page' || !@page_count
117
+ params['per_page'] = @page_count unless params.key?('per_page') || !@page_count
118
118
  query = URI.parse(url).query
119
- p = CGI.parse(query).merge(params)
119
+ p = CGI.parse(query)
120
120
  u = url.gsub("?#{query}", '')
121
- p.each { |k, v| p[k] = v.first if v.is_a?(Array) }
121
+
122
+ # strip value out of array if value is an array and key doesn't have [] (parameter is not an array parameter)
123
+ p.each { |k, v| p[k] = v.first if v.is_a?(Array) && k !~ /\[\]$/ }
124
+ # remove [] from key names, this is copied from rails' {}.transform_keys!
125
+ p.keys.each { |k| p[k.delete('[]')] = p.delete(k) }
126
+ # merge params
127
+ p.merge!(params)
128
+
122
129
  @api_client.connection.send(:get) do |r|
123
130
  r.url(u, p)
124
131
  end
@@ -1,3 +1,3 @@
1
1
  module Bearcat
2
- VERSION = '1.3.10' unless defined?(Bearcat::VERSION)
2
+ VERSION = '1.3.11' unless defined?(Bearcat::VERSION)
3
3
  end
@@ -0,0 +1,55 @@
1
+ require 'helper'
2
+
3
+ describe Bearcat::ApiArray do
4
+ describe 'get_page' do
5
+ let(:api_client) { double }
6
+ let(:original_response) { double(body: [], status: 200, headers: {}, env: {}) }
7
+ let(:api_array) { described_class.process_response(original_response, api_client) }
8
+ let(:connection) { double }
9
+ let(:request) { double }
10
+
11
+ before :each do
12
+ api_array.instance_variable_set('@page_count', nil)
13
+ allow(api_client).to receive(:connection).and_return connection
14
+ allow(connection).to receive(:send) do |&block|
15
+ block.call(request)
16
+ end
17
+ end
18
+
19
+ it 'gets a page of results' do
20
+ expect(request).to receive(:url).with('https://fake.com', 'page' => '2')
21
+ api_array.send(:get_page, 'https://fake.com?page=2', {})
22
+ end
23
+
24
+ it 'merges additonal params to the url query' do
25
+ expect(request).to receive(:url).with('https://fake.com', 'test' => 'param', 'page' => 2)
26
+ api_array.send(:get_page, 'https://fake.com?test=param', 'page' => 2)
27
+ end
28
+
29
+ it 'handles array parameters' do
30
+ expect(request).to receive(:url).with('https://fake.com', 'test' => ['param'], 'second' => ['param'])
31
+ api_array.send(:get_page, 'https://fake.com?test%5B%5D=param', 'second' => ['param'])
32
+ end
33
+
34
+ it 'sets the per_page parameter if not already set and @page_count has a value' do
35
+ api_array.instance_variable_set('@page_count', 50)
36
+
37
+ expect(request).to receive(:url).with('https://fake.com', 'per_page' => 50)
38
+ api_array.send(:get_page, 'https://fake.com?', {})
39
+ end
40
+
41
+ it 'does not set the per_page parameter if @page_count is not available' do
42
+ api_array.instance_variable_set('@page_count', nil)
43
+
44
+ expect(request).to receive(:url).with('https://fake.com', {})
45
+ api_array.send(:get_page, 'https://fake.com?', {})
46
+ end
47
+
48
+ it 'does not set the per_page parameter if it is already set' do
49
+ api_array.instance_variable_set('@page_count', 50)
50
+
51
+ expect(request).to receive(:url).with('https://fake.com', 'per_page' => 10)
52
+ api_array.send(:get_page, 'https://fake.com?', 'per_page' => 10)
53
+ end
54
+ end
55
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bearcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.10
4
+ version: 1.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Mills, Jake Sorce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-07 00:00:00.000000000 Z
11
+ date: 2017-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -140,6 +140,7 @@ files:
140
140
  - lib/bearcat/client/submissions.rb
141
141
  - lib/bearcat/client/users.rb
142
142
  - lib/bearcat/version.rb
143
+ - spec/bearcat/api_array_spec.rb
143
144
  - spec/bearcat/client/accounts_spec.rb
144
145
  - spec/bearcat/client/analytics_spec.rb
145
146
  - spec/bearcat/client/assignment_groups_spec.rb
@@ -313,11 +314,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
313
314
  version: '0'
314
315
  requirements: []
315
316
  rubyforge_project:
316
- rubygems_version: 2.4.8
317
+ rubygems_version: 2.4.5.1
317
318
  signing_key:
318
319
  specification_version: 4
319
320
  summary: Canvas API
320
321
  test_files:
322
+ - spec/bearcat/api_array_spec.rb
321
323
  - spec/bearcat/client/accounts_spec.rb
322
324
  - spec/bearcat/client/analytics_spec.rb
323
325
  - spec/bearcat/client/assignment_groups_spec.rb
@@ -472,3 +474,4 @@ test_files:
472
474
  - spec/fixtures/user_page_views.json
473
475
  - spec/fixtures/user_profile.json
474
476
  - spec/helper.rb
477
+ has_rdoc: