rublox 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rublox.rb CHANGED
@@ -1,136 +1,89 @@
1
- # frozen_string_literal: true
2
-
3
- require "http"
4
-
5
- require "rublox/version"
6
- require "rublox/util/http_client"
7
- require "rublox/util/cache"
8
- require "rublox/models/full_user"
9
- require "rublox/models/full_group"
10
- require "rublox/models/presence"
11
-
12
- # rublox is a Roblox web API wrapper written in Ruby. It aims to provide an
13
- # object oriented interface to get and modify data from Roblox's web API.
14
- #
15
- # Repository: https://github.com/roblox-api-wrappers/rublox
16
- #
17
- # Docs: https://rubydoc.info/gems/rublox
18
- module Rublox
19
- # The {Client} object is the gateway to the API. Tt supplies methods that
20
- # return classes modeled after the interactions you can do with the API.
21
- #
22
- # Initialize the client with a .ROBLOSECURITY cookie if you need functionality
23
- # that requires it.
24
- # @example
25
- # require "rublox"
26
- # # without a cookie
27
- # client = Rublox::Client.new
28
- # # with a cookie
29
- # client = Rublox::Client.new("_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this ...")
30
- class Client
31
- # @note The HTTP client should only be used when there are no methods
32
- # provided by the library to achieve what you want.
33
- # @return [HTTPClient]
34
- attr_reader :http_client
35
-
36
- # Initialize the client with a .ROBLOSECURITY cookie if you require functionality
37
- # that needs it.
38
- # @example
39
- # require "rublox"
40
- # # without a cookie
41
- # client = Rublox::Client.new
42
- # # with a cookie
43
- # client = Rublox::Client.new("_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this ...")
44
- # @param roblosecurity [String, nil] a valid .ROBLOSECURITY cookie
45
- def initialize(roblosecurity = "")
46
- @http_client = HTTPClient.new(roblosecurity)
47
- end
48
-
49
- # @example
50
- # client = Rublox::Client.new
51
- # user = client.user_from_id(1)
52
- # puts user.username # -> Roblox
53
- # @param id [Integer] the user's ID
54
- # @return [FullUser] a model of the user specified by the ID
55
- def user_from_id(id)
56
- user = Cache.get(Cache::USER, id)
57
- return user if user
58
-
59
- data = @http_client.get(
60
- URL.endpoint("users", "v1/users/#{id}")
61
- )
62
- rescue Errors::UnhandledStatusCodeError
63
- raise Errors::UserNotFoundError, id
64
- else
65
- user = FullUser.new(
66
- data,
67
- self
68
- )
69
- Cache.set(Cache::USER, id, user)
70
-
71
- user
72
- end
73
-
74
- # @note This method sends 2 requests, use {#user_from_id} if possible.
75
- # @example
76
- # client = Rublox::Client.new
77
- # user = client.user_from_username("Roblox")
78
- # puts user.id # -> 1
79
- # @param username [String] the user's username
80
- # @return [FullUser] a model of the user specified by the ID
81
- def user_from_username(username)
82
- data = @http_client.post(
83
- URL.endpoint("users", "/v1/usernames/users"),
84
- json: {
85
- usernames: [username],
86
- excludeBannedUsers: false
87
- }
88
- )["data"]
89
- raise Errors::UserNotFoundError.new(nil, username) if data.empty?
90
-
91
- user_from_id(
92
- data[0]["id"]
93
- )
94
- end
95
-
96
- # @example
97
- # client = Rublox::Client.new
98
- # group = client.group_from_id(1)
99
- # puts group.name # -> RobloHunks
100
- # @param id [Integer] the groups's ID
101
- # @return [FullGroup] a model of the group specified by the ID
102
- def group_from_id(id)
103
- group = Cache.get(Cache::GROUP, id)
104
- return group if group
105
-
106
- data = @http_client.get(
107
- URL.endpoint("groups", "v1/groups/#{id}")
108
- )
109
- rescue Errors::UnhandledStatusCodeError
110
- raise Errors::GroupNotFoundError, id
111
- else
112
- group = FullGroup.new(data, self)
113
- Cache.set(Cache::GROUP, id, group)
114
-
115
- group
116
- end
117
-
118
- # @param id [Integer] the user's ID
119
- # @return [Presence] a model of the presence specified by the user's ID
120
- def user_presence_from_id(id)
121
- data = http_client.post(
122
- URL.endpoint("presence", "v1/presence/users"),
123
- json: {
124
- userIds: [id]
125
- }
126
- )
127
- rescue Errors::UnhandledStatusCodeError
128
- raise Errors::PresenceNotFoundError, id
129
- else
130
- Presence.new(
131
- data["userPresences"][0],
132
- self
133
- )
134
- end
135
- end
136
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "rublox/util/api_helper"
4
+ require "rublox/util/errors"
5
+ require "rublox/models/full_user"
6
+ require "rublox/models/skinny_user"
7
+ require "rublox/models/presence"
8
+ require "rublox/bases/base_user"
9
+ require "rublox/bases/base_group"
10
+
11
+ # rublox is a Roblox web API wrapper written in Ruby. It aims to provide an
12
+ # object oriented interface to get and modify data from Roblox's web API.
13
+ # Docs: https://rubydoc.info/gems/rublox
14
+ module Rublox
15
+ # Sets the .ROBLOSECURITY cookie to send authenticated requests
16
+ def self.roblosecurity=(roblosecurity)
17
+ APIHelper.roblosecurity = roblosecurity
18
+ end
19
+
20
+ # Returns the current authenticated user
21
+ def self.authenticated_user
22
+ Models::SkinnyUser.new(APIHelper.get("https://users.roblox.com/v1/users/authenticated"))
23
+ end
24
+
25
+ # Returns a BaseUser
26
+ def self.base_user(id)
27
+ Bases::BaseUser.new(id)
28
+ end
29
+
30
+ # Returns a user
31
+ def self.user_from_id(id)
32
+ Models::FullUser.new(APIHelper.get("https://users.roblox.com/v1/users/#{id}"))
33
+ rescue Errors::UnhandledStatusCodeError => e
34
+ raise Errors::UserNotFoundError, cause: nil if e.response.status == 404
35
+
36
+ raise
37
+ end
38
+
39
+ def self.users_from_ids(ids, exclude_banned_users: false)
40
+ APIHelper.post(
41
+ "https://users.roblox.com/v1/users",
42
+ json: {
43
+ userIds: ids,
44
+ excludeBannedUsers: exclude_banned_users
45
+ }
46
+ )["data"].map { |data| Models::SkinnyUser.new(data) }
47
+ end
48
+
49
+ def self.users_from_usernames(usernames, exclude_banned_users: false)
50
+ APIHelper.post(
51
+ "https://users.roblox.com/v1/usernames/users",
52
+ json: {
53
+ usernames: usernames,
54
+ excludeBannedUsers: exclude_banned_users
55
+ }
56
+ )["data"].map { |data| Models::SkinnyUser.new(data) }
57
+ end
58
+
59
+ def self.user_from_username(username, exclude_banned_users: false)
60
+ users_from_usernames([username], exclude_banned_users: exclude_banned_users)[0] or raise Errors::UserNotFoundError
61
+ end
62
+
63
+ def self.base_group(id)
64
+ Bases::BaseGroup.new(id)
65
+ end
66
+
67
+ def self.group_from_id(id)
68
+ APIHelper.get("https://groups.roblox.com/v1/groups/#{id}")
69
+ rescue Errors::UnhandledStatusCodeError => e
70
+ raise Errors::GroupNotFoundError, cause: nil if e.response.status == 400
71
+
72
+ raise
73
+ end
74
+
75
+ def self.user_presences_from_ids(ids)
76
+ APIHelper.post(
77
+ "https://presence.roblox.com/v1/presence/users",
78
+ json: { userIds: ids }
79
+ )["userPresences"].map { |data| Models::Presence.new(data) }
80
+ rescue Errors::UnhandledStatusCodeError => e
81
+ raise Errors::PresenceRequestError, cause: nil if e.response.status == 400
82
+
83
+ raise
84
+ end
85
+
86
+ def self.user_presence_from_id(id)
87
+ user_presences_from_ids([id])[0]
88
+ end
89
+ end
data/rublox.gemspec CHANGED
@@ -1,32 +1,30 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/rublox/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "rublox"
7
- spec.version = Rublox::VERSION
8
- spec.authors = %w[Zamdie Keef]
9
- spec.email = "rorg.devv@gmail.com"
10
- spec.summary = "A Roblox web API wrapper written in Ruby"
11
- spec.description = "This gem allows easy interaction with the Roblox web API via class models."
12
- spec.homepage = "https://github.com/roblox-api-wrappers/rublox"
13
- spec.license = "MIT"
14
- spec.required_ruby_version = ">= 3.0"
15
- spec.files = Dir[
16
- "LICENSE",
17
- "CHANGELOG.MD",
18
- "lib/**/*.rb",
19
- "rublox.gemspec",
20
- "Gemfile",
21
- "Rakefile"
22
- ]
23
- spec.extra_rdoc_files = ["README.MD"]
24
-
25
- spec.add_dependency "http", "~> 5.0.2"
26
-
27
- spec.add_development_dependency "dotenv", "~> 2.7"
28
- spec.add_development_dependency "rake", "~> 13.0.6"
29
- spec.add_development_dependency "rubocop", "~> 1.21.0"
30
- spec.add_development_dependency "rubocop-performance", "~> 1.11.5"
31
- spec.add_development_dependency "yard", "~> 0.9.26"
32
- end
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "rublox"
5
+ spec.version = "0.3.0"
6
+ spec.authors = %w[zmλdie keef]
7
+ spec.email = "rorg.devv@gmail.com"
8
+ spec.summary = "A Roblox web API wrapper written in Ruby"
9
+ spec.description = "This gem allows easy interaction with the Roblox web API via modules and classes."
10
+ spec.homepage = "https://github.com/roblox-api-wrappers/rublox"
11
+ spec.metadata = {
12
+ "Documentation" => "https://rubydoc.info/gems/rublox",
13
+ "rubygems_mfa_required" => "true"
14
+ }
15
+ spec.license = "MIT"
16
+ spec.required_ruby_version = ">= 2.7.0"
17
+ spec.files = Dir[
18
+ "README.md",
19
+ "LICENSE",
20
+ "lib/**/*.rb",
21
+ "rublox.gemspec"
22
+ ]
23
+
24
+ spec.add_dependency "http", "~> 5.1.1"
25
+
26
+ spec.add_development_dependency "rubocop", "~> 1.44.1"
27
+ spec.add_development_dependency "rubocop-performance", "~> 1.15.2"
28
+ spec.add_development_dependency "rubocop-rake", "~> 0.6.0"
29
+ spec.add_development_dependency "yard", "~> 0.9.28"
30
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rublox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Zamdie
8
- - Keef
7
+ - zmλdie
8
+ - keef
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-10-09 00:00:00.000000000 Z
12
+ date: 2023-02-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: http
@@ -17,117 +17,99 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 5.0.2
20
+ version: 5.1.1
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 5.0.2
27
+ version: 5.1.1
28
28
  - !ruby/object:Gem::Dependency
29
- name: dotenv
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: '2.7'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: '2.7'
42
- - !ruby/object:Gem::Dependency
43
- name: rake
29
+ name: rubocop
44
30
  requirement: !ruby/object:Gem::Requirement
45
31
  requirements:
46
32
  - - "~>"
47
33
  - !ruby/object:Gem::Version
48
- version: 13.0.6
34
+ version: 1.44.1
49
35
  type: :development
50
36
  prerelease: false
51
37
  version_requirements: !ruby/object:Gem::Requirement
52
38
  requirements:
53
39
  - - "~>"
54
40
  - !ruby/object:Gem::Version
55
- version: 13.0.6
41
+ version: 1.44.1
56
42
  - !ruby/object:Gem::Dependency
57
- name: rubocop
43
+ name: rubocop-performance
58
44
  requirement: !ruby/object:Gem::Requirement
59
45
  requirements:
60
46
  - - "~>"
61
47
  - !ruby/object:Gem::Version
62
- version: 1.21.0
48
+ version: 1.15.2
63
49
  type: :development
64
50
  prerelease: false
65
51
  version_requirements: !ruby/object:Gem::Requirement
66
52
  requirements:
67
53
  - - "~>"
68
54
  - !ruby/object:Gem::Version
69
- version: 1.21.0
55
+ version: 1.15.2
70
56
  - !ruby/object:Gem::Dependency
71
- name: rubocop-performance
57
+ name: rubocop-rake
72
58
  requirement: !ruby/object:Gem::Requirement
73
59
  requirements:
74
60
  - - "~>"
75
61
  - !ruby/object:Gem::Version
76
- version: 1.11.5
62
+ version: 0.6.0
77
63
  type: :development
78
64
  prerelease: false
79
65
  version_requirements: !ruby/object:Gem::Requirement
80
66
  requirements:
81
67
  - - "~>"
82
68
  - !ruby/object:Gem::Version
83
- version: 1.11.5
69
+ version: 0.6.0
84
70
  - !ruby/object:Gem::Dependency
85
71
  name: yard
86
72
  requirement: !ruby/object:Gem::Requirement
87
73
  requirements:
88
74
  - - "~>"
89
75
  - !ruby/object:Gem::Version
90
- version: 0.9.26
76
+ version: 0.9.28
91
77
  type: :development
92
78
  prerelease: false
93
79
  version_requirements: !ruby/object:Gem::Requirement
94
80
  requirements:
95
81
  - - "~>"
96
82
  - !ruby/object:Gem::Version
97
- version: 0.9.26
98
- description: This gem allows easy interaction with the Roblox web API via class models.
83
+ version: 0.9.28
84
+ description: This gem allows easy interaction with the Roblox web API via modules
85
+ and classes.
99
86
  email: rorg.devv@gmail.com
100
87
  executables: []
101
88
  extensions: []
102
- extra_rdoc_files:
103
- - README.MD
89
+ extra_rdoc_files: []
104
90
  files:
105
- - CHANGELOG.MD
106
- - Gemfile
107
91
  - LICENSE
108
- - README.MD
109
- - Rakefile
92
+ - README.md
110
93
  - lib/rublox.rb
94
+ - lib/rublox/bases/base_group.rb
95
+ - lib/rublox/bases/base_user.rb
111
96
  - lib/rublox/derive/group.rb
97
+ - lib/rublox/derive/model.rb
112
98
  - lib/rublox/derive/user.rb
113
99
  - lib/rublox/models/full_group.rb
114
100
  - lib/rublox/models/full_user.rb
115
- - lib/rublox/models/group_member.rb
116
- - lib/rublox/models/group_role.rb
117
101
  - lib/rublox/models/group_shout.rb
118
- - lib/rublox/models/limited_user.rb
119
102
  - lib/rublox/models/presence.rb
120
- - lib/rublox/util/cache.rb
103
+ - lib/rublox/models/skinny_user.rb
104
+ - lib/rublox/util/api_helper.rb
121
105
  - lib/rublox/util/errors.rb
122
- - lib/rublox/util/http_client.rb
123
- - lib/rublox/util/pages.rb
124
- - lib/rublox/util/url.rb
125
- - lib/rublox/version.rb
126
106
  - rublox.gemspec
127
107
  homepage: https://github.com/roblox-api-wrappers/rublox
128
108
  licenses:
129
109
  - MIT
130
- metadata: {}
110
+ metadata:
111
+ Documentation: https://rubydoc.info/gems/rublox
112
+ rubygems_mfa_required: 'true'
131
113
  post_install_message:
132
114
  rdoc_options: []
133
115
  require_paths:
@@ -136,14 +118,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
118
  requirements:
137
119
  - - ">="
138
120
  - !ruby/object:Gem::Version
139
- version: '3.0'
121
+ version: 2.7.0
140
122
  required_rubygems_version: !ruby/object:Gem::Requirement
141
123
  requirements:
142
124
  - - ">="
143
125
  - !ruby/object:Gem::Version
144
126
  version: '0'
145
127
  requirements: []
146
- rubygems_version: 3.2.15
128
+ rubygems_version: 3.1.2
147
129
  signing_key:
148
130
  specification_version: 4
149
131
  summary: A Roblox web API wrapper written in Ruby
data/CHANGELOG.MD DELETED
@@ -1,4 +0,0 @@
1
- # 0.1.0 (9th October, 2021)
2
-
3
- - Initial repository and package setup
4
- - User, group, presence, group member and group role APIs added
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "http://rubygems.org"
4
- ruby ">= 3.0"
5
-
6
- gemspec
data/Rakefile DELETED
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rake"
4
-
5
- desc "run rubocop"
6
- task :rubocop do
7
- system "rubocop"
8
- end
9
-
10
- desc "run tests"
11
- task :test do
12
- system "ruby -I ./lib ./tests/run_tests.rb"
13
- end
14
-
15
- desc "build docs"
16
- task :docs do
17
- system "yardoc"
18
- end
19
-
20
- desc "build docs, showing private objects"
21
- task :docs_priv do
22
- system "yardoc --private"
23
- end
24
-
25
- desc "open local server to live preview docs"
26
- task :doc_server do
27
- system "yard server --reload"
28
- end
29
-
30
- desc "list all undocumented objects"
31
- task :list_undoc do
32
- system "yard stats --list-undoc"
33
- end
@@ -1,54 +0,0 @@
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,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rublox/util/Errors"
4
-
5
- module Rublox
6
- # @note This class is handled internally by the public interface such as
7
- # {Group#roles}. You should not be creating it yourself.
8
- # The {GroupRole} class corresponds to a group's role. You can use it to get
9
- # and set information about roles.
10
- class GroupRole
11
- # @return [Integer] the role's ID
12
- attr_reader :id
13
-
14
- # @return [String] the role's name
15
- attr_reader :name
16
-
17
- # @return [String, nil] the role's description. Can be nil if the authenticated
18
- # user does not have access to the group's role settings.
19
- attr_reader :description
20
-
21
- # @return [Integer] the role's rank (0-255)
22
- attr_reader :rank
23
-
24
- # @return [Integer] the count of how many users have the role
25
- attr_reader :member_count
26
-
27
- # @return [Group] the group tied to this role
28
- attr_reader :group
29
-
30
- # @param data [Hash]
31
- # @param group [FullGroup]
32
- # @param client [Client]
33
- def initialize(data, group, client)
34
- @id = data["id"]
35
- @name = data["name"]
36
- @description = data["description"]
37
- @rank = data["rank"]
38
- @member_count = data["memberCount"]
39
- @group = group
40
-
41
- @client = client
42
- end
43
-
44
- # @example
45
- # client = Rublox::Client.new
46
- # client.group_from_id(7384468)
47
- # role = client
48
- # .group_from_id(7384468)
49
- # .member_by_id(1)
50
- # .role
51
- # puts role.rank # -> 1
52
- # # Assume Roblox now has the Owner role
53
- # updated_role = role.refresh
54
- # puts updated_role.rank # -> 255
55
- # @return [GroupRole] a mirrored {GroupRole} object, containing new information
56
- # about the role if it has been changed.
57
- def refresh
58
- data = @client.http_client.get(
59
- URL.endpoint("groups", "/v1/groups/#{@group.id}/roles")
60
- )["roles"].find { |role| role["id"] == @id }
61
- raise Errors::RoleNotFoundError.new(@id, @group.id) unless data
62
-
63
- GroupRole.new(
64
- data,
65
- @group,
66
- @client
67
- )
68
- end
69
- end
70
- end