xrpc 0.1.0 → 0.1.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: 173fc491f2988e7fd7a41435171cd60ec05e3116b838ab4c0257039788e0392a
4
- data.tar.gz: 1afb3fa818ae58646e293afa6f97891fbf32ead4e9cd8be68d5ca8ca38db6c44
3
+ metadata.gz: d7bca4020ba6ae0ace083ebbd62860273590ff6d135d712fd4c221233554913f
4
+ data.tar.gz: 60ed91a5872c8008a2bb6bd64ea1543e1fdf670c822752eb0b9efe99126e7f96
5
5
  SHA512:
6
- metadata.gz: a543fa05e7bcebac74107e6eaf2f655d4e5e37458e7a61e5d8a824760a009baf1b18eefd19c7c0559e3029c5b33a9f4464e11cbcfd92687a3ddb8242e17fbe42
7
- data.tar.gz: 571c2af3661344e704023c444a28f1578d896820f58424b8e9f50118517d51aae92341d21440a5391019461388cc6ae69cf618b5a7db5ab8846c02b99ea57389
6
+ metadata.gz: db08c3afd3532daf9aebc12c2bd32db20512654707a31d32068470f780eba97602e20b6b6bf052eb194bdf08f0d4f469175fe89d824d330ffcf52813c294dd17
7
+ data.tar.gz: c00e3688d413fceec7ea3638f78d8d6bebc234934861fd2afda79b550551b913206124e4c5dc15eeebe8aeff43a047ac3071713b6293d0113b5f198fe71bc26c
data/lib/xrpc/client.rb CHANGED
@@ -11,33 +11,37 @@ module XRPC
11
11
  class Client
12
12
  attr_reader :get, :post
13
13
 
14
- def initialize(base_url)
14
+ def initialize(base_url, token = nil)
15
+ @headers = { :"Content-Type" => "application/json" }
16
+ @headers = @headers.merge { :Authorization => "Bearer #{token}" } unless token.nil?
15
17
  @base_url = base_url
16
- @get = GetRequest.new(base_url)
17
- @post = PostRequest.new(base_url)
18
+ @get = GetRequest.new(base_url, @headers)
19
+ @post = PostRequest.new(base_url, @headers)
18
20
  end
19
21
 
20
22
  class GetRequest
21
23
  include HTTParty
22
24
 
23
- def initialize(base_url)
25
+ def initialize(base_url, headers)
24
26
  self.class.base_uri base_url
27
+ @headers = headers
25
28
  end
26
29
 
27
30
  def method_missing(method_name, **params)
28
- JSON.parse self.class.get("/xrpc/#{method_name.to_s.gsub("_", ".")}", query: params).body
31
+ JSON.parse self.class.get("/xrpc/#{method_name.to_s.gsub("_", ".")}", query: params, headers: @headers).body
29
32
  end
30
33
  end
31
34
 
32
35
  class PostRequest
33
36
  include HTTParty
34
37
 
35
- def initialize(base_url)
38
+ def initialize(base_url, headers)
36
39
  self.class.base_uri base_url
40
+ @headers = headers
37
41
  end
38
42
 
39
43
  def method_missing(method_name, **params)
40
- JSON.parse self.class.post("/xrpc/#{method_name.to_s.gsub("_", ".")}", body: params).body
44
+ JSON.parse self.class.post("/xrpc/#{method_name.to_s.gsub("_", ".")}", body: params.to_json, headers: @headers).body
41
45
  end
42
46
  end
43
47
  end
data/lib/xrpc/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module XRPC
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xrpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shreyan Jain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-02 00:00:00.000000000 Z
11
+ date: 2023-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json