Class: SynapsePayRest::Subnets
- Inherits:
-
Object
- Object
- SynapsePayRest::Subnets
- 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
-
#create(user_id:, node_id:, payload:) ⇒ Hash
Sends a POST request to /subents endpoint to create a new subnet.
-
#get(user_id:, node_id:, subnet_id: nil, **options) ⇒ Hash
Sends a GET request to /subnets endpoint.
-
#initialize(client) ⇒ Subnets
constructor
A new instance of Subnets.
-
#update(user_id:, node_id:, subnet_id:, payload:) ⇒ Hash
Sends a PATCH request to /subnets endpoint to update a subnet.
Constructor Details
#initialize(client) ⇒ Subnets
Returns a new instance of Subnets.
15 16 17 |
# File 'lib/synapse_pay_rest/api/subnets.rb', line 15 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ SynapsePayRest::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
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
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, **) path = create_subnet_path(user_id: user_id, node_id: node_id, subnet_id: subnet_id) params = VALID_QUERY_PARAMS.map do |p| [p] ? "#{p}=#{[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
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 |