Class: Pushover::Glances

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

Overview

Glances provides operations for the Glances API.

Constant Summary collapse

DATA_FIELDS =
%i[title text subtext count percent].freeze
SUPPORTED_FIELDS =
([:device] + DATA_FIELDS).freeze
TEXT_FIELDS =
%i[title text subtext].freeze

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Glances

Returns a new instance of Glances.



10
11
12
# File 'lib/pushover/glances.rb', line 10

def initialize(client)
  @client = client
end

Instance Method Details

#update(user:, **params) ⇒ Response

Update one or more fields shown on a user's registered widgets.

Returns:

  • (Response)

    the Pushover API response



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pushover/glances.rb', line 16

def update(user:, **params)
  params = params.compact
  validate_supported_fields!(params)
  validate_user!(user)
  validate_data_fields!(params)
  validate_device!(params)
  validate_text_fields!(params)
  validate_count!(params)
  validate_percent!(params)

  body = { 'token' => @client.token, 'user' => user }.merge(params.transform_keys(&:to_s))
  response = @client.connection.post(path: '/1/glances.json', body: Oj.dump(body))
  Response.create_from_excon_response(response)
end