Class: ZohoHub::Connection
- Inherits:
-
Object
- Object
- ZohoHub::Connection
- Defined in:
- lib/zoho_hub/connection.rb
Constant Summary collapse
- DEFAULT_DOMAIN =
'https://www.zohoapis.eu'
- BASE_PATH =
'/crm/v2/'
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#api_domain ⇒ Object
Returns the value of attribute api_domain.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#expires_in ⇒ Object
Returns the value of attribute expires_in.
-
#on_refresh_cb ⇒ Object
This is a block to be run when the token is refreshed.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
Class Method Summary collapse
Instance Method Summary collapse
- #access_token? ⇒ Boolean
- #delete(path, params = {}) ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(access_token: nil, api_domain: nil, expires_in: 3600, refresh_token: nil) ⇒ Connection
constructor
A new instance of Connection.
- #log(text) ⇒ Object
- #post(path, params = {}) ⇒ Object
- #put(path, params = {}) ⇒ Object
- #refresh_token? ⇒ Boolean
Constructor Details
#initialize(access_token: nil, api_domain: nil, expires_in: 3600, refresh_token: nil) ⇒ Connection
Returns a new instance of Connection.
34 35 36 37 38 39 |
# File 'lib/zoho_hub/connection.rb', line 34 def initialize(access_token: nil, api_domain: nil, expires_in: 3600, refresh_token: nil) @access_token = access_token @expires_in = expires_in @api_domain = api_domain || self.class.infer_api_domain @refresh_token ||= refresh_token # do not overwrite if it's already set end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
24 25 26 |
# File 'lib/zoho_hub/connection.rb', line 24 def access_token @access_token end |
#api_domain ⇒ Object
Returns the value of attribute api_domain.
24 25 26 |
# File 'lib/zoho_hub/connection.rb', line 24 def api_domain @api_domain end |
#debug ⇒ Object
Returns the value of attribute debug.
24 25 26 |
# File 'lib/zoho_hub/connection.rb', line 24 def debug @debug end |
#expires_in ⇒ Object
Returns the value of attribute expires_in.
24 25 26 |
# File 'lib/zoho_hub/connection.rb', line 24 def expires_in @expires_in end |
#on_refresh_cb ⇒ Object
This is a block to be run when the token is refreshed. This way you can do whatever you want with the new parameters returned by the refresh method.
28 29 30 |
# File 'lib/zoho_hub/connection.rb', line 28 def on_refresh_cb @on_refresh_cb end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
24 25 26 |
# File 'lib/zoho_hub/connection.rb', line 24 def refresh_token @refresh_token end |
Class Method Details
.infer_api_domain ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/zoho_hub/connection.rb', line 13 def infer_api_domain case ZohoHub.configuration.api_domain when 'https://accounts.zoho.com' then 'https://www.zohoapis.com' when 'https://accounts.zoho.com.cn' then 'https://www.zohoapis.com.cn' when 'https://accounts.zoho.in' then 'https://www.zohoapis.in' when 'https://accounts.zoho.eu' then 'https://www.zohoapis.eu' else DEFAULT_DOMAIN end end |
Instance Method Details
#access_token? ⇒ Boolean
69 70 71 |
# File 'lib/zoho_hub/connection.rb', line 69 def access_token? @access_token end |
#delete(path, params = {}) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/zoho_hub/connection.rb', line 62 def delete(path, params = {}) log "DELETE #{path} with #{params}" response = with_refresh { adapter.delete(path, params) } response.body end |
#get(path, params = {}) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/zoho_hub/connection.rb', line 41 def get(path, params = {}) log "GET #{path} with #{params}" response = with_refresh { adapter.get(path, params) } response.body end |
#log(text) ⇒ Object
77 78 79 80 81 |
# File 'lib/zoho_hub/connection.rb', line 77 def log(text) return unless ZohoHub.configuration.debug? puts Rainbow("[ZohoHub] #{text}").magenta.bright end |
#post(path, params = {}) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/zoho_hub/connection.rb', line 48 def post(path, params = {}) log "POST #{path} with #{params}" response = with_refresh { adapter.post(path, params) } response.body end |
#put(path, params = {}) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/zoho_hub/connection.rb', line 55 def put(path, params = {}) log "PUT #{path} with #{params}" response = with_refresh { adapter.put(path, params) } response.body end |
#refresh_token? ⇒ Boolean
73 74 75 |
# File 'lib/zoho_hub/connection.rb', line 73 def refresh_token? @refresh_token end |