gather_town_ruby 0.0.1.pre
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 +7 -0
- data/lib/gather_town_ruby.rb +85 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 20a5d62f8237213d86665d5a0187240d5d8d05cbcf796d9c885acd5614452efa
|
4
|
+
data.tar.gz: 3262ab830fc1225634bf20dfd25415de98e713313f77d44b1ad4b220214d9822
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ac0347d530ec5f87202923ca6280c18fc703fc4ec5f431106a3f9003b4d6fddfa12d16f80f96f199e3ee481e9cfb1f994a3095ab5c193fd7b5a6932301ceed48
|
7
|
+
data.tar.gz: 925ae434ebf393b6b8baf9c69b2232f1c8bf149cdd6f7f4590eced35069f9b01773b31ca473d1b58432a29f57f60b981a125cfc875b657fb48febe4133d91b4e
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
class GatherTown
|
4
|
+
include HTTParty
|
5
|
+
base_uri 'https://gather.town/api'
|
6
|
+
|
7
|
+
attr_reader :space_id
|
8
|
+
attr_accessor :map_id
|
9
|
+
|
10
|
+
def initialize(web_url, map_id: nil, test_connection: true)
|
11
|
+
validate_web_url(web_url)
|
12
|
+
set_space_id(web_url)
|
13
|
+
set_map_id(map_id)
|
14
|
+
get_map if test_connection
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid_map_ids
|
18
|
+
get_map
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_map
|
22
|
+
return_as_response do
|
23
|
+
self.class.get("/getMap", **default_query_params)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def api_key
|
30
|
+
ENV['gather_api_key'] || raise(ArgumentError, "no API key was found (did you set ENV['gather_api_key']?)")
|
31
|
+
end
|
32
|
+
|
33
|
+
def valid_web_url_prefix
|
34
|
+
'https://app.gather.town/app/'
|
35
|
+
end
|
36
|
+
|
37
|
+
def validate_web_url(web_url)
|
38
|
+
raise ArgumentError, "must pass a web URL like 'https://app.gather.town/app/PppGRSubDWjPmcQM/Your%20Office'. You can just copy this from your browser once you're logged in to Gather" unless web_url
|
39
|
+
raise ArgumentError, "web_url must be a String" unless web_url.is_a?(String)
|
40
|
+
raise ArgumentError, "web_url ('#{web_url}') must begin with '#{valid_web_url_prefix}'" unless web_url[0..(valid_web_url_prefix.length - 1)] == valid_web_url_prefix
|
41
|
+
end
|
42
|
+
|
43
|
+
def set_space_id(web_url)
|
44
|
+
raw_space_id_and_name = web_url[valid_web_url_prefix.length..-1]
|
45
|
+
raise ArgumentError, "web_url must end with a space id and a space name, separated by a `/` character" unless raw_space_id_and_name.include?('/') && raw_space_id_and_name.split('/').all?
|
46
|
+
space_id = raw_space_id_and_name.split('/').first
|
47
|
+
raw_space_name = raw_space_id_and_name.split('/').last
|
48
|
+
space_name = (not_encoded?(raw_space_name) ? encode(raw_space_name) : raw_space_name)
|
49
|
+
@space_id = (space_id + '\ ' + space_name).gsub(' ', '') # as per Gather's API spec, the space ID and space name must be separated by a backslash (not a forward slash, as in the URL)
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_map_id(map_id)
|
53
|
+
raise ArgumentError, "must pass a map ID, like 'office-cozy' (you can find a valid map ID by opening the 'Mapmaker', and looking in the 'Rooms' tab on the right)" unless map_id && map_id.is_a?(String)
|
54
|
+
@map_id = map_id
|
55
|
+
end
|
56
|
+
|
57
|
+
def not_encoded?(string)
|
58
|
+
string == CGI.unescape(string)
|
59
|
+
end
|
60
|
+
|
61
|
+
def encode(string)
|
62
|
+
ERB::Util.url_encode(string)
|
63
|
+
end
|
64
|
+
|
65
|
+
def default_query_params
|
66
|
+
{
|
67
|
+
apiKey: api_key,
|
68
|
+
spaceId: @space_id,
|
69
|
+
mapId: @map_id
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
def return_as_response(&block)
|
74
|
+
response = yield
|
75
|
+
if response.header.is_a?(Net::HTTPSuccess)
|
76
|
+
response.parsed_response
|
77
|
+
else
|
78
|
+
raise ArgumentError, "\nthe request:\n #{response.request.inspect}\nyielded an unsuccessful response:\n #{response.header}: #{response.parsed_response}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gather_town_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Greg Matthew Crossley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-03-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.17'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.17'
|
27
|
+
description: Gives you an easy way to read and write to maps and spaces within Gather
|
28
|
+
Town.
|
29
|
+
email: greg@neomindlabs.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/gather_town_ruby.rb
|
35
|
+
homepage:
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.7.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.3.1
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.1.6
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: A Ruby library for interfacing with Gather Town via their API.
|
58
|
+
test_files: []
|