Class: AdvancedBilling::EventsController

Inherits:
BaseController show all
Defined in:
lib/advanced_billing/controllers/events_controller.rb

Overview

EventsController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseController

#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters

Constructor Details

This class inherits a constructor from AdvancedBilling::BaseController

Instance Method Details

#list_events(options = {}) ⇒ Array[EventResponse]

## Events Intro Advanced Billing Events include various activity that happens around a Site. This information is especially useful to track down issues that arise when subscriptions are not created due to errors. Within the Advanced Billing UI, “Events” are referred to as “Site Activity”. Full documentation on how to record view Events / Site Activty in the Advanced Billing UI can be located [here](maxio.zendesk.com/hc/en-us/articles/24250671733517-Site-Act ivity). ## List Events for a Site This method will retrieve a list of events for a site. Use query string filters to narrow down results. You may use the ‘key` filter as part of your query string to narrow down results. ### Legacy Filters The following keys are no longer supported. + `payment_failure_recreated` + `payment_success_recreated` + `renewal_failure_recreated` + `renewal_success_recreated` + `zferral_revenue_post_failure` - (Specific to the deprecated Zferral integration) + `zferral_revenue_post_success` - (Specific to the deprecated Zferral integration) ## Event Specific Data Event Specific Data Each event type has its own `event_specific_data` specified. Here’s an example event for the `subscription_product_change` event: “` {

"event": {
    "id": 351,
    "key": "subscription_product_change",
    "message": "Product changed on Marky Mark's subscription from

‘Basic’ to ‘Pro’“,

    "subscription_id": 205,
    "event_specific_data": {
        "new_product_id": 3,
        "previous_product_id": 2
    },
    "created_at": "2012-01-30T10:43:31-05:00"
}

} “‘ Here’s an example event for the `subscription_state_change` event: “`

{
    "event": {
        "id": 353,
        "key": "subscription_state_change",
        "message": "State changed on Marky Mark's subscription to Pro

from trialing to active“,

        "subscription_id": 205,
        "event_specific_data": {
            "new_subscription_state": "active",
            "previous_subscription_state": "trialing"
        },
        "created_at": "2012-01-30T10:43:33-05:00"
    }
}

“‘ pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned. Use in query `page=1`. many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200. Use in query `per_page=200`. greater than or equal to the one specified than or equal to the one specified returned events. event keys after comma. Use in query `filter=signup_success,payment_success`. filter you would like to apply to your search. YYYY-MM-DD) with which to filter the date_field. Returns components with a timestamp at or after midnight (12:00:00 AM) in your site’s time zone on the date specified. YYYY-MM-DD) with which to filter the date_field. Returns components with a timestamp up to and including 11:59:59PM in your site’s time zone on the date specified. (format YYYY-MM-DD HH:MM:SS) with which to filter the date_field. Returns components with a timestamp at or after exact time provided in query. You can specify timezone in query - otherwise your site’s time zone will be used. If provided, this parameter will be used instead of start_date. (format YYYY-MM-DD HH:MM:SS) with which to filter the date_field. Returns components with a timestamp at or before exact time provided in query. You can specify timezone in query - otherwise your site’s time zone will be used. If provided, this parameter will be used instead of end_date.

Parameters:

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

  • since_id (Integer)

    Optional parameter: Returns events with an id

  • max_id (Integer)

    Optional parameter: Returns events with an id less

  • direction (Direction)

    Optional parameter: The sort direction of the

  • filter (Array[EventType])

    Optional parameter: You can pass multiple

  • date_field (ListEventsDateField)

    Optional parameter: The type of

  • start_date (String)

    Optional parameter: The start date (format

  • end_date (String)

    Optional parameter: The end date (format

  • start_datetime (String)

    Optional parameter: The start date and time

  • end_datetime (String)

    Optional parameter: The end date and time

Returns:



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/advanced_billing/controllers/events_controller.rb', line 110

def list_events(options = {})
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/events.json',
                                 Server::DEFAULT)
               .query_param(new_parameter(options['page'], key: 'page'))
               .query_param(new_parameter(options['per_page'], key: 'per_page'))
               .query_param(new_parameter(options['since_id'], key: 'since_id'))
               .query_param(new_parameter(options['max_id'], key: 'max_id'))
               .query_param(new_parameter(options['direction'], key: 'direction'))
               .query_param(new_parameter(options['filter'], key: 'filter'))
               .query_param(new_parameter(options['date_field'], key: 'date_field'))
               .query_param(new_parameter(options['start_date'], key: 'start_date'))
               .query_param(new_parameter(options['end_date'], key: 'end_date'))
               .query_param(new_parameter(options['start_datetime'], key: 'start_datetime'))
               .query_param(new_parameter(options['end_datetime'], key: 'end_datetime'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth'))
               .array_serialization_format(ArraySerializationFormat::CSV))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(EventResponse.method(:from_hash))
                .is_response_array(true))
    .execute
end

#list_subscription_events(options = {}) ⇒ Array[EventResponse]

The following request will return a list of events for a subscription. Each event type has its own ‘event_specific_data` specified. the subscription pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned. Use in query `page=1`. many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200. Use in query `per_page=200`. greater than or equal to the one specified than or equal to the one specified returned events. event keys after comma. Use in query `filter=signup_success,payment_success`.

Parameters:

  • subscription_id (Integer)

    Required parameter: The Chargify id of

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

  • since_id (Integer)

    Optional parameter: Returns events with an id

  • max_id (Integer)

    Optional parameter: Returns events with an id less

  • direction (Direction)

    Optional parameter: The sort direction of the

  • filter (Array[EventType])

    Optional parameter: You can pass multiple

Returns:



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/advanced_billing/controllers/events_controller.rb', line 161

def list_subscription_events(options = {})
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/subscriptions/{subscription_id}/events.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(options['subscription_id'], key: 'subscription_id')
                                .is_required(true)
                                .should_encode(true))
               .query_param(new_parameter(options['page'], key: 'page'))
               .query_param(new_parameter(options['per_page'], key: 'per_page'))
               .query_param(new_parameter(options['since_id'], key: 'since_id'))
               .query_param(new_parameter(options['max_id'], key: 'max_id'))
               .query_param(new_parameter(options['direction'], key: 'direction'))
               .query_param(new_parameter(options['filter'], key: 'filter'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth'))
               .array_serialization_format(ArraySerializationFormat::CSV))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(EventResponse.method(:from_hash))
                .is_response_array(true))
    .execute
end

#read_events_count(options = {}) ⇒ CountResponse

Get a count of all the events for a given site by using this method. pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned. Use in query ‘page=1`. many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200. Use in query `per_page=200`. greater than or equal to the one specified than or equal to the one specified returned events. event keys after comma. Use in query `filter=signup_success,payment_success`.

Parameters:

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

  • since_id (Integer)

    Optional parameter: Returns events with an id

  • max_id (Integer)

    Optional parameter: Returns events with an id less

  • direction (Direction)

    Optional parameter: The sort direction of the

  • filter (Array[EventType])

    Optional parameter: You can pass multiple

Returns:



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/advanced_billing/controllers/events_controller.rb', line 207

def read_events_count(options = {})
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/events/count.json',
                                 Server::DEFAULT)
               .query_param(new_parameter(options['page'], key: 'page'))
               .query_param(new_parameter(options['per_page'], key: 'per_page'))
               .query_param(new_parameter(options['since_id'], key: 'since_id'))
               .query_param(new_parameter(options['max_id'], key: 'max_id'))
               .query_param(new_parameter(options['direction'], key: 'direction'))
               .query_param(new_parameter(options['filter'], key: 'filter'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth'))
               .array_serialization_format(ArraySerializationFormat::CSV))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CountResponse.method(:from_hash)))
    .execute
end