Class: NewDemoApiClient::MacroClient

Inherits:
Object
  • Object
show all
Defined in:
lib/test_sdk/macro/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ NewDemoApiClient::MacroClient

Parameters:



18
19
20
# File 'lib/test_sdk/macro/client.rb', line 18

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientNewDemoApiClient::RequestClient (readonly)



14
15
16
# File 'lib/test_sdk/macro/client.rb', line 14

def request_client
  @request_client
end

Instance Method Details

#get_components(segmentation:, slug:, request_options: nil) ⇒ Array<NewDemoApiClient::WeatherComponents>

Returns the individual components of the weather indicator and some of the

underlying inputs of those component gauges for the given segmentation slug.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.macro.get_components(segmentation: "segmentation", slug: "slug")

Parameters:

Returns:



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/test_sdk/macro/client.rb', line 149

def get_components(segmentation:, slug:, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/data/weather/#{segmentation}/#{slug}/components"
  end
  parsed_json = JSON.parse(response.body)
  parsed_json&.map do |item|
    item = item.to_json
    NewDemoApiClient::WeatherComponents.from_json(json_object: item)
  end
end

#get_gauge(segmentation:, slug: nil, request_options: nil) ⇒ Array<NewDemoApiClient::WeatherGauge>

Returns the overall weather indicator, combined across all stages, for the given

segmentation slug(s).
If no slug is provided, the endpoint will return the gauge for all available
segmentations.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.macro.get_gauge(segmentation: "segmentation")

Parameters:

Returns:



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/test_sdk/macro/client.rb', line 113

def get_gauge(segmentation:, slug: nil, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    req.params = { **(request_options&.additional_query_parameters || {}), "slug": slug }.compact
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/data/weather/#{segmentation}/gauges"
  end
  parsed_json = JSON.parse(response.body)
  parsed_json&.map do |item|
    item = item.to_json
    NewDemoApiClient::WeatherGauge.from_json(json_object: item)
  end
end

#get_market_context(segmentation:, slug:, request_options: nil) ⇒ Array<NewDemoApiClient::WeatherMarketContext>

Returns simplified contextual metrics about relevant stages and market activity

for the given segmentation slug.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.macro.get_market_context(segmentation: "segmentation", slug: "slug")

Parameters:

Returns:



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/test_sdk/macro/client.rb', line 187

def get_market_context(segmentation:, slug:, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/data/weather/#{segmentation}/#{slug}/market-context"
  end
  parsed_json = JSON.parse(response.body)
  parsed_json&.map do |item|
    item = item.to_json
    NewDemoApiClient::WeatherMarketContext.from_json(json_object: item)
  end
end

#get_metadata(segmentation:, request_options: nil) ⇒ Array<NewDemoApiClient::WeatherMetadata>

Returns segmentation metadata for each of the classes of segmentations “geo” and

"sector".
The geography ("geo") segmentation type refers to major geographic
segmentations.
The "sector" segmentation type refers to major business model categories in the
USA geography.
The metadata includes parameters used to generate the respective indicators, and
the metadata needed to
retrieve the series from the API.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.macro.(segmentation: "segmentation")

Parameters:

Returns:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/test_sdk/macro/client.rb', line 73

def (segmentation:, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/data/weather/#{segmentation}/metadata"
  end
  parsed_json = JSON.parse(response.body)
  parsed_json&.map do |item|
    item = item.to_json
    NewDemoApiClient::WeatherMetadata.from_json(json_object: item)
  end
end

#get_segmentations(request_options: nil) ⇒ Array<String>

Returns the available segmentations for the weather module.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.macro.get_segmentations

Parameters:

Returns:

  • (Array<String>)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/test_sdk/macro/client.rb', line 33

def get_segmentations(request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/data/weather/segmentations"
  end
  JSON.parse(response.body)
end