bearcat 1.3.44 → 1.3.45

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: b91690f9dddf5832886431880e39b72b4a25d973
4
- data.tar.gz: f5a216c9a3260770c07ea61fa7ffe26dafd95c25
3
+ metadata.gz: 4df1420a15e970e9935719b7a6a7366023ad524d
4
+ data.tar.gz: c24ace0db440224f5c56835da55f1218fece1505
5
5
  SHA512:
6
- metadata.gz: 2728a893d0a01330e9976742155c10c3b002ed713c9219188d590569d082e05b782802c02d57e888c049c81d79843002a284e136d4069005cb4d7433994296bd
7
- data.tar.gz: 9c6c6abe1e6c2891b3af32c90d99c687e096a6861f855f017222e0b9dc79219cc2247dbf90d462874bf8ac8b2f56e9ae850bad05888c73ef747bd4042eec4337
6
+ metadata.gz: a44471bb065353b6ff0bb3e3456a657cad85c977168f22b065c4d5b39c0ded885502de9c49209f47e25b6248e9b454a14a06be4de34ba607e95b2f2c2180cb55
7
+ data.tar.gz: 806e9ba0991a8e0bf62182211e8cb69fc365f27c2b0994ce95429f8f7566c42b03930465d40ec44bba9aa683ba469fdd5efa06ddb6282b7d1f047de93f22496c
@@ -62,23 +62,27 @@ module Bearcat
62
62
 
63
63
  def each_page(page_count = 50, &block)
64
64
  @page_count = page_count
65
- response = get_page(@link_hash['first'])
66
- @headers = response.headers
67
- @status = response.status
68
- @method = response.env[:method]
69
- init_pages(@headers[:link])
70
- @members = process_body(response)
71
- block.call(@members)
72
- while @link_hash['next']
73
- response = get_page(@link_hash['next'])
65
+ if pages?
66
+ response = get_page(@link_hash['first'])
74
67
  @headers = response.headers
75
68
  @status = response.status
76
69
  @method = response.env[:method]
77
- @members = process_body(response)
78
70
  init_pages(@headers[:link])
71
+ @members = process_body(response)
72
+ block.call(@members)
73
+ while @link_hash['next']
74
+ response = get_page(@link_hash['next'])
75
+ @headers = response.headers
76
+ @status = response.status
77
+ @method = response.env[:method]
78
+ @members = process_body(response)
79
+ init_pages(@headers[:link])
80
+ block.call(@members)
81
+ end
82
+ @link_hash = {}
83
+ else
79
84
  block.call(@members)
80
85
  end
81
- @link_hash = {}
82
86
  end
83
87
 
84
88
  def all_pages_each(page_count = 50, &block)
@@ -0,0 +1,59 @@
1
+ # Bearcat RSpec Helpers
2
+ # Can be included in your spec_helper.rb file by using:
3
+ # - `require 'bearcat/spec_helpers'`
4
+ # And
5
+ # - `config.include Bearcat::SpecHelpers`
6
+ module Bearcat::SpecHelpers
7
+ SOURCE_REGEX = /(?<method>get|post|delete|put)\((?<quote>\\?('|"))(?<url>.*)\k<quote>/
8
+
9
+ # Helper method to Stub Bearcat requests.
10
+ # Automagically parses the Bearcat method source to determine the correct URL to stub.
11
+ # Accepts optional keyword parameters to interpolate specific values into the URL.
12
+ # Returns a mostly-normal Webmock stub (:to_return has been overridden to allow :body to be set to a Hash)
13
+ def stub_bearcat(endpoint, prefix: nil, **kwargs)
14
+ if prefix == true
15
+ prefix = canvas_api_client if defined? canvas_api_client
16
+ prefix = canvas_sync_client if defined? canvas_sync_client
17
+ end
18
+ prefix = case prefix
19
+ when nil
20
+ ''
21
+ when false
22
+ ''
23
+ when true
24
+ raise "stub_bearcat() prefix: set to true, but neither canvas_(sync|api)_client are defined"
25
+ when Bearcat::Client
26
+ prefix.prefix
27
+ when String
28
+ prefix
29
+ end
30
+
31
+ ruby_method = Bearcat::Client.instance_method(endpoint)
32
+ match = SOURCE_REGEX.match(ruby_method.source)
33
+ url = match[:url]
34
+ url = url.gsub(/#\{(?<key>.*?)\}/) do |match|
35
+ match = Regexp.last_match
36
+ v = kwargs[match[:key].to_sym]
37
+ case v
38
+ when nil
39
+ '\\w+'
40
+ when Regexp
41
+ v.source
42
+ when String
43
+ Regexp.escape(v)
44
+ end
45
+ end
46
+ url = prefix + url if prefix.present?
47
+ url_pattern = Regexp.new(url)
48
+ stub = stub_request(match[:method].to_sym, url_pattern)
49
+ stub.define_singleton_method(:to_return, ->(*resps) {
50
+ resps.map do |resp|
51
+ resp[:headers] ||= {}
52
+ resp[:headers]["Content-Type"] ||= "application/json"
53
+ resp[:body] = resp[:body].to_json
54
+ end
55
+ super(*resps)
56
+ })
57
+ stub
58
+ end
59
+ end
@@ -1,3 +1,3 @@
1
1
  module Bearcat
2
- VERSION = '1.3.44' unless defined?(Bearcat::VERSION)
2
+ VERSION = '1.3.45' unless defined?(Bearcat::VERSION)
3
3
  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.44
4
+ version: 1.3.45
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: 2019-05-30 00:00:00.000000000 Z
11
+ date: 2019-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -172,6 +172,7 @@ files:
172
172
  - lib/bearcat/client/sections.rb
173
173
  - lib/bearcat/client/submissions.rb
174
174
  - lib/bearcat/client/users.rb
175
+ - lib/bearcat/spec_helpers.rb
175
176
  - lib/bearcat/version.rb
176
177
  - spec/bearcat/api_array_spec.rb
177
178
  - spec/bearcat/client/accounts_spec.rb
@@ -370,7 +371,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
370
371
  version: '0'
371
372
  requirements: []
372
373
  rubyforge_project:
373
- rubygems_version: 2.5.1
374
+ rubygems_version: 2.4.5.1
374
375
  signing_key:
375
376
  specification_version: 4
376
377
  summary: Canvas API