Class: Giggly::Rest::Request
- Inherits:
-
Object
- Object
- Giggly::Rest::Request
- Includes:
- HTTParty
- Defined in:
- lib/giggly/rest/request.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#uid ⇒ Object
Returns the value of attribute uid.
Instance Method Summary collapse
-
#initialize(conn_params) ⇒ Request
constructor
Accepts a hash of connection parameters that will be used to authenticate requests with gigya and specify the user that the request is specific to.
-
#post(url, params = {}) ⇒ Object
Wraps around HTTParty’s post method to make API calls.
- #sign(http_method, api_url, params) ⇒ Object
- #signature(http_method, api_url, params) ⇒ Object
Constructor Details
#initialize(conn_params) ⇒ Request
Accepts a hash of connection parameters that will be used to authenticate requests with gigya and specify the user that the request is specific to. The keys for the has are all symbols. The connection parameter hash requires :api_key, :secret_key, and :uid These are the same parameters that can be passed to the constructor for Giggly::Rest::Socialize
example:
@connection = Giggly::Rest::Request.new(
:api_key => 'api key provided from Gigya',
:secret_key => 'secret key provided from Gigya',
:user_id => 'the Gigya User ID',
)
20 21 22 23 24 25 |
# File 'lib/giggly/rest/request.rb', line 20 def initialize(conn_params) @api_key = conn_params[:api_key] @secret_key = conn_params[:secret_key] @uid = conn_params[:user_id] @gigya_secret = Base64.decode64(@secret_key) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
5 6 7 |
# File 'lib/giggly/rest/request.rb', line 5 def api_key @api_key end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
5 6 7 |
# File 'lib/giggly/rest/request.rb', line 5 def secret_key @secret_key end |
#uid ⇒ Object
Returns the value of attribute uid.
5 6 7 |
# File 'lib/giggly/rest/request.rb', line 5 def uid @uid end |
Instance Method Details
#post(url, params = {}) ⇒ Object
Wraps around HTTParty’s post method to make API calls. Responsible for raising errors if they are returned from the API. Returns response data from the post request.
30 31 32 33 34 35 |
# File 'lib/giggly/rest/request.rb', line 30 def post(url, params = {}) response = self.class.post(url, :query => sign('POST', url, params)) response_key, response_data = response.shift raise_errors(response_data) response_data end |
#sign(http_method, api_url, params) ⇒ Object
37 38 39 40 |
# File 'lib/giggly/rest/request.rb', line 37 def sign(http_method, api_url, params) params.merge! "apiKey" => @api_key, "uid" => @uid params.merge "sig" => signature(http_method, api_url, params) end |
#signature(http_method, api_url, params) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/giggly/rest/request.rb', line 42 def signature(http_method, api_url, params) = Time.now.to_i.to_s params.merge!("nonce" => "#{@uid}#{}", "timestamp" => ) #### base_string = build_base_string(http_method, api_url, params) hmacsha1 = HMAC::SHA1.digest(@gigya_secret, base_string) sig = Base64.encode64(hmacsha1).chomp.to_s.gsub(/\n/,'') end |