Class: NewDemoApiClient::UnitEconomicsClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ NewDemoApiClient::UnitEconomicsClient

Parameters:



17
18
19
# File 'lib/test_sdk/unit_economics/client.rb', line 17

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientNewDemoApiClient::RequestClient (readonly)



13
14
15
# File 'lib/test_sdk/unit_economics/client.rb', line 13

def request_client
  @request_client
end

Instance Method Details

#get_contribution(group_id:, deal_id:, user_type:, freq: nil, request_options: nil) ⇒ Array<NewDemoApiClient::ContributionResponse>

Get the contribution for the user type.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.unit_economics.get_contribution(
  group_id: 1,
  deal_id: 1,
  user_type: BUSINESS
)

Parameters:

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/test_sdk/unit_economics/client.rb', line 40

def get_contribution(group_id:, deal_id:, user_type:, freq: 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 || {}),
      "user_type": user_type,
      "freq": freq
    }.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/group/#{group_id}/deal/#{deal_id}/data/contribution"
  end
  parsed_json = JSON.parse(response.body)
  parsed_json&.map do |item|
    item = item.to_json
    NewDemoApiClient::ContributionResponse.from_json(json_object: item)
  end
end