Class: Cubes::Request
- Inherits:
-
Object
- Object
- Cubes::Request
- Defined in:
- lib/cubes/request.rb
Instance Method Summary collapse
-
#get(path, params = {}) ⇒ JSON
Send a get request.
-
#initialize(conn, options = {}) ⇒ Cubes::Request
constructor
Initialize a Request.
-
#post(path, data = {}, params = {}) ⇒ JSON
Send a post request.
Constructor Details
#initialize(conn, options = {}) ⇒ Cubes::Request
Initialize a Request
10 11 12 13 |
# File 'lib/cubes/request.rb', line 10 def initialize(conn, = {}) @conn = conn @prefix = .fetch(:prefix, '/') end |
Instance Method Details
#get(path, params = {}) ⇒ JSON
Send a get request
20 21 22 23 |
# File 'lib/cubes/request.rb', line 20 def get(path, params = {}) path = File.join(@prefix, path) JSON.parse @conn.get(path, params).body end |
#post(path, data = {}, params = {}) ⇒ JSON
Send a post request
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cubes/request.rb', line 31 def post(path, data = {}, params = {}) body = data.to_json path = File.join(@prefix, path) response = @conn.post(path, body) do |req| req.params = params req.headers['Content-Type'] = 'application/json' end JSON.parse response.body end |