rublox 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1fe191ff9c3e921f2a1c0f00ccdf523b5aabc191eb78549f3838da2232950408
4
- data.tar.gz: 1fda6fca724bbff7f182f39a7f7731f3a3e71014a5d6c421d74e604a14a8814d
3
+ metadata.gz: 4d71b3699e8ae0069057c6df240c9ab0199b98f7891c9675543f4b058faf49d3
4
+ data.tar.gz: b1816f4f994d9d5a78d10bd9cb9ce53882ebabcf3847f2bb58ae9d8d0c5d2cc0
5
5
  SHA512:
6
- metadata.gz: 99cd4156f683cdfa1743c4fb28f6264636df0708d5c7a0b9050ae30285222385eba0aa5a144438b5ccdad29a751b41af9c178ae542862649bc8cc44d86ccfe73
7
- data.tar.gz: 5ea680e0d48a0c46f3fc247f113881146d2f60e12c9d8bb5adb7d4f53052d051fc8b871476fcda5e4f73398f872b68a9bb557337b45a279a986e4ba74b32666f
6
+ metadata.gz: 33ab5fe58df3c385f14334db14cfced103b5c7004c62b25b8005041b070cf336e5fffbefc00aa5691a05ee11ba3970157f7533e08e32380d72e0f13f4ff31058
7
+ data.tar.gz: f76ac4fec783276f419fdf1814cd2b6a71cbc82bbeaf5930f373727e6d3c7e0ebd8f2f8ee555596aa53268d1bbb2752c9a79b8efae4d4a6e2154fcf00e2f518e
data/README.md CHANGED
@@ -24,44 +24,34 @@
24
24
  <a href="https://rubydoc.info/gems/rublox">
25
25
  <img alt="docs" src="https://img.shields.io/badge/docs-rubydoc.info-aa0000?style=flat-square">
26
26
  </a>
27
-
28
- <a href="https://guilded.gg/roblox-api-wrappers">
29
- <img alt="support server" src="https://img.shields.io/badge/guilded-support%20server-aa0000.svg?style=flat-square&logo=guilded">
30
- </a>
31
27
  </div>
32
28
 
33
29
  <div align="center"> <i>rublox is a Roblox web API wrapper written in Ruby. It aims to provide an object oriented interface to get and modify data from Roblox's web API. </i> </div>
34
30
 
35
31
  <br>
36
32
 
37
- # Installation
38
-
39
- Include rublox in your application's `Gemfile`
33
+ # Getting Started
40
34
 
35
+ Authentication can be done by setting the .ROBLOSECURITY cookie through `Rublox.roblosecurity=`
41
36
  ```ruby
42
- gem "rublox", "~> 0.2.0"
43
- ```
37
+ require "rublox"
44
38
 
45
- or run
39
+ Rublox.roblosecurity = "cookie"
46
40
 
47
- > $ gem install rublox
41
+ require "dotenv"
42
+ Dotenv.load
48
43
 
49
- on your terminal.
50
-
51
- # Getting started
44
+ Rublox.roblosecurity = ENV["ROBLOSECURITY"]
45
+ ```
52
46
 
53
- The gateway to the API is the [Rublox::Client](https://rubydoc.info/gems/rublox/Rublox/Client) object. You can initialize it with your _.ROBLOSECURITY_ cookie if you need functionality that needs it.
47
+ All classes representing the Roblox API models should not be initialised by the user. Instead, they are all made through methods in modules and classes.
48
+ Models can be found by searching through classes:
54
49
 
55
- ```ruby
56
- # Without a cookie
57
- client = Rublox::Client.new
58
- # With a cookie
59
- client = Rublox::Client.new("_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this ...")
60
- ```
50
+ ![](https://cdn.discordapp.com/attachments/827652175609856053/1070881521348653056/image.png)
61
51
 
62
- **(if you open-source/work with other people on your application, it is recommended to keep your cookie in a `.env` file and load it with a library like [dotenv](https://rubygems.org/gems/dotenv))**
52
+ And methods for getting the corresponding model can be found by searching through methods:
63
53
 
64
- From there, you can build off your application's logic with methods provided via [Rublox::Client](https://rubydoc.info/gems/rublox/Rublox/Client)
54
+ ![](https://cdn.discordapp.com/attachments/827652175609856053/1070881991093919794/image.png)
65
55
 
66
56
  # Documentation
67
57
 
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rublox/derive/group"
4
+
5
+ module Rublox
6
+ module Bases
7
+ class BaseGroup
8
+ include Derive::Group
9
+
10
+ # @return [Integer]
11
+ attr_reader :id
12
+
13
+ # @!visibility private
14
+ def initialize(id)
15
+ @id = id
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rublox/derive/user"
4
+
5
+ module Rublox
6
+ module Bases
7
+ class BaseUser
8
+ include Derive::User
9
+
10
+ # @return [Integer]
11
+ attr_reader :id
12
+
13
+ # @!visibility private
14
+ def initialize(id)
15
+ @id = id
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,50 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rublox/models/group_member"
4
- require "rublox/models/group_role"
3
+ require "rublox/models/group_shout"
4
+ require "rublox/util/api_helper"
5
5
 
6
6
  module Rublox
7
- # This mixin module contains functions that can be called on group objects.
8
- # @abstract
9
- module Group
10
- # @example
11
- # client = Rublox::Client.new
12
- # group = client.group_from_id(1)
13
- # group.roles.each { |role| puts role.rank } # 0, 1, 180, 100, 254, 255
14
- # @return [Array<GroupRole>] the group's roles
15
- def roles
16
- @client.http_client.get(
17
- URL.endpoint("groups", "v1/groups/#{@id}/roles")
18
- )["roles"].map { |role| GroupRole.new(role, self, @client) }
19
- end
7
+ module Derive
8
+ module Group
9
+ # @return [Models::GroupShout] the new group shout
10
+ def update_shout(message)
11
+ Models::GroupShout.new(APIHelper.patch(
12
+ "https://groups.roblox.com/v1/groups/#{@id}/status",
13
+ json: { message: message }
14
+ ))
15
+ end
20
16
 
21
- # @example
22
- # client = Rublox::Client.new
23
- # group = client.group_from_id(7384468)
24
- # member = group.member_by_id(1)
25
- # puts member.role.rank # -> 1
26
- # @param id [Integer] the user's ID
27
- # @return [GroupMember] the user as a group member object
28
- def member_by_id(id)
29
- member_by_user(@client.user_from_id(id))
30
- rescue Errors::UserNotFoundError
31
- raise Errors::MemberNotFoundError.new(id, @id)
32
- end
17
+ # @return [nil]
18
+ def accept_join_request(user_id)
19
+ APIHelper.post("https://groups.roblox.com/v1/groups/#{@id}/join-requests/users/#{user_id}")
20
+ nil
21
+ end
33
22
 
34
- # @example
35
- # client = Rublox::Client.new
36
- # group = client.group_from_id(7384468)
37
- # owner_member = group.member_by_user(group.owner)
38
- # puts owner_member.role.rank # -> 255
39
- # @param user [FullUser, LimitedUser] the user to tie to the group member
40
- # @return [GroupMember] the user as a group member object
41
- def member_by_user(user)
42
- data = @client.http_client.get(
43
- URL.endpoint("groups", "v2/users/#{user.id}/groups/roles")
44
- )["data"].find { |member_data| member_data["group"]["id"] == @id }
45
- raise Errors::MemberNotFoundError.new(user.id, @id) unless data
23
+ # @return [nil]
24
+ def decline_join_request(user_id)
25
+ APIHelper.delete("https://groups.roblox.com/v1/groups/#{@id}/join-requests/users/#{user_id}")
26
+ nil
27
+ end
46
28
 
47
- GroupMember.new(user, GroupRole.new(data["role"], self, @client), self, @client)
48
- end
49
- end
29
+ # @return [nil]
30
+ def kick(user_id)
31
+ APIHelper.delete("https://groups.roblox.com/v1/groups/#{@id}/users/#{user_id}")
32
+ nil
33
+ end
34
+ end
35
+ end
50
36
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rublox
4
+ module Derive
5
+ module Model
6
+ # @return [String]
7
+ def to_s
8
+ "#<#{self.class} of ID #{@id}>"
9
+ end
10
+
11
+ # @return [Boolean]
12
+ def ==(other)
13
+ @id == other.id
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,89 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rublox/util/url"
3
+ require "rublox/util/api_helper"
4
+ require "rublox/derive/model"
4
5
 
5
6
  module Rublox
6
- # This mixin module contains functions that can be called on user objects.
7
- # @abstract
8
- module User
9
- # @example Updating a {FullUser}
10
- # client = Rublox::Client.new
11
- # user = client.user_from_id(1)
12
- # puts user.display_name # -> Roblox
13
- # # suppose the Roblox account changes it's display name to "ABC"
14
- # refreshed_user = user.refresh
15
- # puts refreshed_user.display_name # -> ABC
16
- # @example Updating a {LimitedUser}
17
- # client = Rublox::Client.new
18
- # group = client.group_from_id(1)
19
- # # say we want the user's join date. LimitedUsers do not contain that information, so we can update it to get a
20
- # # FullUser, which has that
21
- # the_full_user_owner = group.owner.refresh
22
- # # we can now get the owner's join date
23
- # puts the_full_user_owner.join_date.inspect # "2008-09-30 15:54:26 UTC"
24
- # @return [FullUser] a mirrored {FullUser} object, containing new information
25
- # about the user if it has been changed, or if the user is a {LimitedUser}.
26
- def refresh
27
- @client.user_from_id(@id)
28
- end
29
-
30
- # @example
31
- # client = Rublox::Client.new
32
- # user = client.user_from_id(1)
33
- # puts user.friend_count # -> 0
34
- # @return [Integer] the count of how many friends the user has
35
- def friend_count
36
- @client.http_client.get(
37
- URL.endpoint("friends", "/v1/users/#{@id}/friends/count")
38
- )["count"]
39
- end
40
-
41
- # @example
42
- # client = Rublox::Client.new
43
- # user = client.user_from_id(1)
44
- # puts user.follower_count # -> around 6 million
45
- # @return [Integer] the count of how many followers the user has
46
- def follower_count
47
- @client.http_client.get(
48
- URL.endpoint("friends", "/v1/users/#{@id}/followers/count")
49
- )["count"]
50
- end
51
-
52
- # @example
53
- # client = Rublox::Client.new
54
- # user = client.user_from_id(1)
55
- # puts user.followings_count # -> 0
56
- # @return [Integer] the count of how many users the user has followed
57
- def followings_count
58
- @client.http_client.get(
59
- URL.endpoint("friends", "/v1/users/#{@id}/followings/count")
60
- )["count"]
61
- end
62
-
63
- # @example
64
- # client = Rublox::Client.new
65
- # user = client.user_from_id(1)
66
- # puts user.status # -> "Welcome to Roblox, the Imagination Platform. Make friends, explore, and play games!"
67
- # @return [String] the user's status
68
- def status
69
- @client.http_client.get(
70
- URL.endpoint("users", "/v1/users/#{@id}/status")
71
- )["status"]
72
- end
73
-
74
- # @example
75
- # client = Rublox::Client.new
76
- # user = client.user_from_id(1)
77
- # presence = user.presence
78
- # puts presence.last_location # -> "Website"
79
- # @return [Presence] the presence state of the user
80
- def presence
81
- @client.user_presence_from_id(@id)
82
- end
83
-
84
- # @return [String] a readable string representation of the user
85
- def to_s
86
- "User of ID #{@id}, username: #{@username}"
87
- end
88
- end
7
+ module Derive
8
+ module User
9
+ include Model
10
+
11
+ # @return [Integer] the amount of robux the current authenticated user has
12
+ def currency
13
+ APIHelper.get("https://economy.roblox.com/v1/users/#{@id}/currency")["robux"]
14
+ end
15
+
16
+ # @return [Boolean]
17
+ def premium?
18
+ APIHelper.get("https://premiumfeatures.roblox.com/v1/users/#{@id}/validate-membership")
19
+ end
20
+
21
+ # @return [Integer]
22
+ def friend_count
23
+ get_generic_count "friends"
24
+ end
25
+
26
+ # @return [Integer]
27
+ def follower_count
28
+ get_generic_count "followers"
29
+ end
30
+
31
+ # @return [Integer]
32
+ def followings_count
33
+ get_generic_count "followings"
34
+ end
35
+
36
+ private
37
+
38
+ def get_generic_count(channel)
39
+ APIHelper.get("https://friends.roblox.com/v1/users/#{@id}/#{channel}/count")["count"]
40
+ end
41
+ end
42
+ end
89
43
  end
@@ -1,60 +1,56 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rublox/models/group_shout"
4
- require "rublox/models/limited_user"
5
3
  require "rublox/derive/group"
4
+ require "rublox/models/skinny_user"
5
+ require "rublox/models/group_shout"
6
6
 
7
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
8
+ module Models
9
+ class FullGroup
10
+ include Derive::Group
11
+
12
+ # @return [Integer]
13
+ attr_reader :id
14
+ # @return [String]
15
+ attr_reader :name
16
+ # @return [String]
17
+ attr_reader :description
18
+ # @return [SkinnyUser, nil]
19
+ attr_reader :owner
20
+ # @return [GroupShout, nil]
21
+ attr_reader :shout
22
+ # @return [Integer]
23
+ attr_reader :member_count
24
+ # @return [Boolean]
25
+ attr_reader :is_builders_club_only
26
+ # @return [Boolean]
27
+ attr_reader :public_entry_allowed
28
+ # @return [Boolean]
29
+ attr_reader :is_locked
30
+ # @return [Boolean]
31
+ attr_reader :has_verified_badge
32
+
33
+ # @!visibility private
34
+ def initialize(data)
35
+ owner_data = data["owner"]
36
+ shout_data = data["shout"]
37
+ @id = data["id"]
38
+ @name = data["name"]
39
+ @description = data["description"]
40
+ @owner = SkinnyUser.new(owner_data) if owner_data
41
+ @shout = GroupShout.new(shout_data) if shout_data
42
+ @member_count = data["memberCount"]
43
+ @is_builders_club_only = data["isBuildersClubOnly"]
44
+ @public_entry_allowed = data["publicEntryAllowed"]
45
+ @is_locked = !data["isLocked"].nil?
46
+ @has_verified_badge = data["hasVerifiedBadge"]
47
+ end
48
+
49
+ # Updates the group shout and sets {#shout} to the new group shout
50
+ # @return [nil]
51
+ def update_shout!(message)
52
+ @shout = update_shout(message)
53
+ end
54
+ end
55
+ end
60
56
  end
@@ -1,49 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "time"
4
-
5
3
  require "rublox/derive/user"
6
4
 
7
5
  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
6
+ module Models
7
+ class FullUser
8
+ include Derive::User
9
+
10
+ # @return [String]
11
+ attr_reader :description
12
+ # @return [Time]
13
+ attr_reader :created
14
+ # @return [Boolean]
15
+ attr_reader :is_banned
16
+ # @return [String, nil]
17
+ attr_reader :external_app_display_name
18
+ # @return [Boolean]
19
+ attr_reader :has_verified_badge
20
+ # @return [Integer]
21
+ attr_reader :id
22
+ # @return [String]
23
+ attr_reader :name
24
+ # @return [String]
25
+ attr_reader :display_name
26
+
27
+ # @!visibility private
28
+ def initialize(data)
29
+ @description = data["description"]
30
+ @created = Time.iso8601(data["created"])
31
+ @is_banned = data["isBanned"]
32
+ @external_app_display_name = data["externalAppDisplayName"]
33
+ @has_verified_badge = data["hasVerifiedBadge"]
34
+ @id = data["id"]
35
+ @name = data["name"]
36
+ @display_name = data["displayName"]
37
+ end
38
+ end
39
+ end
49
40
  end
@@ -1,62 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rublox/models/limited_user"
3
+ require "rublox/models/skinny_user"
4
4
 
5
5
  module Rublox
6
- # @note This class is handled internally by the public interface such as
7
- # {FullGroup#shout}. You should not be creating it yourself.
8
- # The {GroupShout} class corresponds to a shout response. You can use it to get
9
- # and set information about group shouts.
10
- class GroupShout
11
- # @return [String] the shout's body
12
- attr_reader :body
13
-
14
- # @return [LimitedUser, nil] the user that made the shout, can be nil if the
15
- # shout has no poster
16
- attr_reader :poster
17
-
18
- # @param data [Hash]
19
- # @param client [Client]
20
- # @param group_id [Integer]
21
- def initialize(data, client, group_id)
22
- @body = data["body"]
23
- @poster = LimitedUser.new(data["poster"], client) if data["poster"]
24
-
25
- @group_id = group_id
26
- @client = client
27
- end
28
-
29
- # Sends a new shout.
30
- # @example
31
- # client = Rublox::Client.new
32
- # group = client.group_from_id(1)
33
- # group.shout.send_shout("new shout")
34
- # @param new_shout [String] the body of the new shout
35
- # @return [void]
36
- def send_shout(new_shout)
37
- @client.http_client.patch(
38
- URL.endpoint("groups", "v1/groups/#{@group_id}/status"),
39
- json: {
40
- message: new_shout
41
- }
42
- )
43
- end
44
-
45
- # Clears the group shout. Same as calling {#send_shout} with an empty string.
46
- # @example
47
- # client = Rublox::Client.new
48
- # group = client.group_from_id(1)
49
- # group.shout.clear
50
- # # same as
51
- # group.shout.send_shout("")
52
- # @return [void]
53
- def clear
54
- send_shout("")
55
- end
56
-
57
- # @return [GroupShout] A new group shout object with updated information.
58
- def refresh
59
- @client.group_from_id(@group_id).shout
60
- end
61
- end
6
+ module Models
7
+ class GroupShout
8
+ # @return [String]
9
+ attr_reader :body
10
+ # @return [SkinnyUser]
11
+ attr_reader :poster
12
+ # @return [Time]
13
+ attr_reader :created
14
+ # @return [Time]
15
+ attr_reader :updated
16
+
17
+ # @!visibility private
18
+ def initialize(data)
19
+ @body = data["body"]
20
+ @poster = SkinnyUser.new(data["poster"])
21
+ @created = Time.iso8601(data["created"])
22
+ @updated = Time.iso8601(data["updated"])
23
+ end
24
+ end
25
+ end
62
26
  end