Class: MetricsApi::V3::Api

Inherits:
Object
  • Object
show all
Defined in:
app/services/metrics_api/v3/api.rb

Overview

API entry point for V3 of the MetricsAPI

It takes in the request parameters and generates the metrics JSON the API should respond with

Constant Summary collapse

ENDPOINT_BASE =
'MetricsApi::V3::Endpoints::'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, endpoint) ⇒ Api

Returns a new instance of Api.

Parameters:

  • params (Hash)

    request parameters hash, passed onto active endpoint

  • endpoint (Symbol)

    endpoint this API requests is for



16
17
18
19
# File 'app/services/metrics_api/v3/api.rb', line 16

def initialize(params, endpoint)
  @params = params
  @endpoint = (ENDPOINT_BASE + endpoint.to_s.camelize).constantize
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



12
13
14
# File 'app/services/metrics_api/v3/api.rb', line 12

def endpoint
  @endpoint
end

#paramsObject (readonly)

Returns the value of attribute params.



12
13
14
# File 'app/services/metrics_api/v3/api.rb', line 12

def params
  @params
end

Instance Method Details

#callArray<Hash>

Generates an API response using the parameters passed in when the class is created. This response has already been presented and is ready to deliver to the client

Returns:

  • (Array<Hash>)

    the generated API response



25
26
27
# File 'app/services/metrics_api/v3/api.rb', line 25

def call
  endpoint.new(params).call
end