Class: Guh::Base

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

Overview

The base class which all the specific wrapper classes inherit from. It provides some shared code to make development easier.

Constant Summary collapse

@@guh_ip_address =
"127.0.0.1"
@@guh_port =
1234

Class Method Summary collapse

Class Method Details

.configure {|_self| ... } ⇒ Object

Configuration DSL helper method.

The default values are:

  • guh_ip_address: 127.0.0.1

  • guh_port: 1234

Example:

Guh::Base.configure do |config|
  config.guh_ip_address = 10.0.0.1
  config.guh_port = 6789
end

Yields:

  • (_self)

Yield Parameters:

  • _self (Guh::Base)

    the object that the method was called on



85
86
87
# File 'lib/guh/base.rb', line 85

def self.configure(&block)
  yield self
end

.get(request_hash) ⇒ Object

Don’t use this unless you know what you are doing!

Send a request to guh Core and fetch the Response. This is a utility method used by the subclasses.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/guh/base.rb', line 53

def self.get(request_hash)
  request_string = hash_to_json(request_hash)

  response = nil
  client do |c|
    c.puts(request_string)

    response = fetch_message(c)
  end

  if response['status'] == 'success'
    return response['params']
  else
    raise Guh::ResponseError, "The Request was not successful: #{response['error']}"
  end
end

.guh_ip_addressObject

Getter/Setter for the guh_ip_address attribute



8
9
10
# File 'lib/guh/base.rb', line 8

def self.guh_ip_address #:nodoc:
  @@guh_ip_address
end

.guh_ip_address=(hia) ⇒ Object

:nodoc:



11
12
13
# File 'lib/guh/base.rb', line 11

def self.guh_ip_address=(hia) #:nodoc:
  @@guh_ip_address=hia
end

.guh_portObject

Getter/Setter for the guh_port attribute



17
18
19
# File 'lib/guh/base.rb', line 17

def self.guh_port #:nodoc:
   @@guh_port
end

.guh_port=(hia) ⇒ Object

:nodoc:



20
21
22
# File 'lib/guh/base.rb', line 20

def self.guh_port=(hia) #:nodoc:
  @@guh_port=hia
end

.introspectObject

Returns everything that is going on inside guh Core

Example:

Guh::Base.introspect


33
34
35
36
37
38
# File 'lib/guh/base.rb', line 33

def self.introspect
  get({
    id: generate_request_id,
    method: "JSONRPC.Introspect",
  })
end

.versionObject



40
41
42
43
44
45
# File 'lib/guh/base.rb', line 40

def self.version
  get({
    id: generate_request_id,
    method: "JSONRPC.Version",
  })
end