Class: FoodInfo::Adapters::FatSecret::Request
- Inherits:
-
Object
- Object
- FoodInfo::Adapters::FatSecret::Request
- Defined in:
- lib/food_info/adapters/fat_secret/request.rb
Constant Summary collapse
- HOST =
'http://platform.fatsecret.com/rest/server.api'
Instance Method Summary collapse
-
#initialize(method, auth, optional_params = {}) ⇒ Request
constructor
Returns the query string necessary to run the specified
method
against the FatSecret API, using theauth
(key
andsecret
) to sign it. - #signed_request ⇒ Object
Constructor Details
#initialize(method, auth, optional_params = {}) ⇒ Request
Returns the query string necessary to run the specified method
against the FatSecret API, using the auth
(key
and secret
) to sign it.
If this class were accessed externally, I’d refactor it a bit so it didn’t require auth info to be passed on every request.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/food_info/adapters/fat_secret/request.rb', line 17 def initialize(method, auth, optional_params = {}) @auth = auth @request_nonce = (0...10).map{65.+(rand(25)).chr}.join @request_time = Time.now.to_i.to_s @http_method = optional_params.delete(:http_method) || 'GET' @params = { :method => method, :format => 'json' }.merge(optional_params || {}) end |
Instance Method Details
#signed_request ⇒ Object
29 30 31 |
# File 'lib/food_info/adapters/fat_secret/request.rb', line 29 def signed_request "#{HOST}?#{make_query_string(query_params)}&oauth_signature=#{request_signature}" end |