Class: Zoho::People::API

Inherits:
Object
  • Object
show all
Defined in:
lib/zoho/people/api.rb

Constant Summary collapse

URL =
'https://people.zoho.com/people/api'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_token: ENV['ZOHO_PEOPLE_AUTH_TOKEN']) ⇒ API

Returns a new instance of API.



14
15
16
17
18
# File 'lib/zoho/people/api.rb', line 14

def initialize(auth_token: ENV['ZOHO_PEOPLE_AUTH_TOKEN'])
  raise 'You must provide Zoho People authentication token' unless auth_token

  @auth_token = auth_token
end

Instance Attribute Details

#auth_tokenObject (readonly)

Returns the value of attribute auth_token.



12
13
14
# File 'lib/zoho/people/api.rb', line 12

def auth_token
  @auth_token
end

Instance Method Details

#get_attendance_report(email:, from:, to:) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/zoho/people/api.rb', line 32

def get_attendance_report(email:, from:, to:)
  params = {
    'authtoken' => auth_token,
    'dateFormat' => 'yyyy-MM-dd',
    'emailId' => email,
    'sdate' => from.strftime('%Y-%m-%d'),
    'edate' => to.strftime('%Y-%m-%d')
  }

  data = request(:get, 'attendance/getUserReport', params: params)

  AttendanceReport.parse(data)
end

#post_attendance(attendance) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/zoho/people/api.rb', line 20

def post_attendance(attendance)
  params = {
    'authtoken' => auth_token,
    'dateFormat' => 'dd/MM/yyyy HH:mm:ss',
    'emailId' => attendance.email,
    'checkIn' => attendance.check_in.strftime('%d/%m/%Y %H:%M:%S'),
    'checkOut' => attendance.check_out.strftime('%d/%m/%Y %H:%M:%S')
  }

  request(:post, 'attendance', params: params)
end