rublox 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/lib/rublox.rb
CHANGED
@@ -1,136 +1,136 @@
|
|
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 "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
|
data/rublox.gemspec
CHANGED
@@ -1,32 +1,32 @@
|
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
]
|
23
|
-
spec.extra_rdoc_files = ["README.
|
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
|
+
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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rublox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zamdie
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-10
|
12
|
+
date: 2021-11-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: http
|
@@ -100,12 +100,11 @@ email: rorg.devv@gmail.com
|
|
100
100
|
executables: []
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files:
|
103
|
-
- README.
|
103
|
+
- README.md
|
104
104
|
files:
|
105
|
-
- CHANGELOG.MD
|
106
105
|
- Gemfile
|
107
106
|
- LICENSE
|
108
|
-
- README.
|
107
|
+
- README.md
|
109
108
|
- Rakefile
|
110
109
|
- lib/rublox.rb
|
111
110
|
- lib/rublox/derive/group.rb
|
@@ -143,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
142
|
- !ruby/object:Gem::Version
|
144
143
|
version: '0'
|
145
144
|
requirements: []
|
146
|
-
rubygems_version: 3.2.
|
145
|
+
rubygems_version: 3.2.29
|
147
146
|
signing_key:
|
148
147
|
specification_version: 4
|
149
148
|
summary: A Roblox web API wrapper written in Ruby
|
data/CHANGELOG.MD
DELETED