Class: SynapsePayRest::Subscriptions
- Inherits:
-
Object
- Object
- SynapsePayRest::Subscriptions
- Defined in:
- lib/synapse_pay_rest/api/subscriptions.rb
Overview
Implement idempotency keys
Wrapper class for /subscriptions 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(payload:) ⇒ Hash
Sends a POST request to /subscriptions endpoint to create a new subscription.
-
#get(subscription_id: nil, **options) ⇒ Hash
Sends a GET request to /subscriptions endpoint.
-
#initialize(client) ⇒ Subscriptions
constructor
A new instance of Subscriptions.
-
#update(subscription_id:, payload:) ⇒ Hash
Sends a PATCH request to /subscriptions endpoint, updating the current subscription and returns the response.
Constructor Details
#initialize(client) ⇒ Subscriptions
Returns a new instance of Subscriptions.
16 17 18 |
# File 'lib/synapse_pay_rest/api/subscriptions.rb', line 16 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ SynapsePayRest::HTTPClient
13 14 15 |
# File 'lib/synapse_pay_rest/api/subscriptions.rb', line 13 def client @client end |
Instance Method Details
#create(payload:) ⇒ Hash
Sends a POST request to /subscriptions endpoint to create a new subscription. Returns the response.
HTTP response from API
31 32 33 34 |
# File 'lib/synapse_pay_rest/api/subscriptions.rb', line 31 def create(payload:) path = subscription_path client.post(path, payload) end |
#get(subscription_id: nil, **options) ⇒ Hash
Probably should use CGI or RestClient’s param builder instead of
Sends a GET request to /subscriptions endpoint. Queries a specific subscription_id if subs_id supplied, else queries all subscriptions. Returns the response.
HTTP response from API
rolling our own, probably error-prone and untested version github.com/rest-client/rest-client#usage-raw-url
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/synapse_pay_rest/api/subscriptions.rb', line 51 def get(subscription_id: nil, **) path = subscription_path(subscription_id: subscription_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(subscription_id:, payload:) ⇒ Hash
Sends a PATCH request to /subscriptions endpoint, updating the current subscription and returns the response.
HTTP response from API
73 74 75 76 |
# File 'lib/synapse_pay_rest/api/subscriptions.rb', line 73 def update(subscription_id:, payload:) path = subscription_path(subscription_id: subscription_id) client.patch(path, payload) end |