Class: Xeroizer::OAuth
- Inherits:
-
Object
- Object
- Xeroizer::OAuth
- Extended by:
- Forwardable
- Defined in:
- lib/xeroizer/oauth.rb
Overview
Shamelessly taken from the XeroGateway library by Tim Connor which is shamelessly based on the Twitter Gem’s OAuth implementation by John Nunemaker Thanks!
github.com/tlconnor/xero_gateway twitter.rubyforge.org/ github.com/jnunemaker/twitter/
Defined Under Namespace
Classes: RateLimitExceeded, TokenExpired, TokenInvalid, UnknownError
Constant Summary collapse
- XERO_CONSUMER_OPTIONS =
{ :site => "https://api.xero.com", :request_token_path => "/oauth/RequestToken", :access_token_path => "/oauth/AccessToken", :authorize_path => "/oauth/Authorize", :ca_file => File.(File.join(File.dirname(__FILE__), 'ca-certificates.crt')) }.freeze
Instance Attribute Summary collapse
- #authorization_expires_at ⇒ Object readonly
- #consumer_options ⇒ Object readonly
- #csecret ⇒ Object readonly
- #ctoken ⇒ Object readonly
- #expires_at ⇒ Object readonly
- #session_handle ⇒ Object
Instance Method Summary collapse
-
#access_token ⇒ Object
AccessToken created from authorize_from_access method.
-
#authorize_from_access(atoken, asecret) ⇒ Object
Used for PRIVATE applications where the AccessToken uses the token/secret from Xero which would normally be used in the request.
-
#authorize_from_request(rtoken, rsecret, params = {}) ⇒ Object
Create an AccessToken from a PUBLIC/PARTNER authorisation.
-
#consumer ⇒ OAuth::Consumer
OAuth consumer creator.
-
#initialize(ctoken, csecret, options = {}) ⇒ OAuth
constructor
OAuth constructor.
-
#renew_access_token(atoken = nil, asecret = nil, session_handle = nil) ⇒ Object
Renew an access token from a previously authorised token for a PARTNER application.
-
#request_token(params = {}) ⇒ Object
RequestToken for PUBLIC/PARTNER authorisation (used to redirect to Xero for authentication).
Constructor Details
#initialize(ctoken, csecret, options = {}) ⇒ OAuth
OAuth constructor.
70 71 72 73 |
# File 'lib/xeroizer/oauth.rb', line 70 def initialize(ctoken, csecret, = {}) @ctoken, @csecret = ctoken, csecret @consumer_options = XERO_CONSUMER_OPTIONS.merge() end |
Instance Attribute Details
#authorization_expires_at ⇒ Object (readonly)
50 51 52 |
# File 'lib/xeroizer/oauth.rb', line 50 def @authorization_expires_at end |
#consumer_options ⇒ Object (readonly)
50 51 52 |
# File 'lib/xeroizer/oauth.rb', line 50 def @consumer_options end |
#csecret ⇒ Object (readonly)
50 51 52 |
# File 'lib/xeroizer/oauth.rb', line 50 def csecret @csecret end |
#ctoken ⇒ Object (readonly)
50 51 52 |
# File 'lib/xeroizer/oauth.rb', line 50 def ctoken @ctoken end |
#expires_at ⇒ Object (readonly)
50 51 52 |
# File 'lib/xeroizer/oauth.rb', line 50 def expires_at @expires_at end |
#session_handle ⇒ Object
54 55 56 |
# File 'lib/xeroizer/oauth.rb', line 54 def session_handle @session_handle end |
Instance Method Details
#access_token ⇒ Object
AccessToken created from authorize_from_access method.
98 99 100 |
# File 'lib/xeroizer/oauth.rb', line 98 def access_token ::OAuth::AccessToken.new(consumer, @atoken, @asecret) end |
#authorize_from_access(atoken, asecret) ⇒ Object
Used for PRIVATE applications where the AccessToken uses the token/secret from Xero which would normally be used in the request. No request authorisation necessary.
For PUBLIC/PARTNER applications this is used to recreate a client from a stored AccessToken key/secret.
108 109 110 |
# File 'lib/xeroizer/oauth.rb', line 108 def (atoken, asecret) @atoken, @asecret = atoken, asecret end |
#authorize_from_request(rtoken, rsecret, params = {}) ⇒ Object
Create an AccessToken from a PUBLIC/PARTNER authorisation.
91 92 93 94 95 |
# File 'lib/xeroizer/oauth.rb', line 91 def (rtoken, rsecret, params = {}) request_token = ::OAuth::RequestToken.new(consumer, rtoken, rsecret) access_token = request_token.get_access_token(params) update_attributes_from_token(access_token) end |
#consumer ⇒ OAuth::Consumer
OAuth consumer creator.
78 79 80 |
# File 'lib/xeroizer/oauth.rb', line 78 def consumer create_consumer end |
#renew_access_token(atoken = nil, asecret = nil, session_handle = nil) ⇒ Object
Renew an access token from a previously authorised token for a PARTNER application.
114 115 116 117 118 119 120 121 |
# File 'lib/xeroizer/oauth.rb', line 114 def renew_access_token(atoken = nil, asecret = nil, session_handle = nil) old_token = ::OAuth::RequestToken.new(consumer, atoken || @atoken, asecret || @asecret) access_token = old_token.get_access_token({ :oauth_session_handle => (session_handle || @session_handle), :token => old_token }) update_attributes_from_token(access_token) end |
#request_token(params = {}) ⇒ Object
RequestToken for PUBLIC/PARTNER authorisation (used to redirect to Xero for authentication).
86 87 88 |
# File 'lib/xeroizer/oauth.rb', line 86 def request_token(params = {}) consumer.get_request_token(params) end |