Class: Jelastic::Request

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

Constant Summary collapse

TIMEOUT =
1200

Instance Attribute Summary collapse

Instance Method Summary collapse

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.,
        password: client.password
      )
    end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/jelastic/request.rb', line 9

def client
  @client
end

#paramsObject (readonly)

Returns the value of attribute params.



9
10
11
# File 'lib/jelastic/request.rb', line 9

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/jelastic/request.rb', line 9

def path
  @path
end

Instance Method Details

#sendObject



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, 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