Class: SynapsePayRest::Subscriptions

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

Overview

TODO:

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

Constructor Details

#initialize(client) ⇒ Subscriptions

Returns a new instance of Subscriptions.

Parameters:



16
17
18
# File 'lib/synapse_pay_rest/api/subscriptions.rb', line 16

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientSynapsePayRest::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

Parameters:

  • url (String)
  • scope (Array)

Returns:

  • (Hash)

    API response

Raises:

See Also:



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

TODO:

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

Parameters:

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

    (optional) id of a subscription 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:



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, **options)
  path = subscription_path(subscription_id: subscription_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(subscription_id:, payload:) ⇒ Hash

Sends a PATCH request to /subscriptions endpoint, updating the current subscription and returns the response.

HTTP response from API

Parameters:

  • payload (Hash)

Returns:

  • (Hash)

    API response

Raises:

See Also:



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