Class: XRPC::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/xrpc/client.rb

Defined Under Namespace

Classes: GetRequest, PostRequest

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, token = nil) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
# File 'lib/xrpc/client.rb', line 15

def initialize(base_url, token = nil)
  @token = token
  @headers = { :"Content-Type" => "application/json", :Authorization => "Bearer #{@token}" }
  @base_url = base_url
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



13
14
15
# File 'lib/xrpc/client.rb', line 13

def base_url
  @base_url
end

#headersObject

Returns the value of attribute headers.



12
13
14
# File 'lib/xrpc/client.rb', line 12

def headers
  @headers
end

#tokenObject

Returns the value of attribute token.



13
14
15
# File 'lib/xrpc/client.rb', line 13

def token
  @token
end

Instance Method Details

#getObject



30
31
32
# File 'lib/xrpc/client.rb', line 30

def get
  GetRequest.new(base_url, @headers)
end

#headers!Object



21
22
23
# File 'lib/xrpc/client.rb', line 21

def headers!
  @headers[:Authorization] = "Bearer #{@token}"
end

#inspectObject



38
39
40
# File 'lib/xrpc/client.rb', line 38

def inspect
  "XRPC::Client(\"#{@base_url}\")"
end

#postObject



34
35
36
# File 'lib/xrpc/client.rb', line 34

def post
  PostRequest.new(base_url, @headers)
end