Class: Readiness::Pagerduty::Users
- Inherits:
-
Client
- Object
- Client
- Readiness::Pagerduty::Users
show all
- Defined in:
- lib/support_readiness/pagerduty/users.rb
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Client
auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries
Constructor Details
#initialize(object = {}) ⇒ Users
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/support_readiness/pagerduty/users.rb', line 24
def initialize(object = {})
@avatar_url = object['avatar_url']
@color = object['color']
@contact_methods = object['contact_methods']
@description = object['description']
@email = object['email']
@html_url = object['html_url']
@id = object['id']
@invitation_sent = object['invitation_sent']
@job_title = object['job_title']
@license = object['license']
@name = object['name']
@notification_rules = object['notification_rules']
@role = object['role']
@self = object['self']
@summary = object['summary']
@teams = object['teams']
@time_zone = object['time_zone']
@type = object['type']
end
|
Instance Attribute Details
#avatar_url ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def avatar_url
@avatar_url
end
|
#color ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def color
@color
end
|
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def contact_methods
@contact_methods
end
|
#description ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def description
@description
end
|
#email ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def email
@email
end
|
#html_url ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def html_url
@html_url
end
|
#id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def id
@id
end
|
#invitation_sent ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def invitation_sent
@invitation_sent
end
|
#job_title ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def job_title
@job_title
end
|
#license ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def license
@license
end
|
#name ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def name
@name
end
|
#notification_rules ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def notification_rules
@notification_rules
end
|
#role ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def role
@role
end
|
#self ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def self
@self
end
|
#summary ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def summary
@summary
end
|
#teams ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def teams
@teams
end
|
#time_zone ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def time_zone
@time_zone
end
|
#type ⇒ Object
13
14
15
|
# File 'lib/support_readiness/pagerduty/users.rb', line 13
def type
@type
end
|
Class Method Details
.create!(client, user) ⇒ Object
Creates a user within Pagerduty. This will exit on error
190
191
192
193
194
|
# File 'lib/support_readiness/pagerduty/users.rb', line 190
def self.create!(client, user)
response = client.connection.post 'users', to_clean_json_with_key(user, 'user')
handle_request_error(1, 'Pagerduty', response.status, { action: 'Create user', id: user.email }) unless response.status == 201
Users.new(Oj.load(response.body)['user'])
end
|
.find(client, uid) ⇒ Hash
Shows info of a Pagerduty user. This will not exit on error (except for Auth errors)
92
93
94
95
96
97
98
|
# File 'lib/support_readiness/pagerduty/users.rb', line 92
def self.find(client, uid)
response = client.connection.get("users/#{uid}")
handle_request_error(0, 'Pagerduty', response.status, { action: 'get', id: uid }) unless response.status == 200
return Users.new(Oj.load(response.body)['user']) if response.status == 200
Oj.load(response.body)
end
|
.find!(client, uid) ⇒ Object
Shows info of a Pagerduty user. This will exit on error
117
118
119
120
121
|
# File 'lib/support_readiness/pagerduty/users.rb', line 117
def self.find!(client, uid)
response = client.connection.get("users/#{uid}")
handle_request_error(1, 'Pagerduty', response.status, { action: 'Find user', id: uid }) unless response.status == 200
Users.new(Oj.load(response.body)['user'])
end
|
.find_by_email(client, email) ⇒ Object
Shows info of a Pagerduty user using their email to find them. This will not exit on error (except Auth errors)
139
140
141
|
# File 'lib/support_readiness/pagerduty/users.rb', line 139
def self.find_by_email(client, email)
list(client).detect { |u| u.email == email }
end
|
.find_by_email!(client, email) ⇒ Object
Shows info of a Pagerduty user using their email to find them. This will exit on error
159
160
161
162
163
164
|
# File 'lib/support_readiness/pagerduty/users.rb', line 159
def self.find_by_email!(client, email)
response = list(client).detect { |u| u.email == email }
handle_request_error(1, 'Pagerduty', 404, { action: 'Find user by email', id: email }) if response.nil?
response
end
|
.list(client) ⇒ Array
Lists users within Pagerduty
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/support_readiness/pagerduty/users.rb', line 61
def self.list(client)
array = []
offset = 0
loop do
response = client.connection.get "users?limit=100&offset=#{offset}"
body = Oj.load(response.body)
array += body['users'].map { |u| Users.new(u) }
break unless body['more']
offset += 100
end
array.uniq
end
|