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.



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_keyObject



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)
   = {
    :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



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_urlObject



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_uriObject



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