xrpc 0.0.1 → 0.0.2
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 +4 -4
- data/lib/xrpc/version.rb +1 -1
- data/lib/xrpc.rb +34 -5
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd2edff5dc4387dbbfeb6ecf00860e265cc93ed214eb2f7fb1f2fc8c192a1949
|
4
|
+
data.tar.gz: f07553b8c5d1d4e80e4a4f4e22b9e1b3871808f717e308432d9ba68cf51ae75b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5366e5bf46e307c3d7eebd426c79aa488cc8741797a9feedbd58891dc1a21b8ef308e1d03d7d2eeae2e5e948e29ef78ed1223fe96ba7d355ef861e240af9d2a5
|
7
|
+
data.tar.gz: f01c679d2164544877f8338a107966953756818e8d3e7fdcec2fd765a76fbd03dd04c812370ea632799ed4994d89c810e2a8fac69e7077acd45d18cf7b0067b6
|
data/lib/xrpc/version.rb
CHANGED
data/lib/xrpc.rb
CHANGED
@@ -4,20 +4,49 @@ require "httparty"
|
|
4
4
|
require "json"
|
5
5
|
|
6
6
|
module XRPC
|
7
|
+
def request(pds, endpoint_location, params)
|
8
|
+
Endpoint.new(pds, endpoint_location).get(params)
|
9
|
+
end
|
10
|
+
|
11
|
+
module_function :request
|
12
|
+
|
7
13
|
class Endpoint
|
8
14
|
attr_reader :request_uri
|
9
15
|
|
10
|
-
def initialize(pds, endpoint_location,
|
16
|
+
def initialize(pds, endpoint_location, authenticated: false, token: nil)
|
11
17
|
@pds = pds
|
12
18
|
@endpoint_location = endpoint_location
|
13
|
-
@
|
19
|
+
@authenticated = authenticated
|
20
|
+
@headers = default_headers()
|
21
|
+
if token # Ideally, you shouldn't pass the token when creating the endpoint
|
22
|
+
@headers = default_authenticated_headers(token)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def default_headers
|
27
|
+
{ "Content-Type" => "application/json" }
|
28
|
+
end
|
29
|
+
|
30
|
+
def authenticated?() @authenticated end
|
31
|
+
|
32
|
+
def default_authenticated_headers(access_token)
|
33
|
+
default_headers.merge({
|
34
|
+
Authorization: "Bearer #{access_token}",
|
35
|
+
})
|
36
|
+
end
|
37
|
+
|
38
|
+
def authenticate(token) # This is the proper place to authenticate with a token
|
39
|
+
# This is still a pretty weird way to authenticate, but it works (for now)
|
40
|
+
if not @authenticated == true
|
41
|
+
raise Error, "Non-authenticated endpoint cannot be authenticated"
|
42
|
+
end
|
43
|
+
@headers = default_authenticated_headers(token)
|
14
44
|
end
|
15
45
|
|
16
46
|
def get(params)
|
17
|
-
query_params = URI.encode_www_form(params)
|
47
|
+
query_params = URI.encode_www_form(params) # e.g. "foo=bar&baz=qux" from (foo: "bar", baz: "qux")
|
18
48
|
@request_uri = URI("#{@pds}/xrpc/#{@endpoint_location}?#{query_params}")
|
19
|
-
|
20
|
-
response = HTTParty.get(@request_uri)
|
49
|
+
response = HTTParty.get(@request_uri, headers: @headers)
|
21
50
|
JSON.parse(response.body)
|
22
51
|
end
|
23
52
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xrpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shreyan Jain
|
8
|
-
- Tynan Burke
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-16 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: json
|