global_registry_models 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +34 -0
- data/Rakefile +10 -0
- data/bin/console +13 -0
- data/bin/setup +7 -0
- data/global_registry_models.gemspec +31 -0
- data/lib/global_registry_models/entity/api_operations/delete.rb +24 -0
- data/lib/global_registry_models/entity/api_operations/finders.rb +39 -0
- data/lib/global_registry_models/entity/api_operations/search.rb +37 -0
- data/lib/global_registry_models/entity/area.rb +17 -0
- data/lib/global_registry_models/entity/base.rb +73 -0
- data/lib/global_registry_models/entity/collection.rb +68 -0
- data/lib/global_registry_models/entity/global_mcc.rb +17 -0
- data/lib/global_registry_models/entity/iso_country.rb +20 -0
- data/lib/global_registry_models/entity/ministry.rb +23 -0
- data/lib/global_registry_models/entity/target_area.rb +46 -0
- data/lib/global_registry_models/response_parser.rb +28 -0
- data/lib/global_registry_models/retryer.rb +41 -0
- data/lib/global_registry_models/version.rb +3 -0
- data/lib/global_registry_models.rb +21 -0
- metadata +182 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e29c0de9cfad74c834e9cddc425fea1f7c0f8382
|
4
|
+
data.tar.gz: 47ba8ada08097a44a5f0fd68f99866bae37cf320
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f01b912964d9e43f8006cd54c7f945609a9b3a28b4afcbcb002aca8b6703d47b802d1b05ecaac4aff3f5aefe2753bd4348f6211eb964f0c90607771edc613b59
|
7
|
+
data.tar.gz: 02a2d24e3df1c23789d9ac2e54a7bc975fa2409e6d2d3e2440cb1c12816ac1953c81eebe2a600940899851cf736c95444952c67b9a66dc6d6c0e41fa3999cf6a
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
global_registry_models
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Sheldon Dueck
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Global Registry Models
|
2
|
+
|
3
|
+
Provides data models for interacting with the [Global Registry](http://www.global-registry.org/). Built ontop of the [client gem global_registry](https://github.com/CruGlobal/global_registry_client).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'global_registry_models'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install global_registry_models
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
24
|
+
|
25
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sheldond/global_registry_models.
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
34
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'global_registry_models'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
GlobalRegistry.access_token = 'set your token here'
|
10
|
+
GlobalRegistry.base_url = 'https://stage-api.global-registry.org/'
|
11
|
+
|
12
|
+
require 'pry'
|
13
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'global_registry_models/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'global_registry_models'
|
8
|
+
spec.version = GlobalRegistryModels::VERSION
|
9
|
+
spec.authors = ['Sheldon Dueck']
|
10
|
+
spec.email = ['sheldon.dueck@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Data models for the Global Registry.}
|
13
|
+
spec.description = %q{Provides data models for interacting with the Global Registry. Built ontop of the client gem global_registry.}
|
14
|
+
spec.homepage = 'https://github.com/sheldond/global_registry_models'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'activemodel', '~> 4.2'
|
23
|
+
spec.add_dependency 'virtus', '~> 1.0'
|
24
|
+
spec.add_dependency 'global_registry', '~> 1.0'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'minitest', '~> 5.8'
|
29
|
+
spec.add_development_dependency 'webmock', '~> 1.20'
|
30
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module GlobalRegistryModels
|
2
|
+
module Entity
|
3
|
+
module APIOperations
|
4
|
+
module Delete
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def delete(id)
|
9
|
+
GlobalRegistry::Entity.delete id
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete
|
14
|
+
if id.present?
|
15
|
+
self.class.delete id
|
16
|
+
else
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'global_registry'
|
3
|
+
require 'global_registry_models/retryer'
|
4
|
+
|
5
|
+
module GlobalRegistryModels
|
6
|
+
module Entity
|
7
|
+
module APIOperations
|
8
|
+
module Finders
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
|
13
|
+
def all!(filters: nil, start_page: 1, per_page: nil, order: nil, fields: nil, ruleset: nil)
|
14
|
+
GlobalRegistryModels::Entity::Collection.new(meta: {}, entities: []).tap do |collection|
|
15
|
+
page_num = start_page
|
16
|
+
loop do
|
17
|
+
sub_collection = GlobalRegistryModels::Retryer.new(RestClient::InternalServerError).try do
|
18
|
+
self.search(filters: filters, page: page_num, per_page: per_page, order: order, fields: fields, ruleset: ruleset)
|
19
|
+
end
|
20
|
+
break if sub_collection.blank?
|
21
|
+
collection.concat sub_collection.all
|
22
|
+
page_num += 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def find(id)
|
28
|
+
new GlobalRegistry::Entity.find(id)['entity'][name]
|
29
|
+
end
|
30
|
+
|
31
|
+
def page(page_number = 1)
|
32
|
+
search page: page_number
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module GlobalRegistryModels
|
2
|
+
module Entity
|
3
|
+
module APIOperations
|
4
|
+
module Search
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
|
9
|
+
def search(filters: nil, page: nil, per_page: nil, order: nil, fields: nil, ruleset: nil)
|
10
|
+
params = {
|
11
|
+
entity_type: name,
|
12
|
+
page: page,
|
13
|
+
per_page: per_page,
|
14
|
+
order: order,
|
15
|
+
fields: fields,
|
16
|
+
ruleset: ruleset
|
17
|
+
}.delete_if { |_, v| v.blank? }
|
18
|
+
|
19
|
+
filters.try(:reject!) { |_, v| v.blank? }
|
20
|
+
if filters.present?
|
21
|
+
# We need to generate a hash like this: { 'filters[name]' => 'name query', 'filters[attribute][nested_attribute]' => 'nested_attribute query' }
|
22
|
+
# It just so happens we can use CGI::parse to do it.
|
23
|
+
filter_params_hash = CGI::parse({ filters: filters }.to_query)
|
24
|
+
filter_params_hash.each { |k, v| filter_params_hash[k] = v.first if v.is_a?(Array) } # CGI::parse returns values as arrays, we just want string values
|
25
|
+
|
26
|
+
params.merge! filter_params_hash
|
27
|
+
end
|
28
|
+
|
29
|
+
response = GlobalRegistryModels::ResponseParser.new Retryer.new(RestClient::InternalServerError).try { GlobalRegistry::Entity.get(params) }
|
30
|
+
Entity::Collection.new meta: response.meta, entities: response.entities
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module GlobalRegistryModels
|
2
|
+
module Entity
|
3
|
+
class Area < Base
|
4
|
+
attribute :area_code, String
|
5
|
+
attribute :area_name, String
|
6
|
+
attribute :is_active, Boolean
|
7
|
+
|
8
|
+
def self.identifying_attributes
|
9
|
+
[:area_name, :area_code]
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
area_name
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# A base class providing CRUD for GlobalRegistry Entities.
|
2
|
+
# API doc at https://github.com/CruGlobal/global_registry_docs/wiki/Entities
|
3
|
+
|
4
|
+
require 'active_model'
|
5
|
+
require 'virtus'
|
6
|
+
|
7
|
+
module GlobalRegistryModels
|
8
|
+
module Entity
|
9
|
+
class Base
|
10
|
+
include ActiveModel::Model
|
11
|
+
include ActiveModel::Validations
|
12
|
+
include Virtus.model
|
13
|
+
|
14
|
+
include GlobalRegistryModels::Entity::APIOperations::Finders
|
15
|
+
include GlobalRegistryModels::Entity::APIOperations::Search
|
16
|
+
include GlobalRegistryModels::Entity::APIOperations::Delete
|
17
|
+
|
18
|
+
attribute :id, String
|
19
|
+
attribute :client_integration_id, String
|
20
|
+
|
21
|
+
validates_presence_of :client_integration_id
|
22
|
+
|
23
|
+
def self.title
|
24
|
+
name.titleize
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.attribute_names
|
28
|
+
attribute_set.collect(&:name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.filterable_attributes
|
32
|
+
attribute_names
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.identifying_attributes
|
36
|
+
[:id]
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.create(attributes)
|
40
|
+
attributes = attributes.except(:id)
|
41
|
+
if new(attributes).valid?
|
42
|
+
new GlobalRegistry::Entity.post({ entity: { name => attributes }})['entity'][name]
|
43
|
+
else
|
44
|
+
false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.update(id, attributes)
|
49
|
+
attributes = attributes.except(:id)
|
50
|
+
if new(attributes).valid?
|
51
|
+
new GlobalRegistry::Entity.put(id, { entity: { name => attributes }})['entity'][name]
|
52
|
+
else
|
53
|
+
false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# The name of the entity class. The entity name is required in the api responses and requests, hence the need for this class method.
|
58
|
+
def self.name
|
59
|
+
to_s.gsub(/.*::/, '').underscore
|
60
|
+
end
|
61
|
+
|
62
|
+
def save
|
63
|
+
if valid?
|
64
|
+
result = id.present? ? self.class.update(id, attributes) : self.class.create(attributes)
|
65
|
+
result ? self.id = result.id : false
|
66
|
+
else
|
67
|
+
false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module GlobalRegistryModels
|
4
|
+
module Entity
|
5
|
+
class Collection
|
6
|
+
include Enumerable
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :@entities, :[], :size, :concat, :blank?, :present?
|
10
|
+
|
11
|
+
def initialize(meta:, entities:)
|
12
|
+
@meta = meta
|
13
|
+
@entities = entities
|
14
|
+
end
|
15
|
+
|
16
|
+
def each
|
17
|
+
@entities.each { |entity| yield entity }
|
18
|
+
end
|
19
|
+
|
20
|
+
def all
|
21
|
+
@entities
|
22
|
+
end
|
23
|
+
|
24
|
+
def page
|
25
|
+
@meta['page']
|
26
|
+
end
|
27
|
+
|
28
|
+
def last_page?
|
29
|
+
!@meta['next_page']
|
30
|
+
end
|
31
|
+
|
32
|
+
def first_page?
|
33
|
+
page == 1
|
34
|
+
end
|
35
|
+
|
36
|
+
def next_page
|
37
|
+
last_page? ? nil : page + 1
|
38
|
+
end
|
39
|
+
|
40
|
+
def prev_page
|
41
|
+
first_page? ? nil : page - 1
|
42
|
+
end
|
43
|
+
|
44
|
+
def from
|
45
|
+
@meta['from']
|
46
|
+
end
|
47
|
+
|
48
|
+
def to
|
49
|
+
@meta['to']
|
50
|
+
end
|
51
|
+
|
52
|
+
def per
|
53
|
+
(to - from) + 1
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_csv
|
57
|
+
CSV.generate do |csv|
|
58
|
+
attributes = @entities.first.attributes.collect(&:first).sort
|
59
|
+
csv << attributes
|
60
|
+
@entities.each do |entity|
|
61
|
+
csv << attributes.collect { |attribute| entity.attributes[attribute] }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module GlobalRegistryModels
|
2
|
+
module Entity
|
3
|
+
class GlobalMcc < Base
|
4
|
+
attribute :mcc_code, String
|
5
|
+
attribute :name, String
|
6
|
+
attribute :partner_md_total, Integer
|
7
|
+
|
8
|
+
def self.identifying_attributes
|
9
|
+
[:name, :mcc_code]
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
name
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module GlobalRegistryModels
|
2
|
+
module Entity
|
3
|
+
class IsoCountry < Base
|
4
|
+
attribute :currency_code, String
|
5
|
+
attribute :currency_name, String
|
6
|
+
attribute :currency_symbol, String
|
7
|
+
attribute :iso2_code, String
|
8
|
+
attribute :iso3_code, String
|
9
|
+
attribute :name, String
|
10
|
+
|
11
|
+
def self.identifying_attributes
|
12
|
+
[:name, :iso2_code, :iso3_code]
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module GlobalRegistryModels
|
2
|
+
module Entity
|
3
|
+
class Ministry < Base
|
4
|
+
attribute :country, String
|
5
|
+
attribute :city, String
|
6
|
+
attribute :is_active, String
|
7
|
+
attribute :location, String
|
8
|
+
attribute :min_code, String
|
9
|
+
attribute :name, String
|
10
|
+
attribute :ministry_type, String
|
11
|
+
|
12
|
+
def self.identifying_attributes
|
13
|
+
[:name, :country, :city, :min_code]
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module GlobalRegistryModels
|
2
|
+
module Entity
|
3
|
+
class TargetArea < Base
|
4
|
+
attribute :abbrv, String
|
5
|
+
attribute :address1, String
|
6
|
+
attribute :address2, String
|
7
|
+
attribute :alt_name, String
|
8
|
+
attribute :city, String
|
9
|
+
attribute :country, String
|
10
|
+
attribute :email, String
|
11
|
+
attribute :enrollment, Integer
|
12
|
+
attribute :event_id, Integer
|
13
|
+
attribute :event_type, String
|
14
|
+
attribute :fax, String
|
15
|
+
attribute :fice, String
|
16
|
+
attribute :gate, String
|
17
|
+
attribute :highest_offering, String
|
18
|
+
attribute :institution_type, String
|
19
|
+
attribute :is_closed, String
|
20
|
+
attribute :is_global_slm_team_target, Boolean
|
21
|
+
attribute :is_no_fice_ok, String
|
22
|
+
attribute :is_secure, Boolean
|
23
|
+
attribute :latitude, Float
|
24
|
+
attribute :longitude, Float
|
25
|
+
attribute :main_campus_fice, String
|
26
|
+
attribute :name, String
|
27
|
+
attribute :note, String
|
28
|
+
attribute :ongoing_special_event, Boolean
|
29
|
+
attribute :phone, String
|
30
|
+
attribute :region, String
|
31
|
+
attribute :state, String
|
32
|
+
attribute :target_area_ministry_presence, String
|
33
|
+
attribute :type, String
|
34
|
+
attribute :url, String
|
35
|
+
attribute :zip, String
|
36
|
+
|
37
|
+
def self.identifying_attributes
|
38
|
+
[:name, :country, :state, :state]
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_s
|
42
|
+
name
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module GlobalRegistryModels
|
2
|
+
class ResponseParser
|
3
|
+
|
4
|
+
def initialize(global_registry_response)
|
5
|
+
@response_hash = global_registry_response
|
6
|
+
end
|
7
|
+
|
8
|
+
def meta
|
9
|
+
@response_hash['meta']
|
10
|
+
end
|
11
|
+
|
12
|
+
def entities
|
13
|
+
@entities ||= build_entities
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def build_entities
|
19
|
+
@response_hash['entities'].collect(&:flatten).collect do |entity_type, entity_attributes|
|
20
|
+
entity_class(entity_type).new(entity_attributes)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def entity_class(entity_type_string)
|
25
|
+
"GlobalRegistryModels::Entity::#{ entity_type_string.classify }".constantize
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module GlobalRegistryModels
|
2
|
+
class Retryer
|
3
|
+
|
4
|
+
attr_accessor :attempt_number, :sleepiness, :exception_classes, :max_number_of_attempts
|
5
|
+
|
6
|
+
def initialize(*exception_classes, max_attempts: 7)
|
7
|
+
self.attempt_number = 1
|
8
|
+
self.sleepiness = 0
|
9
|
+
self.max_number_of_attempts = max_attempts
|
10
|
+
self.exception_classes = exception_classes.presence || [StandardError]
|
11
|
+
end
|
12
|
+
|
13
|
+
def try
|
14
|
+
yield
|
15
|
+
rescue => exception
|
16
|
+
raise exception unless retry_exception?(exception)
|
17
|
+
puts "Retryer rescued #{ exception.inspect } on attempt #{ self.attempt_number }, sleeping for #{ self.sleepiness} seconds."
|
18
|
+
sleep sleepiness
|
19
|
+
increase_sleepiness
|
20
|
+
puts "Retryer attempting retry #{ self.attempt_number += 1 }.#{ ' This is the last attempt!' if last_attempt? }"
|
21
|
+
retry
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def retry_exception?(exception)
|
27
|
+
exception_classes.include?(exception.class) && !last_attempt?
|
28
|
+
end
|
29
|
+
|
30
|
+
def last_attempt?
|
31
|
+
return false if max_number_of_attempts.nil?
|
32
|
+
attempt_number >= max_number_of_attempts
|
33
|
+
end
|
34
|
+
|
35
|
+
def increase_sleepiness
|
36
|
+
return self.sleepiness = 1 if sleepiness <= 0
|
37
|
+
self.sleepiness = [1000, (sleepiness * 2)].min
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
|
3
|
+
require 'global_registry_models/version'
|
4
|
+
|
5
|
+
require 'global_registry_models/response_parser'
|
6
|
+
require 'global_registry_models/retryer'
|
7
|
+
|
8
|
+
require 'global_registry_models/entity/api_operations/finders'
|
9
|
+
require 'global_registry_models/entity/api_operations/search'
|
10
|
+
require 'global_registry_models/entity/api_operations/delete'
|
11
|
+
|
12
|
+
require 'global_registry_models/entity/base'
|
13
|
+
require 'global_registry_models/entity/area'
|
14
|
+
require 'global_registry_models/entity/collection'
|
15
|
+
require 'global_registry_models/entity/global_mcc'
|
16
|
+
require 'global_registry_models/entity/iso_country'
|
17
|
+
require 'global_registry_models/entity/ministry'
|
18
|
+
require 'global_registry_models/entity/target_area'
|
19
|
+
|
20
|
+
module GlobalRegistryModels
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: global_registry_models
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sheldon Dueck
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: virtus
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: global_registry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.20'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.20'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.10'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.10'
|
125
|
+
description: Provides data models for interacting with the Global Registry. Built
|
126
|
+
ontop of the client gem global_registry.
|
127
|
+
email:
|
128
|
+
- sheldon.dueck@gmail.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- ".ruby-gemset"
|
135
|
+
- ".ruby-version"
|
136
|
+
- ".travis.yml"
|
137
|
+
- Gemfile
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- bin/console
|
142
|
+
- bin/setup
|
143
|
+
- global_registry_models.gemspec
|
144
|
+
- lib/global_registry_models.rb
|
145
|
+
- lib/global_registry_models/entity/api_operations/delete.rb
|
146
|
+
- lib/global_registry_models/entity/api_operations/finders.rb
|
147
|
+
- lib/global_registry_models/entity/api_operations/search.rb
|
148
|
+
- lib/global_registry_models/entity/area.rb
|
149
|
+
- lib/global_registry_models/entity/base.rb
|
150
|
+
- lib/global_registry_models/entity/collection.rb
|
151
|
+
- lib/global_registry_models/entity/global_mcc.rb
|
152
|
+
- lib/global_registry_models/entity/iso_country.rb
|
153
|
+
- lib/global_registry_models/entity/ministry.rb
|
154
|
+
- lib/global_registry_models/entity/target_area.rb
|
155
|
+
- lib/global_registry_models/response_parser.rb
|
156
|
+
- lib/global_registry_models/retryer.rb
|
157
|
+
- lib/global_registry_models/version.rb
|
158
|
+
homepage: https://github.com/sheldond/global_registry_models
|
159
|
+
licenses:
|
160
|
+
- MIT
|
161
|
+
metadata: {}
|
162
|
+
post_install_message:
|
163
|
+
rdoc_options: []
|
164
|
+
require_paths:
|
165
|
+
- lib
|
166
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
requirements: []
|
177
|
+
rubyforge_project:
|
178
|
+
rubygems_version: 2.4.6
|
179
|
+
signing_key:
|
180
|
+
specification_version: 4
|
181
|
+
summary: Data models for the Global Registry.
|
182
|
+
test_files: []
|