Class: Enigma::Client
- Inherits:
-
Object
- Object
- Enigma::Client
- Defined in:
- lib/enigma.rb
Constant Summary collapse
- HTTP_METHODS =
[:get, :post, :put, :delete]
- TIMEOUT =
60 * 5
Instance Attribute Summary collapse
-
#certificate ⇒ Object
readonly
Returns the value of attribute certificate.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #execute(method, path, payload) ⇒ Object
- #http ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
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() @host = [:host] || 'localhost' @port = [:port] || 80 @ssl = [:ssl] || false @certificate = [:certificate] end |
Instance Attribute Details
#certificate ⇒ Object (readonly)
Returns the value of attribute certificate.
44 45 46 |
# File 'lib/enigma.rb', line 44 def certificate @certificate end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
44 45 46 |
# File 'lib/enigma.rb', line 44 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
44 45 46 |
# File 'lib/enigma.rb', line 44 def port @port end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
44 45 46 |
# File 'lib/enigma.rb', line 44 def ssl @ssl end |
#version ⇒ Object (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 |
#http ⇒ Object
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 |