Class: Zohoho::Connection
- Inherits:
-
Object
- Object
- Zohoho::Connection
- Includes:
- HTTParty
- Defined in:
- lib/zohoho/connection.rb
Instance Method Summary collapse
- #api_key ⇒ Object
- #call(entry, api_method, query = {}, http_method = :get) ⇒ Object
-
#initialize(service_name, username, password, apikey) ⇒ Connection
constructor
A new instance of Connection.
- #ticket ⇒ Object
- #ticket_url ⇒ Object
- #zoho_uri ⇒ Object
Constructor Details
#initialize(service_name, username, password, apikey) ⇒ Connection
Returns a new instance of Connection.
9 10 11 |
# File 'lib/zohoho/connection.rb', line 9 def initialize(service_name, username, password, apikey) @service_name, @username, @password, @api_key = service_name, username, password, apikey end |
Instance Method Details
#api_key ⇒ Object
17 18 19 |
# File 'lib/zohoho/connection.rb', line 17 def api_key @api_key end |
#call(entry, api_method, query = {}, http_method = :get) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/zohoho/connection.rb', line 29 def call(entry, api_method, query = {}, http_method = :get) login = { :apikey => api_key, :ticket => ticket } query.merge!(login) url = [zoho_uri, entry, api_method].join('/') case http_method when :get raw = JSON.parse(self.class.get(url, :query => query).parsed_response) parse_raw_get(raw, entry) when :post raw = JSON.parse(self.class.post(url, :body => query).parsed_response) parse_raw_post(raw) else raise "#{http_method} is not a recognized http method" end end |
#ticket ⇒ Object
25 26 27 |
# File 'lib/zohoho/connection.rb', line 25 def ticket Regexp.last_match(1) if self.class.get(ticket_url).to_s =~ /TICKET=(\w+)/ end |
#ticket_url ⇒ Object
13 14 15 |
# File 'lib/zohoho/connection.rb', line 13 def ticket_url "https://accounts.zoho.com/login?servicename=#{@service_name}&FROM_AGENT=true&LOGIN_ID=#{@username}&PASSWORD=#{@password}" end |
#zoho_uri ⇒ Object
21 22 23 |
# File 'lib/zohoho/connection.rb', line 21 def zoho_uri zoho_uri = "https://#{@service_name.downcase}.zoho.com/#{@service_name.downcase}/private/json" end |