Class: Jelastic::Request
- Inherits:
-
Object
- Object
- Jelastic::Request
- Defined in:
- lib/jelastic/request.rb
Constant Summary collapse
- TIMEOUT =
1200
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(client, path = [], params = {}) ⇒ Request
constructor
A new instance of Request.
- #send ⇒ Object
Constructor Details
#initialize(client, path = [], params = {}) ⇒ Request
Returns a new instance of Request.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jelastic/request.rb', line 11 def initialize(client, path = [], params = {}) @client = client @path = build_uri_path(path) @params = if client.authenticated? params.merge( session: client.session, ) else params.merge( login: client.login, password: client.password ) end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/jelastic/request.rb', line 9 def client @client end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
9 10 11 |
# File 'lib/jelastic/request.rb', line 9 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/jelastic/request.rb', line 9 def path @path end |
Instance Method Details
#send ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/jelastic/request.rb', line 26 def send uri = URI.join(client.api_url, path) req = Net::HTTP::Post.new(uri.path, ) req.set_form_data(params) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.read_timeout = TIMEOUT res = http.request(req) out = JSON.parse(res.body) unless out['result'].zero? raise RequestError.new(out['error'], out) else out end end |