Class: Pushover::Users

Inherits:
Object
  • Object
show all
Defined in:
lib/pushover/users.rb

Overview

Users provides operations for the User/Group Validation API.

Constant Summary collapse

USER_PATTERN =
/\A[A-Za-z0-9]{30}\z/
DEVICE_PATTERN =
/\A[A-Za-z0-9_-]{1,25}\z/

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Users

Returns a new instance of Users.



7
8
9
# File 'lib/pushover/users.rb', line 7

def initialize(client)
  @client = client
end

Instance Method Details

#validate(user:, device: nil) ⇒ Response

Validate a user or group identifier and optional device.

Returns:

  • (Response)

    the Pushover API response



13
14
15
16
17
18
19
20
21
22
# File 'lib/pushover/users.rb', line 13

def validate(user:, device: nil)
  validate_user!(user)
  validate_device!(device) unless device.nil?

  body = { 'token' => @client.token, 'user' => user }
  body['device'] = device if device

  response = @client.connection.post(path: '/1/users/validate.json', body: Oj.dump(body))
  Response.create_from_excon_response(response)
end