Module: EventMachine::UCEngine::EventMachineRequest

Included in:
Client, Client::Session
Defined in:
lib/em-ucengine/client_em.rb

Instance Method Summary collapse

Instance Method Details

#delete(path, params = {}, body = {}, session = nil, headers = {}) ⇒ Object



124
125
126
# File 'lib/em-ucengine/client_em.rb', line 124

def delete(path, params={}, body={}, session=nil, headers={})
  http_request(:delete, path, params, body, session, headers)
end

#get(path, params = {}, body = {}, session = nil, headers = nil) ⇒ Object



112
113
114
# File 'lib/em-ucengine/client_em.rb', line 112

def get(path, params={}, body={}, session=nil, headers=nil)
  http_request(:get, path, params, body, session, headers)
end

#http_request(method, path, params = {}, body = {}, session = nil, headers = nil, &block) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/em-ucengine/client_em.rb', line 96

def http_request(method, path, params={}, body={}, session=nil, headers=nil, &block)
  opts ||= {:query => params, :body => body, :head => headers}

  key = (method == :get || method == :delete) ? :query : :body
  opts[key].merge!(:uid => self.uid, :sid => self.sid) if self.class == UCEngine::Client::Session

  # TODO: make a em-http-request middleware
  if headers && headers['Content-Type'] == 'application/json'
    opts[key] = opts[key].to_json
  end

  conn = EM::HttpRequest.new(path)
  req = conn.send(method, opts)
  req
end

#json_post(path, body) ⇒ Object

Perform a post request on the API with a content type application/json

Parameters:

  • path (String)
  • body (Hash)


132
133
134
# File 'lib/em-ucengine/client_em.rb', line 132

def json_post(path, body)
  http_request(:post, path, {}, body, nil, {'Content-Type' => 'application/json'})
end

#post(path, params = {}, body = {}, session = nil, headers = {}) ⇒ Object



116
117
118
# File 'lib/em-ucengine/client_em.rb', line 116

def post(path, params={}, body={}, session=nil, headers={})
  http_request(:post, path, params, body, session, headers)
end

#put(path, params = {}, body = {}, session = nil, headers = {}) ⇒ Object



120
121
122
# File 'lib/em-ucengine/client_em.rb', line 120

def put(path, params={}, body={}, session=nil, headers={})
  http_request(:put, path, params, body, session, headers)
end