Class: Zohoho::Connection

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/zohoho/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(service_name, username, password, apikey) ⇒ Connection

Returns a new instance of Connection.



8
9
10
# File 'lib/zohoho/connection.rb', line 8

def initialize(service_name, username, password, apikey)
  @service_name, @username, @password, @api_key = service_name, username, password, apikey
end

Instance Method Details

#api_keyObject



16
17
18
# File 'lib/zohoho/connection.rb', line 16

def api_key
  @api_key
end

#call(entry, api_method, query = {}, http_method = :get) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/zohoho/connection.rb', line 28

def call(entry, api_method, query = {}, http_method = :get)
   = {
    :apikey => api_key,
    :ticket => ticket
  }    
  query.merge!()
 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

#ticketObject



24
25
26
# File 'lib/zohoho/connection.rb', line 24

def ticket
  Regexp.last_match(1) if self.class.get(ticket_url).parsed_response =~ /TICKET=(\w+)/
end

#ticket_urlObject



12
13
14
# File 'lib/zohoho/connection.rb', line 12

def ticket_url
  "https://accounts.zoho.com/login?servicename=#{@service_name}&FROM_AGENT=true&LOGIN_ID=#{@username}&PASSWORD=#{@password}"
end

#zoho_uriObject



20
21
22
# File 'lib/zohoho/connection.rb', line 20

def zoho_uri
  zoho_uri = "https://#{@service_name.downcase}.zoho.com/#{@service_name.downcase}/private/json"
end