Class: Pushover::Licenses

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

Overview

Licenses provides operations for the Licensing API.

Constant Summary collapse

OPERATING_SYSTEMS =
['Android', 'iOS', 'Desktop'].freeze

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Licenses

Returns a new instance of Licenses.



8
9
10
# File 'lib/pushover/licenses.rb', line 8

def initialize(client)
  @client = client
end

Instance Method Details

#assign(user: nil, email: nil, os: nil) ⇒ Response

Permanently assign one prepaid license credit to a user or e-mail address.

Returns:

  • (Response)

    the Pushover API response



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pushover/licenses.rb', line 24

def assign(user: nil, email: nil, os: nil)
  validate_recipient!(user, email)
  validate_os!(os) unless os.nil?

  body = { 'token' => @client.token }
  body['user'] = user unless user.nil?
  body['email'] = email unless email.nil?
  body['os'] = os unless os.nil?

  response = @client.connection.post(
    path:       '/1/licenses/assign.json',
    body:       Oj.dump(body),
    idempotent: false
  )
  Response.create_from_excon_response(response)
end

#getResponse

Retrieve the application's available prepaid license credits.

Returns:

  • (Response)

    the Pushover API response



14
15
16
17
18
19
20
# File 'lib/pushover/licenses.rb', line 14

def get
  response = @client.connection.get(
    path:  '/1/licenses.json',
    query: { token: @client.token }
  )
  Response.create_from_excon_response(response)
end