Class: Plugzapi::Connections

Inherits:
Object
  • Object
show all
Defined in:
lib/plugzapi/connections.rb

Overview

This main class is for connections with the PlugZapi API. The other classes that will integrate with endpoints need to inherit from Connections.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance_id, token) ⇒ Connections

Returns a new instance of Connections.



13
14
15
16
# File 'lib/plugzapi/connections.rb', line 13

def initialize(instance_id, token)
  @instance_id = instance_id
  @token = token
end

Instance Attribute Details

#instance_idObject (readonly)

Returns the value of attribute instance_id.



7
8
9
# File 'lib/plugzapi/connections.rb', line 7

def instance_id
  @instance_id
end

#tokenObject (readonly)

Returns the value of attribute token.



7
8
9
# File 'lib/plugzapi/connections.rb', line 7

def token
  @token
end

Class Method Details

.perform(instance_id:, token:) ⇒ Object



9
10
11
# File 'lib/plugzapi/connections.rb', line 9

def self.perform(instance_id:, token:)
  new(instance_id, token).call
end

Instance Method Details

#callObject

The call method will invoke response and return the API request’s response.



19
20
21
22
23
24
25
# File 'lib/plugzapi/connections.rb', line 19

def call
  parsed_response = JSON.parse(response.body).transform_keys{ |key| key.to_sym }

  parsed_response[:status] = response.status

  parsed_response
end