class Jelastic::Request
Constants
- TIMEOUT
Attributes
client[R]
params[R]
path[R]
Public Class Methods
new(client, path = [], params = {})
click to toggle source
# 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
Public Instance Methods
send()
click to toggle source
# File lib/jelastic/request.rb, line 26 def send uri = URI.join(client.api_url, path) req = Net::HTTP::Post.new(uri.path, request_options) 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
Private Instance Methods
build_uri_path(path)
click to toggle source
# File lib/jelastic/request.rb, line 47 def build_uri_path(path) path.map do |item| new_path = item new_path[0] = '' if new_path[0] == '/' new_path[-1] = '' if new_path[-1] == '/' new_path end.join('/') end
request_options()
click to toggle source
# File lib/jelastic/request.rb, line 58 def request_options options = {} options['User-Agent'] = client.user_agent unless client.user_agent.nil? options end