Class: Teems::Api::Users

Inherits:
Client
  • Object
show all
Includes:
UsersMailbox, UsersPresence
Defined in:
lib/teems/api/users.rb

Overview

API wrapper for Microsoft Graph user endpoints

Constant Summary collapse

USER_SELECT =
%w[
  id displayName mail userPrincipalName jobTitle
  department officeLocation businessPhones mobilePhone
].join(',').freeze

Constants inherited from Client

Client::ENDPOINT

Instance Method Summary collapse

Methods included from UsersMailbox

#auto_replies, #update_auto_replies

Methods included from UsersPresence

#clear_presence, #clear_status_message, #my_presence, #set_presence, #set_status_message

Methods inherited from Client

#initialize

Constructor Details

This class inherits a constructor from Teems::Api::Client

Instance Method Details

#direct_reports(user_id) ⇒ Object



52
53
54
55
56
# File 'lib/teems/api/users.rb', line 52

def direct_reports(user_id)
  encoded_id = URI.encode_www_form_component(user_id)
  response = get("/v1.0/users/#{encoded_id}/directReports", params: { '$select' => USER_SELECT })
  (response['value'] || []).map { |data| Models::UserProfile.from_api(data) }
end

#direct_reports_meObject



58
59
60
61
# File 'lib/teems/api/users.rb', line 58

def direct_reports_me
  response = get('/v1.0/me/directReports', params: { '$select' => USER_SELECT })
  (response['value'] || []).map { |data| Models::UserProfile.from_api(data) }
end

#get_user(user_id) ⇒ Object



23
24
25
26
27
# File 'lib/teems/api/users.rb', line 23

def get_user(user_id)
  encoded_id = URI.encode_www_form_component(user_id)
  response = get("/v1.0/users/#{encoded_id}", params: { '$select' => USER_SELECT })
  Models::UserProfile.from_api(response)
end

#manager(user_id) ⇒ Object



41
42
43
44
45
# File 'lib/teems/api/users.rb', line 41

def manager(user_id)
  encoded_id = URI.encode_www_form_component(user_id)
  response = get("/v1.0/users/#{encoded_id}/manager", params: { '$select' => USER_SELECT })
  Models::UserProfile.from_api(response)
end

#manager_meObject



47
48
49
50
# File 'lib/teems/api/users.rb', line 47

def manager_me
  response = get('/v1.0/me/manager', params: { '$select' => USER_SELECT })
  Models::UserProfile.from_api(response)
end

#meObject



18
19
20
21
# File 'lib/teems/api/users.rb', line 18

def me
  response = get('/v1.0/me', params: { '$select' => USER_SELECT })
  Models::UserProfile.from_api(response)
end

#presence(user_id) ⇒ Object



63
64
65
66
# File 'lib/teems/api/users.rb', line 63

def presence(user_id)
  encoded_id = URI.encode_www_form_component(user_id)
  get("/v1.0/users/#{encoded_id}/presence")
end

#schedule(email, time_range:) ⇒ Object



72
73
74
75
# File 'lib/teems/api/users.rb', line 72

def schedule(email, time_range:)
  response = post('/v1.0/me/calendar/getSchedule', body: schedule_body(email, time_range))
  response.dig('value', 0)
end

#search(query) ⇒ Object



29
30
31
32
33
34
# File 'lib/teems/api/users.rb', line 29

def search(query)
  sanitized = query.gsub(/["\\]/, '')
  headers = { 'ConsistencyLevel' => 'eventual' }
  response = get('/v1.0/users', params: search_params(sanitized), headers: headers)
  (response['value'] || []).map { |data| Models::UserProfile.from_api(data) }
end

#search_params(sanitized) ⇒ Object



36
37
38
39
# File 'lib/teems/api/users.rb', line 36

def search_params(sanitized)
  { '$search' => "\"displayName:#{sanitized}\" OR \"mail:#{sanitized}\"",
    '$select' => USER_SELECT, '$count' => 'true', '$top' => 10 }
end

#teams_presence(mri) ⇒ Object



68
69
70
# File 'lib/teems/api/users.rb', line 68

def teams_presence(mri)
  post_to(:presence, path: '/v1/presence/getpresence/', body: [{ mri: mri }])
end