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
-
#all_achievements(id:, request_options: nil) ⇒ Array<TrophyApiClient::CompletedAchievementResponse>
Get all of a user’s completed 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
-
#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:, awards: nil, request_options: nil) ⇒ TrophyApiClient::GetUserPointsResponse
Get a user’s points.
-
#points_event_summary(id:, aggregation:, start_date:, end_date:, request_options: nil) ⇒ Array<TrophyApiClient::Users::UsersPointsEventSummaryResponseItem>
Get a summary of points awards over time for a user.
-
#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
447 448 449 |
# File 'lib/trophy_api_client/users/client.rb', line 447 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ TrophyApiClient::AsyncRequestClient (readonly)
443 444 445 |
# File 'lib/trophy_api_client/users/client.rb', line 443 def request_client @request_client end |
Instance Method Details
#all_achievements(id:, request_options: nil) ⇒ Array<TrophyApiClient::CompletedAchievementResponse>
Get all of a user’s completed achievements.
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 |
# File 'lib/trophy_api_client/users/client.rb', line 737 def all_achievements(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(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.
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 |
# File 'lib/trophy_api_client/users/client.rb', line 611 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(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.
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
# File 'lib/trophy_api_client/users/client.rb', line 469 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(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.
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
# File 'lib/trophy_api_client/users/client.rb', line 501 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(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.
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'lib/trophy_api_client/users/client.rb', line 541 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(request_options: )}/users/#{id}" end TrophyApiClient::User.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.
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 |
# File 'lib/trophy_api_client/users/client.rb', line 696 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(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:, awards: nil, request_options: nil) ⇒ TrophyApiClient::GetUserPointsResponse
Get a user’s points.
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 |
# File 'lib/trophy_api_client/users/client.rb', line 813 def points(id:, 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(request_options: )}/users/#{id}/points" end TrophyApiClient::GetUserPointsResponse.from_json(json_object: response.body) end end |
#points_event_summary(id:, aggregation:, start_date:, end_date:, request_options: nil) ⇒ Array<TrophyApiClient::Users::UsersPointsEventSummaryResponseItem>
Get a summary of points awards over time for a user.
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 |
# File 'lib/trophy_api_client/users/client.rb', line 855 def points_event_summary(id:, 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(request_options: )}/users/#{id}/points/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.
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 |
# File 'lib/trophy_api_client/users/client.rb', line 650 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(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.
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 |
# File 'lib/trophy_api_client/users/client.rb', line 777 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(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.
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
# File 'lib/trophy_api_client/users/client.rb', line 579 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(request_options: )}/users/#{id}" end TrophyApiClient::User.from_json(json_object: response.body) end end |