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::CompletedAchievementResponse>
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.
-
#identify(id:, request:, request_options: nil) ⇒ TrophyApiClient::User
Identify a user.
- #initialize(request_client:) ⇒ TrophyApiClient::AsyncUsersClient constructor
-
#leaderboard(id:, key:, run: nil, request_options: nil) ⇒ TrophyApiClient::UserLeaderboardResponse
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_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.
Constructor Details
#initialize(request_client:) ⇒ TrophyApiClient::AsyncUsersClient
502 503 504 |
# File 'lib/trophy_api_client/users/client.rb', line 502 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ TrophyApiClient::AsyncRequestClient (readonly)
498 499 500 |
# File 'lib/trophy_api_client/users/client.rb', line 498 def request_client @request_client end |
Instance Method Details
#achievements(id:, include_incomplete: nil, request_options: nil) ⇒ Array<TrophyApiClient::CompletedAchievementResponse>
Get a user’s achievements.
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 |
# File 'lib/trophy_api_client/users/client.rb', line 800 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: )}/users/#{id}/achievements" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::CompletedAchievementResponse.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.
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 |
# File 'lib/trophy_api_client/users/client.rb', line 669 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: )}/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.
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/trophy_api_client/users/client.rb', line 525 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: )}/users" end TrophyApiClient::User.from_json(json_object: response.body) end end |
#get(id:, request_options: nil) ⇒ TrophyApiClient::User
Get a single user.
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 |
# File 'lib/trophy_api_client/users/client.rb', line 557 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: )}/users/#{id}" end TrophyApiClient::User.from_json(json_object: response.body) end end |
#identify(id:, request:, request_options: nil) ⇒ TrophyApiClient::User
Identify a user.
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 |
# File 'lib/trophy_api_client/users/client.rb', line 598 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: )}/users/#{id}" end TrophyApiClient::User.from_json(json_object: response.body) end end |
#leaderboard(id:, key:, run: nil, request_options: nil) ⇒ TrophyApiClient::UserLeaderboardResponse
Get a user’s rank, value, and history for a specific leaderboard.
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 |
# File 'lib/trophy_api_client/users/client.rb', line 974 def leaderboard(id:, key:, run: 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 }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: )}/users/#{id}/leaderboards/#{key}" end TrophyApiClient::UserLeaderboardResponse.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.
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 |
# File 'lib/trophy_api_client/users/client.rb', line 755 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: )}/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.
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 |
# File 'lib/trophy_api_client/users/client.rb', line 879 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: )}/users/#{id}/points/#{key}" end TrophyApiClient::GetUserPointsResponse.from_json(json_object: response.body) 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.
925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 |
# File 'lib/trophy_api_client/users/client.rb', line 925 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: )}/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.
708 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 708 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: )}/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.
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 |
# File 'lib/trophy_api_client/users/client.rb', line 842 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: )}/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.
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'lib/trophy_api_client/users/client.rb', line 637 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: )}/users/#{id}" end TrophyApiClient::User.from_json(json_object: response.body) end end |