Class: Enigma::Client

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

Constant Summary collapse

HTTP_METHODS =
[:get, :post, :put, :delete]
TIMEOUT =
60 * 5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



37
38
39
40
41
42
# File 'lib/enigma.rb', line 37

def initialize(options)
	@host        = options[:host] || 'localhost'
	@port        = options[:port] || 80
	@ssl         = options[:ssl]  || false
	@certificate = options[:certificate]
end

Instance Attribute Details

#certificateObject (readonly)

Returns the value of attribute certificate.



44
45
46
# File 'lib/enigma.rb', line 44

def certificate
  @certificate
end

#hostObject (readonly)

Returns the value of attribute host.



44
45
46
# File 'lib/enigma.rb', line 44

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



44
45
46
# File 'lib/enigma.rb', line 44

def port
  @port
end

#sslObject (readonly)

Returns the value of attribute ssl.



44
45
46
# File 'lib/enigma.rb', line 44

def ssl
  @ssl
end

#versionObject (readonly)

Returns the value of attribute version.



44
45
46
# File 'lib/enigma.rb', line 44

def version
  @version
end

Instance Method Details

#execute(method, path, payload) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/enigma.rb', line 62

def execute(method, path, payload)
	response = http.send(method, path,
											 :headers => headers(method, path, payload),
											 :body => payload,
											 :timeout => TIMEOUT
											)

											response.body
end

#httpObject



54
55
56
57
58
59
60
# File 'lib/enigma.rb', line 54

def http
	base = "#{ssl ? "https" : "http"}://#{host}:#{port}"
	Class.new do
		include HTTParty
		base_uri base
	end
end