Class: Morpheus::Request
- Inherits:
-
Typhoeus::Request
- Object
- Typhoeus::Request
- Morpheus::Request
- Defined in:
- lib/morpheus/request.rb
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #cache_key ⇒ Object
- #fix_array_param_keys(params) ⇒ Object
-
#initialize(path, options = {}) ⇒ Request
constructor
A new instance of Request.
- #response ⇒ Object
- #response=(response) ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ Request
Returns a new instance of Request.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/morpheus/request.rb', line 5 def initialize(path, = {}) if [:method] == :put [:method] = :post [:params].merge!(:_method => :put) end if [:params] [:params] = fix_array_param_keys([:params]) end [:username] = Configuration.username if Configuration.username [:password] = Configuration.password if Configuration.password super(Configuration.host + path, ) end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
3 4 5 |
# File 'lib/morpheus/request.rb', line 3 def method @method end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/morpheus/request.rb', line 3 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/morpheus/request.rb', line 3 def path @path end |
Class Method Details
.enqueue(method, path, params) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/morpheus/request.rb', line 49 def self.enqueue(method, path, params) = { :method => method } .merge!(:params => params) unless params.blank? new(path, ).tap do |request| RequestQueue.enqueue(request) end end |
Instance Method Details
#cache_key ⇒ Object
34 35 36 |
# File 'lib/morpheus/request.rb', line 34 def cache_key Digest::SHA1.hexdigest([method, url, params].inspect) end |
#fix_array_param_keys(params) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/morpheus/request.rb', line 22 def fix_array_param_keys(params) fixed_params = {} params.each do |key, value| if Array === value fixed_params.store("#{key}[]", value) else fixed_params.store(key, value) end end fixed_params end |
#response ⇒ Object
44 45 46 47 |
# File 'lib/morpheus/request.rb', line 44 def response RequestQueue.run! if RequestQueue.has_request?(self) RequestCache.cache[cache_key] || super end |
#response=(response) ⇒ Object
38 39 40 41 42 |
# File 'lib/morpheus/request.rb', line 38 def response=(response) RequestCache.cache[cache_key] = response response.tag_for_caching! super end |