Class: Hyperpublic::OAuth
- Inherits:
-
Object
- Object
- Hyperpublic::OAuth
- Extended by:
- Forwardable
- Defined in:
- lib/hyperpublic/oauth.rb
Instance Attribute Summary collapse
-
#csecret ⇒ Object
readonly
Returns the value of attribute csecret.
-
#ctoken ⇒ Object
readonly
Returns the value of attribute ctoken.
Instance Method Summary collapse
- #access_token ⇒ Object
- #authorize_from_access(atoken, asecret) ⇒ Object
- #delete(uri, options = {}) ⇒ Object
- #get(uri, options = {}) ⇒ Object
-
#initialize(ctoken, csecret, options = {}) ⇒ OAuth
constructor
A new instance of OAuth.
- #post(uri, body, options = {}) ⇒ Object
- #put(uri, body, options = {}) ⇒ Object
Constructor Details
#initialize(ctoken, csecret, options = {}) ⇒ OAuth
Returns a new instance of OAuth.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hyperpublic/oauth.rb', line 12 def initialize(ctoken, csecret, ={}) @ctoken, @csecret, @consumer_options = ctoken, csecret, {} @api_endpoint = [:api_endpoint] || 'https://api.hyperpublic.com/api/v1' @consumer = ::OAuth::Consumer.new(ctoken, csecret, :site => @api_endpiont) @token = ::OAuth::AccessToken.new(@consumer) @signing_endpoint = [:signing_endpoint] || 'https://api.hyperpublic.com/api/v1' if [:sign_in] @consumer_options[:authorize_path] = '/oauth/authenticate' end @auth_params = "client_id=#{@ctoken}&client_secret=#{@csecret}" + (@token.token.empty? ? "" : "&access_token=#{@token.token}") @auth_params_hash = {"client_id" => @ctoken, "client_secret" => @csecret} @auth_params_hash["access_token"] = @token.token unless @token.token.empty? end |
Instance Attribute Details
#csecret ⇒ Object (readonly)
Returns the value of attribute csecret.
10 11 12 |
# File 'lib/hyperpublic/oauth.rb', line 10 def csecret @csecret end |
#ctoken ⇒ Object (readonly)
Returns the value of attribute ctoken.
10 11 12 |
# File 'lib/hyperpublic/oauth.rb', line 10 def ctoken @ctoken end |
Instance Method Details
#access_token ⇒ Object
47 48 49 |
# File 'lib/hyperpublic/oauth.rb', line 47 def access_token @access_token ||= ::OAuth::AccessToken.new(signing_consumer, @atoken, @asecret) end |
#authorize_from_access(atoken, asecret) ⇒ Object
51 52 53 |
# File 'lib/hyperpublic/oauth.rb', line 51 def (atoken, asecret) @atoken, @asecret = atoken, asecret end |
#delete(uri, options = {}) ⇒ Object
41 42 43 44 45 |
# File 'lib/hyperpublic/oauth.rb', line 41 def delete(uri, ={}) path = @api_endpoint + uri sep = (path =~ /\/.*\?/) ? "&" : "?" @token.delete(path + sep + @auth_params) end |
#get(uri, options = {}) ⇒ Object
26 27 28 29 30 |
# File 'lib/hyperpublic/oauth.rb', line 26 def get(uri, ={}) path = @api_endpoint + uri sep = (path =~ /\/.*\?/) ? "&" : "?" @token.get(path + sep + @auth_params) end |
#post(uri, body, options = {}) ⇒ Object
32 33 34 35 |
# File 'lib/hyperpublic/oauth.rb', line 32 def post(uri, body, ={}) body.merge!("client_id" => @ctoken, "client_secret" => @csecret) @token.post(@api_endpoint + uri, body.to_json, {"Content-Type" => 'application/json'}) end |
#put(uri, body, options = {}) ⇒ Object
37 38 39 |
# File 'lib/hyperpublic/oauth.rb', line 37 def put(uri, body, ={}) @token.put(@api_endpoint + uri, body.merge(@auth_params_hash).to_json, {'Content-Type' => 'application/json'}) end |