Class: ZohoTools::Oauth
- Inherits:
-
Object
- Object
- ZohoTools::Oauth
- Defined in:
- lib/zoho_tools/oauth.rb
Constant Summary collapse
- OAUTH_URL =
'/oauth/v2/auth'.freeze
- TOKEN_URL =
'/oauth/v2/token'.freeze
Class Method Summary collapse
- .auth_params ⇒ Object
- .authorization_code(code) ⇒ Object
- .authorize(access_type: 'offline', scope: %w[ZohoCampaigns.campaign.ALL ZohoCampaigns.contact.ALL])) ⇒ Object
- .refresh_access_token(refresh_token) ⇒ Object
Class Method Details
.auth_params ⇒ Object
29 30 31 32 |
# File 'lib/zoho_tools/oauth.rb', line 29 def self.auth_params { client_id: ZohoTools.config.client_id, client_secret: ZohoTools.config.client_secret } end |
.authorization_code(code) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/zoho_tools/oauth.rb', line 15 def self.(code) response = RestClient.post(URI.join(ZohoTools.config.accounts_api_url, TOKEN_URL).to_s, self.auth_params.merge(code: code, grant_type: 'authorization_code', redirect_uri: ZohoTools.config.callback_url), { accept: :json }) ZohoTools::Response.new(response) end |
.authorize(access_type: 'offline', scope: %w[ZohoCampaigns.campaign.ALL ZohoCampaigns.contact.ALL])) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/zoho_tools/oauth.rb', line 6 def self.(access_type: 'offline', scope: %w[ZohoCampaigns.campaign.ALL ZohoCampaigns.contact.ALL]) uri = URI.join(ZohoTools.config.accounts_api_url, OAUTH_URL) uri.query = URI.encode_www_form(self.auth_params.merge({ redirect_uri: ZohoTools.config.callback_url, access_type: access_type, response_type: 'code', scope: scope.join(',') })) uri.to_s end |
.refresh_access_token(refresh_token) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/zoho_tools/oauth.rb', line 22 def self.refresh_access_token(refresh_token) response = RestClient.post(URI.join(ZohoTools.config.accounts_api_url, TOKEN_URL).to_s, self.auth_params.merge(refresh_token: refresh_token, grant_type: 'refresh_token'), { accept: :json }) ZohoTools::Response.new(response) end |