focus-utils 0.0.4
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 +34 -0
- data/lib/ares/remove_format_extension.rb +44 -0
- data/lib/ares/use_config_file.rb +16 -0
- data/lib/focus-utils.rb +10 -0
- metadata +65 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module ActiveResource
|
|
4
|
+
module Extend
|
|
5
|
+
module AuthWithApiKey
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
included do
|
|
9
|
+
class << self
|
|
10
|
+
alias_method_chain :headers, :auth
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
module ClassMethods
|
|
15
|
+
def api_key
|
|
16
|
+
# Not using superclass_delegating_reader. See +site+ for explanation
|
|
17
|
+
if defined?(@api_key)
|
|
18
|
+
@api_key
|
|
19
|
+
elsif superclass != Object && superclass.api_key
|
|
20
|
+
superclass.api_key.dup.freeze
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def api_key=(api_key)
|
|
25
|
+
@api_key = api_key
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def headers_with_auth
|
|
29
|
+
api_key.nil? ? headers_without_auth : headers_without_auth.merge({"Ft-Api-Key" => self.api_key})
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module ActiveResource
|
|
4
|
+
module Extend
|
|
5
|
+
module RemoveExtension
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
included do
|
|
9
|
+
class << self
|
|
10
|
+
alias_method_chain :element_path, :extension
|
|
11
|
+
alias_method_chain :new_element_path, :extension
|
|
12
|
+
alias_method_chain :collection_path, :extension
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
module ClassMethods
|
|
17
|
+
def custom_method_collection_url(*args)
|
|
18
|
+
super.gsub(/\.json|\.xml/,'')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def element_path_with_extension(*args)
|
|
22
|
+
element_path_without_extension(*args).gsub(/\.json|\.xml/,'')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def new_element_path_with_extension(*args)
|
|
26
|
+
new_element_path_without_extension(*args).gsub(/\.json|\.xml/,'')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def collection_path_with_extension(*args)
|
|
30
|
+
collection_path_without_extension(*args).gsub(/\.json|\.xml/,'')
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
def custom_method_element_url(*args)
|
|
36
|
+
super.gsub(/\.json|\.xml/,'')
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def custom_method_new_element_url(*args)
|
|
40
|
+
super.gsub(/\.json|\.xml/,'')
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Similar to database.yml, this adds a YAML file for each environment with the settings for
|
|
2
|
+
# each site. It DRYs up the implementation. Each ARes model can override any setting if needed.
|
|
3
|
+
class ActiveResource::Base
|
|
4
|
+
protected
|
|
5
|
+
def self.establish_site_connection
|
|
6
|
+
filename = File.join('config', 'sites.yml')
|
|
7
|
+
if File.exist?(filename)
|
|
8
|
+
environment_configurations = YAML.load File.new(filename)
|
|
9
|
+
site_configurations = environment_configurations[Rails.env]
|
|
10
|
+
site_configurations.each{|k, v| self.send("#{k}=", v)}
|
|
11
|
+
else
|
|
12
|
+
puts "Error finding ActiveResource config file: #{filename}! Make sure this file exists.\n"
|
|
13
|
+
exit
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/focus-utils.rb
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'active_resource'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
require 'ares/remove_format_extension'
|
|
4
|
+
require 'ares/add_api_key'
|
|
5
|
+
require 'ares/use_config_file'
|
|
6
|
+
|
|
7
|
+
#ActiveResource::Base.include_format_in_path = false
|
|
8
|
+
ActiveResource::Base.send(:include, ActiveResource::Extend::RemoveExtension)
|
|
9
|
+
ActiveResource::Base.send(:include, ActiveResource::Extend::AuthWithApiKey)
|
|
10
|
+
ActiveResource::Base.establish_site_connection
|
metadata
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: focus-utils
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.4
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Spencer Davis
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-12-27 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: activeresource
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '3.0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ~>
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '3.0'
|
|
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.
|
|
32
|
+
email: spencer.davis@bipt.com
|
|
33
|
+
executables: []
|
|
34
|
+
extensions: []
|
|
35
|
+
extra_rdoc_files: []
|
|
36
|
+
files:
|
|
37
|
+
- lib/ares/add_api_key.rb
|
|
38
|
+
- lib/ares/remove_format_extension.rb
|
|
39
|
+
- lib/ares/use_config_file.rb
|
|
40
|
+
- lib/focus-utils.rb
|
|
41
|
+
homepage: https://github.com/spencerfdavis/ares-focus-extensions
|
|
42
|
+
licenses: []
|
|
43
|
+
post_install_message:
|
|
44
|
+
rdoc_options: []
|
|
45
|
+
require_paths:
|
|
46
|
+
- lib
|
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
|
+
none: false
|
|
49
|
+
requirements:
|
|
50
|
+
- - ! '>='
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '0'
|
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
|
+
none: false
|
|
55
|
+
requirements:
|
|
56
|
+
- - ! '>='
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
version: '0'
|
|
59
|
+
requirements: []
|
|
60
|
+
rubyforge_project:
|
|
61
|
+
rubygems_version: 1.8.23
|
|
62
|
+
signing_key:
|
|
63
|
+
specification_version: 3
|
|
64
|
+
summary: Add-ons/patches for Focus Tech Projects.
|
|
65
|
+
test_files: []
|