class GoCardless::Services::SubscriptionService
Service for making requests to the Subscription endpoints
Public Instance Methods
Get a lazily enumerated list of all the items returned. This is simmilar to the ‘list` method but will paginate for you automatically.
@param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Otherwise they will be the body of the request.
# File lib/gocardless-pro/services/subscription_service.rb, line 48 def all(options = {}) Paginator.new( service: self, path: '/subscriptions', options: options ).enumerator end
Immediately cancels a subscription; no more payments will be created under it. Any metadata supplied to this endpoint will be stored on the payment cancellation event it causes.
This will fail with a cancellation_failed error if the subscription is already cancelled or finished. Example URL: /subscriptions/:identity/actions/cancel
@param identity # Unique identifier, beginning with “SB” @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Else, they will be the body of the request.
# File lib/gocardless-pro/services/subscription_service.rb, line 98 def cancel(identity, options = {}, custom_headers = {}) path = sub_url('/subscriptions/:identity/actions/cancel', 'identity' => identity) new_options = {} new_options['data'] = options options = new_options response = make_request(:post, path, options, custom_headers) Resources::Subscription.new(unenvelope_body(response.body)) end
Creates a new subscription object Example URL: /subscriptions @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Else, they will be the body of the request.
# File lib/gocardless-pro/services/subscription_service.rb, line 17 def create(options = {}, custom_headers = {}) path = '/subscriptions' new_options = {} new_options[envelope_key] = options options = new_options response = make_request(:post, path, options, custom_headers) Resources::Subscription.new(unenvelope_body(response.body)) end
Retrieves the details of a single subscription. Example URL: /subscriptions/:identity
@param identity # Unique identifier, beginning with “SB” @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Else, they will be the body of the request.
# File lib/gocardless-pro/services/subscription_service.rb, line 62 def get(identity, options = {}, custom_headers = {}) path = sub_url('/subscriptions/:identity', 'identity' => identity) response = make_request(:get, path, options, custom_headers) Resources::Subscription.new(unenvelope_body(response.body)) end
Returns a [cursor-paginated](developer.gocardless.com/pro/#overview-cursor-pagination) list of your subscriptions. Example URL: /subscriptions @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Else, they will be the body of the request.
# File lib/gocardless-pro/services/subscription_service.rb, line 33 def list(options = {}, custom_headers = {}) path = '/subscriptions' response = make_request(:get, path, options, custom_headers) ListResponse.new( raw_response: response, unenveloped_body: unenvelope_body(response.body), resource_class: Resources::Subscription ) end
Unenvelope the response of the body using the service’s ‘envelope_key`
@param body [Hash]
# File lib/gocardless-pro/services/subscription_service.rb, line 112 def unenvelope_body(body) body[envelope_key] || body['data'] end
Updates a subscription object. Example URL: /subscriptions/:identity
@param identity # Unique identifier, beginning with “SB” @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Else, they will be the body of the request.
# File lib/gocardless-pro/services/subscription_service.rb, line 76 def update(identity, options = {}, custom_headers = {}) path = sub_url('/subscriptions/:identity', 'identity' => identity) new_options = {} new_options[envelope_key] = options options = new_options response = make_request(:put, path, options, custom_headers) Resources::Subscription.new(unenvelope_body(response.body)) end
Private Instance Methods
return the key which API responses will envelope data under
# File lib/gocardless-pro/services/subscription_service.rb, line 119 def envelope_key 'subscriptions' end
take a URL with placeholder params and substitute them out for the acutal value @param url [String] the URL with placeholders in @param param_map [Hash] a hash of placeholders and their actual values
# File lib/gocardless-pro/services/subscription_service.rb, line 126 def sub_url(url, param_map) param_map.reduce(url) do |new_url, (param, value)| new_url.gsub(":#{param}", value) end end