focus-utils 0.0.6 → 0.0.7
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.
- data/lib/ares/add_api_key.rb +23 -5
- data/lib/ares/threadsafe_authentication.rb +28 -0
- data/lib/focus-utils.rb +4 -0
- metadata +18 -22
data/lib/ares/add_api_key.rb
CHANGED
@@ -7,11 +7,11 @@ module ActiveResource
|
|
7
7
|
|
8
8
|
included do
|
9
9
|
class << self
|
10
|
-
alias_method_chain :headers, :auth
|
10
|
+
alias_method_chain :headers, :auth
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
module ClassMethods
|
14
|
+
module ClassMethods
|
15
15
|
def api_key
|
16
16
|
# Not using superclass_delegating_reader. See +site+ for explanation
|
17
17
|
if defined?(@api_key)
|
@@ -20,14 +20,32 @@ module ActiveResource
|
|
20
20
|
superclass.api_key.dup.freeze
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def api_key=(api_key)
|
25
25
|
@api_key = api_key
|
26
|
-
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def api_client
|
29
|
+
# Not using superclass_delegating_reader. See +site+ for explanation
|
30
|
+
if defined?(@api_client)
|
31
|
+
@api_client
|
32
|
+
elsif superclass != Object && superclass.api_client
|
33
|
+
superclass.api_client.dup.freeze
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def api_client=(api_client)
|
38
|
+
@api_client = api_client
|
39
|
+
end
|
27
40
|
|
28
41
|
def headers_with_auth
|
29
|
-
api_key.nil?
|
42
|
+
if (api_key.nil? || api_client.nil?)
|
43
|
+
headers_without_auth
|
44
|
+
else
|
45
|
+
headers_without_auth.merge({"Ft-Api-Key" => self.api_key, "Ft-Client" => self.api_client})
|
46
|
+
end
|
30
47
|
end
|
48
|
+
|
31
49
|
end
|
32
50
|
end
|
33
51
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module ActiveResource
|
4
|
+
module Extend
|
5
|
+
module ThreadsafeAuthentication
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
class << self
|
10
|
+
# Overriding both methods to get/set inside of current thread.
|
11
|
+
# Necessary for multi-threaded env jruby to allow api_key and
|
12
|
+
# api client to be sent with every request without overriding
|
13
|
+
# it for other threads (users)
|
14
|
+
%w(api_key api_client).each do |attr|
|
15
|
+
define_method(attr) do
|
16
|
+
Thread.current["active_resource.#{attr}"]
|
17
|
+
end
|
18
|
+
|
19
|
+
define_method("#{attr}=") do |val|
|
20
|
+
Thread.current["active_resource.#{attr}"] = val
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/focus-utils.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
require 'active_resource'
|
2
2
|
require 'yaml'
|
3
|
+
require 'ares/add_api_key'
|
3
4
|
require 'ares/add_relative_prefix'
|
4
5
|
require 'ares/remove_format_extension'
|
5
6
|
require 'ares/add_custom_header'
|
6
7
|
require 'ares/use_config_file'
|
8
|
+
require 'ares/threadsafe_authentication'
|
7
9
|
|
8
10
|
#ActiveResource::Base.include_format_in_path = false
|
11
|
+
ActiveResource::Base.send(:include, ActiveResource::Extend::AuthWithApiKey)
|
9
12
|
ActiveResource::Base.send(:include, ActiveResource::Extend::RemoveExtension)
|
10
13
|
ActiveResource::Base.send(:include, ActiveResource::Extend::AddRelativePrefix)
|
11
14
|
ActiveResource::Base.send(:include, ActiveResource::Extend::AddCustomHeaders)
|
15
|
+
ActiveResource::Base.send(:include, ActiveResource::Extend::ThreadsafeAuthentication)
|
12
16
|
ActiveResource::Base.establish_site_connection
|
metadata
CHANGED
@@ -1,67 +1,63 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: focus-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Spencer Davis
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-27 00:00:00.
|
12
|
+
date: 2012-12-27 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activeresource
|
16
|
-
|
17
|
-
none: false
|
16
|
+
version_requirements: &2056 !ruby/object:Gem::Requirement
|
18
17
|
requirements:
|
19
18
|
- - ~>
|
20
19
|
- !ruby/object:Gem::Version
|
21
20
|
version: '3.0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
21
|
none: false
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
description: Add-ons including API Key, remove format extensions (.json, .xml) for
|
31
|
-
requests, and configuration file (sites.yml) for each environment's default settings.
|
22
|
+
requirement: *2056
|
23
|
+
prerelease: false
|
24
|
+
type: :runtime
|
25
|
+
description: Add-ons including API Key, remove format extensions (.json, .xml) for requests, and configuration file (sites.yml) for each environment's default settings.
|
32
26
|
email: spencer.davis@bipt.com
|
33
27
|
executables: []
|
34
28
|
extensions: []
|
35
29
|
extra_rdoc_files: []
|
36
30
|
files:
|
31
|
+
- lib/focus-utils.rb
|
37
32
|
- lib/ares/add_api_key.rb
|
38
33
|
- lib/ares/add_custom_header.rb
|
39
34
|
- lib/ares/add_relative_prefix.rb
|
40
35
|
- lib/ares/remove_format_extension.rb
|
36
|
+
- lib/ares/threadsafe_authentication.rb
|
41
37
|
- lib/ares/use_config_file.rb
|
42
|
-
- lib/focus-utils.rb
|
43
38
|
homepage: https://github.com/spencerfdavis/ares-focus-extensions
|
44
39
|
licenses: []
|
45
|
-
post_install_message:
|
40
|
+
post_install_message:
|
46
41
|
rdoc_options: []
|
47
42
|
require_paths:
|
48
43
|
- lib
|
49
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
46
|
- - ! '>='
|
53
47
|
- !ruby/object:Gem::Version
|
54
48
|
version: '0'
|
55
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
49
|
none: false
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
51
|
requirements:
|
58
52
|
- - ! '>='
|
59
53
|
- !ruby/object:Gem::Version
|
60
54
|
version: '0'
|
55
|
+
none: false
|
61
56
|
requirements: []
|
62
|
-
rubyforge_project:
|
63
|
-
rubygems_version: 1.8.
|
64
|
-
signing_key:
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.8.15
|
59
|
+
signing_key:
|
65
60
|
specification_version: 3
|
66
61
|
summary: Add-ons/patches for Focus Tech Projects.
|
67
62
|
test_files: []
|
63
|
+
...
|