Class: SynapsePayRest::Subnets

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse_pay_rest/api/subnets.rb

Overview

Wrapper class for /subnets endpoints

Constant Summary collapse

VALID_QUERY_PARAMS =
TODO:

Refactor to HTTPClient

Valid optional args for #get

[:page, :per_page].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Subnets

Returns a new instance of Subnets.

Parameters:



15
16
17
# File 'lib/synapse_pay_rest/api/subnets.rb', line 15

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientSynapsePayRest::HTTPClient



12
13
14
# File 'lib/synapse_pay_rest/api/subnets.rb', line 12

def client
  @client
end

Instance Method Details

#create(user_id:, node_id:, payload:) ⇒ Hash

Sends a POST request to /subents endpoint to create a new subnet. Returns the response.

HTTP response from API

Parameters:

  • user_id (String)

    user_id associated with the subnet

  • node_id (String)

    node the subnet belongs to

  • payload (Hash)

Returns:

  • (Hash)

    API response

Raises:

See Also:



56
57
58
59
# File 'lib/synapse_pay_rest/api/subnets.rb', line 56

def create(user_id:, node_id:, payload:)
  path = create_subnet_path(user_id: user_id, node_id: node_id)
  client.post(path, payload)
end

#get(user_id:, node_id:, subnet_id: nil, **options) ⇒ Hash

Sends a GET request to /subnets endpoint. Queries a specific subnet_id if subnet_id supplied, else queries all transactions. Returns the response.

HTTP response from API

Parameters:

  • user_id (String)
  • node_id (String)

    id of node

  • subnet_id (String, void) (defaults to: nil)

    (optional) id of a subnet to look up

  • page (String, Integer)

    (optional) response will default to 1

  • per_page (String, Integer)

    (optional) response will default to 20

Returns:

  • (Hash)

    API response

Raises:



33
34
35
36
37
38
39
40
41
42
# File 'lib/synapse_pay_rest/api/subnets.rb', line 33

def get(user_id:, node_id:, subnet_id: nil, **options)
  path = create_subnet_path(user_id: user_id, node_id: node_id, subnet_id: subnet_id)

  params = VALID_QUERY_PARAMS.map do |p|
    options[p] ? "#{p}=#{options[p]}" : nil
  end.compact

  path += '?' + params.join('&') if params.any?
  client.get(path)
end

#update(user_id:, node_id:, subnet_id:, payload:) ⇒ Hash

Sends a PATCH request to /subnets endpoint to update a subnet. Returns the response.

HTTP response from API

Parameters:

  • user_id (String)

    id of user associated with the subnet

  • node_id (String)

    id of node the subnet belongs to

  • subnet_id (String)

    id of subnet

  • payload (Hash)

Returns:

  • (Hash)

    API response

Raises:

See Also:



74
75
76
77
# File 'lib/synapse_pay_rest/api/subnets.rb', line 74

def update(user_id:, node_id:, subnet_id:, payload:)
  path = create_subnet_path(user_id: user_id, node_id: node_id, subnet_id: subnet_id)
  client.patch(path, payload)
end