Class: AdvancedBilling::InsightsController

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

Overview

InsightsController

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_mrr_movements(options = {}) ⇒ ListMRRResponse

This endpoint returns your site’s MRR movements. ## Understanding MRR movements This endpoint will aid in accessing your site’s [MRR Report](maxio.zendesk.com/hc/en-us/articles/24285894587021-MRR-Ana lytics) data. Whenever a subscription event occurs that causes your site’s MRR to change (such as a signup or upgrade), we record an MRR movement. These records are accessible via the MRR Movements endpoint. Each MRR Movement belongs to a subscription and contains a timestamp, category, and an amount. ‘line_items` represent the subscription’s product configuration at the time of the movement. ### Plan & Usage Breakouts In the MRR Report UI, we support a setting to [include or exclude](maxio.zendesk.com/hc/en-us/articles/24285894587021-MRR-An alytics#displaying-component-based-metered-usage-in-mrr) usage revenue. In the MRR APIs, responses include ‘plan` and `usage` breakouts. Plan includes revenue from:

  • Products

  • Quantity-Based Components

  • On/Off Components

Usage includes revenue from:

  • Metered Components

  • Prepaid Usage Components

results by 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 10. The maximum allowed values is 50; any per_page value over 50 will be changed to 50. Use in query `per_page=20`. in which results are returned. Use in query `direction=asc`.

Parameters:

  • subscription_id (Integer)

    Optional parameter: optionally filter

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

  • direction (SortingDirection)

    Optional parameter: Controls the order

Returns:



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/advanced_billing/controllers/insights_controller.rb', line 95

def list_mrr_movements(options = {})
  warn 'Endpoint list_mrr_movements in InsightsController is deprecated'
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/mrr_movements.json',
                                 Server::DEFAULT)
               .query_param(new_parameter(options['subscription_id'], key: 'subscription_id'))
               .query_param(new_parameter(options['page'], key: 'page'))
               .query_param(new_parameter(options['per_page'], key: 'per_page'))
               .query_param(new_parameter(options['direction'], key: 'direction'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ListMRRResponse.method(:from_hash)))
    .execute
end

#list_mrr_per_subscription(options = {}) ⇒ SubscriptionMRRResponse

This endpoint returns your site’s current MRR, including plan and usage breakouts split per subscription. MRR per subscription operation format to request MRR for a historic time. Use in query: ‘at_time=2022-01-10T10:00:00-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`. which results are returned. Records are ordered by subscription_id in ascending order by default. Use in query `direction=desc`.

Parameters:

  • filter (ListMrrFilter)

    Optional parameter: Filter to use for List

  • at_time (String)

    Optional parameter: Submit a timestamp in ISO8601

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

  • direction (Direction)

    Optional parameter: Controls the order in

Returns:



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/advanced_billing/controllers/insights_controller.rb', line 135

def list_mrr_per_subscription(options = {})
  warn 'Endpoint list_mrr_per_subscription in InsightsController is deprec'\
       'ated'
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/subscriptions_mrr.json',
                                 Server::DEFAULT)
               .query_param(new_parameter(options['filter'], key: 'filter'))
               .query_param(new_parameter(options['at_time'], key: 'at_time'))
               .query_param(new_parameter(options['page'], key: 'page'))
               .query_param(new_parameter(options['per_page'], key: 'per_page'))
               .query_param(new_parameter(options['direction'], key: 'direction'))
               .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(SubscriptionMRRResponse.method(:from_hash))
                .local_error_template('400',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      SubscriptionsMrrErrorResponseException))
    .execute
end

#read_mrr(at_time: nil, subscription_id: nil) ⇒ MRRResponse

This endpoint returns your site’s current MRR, including plan and usage breakouts. ISO8601 format to request MRR for a historic time subscription in order to limit results

Parameters:

  • at_time (DateTime) (defaults to: nil)

    Optional parameter: submit a timestamp in

  • subscription_id (Integer) (defaults to: nil)

    Optional parameter: submit the id of a

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/advanced_billing/controllers/insights_controller.rb', line 39

def read_mrr(at_time: nil,
             subscription_id: nil)
  warn 'Endpoint read_mrr in InsightsController is deprecated'
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/mrr.json',
                                 Server::DEFAULT)
               .query_param(new_parameter(at_time, key: 'at_time'))
               .query_param(new_parameter(subscription_id, key: 'subscription_id'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(MRRResponse.method(:from_hash)))
    .execute
end

#read_site_statsSiteSummary

The Stats API is a very basic view of some Site-level stats. This API call only answers with JSON responses. An XML version is not provided. ## Stats Documentation There currently is not a complimentary matching set of documentation that compliments this endpoint. However, each Site’s dashboard will reflect the summary of information provided in the Stats reposnse. “‘ subdomain.chargify.com/dashboard “`

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/advanced_billing/controllers/insights_controller.rb', line 19

def read_site_stats
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/stats.json',
                                 Server::DEFAULT)
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(SiteSummary.method(:from_hash)))
    .execute
end