class SynapsePayRest::Subnets

Wrapper class for /subnets endpoints

Constants

VALID_QUERY_PARAMS

Valid optional args for get @todo Refactor to HTTPClient

Attributes

client[RW]

@!attribute [rw] client

@return [SynapsePayRest::HTTPClient]

Public Class Methods

new(client) click to toggle source

@param client [SynapsePayRest::HTTPClient]

# File lib/synapse_pay_rest/api/subnets.rb, line 15
def initialize(client)
  @client = client
end

Public Instance Methods

create(user_id:, node_id:, payload:) click to toggle source

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

@param user_id [String] user_id associated with the subnet @param node_id [String] node the subnet belongs to @param payload [Hash] @see docs.synapsepay.com/docs/create-subnet payload structure

@raise [SynapsePayRest::Error] may return subclasses of error based on HTTP response from API

@return [Hash] API response

# 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) click to toggle source

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

@param user_id [String] @param node_id [String] id of node @param subnet_id [String,void] (optional) id of a subnet to look up @param page [String,Integer] (optional) response will default to 1 @param per_page [String,Integer] (optional) response will default to 20

@raise [SynapsePayRest::Error] may return subclasses of error based on HTTP response from API

@return [Hash] API response

# 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:) click to toggle source

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

@param user_id [String] id of user associated with the subnet @param node_id [String] id of node the subnet belongs to @param subnet_id [String] id of subnet @param payload [Hash] @see docs.synapsepay.com/docs/subnet-1 payload structure

@raise [SynapsePayRest::Error] may return subclasses of error based on HTTP response from API

@return [Hash] API response

# 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

Private Instance Methods

create_subnet_path(user_id:, node_id:, subnet_id: nil) click to toggle source
# File lib/synapse_pay_rest/api/subnets.rb, line 81
def create_subnet_path(user_id:, node_id:, subnet_id: nil)
  path = "/users/#{user_id}/nodes/#{node_id}/subnets"
  path += "/#{subnet_id}" if subnet_id
  path
end