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_per_subscription(options = {}) ⇒ SubscriptionMRRResponse

This endpoint returns your site’s current MRR, including plan and usage breakouts split per subscription. ids in order to limit results. Use in query: ‘filter=1,2,3`. 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`.



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/advanced_billing/controllers/insights_controller.rb', line 143

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_subscription_ids'], key: 'filter[subscription_ids]'))
               .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
                .is_nullify404(true)
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(SubscriptionMRRResponse.method(:from_hash))
                .local_error('400',
                             'Bad Request',
                             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



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

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
                .is_nullify404(true)
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(MRRResponse.method(:from_hash)))
    .execute
end

#read_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](chargify.zendesk.com/hc/en-us/articles/4407838249627) 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](chargify.zendesk.com/hc/en-us/articles/4407838249627#disp laying-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`. order in which results are returned. Use in query `direction=asc`.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/advanced_billing/controllers/insights_controller.rb', line 97

def read_mrr_movements(options = {})
  warn 'Endpoint read_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')
                             .validator(proc do |value|
                               UnionTypeLookUp.get(:ReadMrrMovementsInputDirection)
                                              .validate(value)
                             end))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .is_nullify404(true)
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ListMRRResponse.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 “`



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/advanced_billing/controllers/insights_controller.rb', line 44

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
                .is_nullify404(true)
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(SiteSummary.method(:from_hash)))
    .execute
end