Class: TrophyApiClient::PointsClient
- Inherits:
-
Object
- Object
- TrophyApiClient::PointsClient
- Defined in:
- lib/trophy_api_client/points/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#boosts(key:, include_finished: nil, request_options: nil) ⇒ Array<TrophyApiClient::PointsBoost>
Get all global boosts for a points system.
- #initialize(request_client:) ⇒ TrophyApiClient::PointsClient constructor
-
#level_summary(key:, request_options: nil) ⇒ TrophyApiClient::POINTS_LEVEL_SUMMARY_RESPONSE
Get a breakdown of the number of users at each level in a points system.
-
#levels(key:, request_options: nil) ⇒ Array<TrophyApiClient::PointsLevel>
Get all levels for a points system.
-
#summary(key:, user_attributes: nil, request_options: nil) ⇒ TrophyApiClient::POINTS_SUMMARY_RESPONSE
Get a breakdown of the number of users with points in each range.
-
#system(key:, request_options: nil) ⇒ TrophyApiClient::PointsSystemResponse
Get a points system with its triggers.
Constructor Details
#initialize(request_client:) ⇒ TrophyApiClient::PointsClient
19 20 21 |
# File 'lib/trophy_api_client/points/client.rb', line 19 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ TrophyApiClient::RequestClient (readonly)
15 16 17 |
# File 'lib/trophy_api_client/points/client.rb', line 15 def request_client @request_client end |
Instance Method Details
#boosts(key:, include_finished: nil, request_options: nil) ⇒ Array<TrophyApiClient::PointsBoost>
Get all global boosts for a points system. Finished boosts are excluded by
default.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/trophy_api_client/points/client.rb', line 110 def boosts(key:, include_finished: nil, request_options: nil) response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["X-API-KEY"] = .api_key unless &.api_key.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "includeFinished": include_finished }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: )}/points/#{key}/boosts" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::PointsBoost.from_json(json_object: item) end end |
#level_summary(key:, request_options: nil) ⇒ TrophyApiClient::POINTS_LEVEL_SUMMARY_RESPONSE
Get a breakdown of the number of users at each level in a points system.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/trophy_api_client/points/client.rb', line 183 def level_summary(key:, request_options: nil) response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["X-API-KEY"] = .api_key unless &.api_key.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: )}/points/#{key}/level-summary" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::PointsLevelSummaryResponseItem.from_json(json_object: item) end end |
#levels(key:, request_options: nil) ⇒ Array<TrophyApiClient::PointsLevel>
Get all levels for a points system.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/trophy_api_client/points/client.rb', line 147 def levels(key:, request_options: nil) response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["X-API-KEY"] = .api_key unless &.api_key.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: )}/points/#{key}/levels" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::PointsLevel.from_json(json_object: item) end end |
#summary(key:, user_attributes: nil, request_options: nil) ⇒ TrophyApiClient::POINTS_SUMMARY_RESPONSE
Get a breakdown of the number of users with points in each range.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/trophy_api_client/points/client.rb', line 38 def summary(key:, user_attributes: nil, request_options: nil) response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["X-API-KEY"] = .api_key unless &.api_key.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "userAttributes": user_attributes }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: )}/points/#{key}/summary" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::PointsRange.from_json(json_object: item) end end |
#system(key:, request_options: nil) ⇒ TrophyApiClient::PointsSystemResponse
Get a points system with its triggers.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/trophy_api_client/points/client.rb', line 75 def system(key:, request_options: nil) response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["X-API-KEY"] = .api_key unless &.api_key.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: )}/points/#{key}" end TrophyApiClient::PointsSystemResponse.from_json(json_object: response.body) end |