Class: Zendesk2::User

Inherits:
Object
  • Object
show all
Extended by:
Attributes
Includes:
Model
Defined in:
lib/zendesk2/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Attributes

assoc_accessor, assoc_reader, assoc_writer

Methods included from Model

#destroy, #missing_attributes, #save, #update!

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



69
70
71
# File 'lib/zendesk2/user.rb', line 69

def errors
  @errors
end

Instance Method Details

#activeBoolean

Returns Users that have been deleted will have the value false here.

Returns:

  • (Boolean)

    Users that have been deleted will have the value false here



11
# File 'lib/zendesk2/user.rb', line 11

attribute :active, type: :boolean

#aliasString

Returns Agents can have an alias that is displayed to end-users.

Returns:

  • (String)

    Agents can have an alias that is displayed to end-users



13
# File 'lib/zendesk2/user.rb', line 13

attribute :alias, type: :string

#ccd_ticketsZendesk2::Tickets

Returns tickets this user is CC’d.

Returns:



172
173
174
175
176
# File 'lib/zendesk2/user.rb', line 172

def ccd_tickets
  requires :identity

  cistern.tickets(collaborator_id: identity)
end

#created_atTime

Returns The time the user was created.

Returns:

  • (Time)

    The time the user was created



15
# File 'lib/zendesk2/user.rb', line 15

attribute :created_at, type: :time

#custom_role_idInteger

Returns A custom role on the user if the user is an agent on the entreprise plan.

Returns:

  • (Integer)

    A custom role on the user if the user is an agent on the entreprise plan



17
# File 'lib/zendesk2/user.rb', line 17

attribute :custom_role_id, type: :integer

#destroy!Object



86
87
88
89
90
91
92
93
94
# File 'lib/zendesk2/user.rb', line 86

def destroy!
  requires :identity

  raise "don't nuke yourself" if email == cistern.username

  merge_attributes(
    cistern.destroy_user('user' => { 'id' => identity }).body['user']
  )
end

#destroyed?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/zendesk2/user.rb', line 96

def destroyed?
  !reload || !active
end

#detailsString

Returns In this field you can store any details obout the user. e.g. the address.

Returns:

  • (String)

    In this field you can store any details obout the user. e.g. the address



19
# File 'lib/zendesk2/user.rb', line 19

attribute :details, type: :string

#emailString

Returns The primary email address of this user.

Returns:

  • (String)

    The primary email address of this user



21
# File 'lib/zendesk2/user.rb', line 21

attribute :email, type: :string

#external_idString

Returns A unique id you can set on a user.

Returns:

  • (String)

    A unique id you can set on a user



23
# File 'lib/zendesk2/user.rb', line 23

attribute :external_id, type: :string

#idInteger

Returns Automatically assigned when creating users.

Returns:

  • (Integer)

    Automatically assigned when creating users



8
# File 'lib/zendesk2/user.rb', line 8

identity :id, type: :integer

#identitiesZendesk2::UserIdentities

Returns the identities of this user.

Returns:



25
# File 'lib/zendesk2/user.rb', line 25

attribute :identities, type: :array

#jwt_login_url(options = {}) ⇒ String

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :return_to (String) — default: nil

    url to return to after initial auth

Returns:

  • (String)

    url to redirect your user’s browser to for login

See Also:



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/zendesk2/user.rb', line 135

def (options = {})
  requires :name, :email

  return_to = options[:return_to]
  jwt_token = cistern.jwt_token || options[:jwt_token]

  uri       = URI.parse(cistern.url)
  uri.path  = '/access/jwt'

  iat = Time.now.to_i
  jti = "#{iat}/#{rand(36**64).to_s(36)}"
  payload = JWT.encode({
                         iat: iat, # Seconds since epoch, determine when this token is stale
                         jti: jti, # Unique token id, helps prevent replay attacks
                         name: name,
                         email: email,
                       }, jwt_token)

  query_values = {
    'jwt' => payload,
  }
  query_values['return_to'] = return_to unless Zendesk2.blank?(return_to)

  uri.query = Faraday::NestedParamsEncoder.encode(query_values)

  uri.to_s
end

#last_login_atTime

Returns A time-stamp of the last time this user logged in to Zendesk.

Returns:

  • (Time)

    A time-stamp of the last time this user logged in to Zendesk



27
# File 'lib/zendesk2/user.rb', line 27

attribute :last_login_at, type: :time

#locale_idInteger

Returns The language identifier for this user.

Returns:

  • (Integer)

    The language identifier for this user



29
# File 'lib/zendesk2/user.rb', line 29

attribute :locale_id, type: :integer

#login_url(timestamp, options = {}) ⇒ String

Using this method requires you to implement the additional (user-defined) /handshake endpoint

Parameters:

  • timestamp (Time)

    time sent with intial handshake

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :return_to (String) — default: nil

    url to return to after handshake

Returns:

  • (String)

    remote authentication login url

See Also:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/zendesk2/user.rb', line 105

def (timestamp, options = {})
  requires :name, :email

  return_to = options[:return_to]
  token     = cistern.token || options[:token]

  uri      = URI.parse(cistern.url)
  uri.path = '/access/remote'

  raise 'timestamp cannot be nil' unless timestamp

  hash_str = "#{name}#{email}#{token}#{timestamp}"
  query_values = {
    'name'      => name,
    'email'     => email,
    'timestamp' => timestamp,
    'hash'      => Digest::MD5.hexdigest(hash_str),
  }

  query_values['return_to'] = return_to unless Zendesk2.blank?(return_to)

  uri.query = Faraday::NestedParamsEncoder.encode(query_values)

  uri.to_s
end

#membershipsZendesk2::Memberships

Returns the organization memberships of this user.

Returns:



184
185
186
# File 'lib/zendesk2/user.rb', line 184

def memberships
  cistern.memberships(user: self)
end

#moderatorBoolean

Returns Designates whether this user has forum moderation capabilities.

Returns:

  • (Boolean)

    Designates whether this user has forum moderation capabilities



31
# File 'lib/zendesk2/user.rb', line 31

attribute :moderator, type: :boolean

#nameString

Returns The name of the user.

Returns:

  • (String)

    The name of the user



33
# File 'lib/zendesk2/user.rb', line 33

attribute :name, type: :string

#notesString

Returns In this field you can store any notes you have about the user.

Returns:

  • (String)

    In this field you can store any notes you have about the user



35
# File 'lib/zendesk2/user.rb', line 35

attribute :notes, type: :string

#only_private_commentsBoolean

Returns true if this user only can create private comments.

Returns:

  • (Boolean)

    true if this user only can create private comments



37
# File 'lib/zendesk2/user.rb', line 37

attribute :only_private_comments, type: :boolean

#organization_idInteger

Returns The id of the organization this user is associated with.

Returns:

  • (Integer)

    The id of the organization this user is associated with



39
# File 'lib/zendesk2/user.rb', line 39

attribute :organization_id, type: :integer

#organizationsZendesk2::Organizations

Returns the organizations of this user through memberships.

Returns:



189
190
191
# File 'lib/zendesk2/user.rb', line 189

def organizations
  cistern.organizations(user: self)
end

#phoneString

Returns The primary phone number of this user.

Returns:

  • (String)

    The primary phone number of this user



41
# File 'lib/zendesk2/user.rb', line 41

attribute :phone, type: :string

#photoAttachment

Returns The user’s profile picture represented as an Attachment object.

Returns:

  • (Attachment)

    The user’s profile picture represented as an Attachment object



43
# File 'lib/zendesk2/user.rb', line 43

attribute :photo, type: :Attachment

#postsZendesk2::HelpCenter::Post

Returns authored posts.

Returns:



201
202
203
204
205
# File 'lib/zendesk2/user.rb', line 201

def posts
  requires :identity

  cistern.help_center_posts(user_id: identity)
end

#roleString

Returns The role of the user. Possible values: “end-user”, “agent”, “admin”.

Returns:

  • (String)

    The role of the user. Possible values: “end-user”, “agent”, “admin”



45
# File 'lib/zendesk2/user.rb', line 45

attribute :role, type: :string

#save!Object



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/zendesk2/user.rb', line 72

def save!
  data = if new_record?
           requires :name, :email

           cistern.create_user('user' => attributes)
         else
           requires :identity

           cistern.update_user('user' => attributes)
         end.body['user']

  merge_attributes(data)
end

#sharedBoolean

Returns If this user is shared from a different Zendesk, ticket sharing accounts only.

Returns:

  • (Boolean)

    If this user is shared from a different Zendesk, ticket sharing accounts only



47
# File 'lib/zendesk2/user.rb', line 47

attribute :shared, type: :boolean

#signatureString

Returns The signature of this user. Only agents and admins can have signatures.

Returns:

  • (String)

    The signature of this user. Only agents and admins can have signatures



49
# File 'lib/zendesk2/user.rb', line 49

attribute :signature, type: :string

#subscriptionsZendesk2::HelpCenter::Subscriptions

Returns subscriptions.

Returns:



194
195
196
197
198
# File 'lib/zendesk2/user.rb', line 194

def subscriptions
  requires :identity

  cistern.help_center_subscriptions(user_id: identity)
end

#suspendedBoolean

Returns Tickets from suspended users are also suspended, and these users cannot log in to the end-user portal.

Returns:

  • (Boolean)

    Tickets from suspended users are also suspended, and these users cannot log in to the end-user portal



52
# File 'lib/zendesk2/user.rb', line 52

attribute :suspended, type: :boolean

#tagsArray

Returns The tags of the user. Only present if your account has user tagging enabled.

Returns:

  • (Array)

    The tags of the user. Only present if your account has user tagging enabled



54
# File 'lib/zendesk2/user.rb', line 54

attribute :tags, type: :array

#ticket_restrictionString

Returns Specified which tickets this user has access to. Possible values are: “organization”, “groups”, “assigned”, “requested”, null.

Returns:

  • (String)

    Specified which tickets this user has access to. Possible values are: “organization”, “groups”, “assigned”, “requested”, null



57
# File 'lib/zendesk2/user.rb', line 57

attribute :ticket_restriction, type: :string

#ticketsZendesk2::Tickets Also known as: requested_tickets

Returns tickets this user requested.

Returns:



164
165
166
167
168
# File 'lib/zendesk2/user.rb', line 164

def tickets
  requires :identity

  cistern.tickets(requester_id: identity)
end

#time_zoneString

Returns The time-zone of this user.

Returns:

  • (String)

    The time-zone of this user



59
# File 'lib/zendesk2/user.rb', line 59

attribute :time_zone, type: :string

#updated_atTime

Returns The time of the last update of the user.

Returns:

  • (Time)

    The time of the last update of the user



61
# File 'lib/zendesk2/user.rb', line 61

attribute :updated_at, type: :time

#urlString

Returns The API url of this user.

Returns:

  • (String)

    The API url of this user



63
# File 'lib/zendesk2/user.rb', line 63

attribute :url, type: :string

#user_fieldsHash

Returns Custom fields for the user.

Returns:

  • (Hash)

    Custom fields for the user



65
# File 'lib/zendesk2/user.rb', line 65

attribute :user_fields

#verifiedBoolean

Returns Zendesk has verified that this user is who he says he is.

Returns:

  • (Boolean)

    Zendesk has verified that this user is who he says he is



67
# File 'lib/zendesk2/user.rb', line 67

attribute :verified, type: :boolean