wcc-data 0.3.2 → 0.4.0.pre.pre.2

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: 02d7a1ec54bdcac827469f19b3070bd28caa171b
4
- data.tar.gz: 87047ce1841ca72d6e3f63010ce906d1c068a268
3
+ metadata.gz: '0827526634396239dc87b1b525c01bd9b1d6af64'
4
+ data.tar.gz: a6cabddbb27e0fd43550fdf5c300d216c34ba8e6
5
5
  SHA512:
6
- metadata.gz: 5dbc59326f6d74240b8f73edbc6119c549460c4350fcb21df324794ee513be5f1ad70ea9a6ef94961bfc982130cb2203d9b11440f401aebd0e589a9fffd7445a
7
- data.tar.gz: 182635eddf51ab2b626d926ffb4e4177f8ce47c40f17f19594eae2741841dd9333b97d3bccb58b28371a8e68d5d18928ec583df203194af74cfc6d4860ba777a
6
+ metadata.gz: 9f6b442582b46ef65f64c08c2621f1b56310610bc074b5ba3ce05301b8ce124fa6017067dc777aa23d91f16faa92fe565e1dc6f57e7e8cc1b16ccde607706542
7
+ data.tar.gz: 4062f09e04552c5afe9aef4b2dcbcaf89fd29915ec2f751c6bd79a2d471c6941a66ab49ca57a35b92347ffde424edc93a9f98731ab548c5dfe6fff7ac3030d12
@@ -15,6 +15,7 @@ module WCC::Data
15
15
  private
16
16
 
17
17
  def set_default_applications
18
+ raise ArgumentError, "Missing NUCLEUS_URL environment variable" unless ENV['NUCLEUS_URL']
18
19
  applications[:nucleus].uri = ENV['NUCLEUS_URL']
19
20
  if ENV['APP_CLIENT_ID'] && ENV['APP_CLIENT_SECRET']
20
21
  applications[:nucleus].connection
@@ -1,64 +1,83 @@
1
+
2
+ begin
3
+ gem 'faraday'
4
+ require 'faraday'
5
+ rescue Gem::LoadError
6
+ # suppress
7
+ end
8
+
9
+
1
10
  module WCC::Data
2
- class FaradayClientAppTokenAuth < Faraday::Middleware
3
- class RedisCache
4
- DEFAULT_CACHE_KEY = "org.watermark.data.client-app-token-cache-store"
5
- attr_reader :connection, :cache_key
11
+ if defined?(Faraday)
12
+ class FaradayClientAppTokenAuth < Faraday::Middleware
13
+ class RedisCache
14
+ DEFAULT_CACHE_KEY = "org.watermark.data.client-app-token-cache-store"
15
+ attr_reader :connection, :cache_key
6
16
 
7
- def initialize(connection, cache_key: DEFAULT_CACHE_KEY)
8
- @connection = connection
9
- @cache_key = cache_key
10
- end
17
+ def initialize(connection, cache_key: DEFAULT_CACHE_KEY)
18
+ @connection = connection
19
+ @cache_key = cache_key
20
+ end
11
21
 
12
- def [](hostname)
13
- connection.call { |r| r.hget cache_key, hostname }
14
- end
22
+ def [](hostname)
23
+ connection.call { |r| r.hget cache_key, hostname }
24
+ end
15
25
 
16
- def []=(hostname, token)
17
- if token
18
- connection.call { |r| r.hset cache_key, hostname, token }
19
- else
20
- connection.call { |r| r.hdel cache_key, hostname }
26
+ def []=(hostname, token)
27
+ if token
28
+ connection.call { |r| r.hset cache_key, hostname, token }
29
+ else
30
+ connection.call { |r| r.hdel cache_key, hostname }
31
+ end
21
32
  end
22
33
  end
23
- end
24
34
 
25
- attr_reader :cache, :token_factory
35
+ attr_reader :cache, :token_factory
26
36
 
27
- def initialize(app, cache: default_cache, token_factory: method(:default_token_factory))
28
- super(app)
29
- @cache = cache
30
- @token_factory = token_factory
31
- end
37
+ def initialize(app, cache: default_cache, token_factory: method(:default_token_factory))
38
+ super(app)
39
+ @cache = cache
40
+ @token_factory = token_factory
41
+ end
32
42
 
33
- def token_for(host)
34
- @cache[host] ||= token_factory.(host)
35
- end
43
+ def token_for(host)
44
+ @cache[host] ||= token_factory.(host)
45
+ end
36
46
 
37
- def call(env, retry_on_forbidden: true)
38
- request_body = env[:body]
39
- host = env[:url].host
40
- env[:request_headers]["Authorization"] = "Bearer #{token_for(host)}"
41
- @app.call(env).on_complete do |response_env|
42
- response = Faraday::Response.new(response_env)
43
- cache[host] = nil unless response.success?
44
- if response.status == 403 && retry_on_forbidden
45
- env[:body] = request_body
46
- call(env, retry_on_forbidden: false)
47
+ def call(env, retry_on_forbidden: true)
48
+ request_body = env[:body]
49
+ host = env[:url].host
50
+ env[:request_headers]["Authorization"] = "Bearer #{token_for(host)}"
51
+ @app.call(env).on_complete do |response_env|
52
+ response = Faraday::Response.new(response_env)
53
+ cache[host] = nil unless response.success?
54
+ if response.status == 403 && retry_on_forbidden
55
+ env[:body] = request_body
56
+ call(env, retry_on_forbidden: false)
57
+ end
47
58
  end
48
59
  end
49
- end
50
60
 
51
- private
61
+ private
52
62
 
53
- def default_token_factory(host)
54
- WCC::Data::Nucleus::ClientAppToken.create(hostname: host).token
55
- end
63
+ def default_token_factory(host)
64
+ WCC::Data::Nucleus::ClientAppToken.create(hostname: host).token
65
+ end
56
66
 
57
- def default_cache
58
- RedisCache.new(Sidekiq.method(:redis))
67
+ def default_cache
68
+ RedisCache.new(Sidekiq.method(:redis))
69
+ end
70
+ end
71
+ else
72
+ class FaradayClientAppTokenAuth
73
+ def initialize(app, cache: default_cache, token_factory: method(:default_token_factory))
74
+ raise NotSupportedError, 'Please include the "faraday" gem to use this authentication method'
75
+ end
59
76
  end
60
77
  end
61
78
  end
62
79
 
63
- Faraday::Middleware.register_middleware :client_app_token => lambda { WCC::Data::FaradayClientAppTokenAuth }
80
+ if defined?(Faraday)
81
+ Faraday::Middleware.register_middleware :client_app_token => lambda { WCC::Data::FaradayClientAppTokenAuth }
82
+ end
64
83
 
@@ -5,6 +5,7 @@ module WCC::Data
5
5
  class EndpointUndefined < MapperError; end
6
6
  class InvalidResponse < MapperError; end
7
7
  class RecordNotFound < MapperError; end
8
+ class ServiceUnavailable < MapperError; end
8
9
  end
9
10
 
10
11
  end
@@ -4,6 +4,7 @@ module WCC::Data::Mapper
4
4
 
5
5
  def new_from_response(response)
6
6
  raise RecordNotFound if response.status == 404
7
+ raise ServiceUnavailable if response.status == 503
7
8
  case response.json
8
9
  when Array
9
10
  response.json.collect { |obj| new(obj) }
@@ -27,11 +27,11 @@ module WCC::Data::Nucleus
27
27
  code: 'FTW',
28
28
  name: 'Fort Worth',
29
29
  key: :ft_worth,
30
- street: '3345 Winthrop Avenue',
30
+ street: '8000 Western Hills Blvd',
31
31
  city: 'Fort Worth',
32
32
  state: 'TX',
33
- zip: '76116',
34
- geo: [32.7280064, -97.4146727]
33
+ zip: '76108',
34
+ geo: [32.739972, -97.455414]
35
35
  },
36
36
  {
37
37
  id: 3,
@@ -1,5 +1,5 @@
1
1
  module WCC
2
2
  module Data
3
- VERSION = '0.3.2'.freeze
3
+ VERSION = '0.4.0.pre-2'.freeze
4
4
  end
5
5
  end
data/wcc-data.gemspec CHANGED
@@ -13,14 +13,14 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.files = Dir['lib/**/*'] + %w[LICENSE.txt README.md wcc-data.gemspec]
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
18
+ spec.require_paths = ['lib']
20
19
 
21
- spec.required_ruby_version = '~> 2.2'
20
+ spec.required_ruby_version = '>= 2.2'
22
21
 
23
- spec.add_dependency "faraday", "~> 0.8"
22
+ # Required if you use faraday_client_app_token_auth but must be included separately
23
+ spec.add_development_dependency "faraday", "~> 0.8"
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.3"
26
26
  spec.add_development_dependency "dotenv", "~> 0.10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wcc-data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0.pre.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Watermark Dev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-23 00:00:00.000000000 Z
11
+ date: 2021-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -17,7 +17,7 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.8'
20
- type: :runtime
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
@@ -97,20 +97,12 @@ dependencies:
97
97
  description: Watermark's library for interapp communication via APIs
98
98
  email:
99
99
  - dev@watermark.org
100
- executables:
101
- - rspec
100
+ executables: []
102
101
  extensions: []
103
102
  extra_rdoc_files: []
104
103
  files:
105
- - ".env.example"
106
- - ".gitignore"
107
- - ".rspec"
108
- - Gemfile
109
104
  - LICENSE.txt
110
105
  - README.md
111
- - Rakefile
112
- - bin/rspec
113
- - circle.yml
114
106
  - lib/wcc/data.rb
115
107
  - lib/wcc/data/config.rb
116
108
  - lib/wcc/data/enumerated_type.rb
@@ -136,61 +128,29 @@ files:
136
128
  - lib/wcc/data/rest_endpoint.rb
137
129
  - lib/wcc/data/service.rb
138
130
  - lib/wcc/data/version.rb
139
- - spec/spec_helper.rb
140
- - spec/support/inheritable_class_attribute_examples.rb
141
- - spec/wcc/data/config_spec.rb
142
- - spec/wcc/data/enumerated_type_spec.rb
143
- - spec/wcc/data/faraday_client_app_token_auth_spec.rb
144
- - spec/wcc/data/mapper/attributes_spec.rb
145
- - spec/wcc/data/mapper/json_response_spec.rb
146
- - spec/wcc/data/mapper/rest_configuration_spec.rb
147
- - spec/wcc/data/mapper/rest_query_spec.rb
148
- - spec/wcc/data/model_spec.rb
149
- - spec/wcc/data/nucleus/campus_spec.rb
150
- - spec/wcc/data/rack_client_app_token_auth_spec.rb
151
- - spec/wcc/data/response_spec.rb
152
- - spec/wcc/data/rest_endpoint_spec.rb
153
- - spec/wcc/data/service_spec.rb
154
- - spec/wcc/data_spec.rb
155
131
  - wcc-data.gemspec
156
132
  homepage: ''
157
133
  licenses:
158
134
  - MIT
159
135
  metadata: {}
160
- post_install_message:
136
+ post_install_message:
161
137
  rdoc_options: []
162
138
  require_paths:
163
139
  - lib
164
140
  required_ruby_version: !ruby/object:Gem::Requirement
165
141
  requirements:
166
- - - "~>"
142
+ - - ">="
167
143
  - !ruby/object:Gem::Version
168
144
  version: '2.2'
169
145
  required_rubygems_version: !ruby/object:Gem::Requirement
170
146
  requirements:
171
- - - ">="
147
+ - - ">"
172
148
  - !ruby/object:Gem::Version
173
- version: '0'
149
+ version: 1.3.1
174
150
  requirements: []
175
- rubyforge_project:
176
- rubygems_version: 2.6.11
177
- signing_key:
151
+ rubyforge_project:
152
+ rubygems_version: 2.5.2.3
153
+ signing_key:
178
154
  specification_version: 4
179
155
  summary: Watermark's library for interapp communication via APIs
180
- test_files:
181
- - spec/spec_helper.rb
182
- - spec/support/inheritable_class_attribute_examples.rb
183
- - spec/wcc/data/config_spec.rb
184
- - spec/wcc/data/enumerated_type_spec.rb
185
- - spec/wcc/data/faraday_client_app_token_auth_spec.rb
186
- - spec/wcc/data/mapper/attributes_spec.rb
187
- - spec/wcc/data/mapper/json_response_spec.rb
188
- - spec/wcc/data/mapper/rest_configuration_spec.rb
189
- - spec/wcc/data/mapper/rest_query_spec.rb
190
- - spec/wcc/data/model_spec.rb
191
- - spec/wcc/data/nucleus/campus_spec.rb
192
- - spec/wcc/data/rack_client_app_token_auth_spec.rb
193
- - spec/wcc/data/response_spec.rb
194
- - spec/wcc/data/rest_endpoint_spec.rb
195
- - spec/wcc/data/service_spec.rb
196
- - spec/wcc/data_spec.rb
156
+ test_files: []
data/.env.example DELETED
@@ -1,3 +0,0 @@
1
- NUCLEUS_CLIENT_ID=client-id-3
2
- NUCLEUS_CLIENT_SECRET=client-secret-3
3
- NUCLEUS_URL=http://login.wcc/
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .env*.local
6
- .yardoc
7
- Gemfile.lock
8
- InstalledFiles
9
- _yardoc
10
- coverage
11
- doc/
12
- lib/bundler/man
13
- pkg
14
- rdoc
15
- spec/reports
16
- test/tmp
17
- test/version_tmp
18
- tmp
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format progress
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in wcc-data.gemspec
4
- gemspec
5
-
6
- gem 'rack', '~>1.6.5'
data/Rakefile DELETED
@@ -1,36 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'dotenv/tasks'
3
-
4
- PROJECT_PATH = File.dirname(__FILE__)
5
- LIB_PATH = File.join(PROJECT_PATH, "lib")
6
-
7
- task :default => :test
8
-
9
- desc 'run test examples'
10
- task :test do
11
- exec 'rspec .'
12
- end
13
-
14
- task :environment => :dotenv do
15
- $LOAD_PATH.unshift(LIB_PATH)
16
- require 'wcc/data'
17
- end
18
-
19
- task :development => [:environment] do
20
- WCC::Data.setup do |config|
21
- conn = config.applications[:nucleus].connection
22
- conn.use Faraday::Response::Logger
23
- conn.basic_auth(ENV['NUCLEUS_CLIENT_ID'], ENV['NUCLEUS_CLIENT_SECRET'])
24
- end
25
- end
26
-
27
- desc 'launch IRB shell with base environment loaded'
28
- task :irb => :environment do
29
- require 'irb'
30
- ARGV.clear
31
- IRB.start
32
- end
33
-
34
- desc 'launch IRB shell with development environment loaded'
35
- task :console => [:development, :irb]
36
-
data/bin/rspec DELETED
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
- #
4
- # This file was generated by Bundler.
5
- #
6
- # The application 'rspec' is installed as part of a gem, and
7
- # this file is here to facilitate running it.
8
- #
9
-
10
- require "pathname"
11
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
- Pathname.new(__FILE__).realpath)
13
-
14
- require "rubygems"
15
- require "bundler/setup"
16
-
17
- load Gem.bin_path("rspec-core", "rspec")
data/circle.yml DELETED
@@ -1,6 +0,0 @@
1
- machine:
2
- ruby:
3
- version: 2.2.2
4
- dependencies:
5
- pre:
6
- - cp .env.example .env
data/spec/spec_helper.rb DELETED
@@ -1,22 +0,0 @@
1
- SPEC_DIR = File.dirname(__FILE__)
2
- FIXTURES_DIR = File.join(SPEC_DIR, "fixtures")
3
-
4
- $LOAD_PATH.unshift File.join(SPEC_DIR, "..", "lib")
5
- $LOAD_PATH.unshift SPEC_DIR
6
-
7
- require 'dotenv'
8
- Dotenv.load
9
-
10
- require 'wcc/data'
11
- require 'sidekiq'
12
-
13
- Dir[File.join(SPEC_DIR, "support", "*.rb")].each do |support_file|
14
- require "support/#{File.basename(support_file, ".rb")}"
15
- end
16
-
17
- RSpec.configure do |config|
18
- config.run_all_when_everything_filtered = true
19
- config.filter_run :focus
20
-
21
- config.order = 'random'
22
- end