Class: SynapsePayRest::PublicKey

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse_pay_rest/models/client/issue_public_key.rb

Overview

Represents a public key record and holds methods for getting public key instances from API calls. This is built on top of the SynapsePayRest::Client class and is intended to make it easier to use the API without knowing payload formats or knowledge of REST.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ PublicKey

Note:

Do not call directly. Use PublicKey.issue or other class method to instantiate via API action.

Returns a new instance of PublicKey.



42
43
44
# File 'lib/synapse_pay_rest/models/client/issue_public_key.rb', line 42

def initialize(**options)
  options.each { |key, value| instance_variable_set("@#{key}", value) }
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/synapse_pay_rest/models/client/issue_public_key.rb', line 7

def client
  @client
end

#client_obj_idObject (readonly)

Returns the value of attribute client_obj_id.



7
8
9
# File 'lib/synapse_pay_rest/models/client/issue_public_key.rb', line 7

def client_obj_id
  @client_obj_id
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



7
8
9
# File 'lib/synapse_pay_rest/models/client/issue_public_key.rb', line 7

def expires_at
  @expires_at
end

#expires_inObject (readonly)

Returns the value of attribute expires_in.



7
8
9
# File 'lib/synapse_pay_rest/models/client/issue_public_key.rb', line 7

def expires_in
  @expires_in
end

#public_keyObject (readonly)

Returns the value of attribute public_key.



7
8
9
# File 'lib/synapse_pay_rest/models/client/issue_public_key.rb', line 7

def public_key
  @public_key
end

#scopeObject (readonly)

Returns the value of attribute scope.



7
8
9
# File 'lib/synapse_pay_rest/models/client/issue_public_key.rb', line 7

def scope
  @scope
end

Class Method Details

.from_response(response) ⇒ Object

Note:

Shouldn’t need to call this directly.

Creates a client public key from a response hash.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/synapse_pay_rest/models/client/issue_public_key.rb', line 12

def from_response(response)
  args = {
    client:                    response['client'],
    client_obj_id:             response['public_key_obj']['client_obj_id'],
    expires_at:                response['public_key_obj']['expires_at'],
    expires_in:                response['public_key_obj']['expires_in'],
    public_key:                response['public_key_obj']['public_key'],
    scope:                     response['public_key_obj']['scope']
  }
  self.new(args)
end

.issue(client:, scope: "OAUTH|POST,USERS|POST,USERS|GET,USER|GET,USER|PATCH,SUBSCRIPTIONS|GET,SUBSCRIPTIONS|POST,SUBSCRIPTION|GET,SUBSCRIPTION|PATCH,CLIENT|REPORTS,CLIENT|CONTROLS") ⇒ SynapsePayRest::PublicKey

Issues public key for client.

Parameters:

  • client (SynapsePayRest::Client)
  • scope (String) (defaults to: "OAUTH|POST,USERS|POST,USERS|GET,USER|GET,USER|PATCH,SUBSCRIPTIONS|GET,SUBSCRIPTIONS|POST,SUBSCRIPTION|GET,SUBSCRIPTION|PATCH,CLIENT|REPORTS,CLIENT|CONTROLS")

Returns:

Raises:



31
32
33
34
35
36
37
# File 'lib/synapse_pay_rest/models/client/issue_public_key.rb', line 31

def issue(client:, scope: "OAUTH|POST,USERS|POST,USERS|GET,USER|GET,USER|PATCH,SUBSCRIPTIONS|GET,SUBSCRIPTIONS|POST,SUBSCRIPTION|GET,SUBSCRIPTION|PATCH,CLIENT|REPORTS,CLIENT|CONTROLS")
  raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
  raise ArgumentError, 'scope must be a String' unless scope.is_a?(String)

  response = client.client_endpoint.issue_public_key(scope: scope)
  from_response(response)
end