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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c1da68dc3d18b0e400a36959cc3490b8305854e
4
- data.tar.gz: 1bcf5038d5945ea5f38ac765e8fd33df78519156
3
+ metadata.gz: 1c5eac3c107ef2d7c8fcc50f8b94f63146c2d595
4
+ data.tar.gz: 7bf4cb81296e04bc2063732e4bbed0dcea1d4b48
5
5
  SHA512:
6
- metadata.gz: 6a24e9f1d705dae61f8f0927c2aab03aa27e7c728dc939140693b3e407c014d6cc79709dab665fd8849f0d8ff2bf053e35bf19591022bbe6430a8d3bc7b19159
7
- data.tar.gz: 3da71e5ad1571c46d787ee3b172c6060eb1a5d87cbe3dfc387eff81898b6028f6cb6c038015c0a5f299de43edb56180674cb5662e1cce668a7ea3a8a3a20392f
6
+ metadata.gz: 202c311693c06b8bc520d3327a1edc7c56f0b65be97440d6ab554d4592b5cd90c209888c5f0512424120f455bb846e12eb25ef60e21d7e83db9ab70ab0badde1
7
+ data.tar.gz: 442bd5bf891b9a8fc7bf8854e43198c82632d4c0bc290fa5413c6872fdb3a8ef55a8dbb91df235304d3af3f526800b49d936a2fb487f633aa8f52a964fbe65e7
@@ -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 = "global_registry"
7
+ gem.name = 'global_registry'
8
8
  gem.version = GlobalRegistry::VERSION
9
- gem.authors = ["Josh Starcher"]
10
- gem.email = ["josh.starcher@gmail.com"]
11
- gem.description = %q{This gem wraps an API for the Global Registry.}
12
- gem.summary = %q{Push and pull data from the Global Registry}
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 = ["lib"]
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
@@ -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
@@ -1,6 +1,8 @@
1
1
  module GlobalRegistry
2
2
  class EntityType < Base
3
-
3
+ # This doesn't do any paging yet since, but we can add it later if needed.
4
+ def self.for_names(names)
5
+ get_all_pages('filters[name][]' => names)['entity_types']
6
+ end
4
7
  end
5
8
  end
6
-
@@ -0,0 +1,11 @@
1
+ module GlobalRegistry
2
+ class Subscription < Base
3
+ def self.all
4
+ get_all_pages['subscriptions']
5
+ end
6
+
7
+ def self.create(params)
8
+ post(subscription: params)
9
+ end
10
+ end
11
+ end
@@ -1,4 +1,3 @@
1
1
  module GlobalRegistry
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.1'.freeze
3
3
  end
4
-
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.0
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-10 00:00:00.000000000 Z
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.5.1
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