rublox 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,98 +1,98 @@
1
- # frozen_string_literal: true
2
-
3
- require "time"
4
-
5
- module Rublox
6
- # The state of the presence.
7
- #
8
- # Can be offline, online/on the website, playing a game, developing on studio.
9
- module PresenceType
10
- # The user is/was offline.
11
- OFFLINE = :Offline
12
- # The user is/was online (this also applies to the website).
13
- ONLINE = :Online
14
- # The user is/was playing a game.
15
- GAME = :"In game"
16
- # The user is/was developing on studio.
17
- STUDIO = :"In Studio"
18
-
19
- # @!visibility private
20
- PRESENCE_MAP = [
21
- OFFLINE,
22
- ONLINE,
23
- GAME,
24
- STUDIO
25
- ].freeze
26
-
27
- # Convert the Roblox PresenceType enum response to rublox's PresenceType
28
- # equivalent.
29
- # @!visibility private
30
- # @param enum [Integer]
31
- # @return [Symbol]
32
- def self.enum_to_presence_type(enum)
33
- PRESENCE_MAP[enum]
34
- end
35
- end
36
-
37
- # @note This class is handled internally by the public interface such as
38
- # {Client#user_presence_from_id}. You should not be creating it yourself.
39
- # The {Presence} class corresponds to a response you can get via
40
- # https://presence.roblox.com/v1/presence/users. You can use it to get information
41
- # about the presence states of users.
42
- class Presence
43
- # @return [PresenceType] the current presence type
44
- attr_reader :presence_type
45
-
46
- # @return [PresenceType] the last presence type of the user
47
- attr_reader :last_presence_type
48
-
49
- # @note Unlike it sounds, this is not a numerical ID like of a user. It's a
50
- # randomly generated string with hexadecimal numbers containing the server's
51
- # job ID (which looks like "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"), it can be
52
- # also accessed in-game via the game.JobId property.
53
- # @return [String, nil] the job ID of the game last played by the user.
54
- attr_reader :game_job_id
55
-
56
- # @return [Time] the date at which the user was last online
57
- attr_reader :last_online_date
58
-
59
- def initialize(data, client)
60
- @presence_type = PresenceType.enum_to_presence_type(data["userPresenceType"])
61
- @last_location = data["lastLocation"]
62
- @place_id = data["placeId"]
63
- @root_place_id = data["rootPlaceId"]
64
- @game_job_id = data["gameId"]
65
- @universe_id = data["universeId"]
66
- @user_id = data["userId"]
67
- @last_online_date = Time.iso8601(data["lastOnline"])
68
-
69
- @client = client
70
- end
71
-
72
- # @todo add Place class
73
- # @return [Place, nil] the place last visited by the user, can be nil if the
74
- # user has never played a game
75
- def place
76
- return unless @place_id
77
- end
78
-
79
- # @todo add Place class
80
- # @return [Place, nil] the root of the place last visited by the user, can
81
- # be nil if the user has never played a game
82
- def root_place
83
- return unless @root_place_id
84
- end
85
-
86
- # @todo add Universe class
87
- # @return [Universe, nil] the universe of the place last visited by the user,
88
- # can be nil if the user has never played a game
89
- def universe
90
- return unless @universe_id
91
- end
92
-
93
- # @return [FullUser] the user tied to the presence
94
- def user
95
- @client.user_from_id(@user_id)
96
- end
97
- end
98
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "time"
4
+
5
+ module Rublox
6
+ # The state of the presence.
7
+ #
8
+ # Can be offline, online/on the website, playing a game, developing on studio.
9
+ module PresenceType
10
+ # The user is/was offline.
11
+ OFFLINE = :Offline
12
+ # The user is/was online (this also applies to the website).
13
+ ONLINE = :Online
14
+ # The user is/was playing a game.
15
+ GAME = :"In game"
16
+ # The user is/was developing on studio.
17
+ STUDIO = :"In Studio"
18
+
19
+ # @!visibility private
20
+ PRESENCE_MAP = [
21
+ OFFLINE,
22
+ ONLINE,
23
+ GAME,
24
+ STUDIO
25
+ ].freeze
26
+
27
+ # Convert the Roblox PresenceType enum response to rublox's PresenceType
28
+ # equivalent.
29
+ # @!visibility private
30
+ # @param enum [Integer]
31
+ # @return [Symbol]
32
+ def self.enum_to_presence_type(enum)
33
+ PRESENCE_MAP[enum]
34
+ end
35
+ end
36
+
37
+ # @note This class is handled internally by the public interface such as
38
+ # {Client#user_presence_from_id}. You should not be creating it yourself.
39
+ # The {Presence} class corresponds to a response you can get via
40
+ # https://presence.roblox.com/v1/presence/users. You can use it to get information
41
+ # about the presence states of users.
42
+ class Presence
43
+ # @return [PresenceType] the current presence type
44
+ attr_reader :presence_type
45
+
46
+ # @return [PresenceType] the last presence type of the user
47
+ attr_reader :last_presence_type
48
+
49
+ # @note Unlike it sounds, this is not a numerical ID like of a user. It's a
50
+ # randomly generated string with hexadecimal numbers containing the server's
51
+ # job ID (which looks like "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"), it can be
52
+ # also accessed in-game via the game.JobId property.
53
+ # @return [String, nil] the job ID of the game last played by the user.
54
+ attr_reader :game_job_id
55
+
56
+ # @return [Time] the date at which the user was last online
57
+ attr_reader :last_online_date
58
+
59
+ def initialize(data, client)
60
+ @presence_type = PresenceType.enum_to_presence_type(data["userPresenceType"])
61
+ @last_location = data["lastLocation"]
62
+ @place_id = data["placeId"]
63
+ @root_place_id = data["rootPlaceId"]
64
+ @game_job_id = data["gameId"]
65
+ @universe_id = data["universeId"]
66
+ @user_id = data["userId"]
67
+ @last_online_date = Time.iso8601(data["lastOnline"])
68
+
69
+ @client = client
70
+ end
71
+
72
+ # @todo add Place class
73
+ # @return [Place, nil] the place last visited by the user, can be nil if the
74
+ # user has never played a game
75
+ def place
76
+ return unless @place_id
77
+ end
78
+
79
+ # @todo add Place class
80
+ # @return [Place, nil] the root of the place last visited by the user, can
81
+ # be nil if the user has never played a game
82
+ def root_place
83
+ return unless @root_place_id
84
+ end
85
+
86
+ # @todo add Universe class
87
+ # @return [Universe, nil] the universe of the place last visited by the user,
88
+ # can be nil if the user has never played a game
89
+ def universe
90
+ return unless @universe_id
91
+ end
92
+
93
+ # @return [FullUser] the user tied to the presence
94
+ def user
95
+ @client.user_from_id(@user_id)
96
+ end
97
+ end
98
+ end
@@ -1,39 +1,39 @@
1
- # frozen_string_literal: true
2
-
3
- module Rublox
4
- # @note Only use if you have an use case that the library doesn't cover (and
5
- # create an issue and perhaps we'll implement it!).
6
- module Cache
7
- # The key for the user cache.
8
- USER = :users
9
- # The key for the group cache.
10
- GROUP = :groups
11
- # The key for the page cache.
12
- PAGE = :pages
13
-
14
- # @!visiblity private
15
- @cache = {
16
- users: {},
17
- groups: {},
18
- pages: {}
19
- }
20
-
21
- # Try to get an object from cache.
22
- # @param type [Symbol] {USER}, {GROUP} or {PAGE}
23
- # @param id [Integer] the ID of the object
24
- # @return [FullUser, FullGroup, Pages, nil]
25
- def self.get(type, id)
26
- @cache[type][id]
27
- end
28
-
29
- # Set an object in the cache, under the type's key.
30
- # @param type [Symbol] {USER}, {GROUP} or {PAGE}
31
- # @param id [Integer] the ID of the object
32
- # @param object [FullUser, FullGroup, Pages] the object to be added to the
33
- # cache
34
- # @return [nil]
35
- def self.set(type, id, object)
36
- @cache[type][id] = object
37
- end
38
- end
39
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Rublox
4
+ # @note Only use if you have an use case that the library doesn't cover (and
5
+ # create an issue and perhaps we'll implement it!).
6
+ module Cache
7
+ # The key for the user cache.
8
+ USER = :users
9
+ # The key for the group cache.
10
+ GROUP = :groups
11
+ # The key for the page cache.
12
+ PAGE = :pages
13
+
14
+ # @!visiblity private
15
+ @cache = {
16
+ users: {},
17
+ groups: {},
18
+ pages: {}
19
+ }
20
+
21
+ # Try to get an object from cache.
22
+ # @param type [Symbol] {USER}, {GROUP} or {PAGE}
23
+ # @param id [Integer] the ID of the object
24
+ # @return [FullUser, FullGroup, Pages, nil]
25
+ def self.get(type, id)
26
+ @cache[type][id]
27
+ end
28
+
29
+ # Set an object in the cache, under the type's key.
30
+ # @param type [Symbol] {USER}, {GROUP} or {PAGE}
31
+ # @param id [Integer] the ID of the object
32
+ # @param object [FullUser, FullGroup, Pages] the object to be added to the
33
+ # cache
34
+ # @return [nil]
35
+ def self.set(type, id, object)
36
+ @cache[type][id] = object
37
+ end
38
+ end
39
+ end
@@ -1,109 +1,109 @@
1
- # frozen_string_literal: true
2
-
3
- module Rublox
4
- # This module contains errors that can be raised by rublox methods.
5
- module Errors
6
- # Exception raised when a user cannot be found.
7
- class UserNotFoundError < StandardError
8
- # @return [Integer, "(no ID information provided)"] the given user's ID
9
- attr_reader :user_id
10
-
11
- # @return [String, "(no username information provided)"] the given user's
12
- # username
13
- attr_reader :user_username
14
-
15
- # @param user_id [Integer]
16
- # @param username [String, nil]
17
- def initialize(
18
- user_id = "(no ID information provided)",
19
- username = "(no username information provided)"
20
- )
21
- @user_id = user_id
22
- @user_username = username
23
- super("The user of ID #{user_id} and username #{username} could not be found.")
24
- end
25
- end
26
-
27
- # Exception raised when a group cannot be found.
28
- class GroupNotFoundError < StandardError
29
- # @return [Integer] the given group's ID
30
- attr_reader :group_id
31
-
32
- # @param group_id [Integer]
33
- def initialize(group_id)
34
- @group_id = group_id
35
- super("The group of ID #{group_id} could not be found.")
36
- end
37
- end
38
-
39
- # Exception raised when a user's presence cannot be found.
40
- class PresenceNotFoundError < StandardError
41
- # @return [Integer] the presence user's ID
42
- attr_reader :user_id
43
-
44
- def initialize(user_id)
45
- @user_id = user_id
46
- super("The presence of the user with ID #{user_id} could not be found.")
47
- end
48
- end
49
-
50
- # Exception raised when a user is not part of a group.
51
- class MemberNotFoundError < StandardError
52
- # @return [Integer] the given user's ID
53
- attr_reader :user_id
54
-
55
- # @return [Integer] the given group's ID
56
- attr_reader :group_id
57
-
58
- # @param id [Integer]
59
- # @param group_id [Integer]
60
- def initialize(id, group_id)
61
- @user_id = id
62
- @group_id = group_id
63
- super("The user of ID #{id} is not part of this group of ID #{group_id}")
64
- end
65
- end
66
-
67
- # Exception raised when a role doesn't exist.
68
- class RoleNotFoundError < StandardError
69
- # @return [Integer] the given role's ID
70
- attr_reader :role_id
71
-
72
- # @return [Integer] the given group's ID
73
- attr_reader :group_id
74
-
75
- # @param role_id [Integer]
76
- # @param group_id [Integer]
77
- def initialize(role_id, group_id)
78
- @role_id = role_id
79
- @group_id = group_id
80
- super("The role of ID #{role_id} does not exist in group of ID #{group_id}.")
81
- end
82
- end
83
-
84
- # Exception raised when an unhandled status code is returned.
85
- class UnhandledStatusCodeError < StandardError
86
- # @return [HTTP::Response::Status] the unhandled status code
87
- attr_reader :status_code
88
-
89
- # @return [String] a string containing all the errors returned by the API
90
- # neatly formatted
91
- attr_reader :errors
92
-
93
- # @param status_code [Integer]
94
- # @param errors [String, nil]
95
- def initialize(status_code, errors = "")
96
- super("Unhandled status code #{status_code}.\nRoblox errors:\n#{errors}")
97
- @status_code = status_code
98
- @errors = errors
99
- end
100
- end
101
-
102
- # Exception raised when an invalid .ROBLOSECURITY cookie is used.
103
- class InvalidROBLOSECURITYError < StandardError
104
- def initialize
105
- super("A valid .ROBLOSECURITY cookie needs to be passed to Rublox's constructor for this action.")
106
- end
107
- end
108
- end
109
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Rublox
4
+ # This module contains errors that can be raised by rublox methods.
5
+ module Errors
6
+ # Exception raised when a user cannot be found.
7
+ class UserNotFoundError < StandardError
8
+ # @return [Integer, "(no ID information provided)"] the given user's ID
9
+ attr_reader :user_id
10
+
11
+ # @return [String, "(no username information provided)"] the given user's
12
+ # username
13
+ attr_reader :user_username
14
+
15
+ # @param user_id [Integer]
16
+ # @param username [String, nil]
17
+ def initialize(
18
+ user_id = "(no ID information provided)",
19
+ username = "(no username information provided)"
20
+ )
21
+ @user_id = user_id
22
+ @user_username = username
23
+ super("The user of ID #{user_id} and username #{username} could not be found.")
24
+ end
25
+ end
26
+
27
+ # Exception raised when a group cannot be found.
28
+ class GroupNotFoundError < StandardError
29
+ # @return [Integer] the given group's ID
30
+ attr_reader :group_id
31
+
32
+ # @param group_id [Integer]
33
+ def initialize(group_id)
34
+ @group_id = group_id
35
+ super("The group of ID #{group_id} could not be found.")
36
+ end
37
+ end
38
+
39
+ # Exception raised when a user's presence cannot be found.
40
+ class PresenceNotFoundError < StandardError
41
+ # @return [Integer] the presence user's ID
42
+ attr_reader :user_id
43
+
44
+ def initialize(user_id)
45
+ @user_id = user_id
46
+ super("The presence of the user with ID #{user_id} could not be found.")
47
+ end
48
+ end
49
+
50
+ # Exception raised when a user is not part of a group.
51
+ class MemberNotFoundError < StandardError
52
+ # @return [Integer] the given user's ID
53
+ attr_reader :user_id
54
+
55
+ # @return [Integer] the given group's ID
56
+ attr_reader :group_id
57
+
58
+ # @param id [Integer]
59
+ # @param group_id [Integer]
60
+ def initialize(id, group_id)
61
+ @user_id = id
62
+ @group_id = group_id
63
+ super("The user of ID #{id} is not part of this group of ID #{group_id}")
64
+ end
65
+ end
66
+
67
+ # Exception raised when a role doesn't exist.
68
+ class RoleNotFoundError < StandardError
69
+ # @return [Integer] the given role's ID
70
+ attr_reader :role_id
71
+
72
+ # @return [Integer] the given group's ID
73
+ attr_reader :group_id
74
+
75
+ # @param role_id [Integer]
76
+ # @param group_id [Integer]
77
+ def initialize(role_id, group_id)
78
+ @role_id = role_id
79
+ @group_id = group_id
80
+ super("The role of ID #{role_id} does not exist in group of ID #{group_id}.")
81
+ end
82
+ end
83
+
84
+ # Exception raised when an unhandled status code is returned.
85
+ class UnhandledStatusCodeError < StandardError
86
+ # @return [HTTP::Response::Status] the unhandled status code
87
+ attr_reader :status_code
88
+
89
+ # @return [String] a string containing all the errors returned by the API
90
+ # neatly formatted
91
+ attr_reader :errors
92
+
93
+ # @param status_code [Integer]
94
+ # @param errors [String, nil]
95
+ def initialize(status_code, errors = "")
96
+ super("Unhandled status code #{status_code}.\nRoblox errors:\n#{errors}")
97
+ @status_code = status_code
98
+ @errors = errors
99
+ end
100
+ end
101
+
102
+ # Exception raised when an invalid .ROBLOSECURITY cookie is used.
103
+ class InvalidROBLOSECURITYError < StandardError
104
+ def initialize
105
+ super("A valid .ROBLOSECURITY cookie needs to be passed to Rublox's constructor for this action.")
106
+ end
107
+ end
108
+ end
109
+ end