Class: SolovisApiClient::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/solovis_api_client/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base



4
5
6
7
# File 'lib/solovis_api_client/base.rb', line 4

def initialize(options = {})
  config.add(:url, options[:url])
  config.add(:api_key, options[:api_key])
end

Instance Attribute Details

#siteObject (readonly)

Returns the value of attribute site.



2
3
4
# File 'lib/solovis_api_client/base.rb', line 2

def site
  @site
end

Instance Method Details

#configObject



9
10
11
# File 'lib/solovis_api_client/base.rb', line 9

def config
  SolovisApiClient.config
end

#connectionObject



13
14
15
# File 'lib/solovis_api_client/base.rb', line 13

def connection
  SolovisApiClient::Connection.new.rpc_connection
end

#rpc_invoke(uri_path, message) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/solovis_api_client/base.rb', line 21

def rpc_invoke(uri_path, message)
  response = connection.post do |req|
    req.headers["Content-Type"] = "x-post-rpc/json"
    req.headers["Content-Encoding"] = "utf-8"
    req.url uri_path
    req.body = message.to_json
  end
  body = response.body
  if body["result"]
    return body
  elsif body["error"]
    raise RuntimeError.new(body["error"])
  end
end