Class: Tim::ImageFactory::Base
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- Tim::ImageFactory::Base
- Defined in:
- lib/image_factory/model/base.rb
Direct Known Subclasses
Class Method Summary collapse
- .callback_url ⇒ Object
-
.callback_url=(url) ⇒ Object
Add Callback URL for listening to callback requests.
-
.collection_path(prefix_options = {}, query_options = nil) ⇒ Object
Remove format from the url for collections.
-
.config ⇒ Object
This approach does mean you’re limited to one server at a time.
- .config=(conf = {}) ⇒ Object
-
.custom_method_collection_url(method_name, options = {}) ⇒ Object
Modifying the url formations to make them Factory compliant.
-
.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object
Remove format from the url for resources.
-
.get(method_name, options = {}) ⇒ Object
The objects returned from this method are not automatically converted into ActiveResource instances - they are ordinary Hashes.
-
.instantiate_collection(collection, prefix_options = {}) ⇒ Object
For a collection call, ActiveResource formatting is not compliant with Factory’s output.
-
.use_oauth? ⇒ Boolean
Should we use OAuth?.
Instance Method Summary collapse
-
#custom_method_element_url(method_name, options = {}) ⇒ Object
Modifying the url formations to make them Factory compliant.
-
#get(method_name, options = {}) ⇒ Object
Instance Methods: (modifying the ActiveRecord::CustomMethods).
Class Method Details
.callback_url ⇒ Object
16 17 18 |
# File 'lib/image_factory/model/base.rb', line 16 def callback_url @callback_url end |
.callback_url=(url) ⇒ Object
Add Callback URL for listening to callback requests
12 13 14 |
# File 'lib/image_factory/model/base.rb', line 12 def callback_url=(url) @callback_url = URI.parse(url) end |
.collection_path(prefix_options = {}, query_options = nil) ⇒ Object
Remove format from the url for collections
27 28 29 30 |
# File 'lib/image_factory/model/base.rb', line 27 def collection_path( = {}, = nil) , = () if .nil? "#{prefix()}#{collection_name}#{query_string()}" end |
.config ⇒ Object
This approach does mean you’re limited to one server at a time
54 55 56 |
# File 'lib/image_factory/model/base.rb', line 54 def config defined?(@@config) ? @@config : {} end |
.config=(conf = {}) ⇒ Object
57 58 59 60 |
# File 'lib/image_factory/model/base.rb', line 57 def config=(conf={}) @@config = conf self.site = @@config[:site] end |
.custom_method_collection_url(method_name, options = {}) ⇒ Object
Modifying the url formations to make them Factory compliant
81 82 83 84 85 |
# File 'lib/image_factory/model/base.rb', line 81 def self.custom_method_collection_url(method_name, = {}) , = () url = "#{prefix()}#{collection_name}/#{method_name}#{query_string()}" url end |
.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object
Remove format from the url for resources
21 22 23 24 |
# File 'lib/image_factory/model/base.rb', line 21 def element_path(id, = {}, = nil) , = () if .nil? "#{prefix()}#{collection_name}/#{id}#{query_string()}" end |
.get(method_name, options = {}) ⇒ Object
The objects returned from this method are not automatically converted into ActiveResource instances - they are ordinary Hashes.
Modifications below ensures that you get ActiveResource instances.
44 45 46 47 48 49 50 51 |
# File 'lib/image_factory/model/base.rb', line 44 def get(method_name, = {}) object_array = connection.get(custom_method_collection_url(method_name, ), headers) if object_array.class.to_s=="Array" object_array.collect! {|record| self.class.new.load(record)} else self.class.new.load(object_array) end end |
.instantiate_collection(collection, prefix_options = {}) ⇒ Object
For a collection call, ActiveResource formatting is not compliant with Factory’s output.
34 35 36 37 38 39 40 |
# File 'lib/image_factory/model/base.rb', line 34 def instantiate_collection(collection, = {}) unless collection.kind_of? Array [instantiate_record(collection, )] else collection.collect! { |record| instantiate_record(record, ) } end end |
.use_oauth? ⇒ Boolean
Should we use OAuth?
63 64 65 |
# File 'lib/image_factory/model/base.rb', line 63 def use_oauth? config[:consumer_key] && config[:consumer_secret] && config[:site] end |
Instance Method Details
#custom_method_element_url(method_name, options = {}) ⇒ Object
Modifying the url formations to make them Factory compliant
75 76 77 78 |
# File 'lib/image_factory/model/base.rb', line 75 def custom_method_element_url(method_name, = {}) "#{self.class.prefix()}#{self.class.collection_name}/#{id}/" + "#{method_name}#{self.class.send!(:query_string, )}" end |
#get(method_name, options = {}) ⇒ Object
Instance Methods: (modifying the ActiveRecord::CustomMethods). This modification is same as defined in above method
70 71 72 |
# File 'lib/image_factory/model/base.rb', line 70 def get(method_name, = {}) self.class.new.load(connection.get(custom_method_element_url(method_name, ), self.class.headers)) end |