Class: TrophyApiClient::AsyncUsersClient
- Inherits:
-
Object
- Object
- TrophyApiClient::AsyncUsersClient
- Defined in:
- lib/trophy_api_client/users/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#achievements(id:, include_incomplete: nil, request_options: nil) ⇒ Array<TrophyApiClient::UserAchievementWithStatsResponse>
Get a user’s achievements.
-
#all_metrics(id:, request_options: nil) ⇒ Array<TrophyApiClient::MetricResponse>
Get a single user’s progress against all active metrics.
-
#create(request:, request_options: nil) ⇒ TrophyApiClient::User
Create a new user.
-
#get(id:, request_options: nil) ⇒ TrophyApiClient::User
Get a single user.
-
#get_preferences(id:, request_options: nil) ⇒ TrophyApiClient::UserPreferencesResponse
Get a user’s notification preferences.
-
#identify(id:, request:, request_options: nil) ⇒ TrophyApiClient::User
Identify a user.
- #initialize(request_client:) ⇒ TrophyApiClient::AsyncUsersClient constructor
-
#leaderboard(id:, key:, run: nil, num_events: nil, request_options: nil) ⇒ TrophyApiClient::UserLeaderboardResponseWithHistory
Get a user’s rank, value, and history for a specific leaderboard.
-
#metric_event_summary(id:, key:, aggregation:, start_date:, end_date:, request_options: nil) ⇒ Array<TrophyApiClient::Users::UsersMetricEventSummaryResponseItem>
Get a summary of metric events over time for a user.
-
#points(id:, key:, awards: nil, request_options: nil) ⇒ TrophyApiClient::GetUserPointsResponse
Get a user’s points for a specific points system.
-
#points_boosts(id:, key:, request_options: nil) ⇒ Array<TrophyApiClient::PointsBoost>
Get active points boosts for a user in a specific points system.
-
#points_event_summary(id:, key:, aggregation:, start_date:, end_date:, request_options: nil) ⇒ Array<TrophyApiClient::Users::UsersPointsEventSummaryResponseItem>
Get a summary of points awards over time for a user for a specific points system.
-
#single_metric(id:, key:, request_options: nil) ⇒ TrophyApiClient::MetricResponse
Get a user’s progress against a single active metric.
-
#streak(id:, history_periods: nil, request_options: nil) ⇒ TrophyApiClient::StreakResponse
Get a user’s streak data.
-
#update(id:, request:, request_options: nil) ⇒ TrophyApiClient::User
Update a user.
-
#update_preferences(id:, notifications: nil, request_options: nil) ⇒ TrophyApiClient::UserPreferencesResponse
Update a user’s notification preferences.
-
#wrapped(id:, year: nil, request_options: nil) ⇒ TrophyApiClient::WrappedResponse
Get a user’s year-in-review wrapped data.
Constructor Details
#initialize(request_client:) ⇒ TrophyApiClient::AsyncUsersClient
654 655 656 |
# File 'lib/trophy_api_client/users/client.rb', line 654 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ TrophyApiClient::AsyncRequestClient (readonly)
650 651 652 |
# File 'lib/trophy_api_client/users/client.rb', line 650 def request_client @request_client end |
Instance Method Details
#achievements(id:, include_incomplete: nil, request_options: nil) ⇒ Array<TrophyApiClient::UserAchievementWithStatsResponse>
Get a user’s achievements.
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 |
# File 'lib/trophy_api_client/users/client.rb', line 1025 def achievements(id:, include_incomplete: nil, request_options: nil) Async do 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 || {}), "includeIncomplete": include_incomplete }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}/achievements" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::UserAchievementWithStatsResponse.from_json(json_object: item) end end end |
#all_metrics(id:, request_options: nil) ⇒ Array<TrophyApiClient::MetricResponse>
Get a single user’s progress against all active metrics.
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 |
# File 'lib/trophy_api_client/users/client.rb', line 894 def all_metrics(id:, request_options: nil) Async do 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: request_options)}/users/#{id}/metrics" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::MetricResponse.from_json(json_object: item) end end end |
#create(request:, request_options: nil) ⇒ TrophyApiClient::User
Create a new user.
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 |
# File 'lib/trophy_api_client/users/client.rb', line 677 def create(request:, request_options: nil) Async do response = @request_client.conn.post 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 req.body = { **(request || {}), **(&.additional_body_parameters || {}) }.compact req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users" end TrophyApiClient::User.from_json(json_object: response.body) end end |
#get(id:, request_options: nil) ⇒ TrophyApiClient::User
Get a single user.
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 |
# File 'lib/trophy_api_client/users/client.rb', line 709 def get(id:, request_options: nil) Async do 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: request_options)}/users/#{id}" end TrophyApiClient::User.from_json(json_object: response.body) end end |
#get_preferences(id:, request_options: nil) ⇒ TrophyApiClient::UserPreferencesResponse
Get a user’s notification preferences.
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 |
# File 'lib/trophy_api_client/users/client.rb', line 821 def get_preferences(id:, request_options: nil) Async do 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: request_options)}/users/#{id}/preferences" end TrophyApiClient::UserPreferencesResponse.from_json(json_object: response.body) end end |
#identify(id:, request:, request_options: nil) ⇒ TrophyApiClient::User
Identify a user.
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 |
# File 'lib/trophy_api_client/users/client.rb', line 750 def identify(id:, request:, request_options: nil) Async do response = @request_client.conn.put 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 req.body = { **(request || {}), **(&.additional_body_parameters || {}) }.compact req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}" end TrophyApiClient::User.from_json(json_object: response.body) end end |
#leaderboard(id:, key:, run: nil, num_events: nil, request_options: nil) ⇒ TrophyApiClient::UserLeaderboardResponseWithHistory
Get a user’s rank, value, and history for a specific leaderboard.
1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 |
# File 'lib/trophy_api_client/users/client.rb', line 1246 def leaderboard(id:, key:, run: nil, num_events: nil, request_options: nil) Async do 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 || {}), "run": run, "numEvents": num_events }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}/leaderboards/#{key}" end TrophyApiClient::UserLeaderboardResponseWithHistory.from_json(json_object: response.body) end end |
#metric_event_summary(id:, key:, aggregation:, start_date:, end_date:, request_options: nil) ⇒ Array<TrophyApiClient::Users::UsersMetricEventSummaryResponseItem>
Get a summary of metric events over time for a user.
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 |
# File 'lib/trophy_api_client/users/client.rb', line 980 def metric_event_summary(id:, key:, aggregation:, start_date:, end_date:, request_options: nil) Async do 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 || {}), "aggregation": aggregation, "startDate": start_date, "endDate": end_date }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}/metrics/#{key}/event-summary" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::Users::UsersMetricEventSummaryResponseItem.from_json(json_object: item) end end end |
#points(id:, key:, awards: nil, request_options: nil) ⇒ TrophyApiClient::GetUserPointsResponse
Get a user’s points for a specific points system.
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 |
# File 'lib/trophy_api_client/users/client.rb', line 1108 def points(id:, key:, awards: nil, request_options: nil) Async do 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 || {}), "awards": awards }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}/points/#{key}" end TrophyApiClient::GetUserPointsResponse.from_json(json_object: response.body) end end |
#points_boosts(id:, key:, request_options: nil) ⇒ Array<TrophyApiClient::PointsBoost>
Get active points boosts for a user in a specific points system. Returns both
global boosts the user is eligible for and user-specific boosts.
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 |
# File 'lib/trophy_api_client/users/client.rb', line 1143 def points_boosts(id:, key:, request_options: nil) Async do 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: request_options)}/users/#{id}/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 end |
#points_event_summary(id:, key:, aggregation:, start_date:, end_date:, request_options: nil) ⇒ Array<TrophyApiClient::Users::UsersPointsEventSummaryResponseItem>
Get a summary of points awards over time for a user for a specific points
system.
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 |
# File 'lib/trophy_api_client/users/client.rb', line 1195 def points_event_summary(id:, key:, aggregation:, start_date:, end_date:, request_options: nil) Async do 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 || {}), "aggregation": aggregation, "startDate": start_date, "endDate": end_date }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}/points/#{key}/event-summary" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::Users::UsersPointsEventSummaryResponseItem.from_json(json_object: item) end end end |
#single_metric(id:, key:, request_options: nil) ⇒ TrophyApiClient::MetricResponse
Get a user’s progress against a single active metric.
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 |
# File 'lib/trophy_api_client/users/client.rb', line 933 def single_metric(id:, key:, request_options: nil) Async do 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: request_options)}/users/#{id}/metrics/#{key}" end TrophyApiClient::MetricResponse.from_json(json_object: response.body) end end |
#streak(id:, history_periods: nil, request_options: nil) ⇒ TrophyApiClient::StreakResponse
Get a user’s streak data.
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 |
# File 'lib/trophy_api_client/users/client.rb', line 1067 def streak(id:, history_periods: nil, request_options: nil) Async do 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 || {}), "historyPeriods": history_periods }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}/streak" end TrophyApiClient::StreakResponse.from_json(json_object: response.body) end end |
#update(id:, request:, request_options: nil) ⇒ TrophyApiClient::User
Update a user.
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 |
# File 'lib/trophy_api_client/users/client.rb', line 789 def update(id:, request:, request_options: nil) Async do response = @request_client.conn.patch 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 req.body = { **(request || {}), **(&.additional_body_parameters || {}) }.compact req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}" end TrophyApiClient::User.from_json(json_object: response.body) end end |
#update_preferences(id:, notifications: nil, request_options: nil) ⇒ TrophyApiClient::UserPreferencesResponse
Update a user’s notification preferences.
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 |
# File 'lib/trophy_api_client/users/client.rb', line 861 def update_preferences(id:, notifications: nil, request_options: nil) Async do response = @request_client.conn.patch 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 req.body = { **(&.additional_body_parameters || {}), notifications: notifications }.compact req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}/preferences" end TrophyApiClient::UserPreferencesResponse.from_json(json_object: response.body) end end |
#wrapped(id:, year: nil, request_options: nil) ⇒ TrophyApiClient::WrappedResponse
Get a user’s year-in-review wrapped data.
1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 |
# File 'lib/trophy_api_client/users/client.rb', line 1285 def wrapped(id:, year: nil, request_options: nil) Async do 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 || {}), "year": year }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}/wrapped" end TrophyApiClient::WrappedResponse.from_json(json_object: response.body) end end |