rublox 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/Gemfile +6 -6
 - data/LICENSE +21 -21
 - data/{README.MD → README.md} +68 -68
 - data/Rakefile +33 -33
 - data/lib/rublox/derive/group.rb +50 -50
 - data/lib/rublox/derive/user.rb +89 -89
 - data/lib/rublox/models/full_group.rb +60 -60
 - data/lib/rublox/models/full_user.rb +49 -49
 - data/lib/rublox/models/group_member.rb +54 -54
 - data/lib/rublox/models/group_role.rb +355 -70
 - data/lib/rublox/models/group_shout.rb +62 -62
 - data/lib/rublox/models/limited_user.rb +34 -34
 - data/lib/rublox/models/presence.rb +98 -98
 - data/lib/rublox/util/cache.rb +39 -39
 - data/lib/rublox/util/errors.rb +109 -109
 - data/lib/rublox/util/http_client.rb +95 -95
 - data/lib/rublox/util/pages.rb +85 -85
 - data/lib/rublox/util/url.rb +25 -25
 - data/lib/rublox/version.rb +6 -6
 - data/lib/rublox.rb +136 -136
 - data/rublox.gemspec +32 -32
 - metadata +5 -6
 - data/CHANGELOG.MD +0 -4
 
| 
         @@ -1,60 +1,60 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # frozen_string_literal: true
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require "rublox/models/group_shout"
         
     | 
| 
       4 
     | 
    
         
            -
            require "rublox/models/limited_user"
         
     | 
| 
       5 
     | 
    
         
            -
            require "rublox/derive/group"
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            module Rublox
         
     | 
| 
       8 
     | 
    
         
            -
              # @note This class is handled internally by the public interface such as
         
     | 
| 
       9 
     | 
    
         
            -
              #   {Client#group_from_id}. You should not be creating it yourself.
         
     | 
| 
       10 
     | 
    
         
            -
              # The {FullGroup} class corresponds to a full group response you can get via
         
     | 
| 
       11 
     | 
    
         
            -
              # https://groups.roblox.com/v1/groups/groupId. You can use it to get information
         
     | 
| 
       12 
     | 
    
         
            -
              # about groups.
         
     | 
| 
       13 
     | 
    
         
            -
              #
         
     | 
| 
       14 
     | 
    
         
            -
              # See {Group} for methods you can call on groups!
         
     | 
| 
       15 
     | 
    
         
            -
              class FullGroup
         
     | 
| 
       16 
     | 
    
         
            -
                include Group
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                # @return [Integer] the group's ID
         
     | 
| 
       19 
     | 
    
         
            -
                attr_reader :id
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                # @return [String] the group's name
         
     | 
| 
       22 
     | 
    
         
            -
                attr_reader :name
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                # @return [String] the group's description
         
     | 
| 
       25 
     | 
    
         
            -
                attr_reader :description
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                # @return [LimitedUser, nil] the group's owner, can be nil if the group has
         
     | 
| 
       28 
     | 
    
         
            -
                #   no owner
         
     | 
| 
       29 
     | 
    
         
            -
                attr_reader :owner
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                # @return [GroupShout, nil] the group's shout, can be nil if the group has
         
     | 
| 
       32 
     | 
    
         
            -
                #   no shout
         
     | 
| 
       33 
     | 
    
         
            -
                attr_reader :shout
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                # @return [Integer] the count of how many members the group has
         
     | 
| 
       36 
     | 
    
         
            -
                attr_reader :member_count
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                # @return [true, false] is the group locked?
         
     | 
| 
       39 
     | 
    
         
            -
                attr_reader :locked
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                # @return [true, false] is the group private/invite only?
         
     | 
| 
       42 
     | 
    
         
            -
                attr_reader :private
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                # @param data [Hash]
         
     | 
| 
       45 
     | 
    
         
            -
                # @param client [Client]
         
     | 
| 
       46 
     | 
    
         
            -
                def initialize(data, client)
         
     | 
| 
       47 
     | 
    
         
            -
                  @id = data["id"]
         
     | 
| 
       48 
     | 
    
         
            -
                  @name = data["name"]
         
     | 
| 
       49 
     | 
    
         
            -
                  @description = data["description"]
         
     | 
| 
       50 
     | 
    
         
            -
                  @owner = LimitedUser.new(data["owner"], client) if data["owner"]
         
     | 
| 
       51 
     | 
    
         
            -
                  @shout = GroupShout.new(data["shout"], client, @id) if data["shout"]
         
     | 
| 
       52 
     | 
    
         
            -
                  @member_count = data["memberCount"]
         
     | 
| 
       53 
     | 
    
         
            -
                  # isLocked is only returned if the group is locked, else it is just null (awesome)
         
     | 
| 
       54 
     | 
    
         
            -
                  @locked = !data["isLocked"].nil?
         
     | 
| 
       55 
     | 
    
         
            -
                  @private = data["publicEntryAllowed"]
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
                  @client = client
         
     | 
| 
       58 
     | 
    
         
            -
                end
         
     | 
| 
       59 
     | 
    
         
            -
              end
         
     | 
| 
       60 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require "rublox/models/group_shout"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "rublox/models/limited_user"
         
     | 
| 
      
 5 
     | 
    
         
            +
            require "rublox/derive/group"
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            module Rublox
         
     | 
| 
      
 8 
     | 
    
         
            +
              # @note This class is handled internally by the public interface such as
         
     | 
| 
      
 9 
     | 
    
         
            +
              #   {Client#group_from_id}. You should not be creating it yourself.
         
     | 
| 
      
 10 
     | 
    
         
            +
              # The {FullGroup} class corresponds to a full group response you can get via
         
     | 
| 
      
 11 
     | 
    
         
            +
              # https://groups.roblox.com/v1/groups/groupId. You can use it to get information
         
     | 
| 
      
 12 
     | 
    
         
            +
              # about groups.
         
     | 
| 
      
 13 
     | 
    
         
            +
              #
         
     | 
| 
      
 14 
     | 
    
         
            +
              # See {Group} for methods you can call on groups!
         
     | 
| 
      
 15 
     | 
    
         
            +
              class FullGroup
         
     | 
| 
      
 16 
     | 
    
         
            +
                include Group
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                # @return [Integer] the group's ID
         
     | 
| 
      
 19 
     | 
    
         
            +
                attr_reader :id
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                # @return [String] the group's name
         
     | 
| 
      
 22 
     | 
    
         
            +
                attr_reader :name
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                # @return [String] the group's description
         
     | 
| 
      
 25 
     | 
    
         
            +
                attr_reader :description
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                # @return [LimitedUser, nil] the group's owner, can be nil if the group has
         
     | 
| 
      
 28 
     | 
    
         
            +
                #   no owner
         
     | 
| 
      
 29 
     | 
    
         
            +
                attr_reader :owner
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                # @return [GroupShout, nil] the group's shout, can be nil if the group has
         
     | 
| 
      
 32 
     | 
    
         
            +
                #   no shout
         
     | 
| 
      
 33 
     | 
    
         
            +
                attr_reader :shout
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                # @return [Integer] the count of how many members the group has
         
     | 
| 
      
 36 
     | 
    
         
            +
                attr_reader :member_count
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                # @return [true, false] is the group locked?
         
     | 
| 
      
 39 
     | 
    
         
            +
                attr_reader :locked
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                # @return [true, false] is the group private/invite only?
         
     | 
| 
      
 42 
     | 
    
         
            +
                attr_reader :private
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                # @param data [Hash]
         
     | 
| 
      
 45 
     | 
    
         
            +
                # @param client [Client]
         
     | 
| 
      
 46 
     | 
    
         
            +
                def initialize(data, client)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  @id = data["id"]
         
     | 
| 
      
 48 
     | 
    
         
            +
                  @name = data["name"]
         
     | 
| 
      
 49 
     | 
    
         
            +
                  @description = data["description"]
         
     | 
| 
      
 50 
     | 
    
         
            +
                  @owner = LimitedUser.new(data["owner"], client) if data["owner"]
         
     | 
| 
      
 51 
     | 
    
         
            +
                  @shout = GroupShout.new(data["shout"], client, @id) if data["shout"]
         
     | 
| 
      
 52 
     | 
    
         
            +
                  @member_count = data["memberCount"]
         
     | 
| 
      
 53 
     | 
    
         
            +
                  # isLocked is only returned if the group is locked, else it is just null (awesome)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  @locked = !data["isLocked"].nil?
         
     | 
| 
      
 55 
     | 
    
         
            +
                  @private = data["publicEntryAllowed"]
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                  @client = client
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,49 +1,49 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # frozen_string_literal: true
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require "time"
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            require "rublox/derive/user"
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            module Rublox
         
     | 
| 
       8 
     | 
    
         
            -
              # @note This class is handled internally by the public interface such as
         
     | 
| 
       9 
     | 
    
         
            -
              #   {Client#user_from_id}. You should not be creating it yourself.
         
     | 
| 
       10 
     | 
    
         
            -
              # The {FullUser} class corresponds to a full user response you can get via
         
     | 
| 
       11 
     | 
    
         
            -
              # https://users.roblox.com/v1/users/userId. You can use it to get information
         
     | 
| 
       12 
     | 
    
         
            -
              # about users.
         
     | 
| 
       13 
     | 
    
         
            -
              #
         
     | 
| 
       14 
     | 
    
         
            -
              # See {User} for methods you can call on users!
         
     | 
| 
       15 
     | 
    
         
            -
              class FullUser
         
     | 
| 
       16 
     | 
    
         
            -
                include User
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                # @return [Integer] the user's ID
         
     | 
| 
       19 
     | 
    
         
            -
                attr_reader :id
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                # @return [String] the user's username
         
     | 
| 
       22 
     | 
    
         
            -
                attr_reader :username
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                # @return [String] the user's display name
         
     | 
| 
       25 
     | 
    
         
            -
                attr_reader :display_name
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                # @return [String] the user's profile description
         
     | 
| 
       28 
     | 
    
         
            -
                attr_reader :description
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
                # @return [true, false] is the user banned?
         
     | 
| 
       31 
     | 
    
         
            -
                attr_reader :banned
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                # @return [Time] the user's join date
         
     | 
| 
       34 
     | 
    
         
            -
                attr_reader :join_date
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                # @param data [Hash]
         
     | 
| 
       37 
     | 
    
         
            -
                # @param client [Client]
         
     | 
| 
       38 
     | 
    
         
            -
                def initialize(data, client)
         
     | 
| 
       39 
     | 
    
         
            -
                  @id = data["id"]
         
     | 
| 
       40 
     | 
    
         
            -
                  @username = data["name"]
         
     | 
| 
       41 
     | 
    
         
            -
                  @display_name = data["displayName"]
         
     | 
| 
       42 
     | 
    
         
            -
                  @description = data["description"]
         
     | 
| 
       43 
     | 
    
         
            -
                  @banned = data["banned"]
         
     | 
| 
       44 
     | 
    
         
            -
                  @join_date = Time.iso8601(data["created"])
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                  @client = client
         
     | 
| 
       47 
     | 
    
         
            -
                end
         
     | 
| 
       48 
     | 
    
         
            -
              end
         
     | 
| 
       49 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require "time"
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            require "rublox/derive/user"
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            module Rublox
         
     | 
| 
      
 8 
     | 
    
         
            +
              # @note This class is handled internally by the public interface such as
         
     | 
| 
      
 9 
     | 
    
         
            +
              #   {Client#user_from_id}. You should not be creating it yourself.
         
     | 
| 
      
 10 
     | 
    
         
            +
              # The {FullUser} class corresponds to a full user response you can get via
         
     | 
| 
      
 11 
     | 
    
         
            +
              # https://users.roblox.com/v1/users/userId. You can use it to get information
         
     | 
| 
      
 12 
     | 
    
         
            +
              # about users.
         
     | 
| 
      
 13 
     | 
    
         
            +
              #
         
     | 
| 
      
 14 
     | 
    
         
            +
              # See {User} for methods you can call on users!
         
     | 
| 
      
 15 
     | 
    
         
            +
              class FullUser
         
     | 
| 
      
 16 
     | 
    
         
            +
                include User
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                # @return [Integer] the user's ID
         
     | 
| 
      
 19 
     | 
    
         
            +
                attr_reader :id
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                # @return [String] the user's username
         
     | 
| 
      
 22 
     | 
    
         
            +
                attr_reader :username
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                # @return [String] the user's display name
         
     | 
| 
      
 25 
     | 
    
         
            +
                attr_reader :display_name
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                # @return [String] the user's profile description
         
     | 
| 
      
 28 
     | 
    
         
            +
                attr_reader :description
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                # @return [true, false] is the user banned?
         
     | 
| 
      
 31 
     | 
    
         
            +
                attr_reader :banned
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                # @return [Time] the user's join date
         
     | 
| 
      
 34 
     | 
    
         
            +
                attr_reader :join_date
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                # @param data [Hash]
         
     | 
| 
      
 37 
     | 
    
         
            +
                # @param client [Client]
         
     | 
| 
      
 38 
     | 
    
         
            +
                def initialize(data, client)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  @id = data["id"]
         
     | 
| 
      
 40 
     | 
    
         
            +
                  @username = data["name"]
         
     | 
| 
      
 41 
     | 
    
         
            +
                  @display_name = data["displayName"]
         
     | 
| 
      
 42 
     | 
    
         
            +
                  @description = data["description"]
         
     | 
| 
      
 43 
     | 
    
         
            +
                  @banned = data["banned"]
         
     | 
| 
      
 44 
     | 
    
         
            +
                  @join_date = Time.iso8601(data["created"])
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                  @client = client
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,54 +1,54 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # frozen_string_literal: true
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            module Rublox
         
     | 
| 
       4 
     | 
    
         
            -
              # @note This class is handled internally by the public interface such as
         
     | 
| 
       5 
     | 
    
         
            -
              #   such as {Group#member_by_user}. You should not be creating it yourself.
         
     | 
| 
       6 
     | 
    
         
            -
              # The {GroupMember} class corresponds to a member response, which contains
         
     | 
| 
       7 
     | 
    
         
            -
              # information about the user, their role and group.
         
     | 
| 
       8 
     | 
    
         
            -
              class GroupMember
         
     | 
| 
       9 
     | 
    
         
            -
                # @return [LimitedUser] the user object tied to this member
         
     | 
| 
       10 
     | 
    
         
            -
                attr_reader :user
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                # @return {GroupRole} the role object tied to this member
         
     | 
| 
       13 
     | 
    
         
            -
                attr_reader :role
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                # @return [FullGroup] the group object tied to this member
         
     | 
| 
       16 
     | 
    
         
            -
                attr_reader :group
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                # @param user [FullUser, LimitedUser]
         
     | 
| 
       19 
     | 
    
         
            -
                # @param role [GroupRole]
         
     | 
| 
       20 
     | 
    
         
            -
                # @param group [FullGroup]
         
     | 
| 
       21 
     | 
    
         
            -
                # @param client [Client]
         
     | 
| 
       22 
     | 
    
         
            -
                def initialize(user, role, group, client)
         
     | 
| 
       23 
     | 
    
         
            -
                  @user = user
         
     | 
| 
       24 
     | 
    
         
            -
                  @role = role
         
     | 
| 
       25 
     | 
    
         
            -
                  @group = group
         
     | 
| 
       26 
     | 
    
         
            -
                  @client = client
         
     | 
| 
       27 
     | 
    
         
            -
                end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                # @note Use this if you need the state of the member changed. If you only
         
     | 
| 
       30 
     | 
    
         
            -
                #   want the role's state updated without updating the member's state, use
         
     | 
| 
       31 
     | 
    
         
            -
                #   {GroupRole#refresh}
         
     | 
| 
       32 
     | 
    
         
            -
                # @example
         
     | 
| 
       33 
     | 
    
         
            -
                #   client = Rublox::Client.new
         
     | 
| 
       34 
     | 
    
         
            -
                #   group = client.group_from_id(7384468)
         
     | 
| 
       35 
     | 
    
         
            -
                #   member = group.member_by_id(1)
         
     | 
| 
       36 
     | 
    
         
            -
                #   puts member.role.rank # -> 1
         
     | 
| 
       37 
     | 
    
         
            -
                #   # Assume Roblox now has the Owner role
         
     | 
| 
       38 
     | 
    
         
            -
                #   updated_member = member.refresh_role
         
     | 
| 
       39 
     | 
    
         
            -
                #   puts updated_member.role.rank # -> 255
         
     | 
| 
       40 
     | 
    
         
            -
                # @return [GroupMember] a new {GroupMember} with a new {#role}, if it has been changed.
         
     | 
| 
       41 
     | 
    
         
            -
                def refresh_role
         
     | 
| 
       42 
     | 
    
         
            -
                  data = @client.http_client.get(
         
     | 
| 
       43 
     | 
    
         
            -
                    URL.endpoint("groups", "/v2/users/#{@user.id}/groups/roles")
         
     | 
| 
       44 
     | 
    
         
            -
                  )["data"].find { |role| role["group"]["id"] == @group.id }
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                  GroupMember.new(
         
     | 
| 
       47 
     | 
    
         
            -
                    @user,
         
     | 
| 
       48 
     | 
    
         
            -
                    GroupRole.new(data["role"], @group, @client),
         
     | 
| 
       49 
     | 
    
         
            -
                    @group,
         
     | 
| 
       50 
     | 
    
         
            -
                    @client
         
     | 
| 
       51 
     | 
    
         
            -
                  )
         
     | 
| 
       52 
     | 
    
         
            -
                end
         
     | 
| 
       53 
     | 
    
         
            -
              end
         
     | 
| 
       54 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Rublox
         
     | 
| 
      
 4 
     | 
    
         
            +
              # @note This class is handled internally by the public interface such as
         
     | 
| 
      
 5 
     | 
    
         
            +
              #   such as {Group#member_by_user}. You should not be creating it yourself.
         
     | 
| 
      
 6 
     | 
    
         
            +
              # The {GroupMember} class corresponds to a member response, which contains
         
     | 
| 
      
 7 
     | 
    
         
            +
              # information about the user, their role and group.
         
     | 
| 
      
 8 
     | 
    
         
            +
              class GroupMember
         
     | 
| 
      
 9 
     | 
    
         
            +
                # @return [LimitedUser] the user object tied to this member
         
     | 
| 
      
 10 
     | 
    
         
            +
                attr_reader :user
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                # @return {GroupRole} the role object tied to this member
         
     | 
| 
      
 13 
     | 
    
         
            +
                attr_reader :role
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                # @return [FullGroup] the group object tied to this member
         
     | 
| 
      
 16 
     | 
    
         
            +
                attr_reader :group
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                # @param user [FullUser, LimitedUser]
         
     | 
| 
      
 19 
     | 
    
         
            +
                # @param role [GroupRole]
         
     | 
| 
      
 20 
     | 
    
         
            +
                # @param group [FullGroup]
         
     | 
| 
      
 21 
     | 
    
         
            +
                # @param client [Client]
         
     | 
| 
      
 22 
     | 
    
         
            +
                def initialize(user, role, group, client)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  @user = user
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @role = role
         
     | 
| 
      
 25 
     | 
    
         
            +
                  @group = group
         
     | 
| 
      
 26 
     | 
    
         
            +
                  @client = client
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                # @note Use this if you need the state of the member changed. If you only
         
     | 
| 
      
 30 
     | 
    
         
            +
                #   want the role's state updated without updating the member's state, use
         
     | 
| 
      
 31 
     | 
    
         
            +
                #   {GroupRole#refresh}
         
     | 
| 
      
 32 
     | 
    
         
            +
                # @example
         
     | 
| 
      
 33 
     | 
    
         
            +
                #   client = Rublox::Client.new
         
     | 
| 
      
 34 
     | 
    
         
            +
                #   group = client.group_from_id(7384468)
         
     | 
| 
      
 35 
     | 
    
         
            +
                #   member = group.member_by_id(1)
         
     | 
| 
      
 36 
     | 
    
         
            +
                #   puts member.role.rank # -> 1
         
     | 
| 
      
 37 
     | 
    
         
            +
                #   # Assume Roblox now has the Owner role
         
     | 
| 
      
 38 
     | 
    
         
            +
                #   updated_member = member.refresh_role
         
     | 
| 
      
 39 
     | 
    
         
            +
                #   puts updated_member.role.rank # -> 255
         
     | 
| 
      
 40 
     | 
    
         
            +
                # @return [GroupMember] a new {GroupMember} with a new {#role}, if it has been changed.
         
     | 
| 
      
 41 
     | 
    
         
            +
                def refresh_role
         
     | 
| 
      
 42 
     | 
    
         
            +
                  data = @client.http_client.get(
         
     | 
| 
      
 43 
     | 
    
         
            +
                    URL.endpoint("groups", "/v2/users/#{@user.id}/groups/roles")
         
     | 
| 
      
 44 
     | 
    
         
            +
                  )["data"].find { |role| role["group"]["id"] == @group.id }
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                  GroupMember.new(
         
     | 
| 
      
 47 
     | 
    
         
            +
                    @user,
         
     | 
| 
      
 48 
     | 
    
         
            +
                    GroupRole.new(data["role"], @group, @client),
         
     | 
| 
      
 49 
     | 
    
         
            +
                    @group,
         
     | 
| 
      
 50 
     | 
    
         
            +
                    @client
         
     | 
| 
      
 51 
     | 
    
         
            +
                  )
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
              end
         
     | 
| 
      
 54 
     | 
    
         
            +
            end
         
     |