global_registry 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/global_registry.gemspec +10 -10
- data/lib/global_registry/base.rb +27 -4
- data/lib/global_registry/entity_type.rb +4 -2
- data/lib/global_registry/subscription.rb +11 -0
- data/lib/global_registry/version.rb +1 -2
- data/spec/base_spec.rb +35 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c5eac3c107ef2d7c8fcc50f8b94f63146c2d595
|
4
|
+
data.tar.gz: 7bf4cb81296e04bc2063732e4bbed0dcea1d4b48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 202c311693c06b8bc520d3327a1edc7c56f0b65be97440d6ab554d4592b5cd90c209888c5f0512424120f455bb846e12eb25ef60e21d7e83db9ab70ab0badde1
|
7
|
+
data.tar.gz: 442bd5bf891b9a8fc7bf8854e43198c82632d4c0bc290fa5413c6872fdb3a8ef55a8dbb91df235304d3af3f526800b49d936a2fb487f633aa8f52a964fbe65e7
|
data/global_registry.gemspec
CHANGED
@@ -4,23 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'global_registry/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name =
|
7
|
+
gem.name = 'global_registry'
|
8
8
|
gem.version = GlobalRegistry::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
11
|
-
gem.description =
|
12
|
-
gem.summary =
|
13
|
-
gem.homepage =
|
9
|
+
gem.authors = ['Josh Starcher']
|
10
|
+
gem.email = ['josh.starcher@gmail.com']
|
11
|
+
gem.description = 'This gem wraps an API for the Global Registry.'
|
12
|
+
gem.summary = 'Push and pull data from the Global Registry'
|
13
|
+
gem.homepage = ''
|
14
14
|
|
15
|
-
gem.files = `git ls-files`.split(
|
16
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
-
gem.require_paths = [
|
18
|
+
gem.require_paths = ['lib']
|
19
19
|
|
20
20
|
gem.add_dependency('rest-client', '~> 1.6.7')
|
21
21
|
gem.add_dependency('oj', '~> 2.13.0')
|
22
22
|
gem.add_dependency('oj_mimic_json')
|
23
23
|
gem.add_dependency('activesupport')
|
24
24
|
gem.add_dependency('retryable-rb', '~> 1.1.0')
|
25
|
-
|
25
|
+
gem.add_dependency('addressable', '~> 2.4.0')
|
26
26
|
end
|
data/lib/global_registry/base.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rest-client'
|
2
2
|
require 'oj'
|
3
3
|
require 'retryable'
|
4
|
+
require 'addressable/uri'
|
4
5
|
|
5
6
|
module GlobalRegistry
|
6
7
|
class Base
|
@@ -23,6 +24,11 @@ module GlobalRegistry
|
|
23
24
|
def get(params = {}, headers = {})
|
24
25
|
request(:get, params, nil, headers)
|
25
26
|
end
|
27
|
+
def get_all_pages(params = {}, headers = {})
|
28
|
+
results = results_from_all_pages(params, headers)
|
29
|
+
return results unless block_given?
|
30
|
+
results.each { |result| yield result }
|
31
|
+
end
|
26
32
|
|
27
33
|
def self.post(params = {}, headers = {})
|
28
34
|
new.post(params, headers)
|
@@ -134,9 +140,26 @@ module GlobalRegistry
|
|
134
140
|
def access_token
|
135
141
|
@access_token || GlobalRegistry.access_token
|
136
142
|
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
|
141
143
|
|
144
|
+
def results_from_all_pages(params, headers)
|
145
|
+
result = get(params, headers)
|
146
|
+
overall_result = result
|
147
|
+
loop do
|
148
|
+
break unless result['meta'] && result['meta']['next_page']
|
149
|
+
page = result['meta']['page'].to_i + 1
|
150
|
+
result = get(params.merge(page: page), headers)
|
151
|
+
add_result(overall_result, result)
|
152
|
+
end
|
153
|
+
# Return the root result node
|
154
|
+
overall_result.values.first
|
155
|
+
end
|
142
156
|
|
157
|
+
def add_result(overall_result, result)
|
158
|
+
overall_result.each do |key, value|
|
159
|
+
next unless value.is_a?(Array)
|
160
|
+
overall_result[key] = value.concat(result[key])
|
161
|
+
end
|
162
|
+
overall_result.delete('meta')
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
data/spec/base_spec.rb
CHANGED
@@ -24,6 +24,40 @@ describe 'Base' do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
describe '#get_all_pages' do
|
28
|
+
it 'aggregates results from all pages' do
|
29
|
+
stub_page_results
|
30
|
+
|
31
|
+
expect(GlobalRegistry::Base.new(access_token: 'asdf').get_all_pages)
|
32
|
+
.to eq([{ 'id' => '1' }, { 'id' => '2' }])
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'yields results if given a block' do
|
36
|
+
stub_page_results
|
37
|
+
|
38
|
+
expect do |b|
|
39
|
+
GlobalRegistry::Base.new(access_token: 'asdf').get_all_pages.each(&b)
|
40
|
+
end.to yield_successive_args({ 'id' => '1' }, { 'id' => '2' })
|
41
|
+
end
|
42
|
+
|
43
|
+
def stub_page_results
|
44
|
+
page1 = {
|
45
|
+
entity_types: [{ id: '1' }],
|
46
|
+
meta: { page: 1, next_page: true, from: 1, to: 1 }
|
47
|
+
}
|
48
|
+
page2 = {
|
49
|
+
entity_types: [{ id: '2' }],
|
50
|
+
meta: { page: 2, next_page: false, from: 2, to: 2 }
|
51
|
+
}
|
52
|
+
stub_request(:get, 'http://google.com/bases')
|
53
|
+
.with(headers: { authorization: 'Bearer asdf' })
|
54
|
+
.to_return(body: page1.to_json)
|
55
|
+
stub_request(:get, 'http://google.com/bases?page=2')
|
56
|
+
.with(headers: { authorization: 'Bearer asdf' })
|
57
|
+
.to_return(body: page2.to_json)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
27
61
|
describe '#find' do
|
28
62
|
it 'correctly handles array params' do
|
29
63
|
@custom_gr_url = stub_request(:get, 'http://google.com/bases/1?a[]=b&a[]=c')
|
@@ -31,4 +65,4 @@ describe 'Base' do
|
|
31
65
|
expect(@custom_gr_url).to have_been_requested
|
32
66
|
end
|
33
67
|
end
|
34
|
-
end
|
68
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: global_registry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Starcher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 1.1.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: addressable
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.4.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.4.0
|
83
97
|
description: This gem wraps an API for the Global Registry.
|
84
98
|
email:
|
85
99
|
- josh.starcher@gmail.com
|
@@ -103,6 +117,7 @@ files:
|
|
103
117
|
- lib/global_registry/measurement_type.rb
|
104
118
|
- lib/global_registry/relationship.rb
|
105
119
|
- lib/global_registry/relationship_type.rb
|
120
|
+
- lib/global_registry/subscription.rb
|
106
121
|
- lib/global_registry/system.rb
|
107
122
|
- lib/global_registry/version.rb
|
108
123
|
- spec/base_spec.rb
|
@@ -127,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
142
|
version: '0'
|
128
143
|
requirements: []
|
129
144
|
rubyforge_project:
|
130
|
-
rubygems_version: 2.4.
|
145
|
+
rubygems_version: 2.4.8
|
131
146
|
signing_key:
|
132
147
|
specification_version: 4
|
133
148
|
summary: Push and pull data from the Global Registry
|