Class: NewDemoApiClient::AsyncUnitEconomicsClient

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::AsyncUnitEconomicsClient

Parameters:



73
74
75
# File 'lib/test_sdk/unit_economics/client.rb', line 73

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientNewDemoApiClient::AsyncRequestClient (readonly)



69
70
71
# File 'lib/test_sdk/unit_economics/client.rb', line 69

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:



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/test_sdk/unit_economics/client.rb', line 96

def get_contribution(group_id:, deal_id:, user_type:, freq: nil, request_options: nil)
  Async do
    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
end