Class: Pushover::Subscriptions

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

Overview

Subscriptions provides operations for the Subscription API.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Subscriptions

Returns a new instance of Subscriptions.



6
7
8
# File 'lib/pushover/subscriptions.rb', line 6

def initialize(client)
  @client = client
end

Instance Method Details

#migrate(subscription:, user:, device_name: nil, sound: nil) ⇒ Response

Migrate an existing user key to an application subscription.

Returns:

  • (Response)

    the Pushover API response



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

def migrate(subscription:, user:, device_name: nil, sound: nil)
  validate_subscription!(subscription)
  validate_user!(user)
  validate_device_name!(device_name) unless device_name.nil?
  validate_sound!(sound) unless sound.nil?

  body = { 'token' => @client.token, 'subscription' => subscription, 'user' => user }
  body['device_name'] = device_name unless device_name.nil?
  body['sound'] = sound unless sound.nil?

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