ares-focus-extensions 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
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.send(:include, ActiveResource::Extend::WithoutExtension)
8
+ ActiveResource::Base.send(:include, ActiveResource::Extend::AuthWithApiKey)
9
+ ActiveResource::Base.establish_site_connection
@@ -0,0 +1,42 @@
1
+ module ActiveResource
2
+ module Extend
3
+ module AuthWithApiKey
4
+ module ClassMethods
5
+ def element_path_with_auth(*args)
6
+ element_path_without_auth(*args).concat("?Ft-Api-Key=#{self.api_key}")
7
+ end
8
+ def new_element_path_with_auth(*args)
9
+ new_element_path_without_auth(*args).concat("?Ft-Api-Key=#{self.api_key}")
10
+ end
11
+ def collection_path_with_auth(*args)
12
+ collection_path_without_auth(*args).concat("?Ft-Api-Key=#{self.api_key}")
13
+ end
14
+
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
+ end
28
+
29
+ def self.included(base)
30
+ base.class_eval do
31
+ extend ClassMethods
32
+ class << self
33
+ alias_method_chain :element_path, :auth
34
+ alias_method_chain :new_element_path, :auth
35
+ alias_method_chain :collection_path, :auth
36
+ #attr_accessor :api_key
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,28 @@
1
+ module ActiveResource
2
+ module Extend
3
+ module WithoutExtension
4
+ module ClassMethods
5
+ def element_path_with_extension(*args)
6
+ element_path_without_extension(*args).gsub(/.json|.xml/,'')
7
+ end
8
+ def new_element_path_with_extension(*args)
9
+ new_element_path_without_extension(*args).gsub(/.json|.xml/,'')
10
+ end
11
+ def collection_path_with_extension(*args)
12
+ collection_path_without_extension(*args).gsub(/.json|.xml/,'')
13
+ end
14
+ end
15
+
16
+ def self.included(base)
17
+ base.class_eval do
18
+ extend ClassMethods
19
+ class << self
20
+ alias_method_chain :element_path, :extension
21
+ alias_method_chain :new_element_path, :extension
22
+ alias_method_chain :collection_path, :extension
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ 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
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ares-focus-extensions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Spencer Davis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-24 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: Several add-ons and modifications to ActiveResource
31
+ email: spencerfdavis@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/ares/add_api_key.rb
37
+ - lib/ares/remove_format_extension.rb
38
+ - lib/ares/use_config_file.rb
39
+ - lib/ares-focus-extensions.rb
40
+ homepage: http://github.com/spencerfdavis
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.23
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Extensions for ActiveResource (Rails 3).
64
+ test_files: []