Module: MagicWrite::HTTP
- Included in:
- Client
- Defined in:
- lib/magicwrite/http.rb
Instance Method Summary collapse
- #delete(path:) ⇒ Object
- #get(path:, parameters: {}) ⇒ Object
- #json_post(path:, parameters:) ⇒ Object
- #json_put(path:, parameters:) ⇒ Object
- #multipart_post(path:, parameters: nil) ⇒ Object
Instance Method Details
#delete(path:) ⇒ Object
45 46 47 48 49 |
# File 'lib/magicwrite/http.rb', line 45 def delete(path:) build_response(conn.delete(uri(path: path)) do |request| request.headers = headers end) end |
#get(path:, parameters: {}) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/magicwrite/http.rb', line 3 def get(path:, parameters: {}) build_response(conn.get(uri(path: path)) do |request| request.headers = headers request.body = parameters.to_json end) end |
#json_post(path:, parameters:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/magicwrite/http.rb', line 10 def json_post(path:, parameters:) build_response(conn.post(uri(path: path)) do |request| if parameters[:stream].respond_to?(:call) request..on_data = to_json_stream(user_proc: parameters[:stream]) parameters[:stream] = true elsif parameters[:stream] raise ArgumentError, 'The stream parameter must be a Proc or have a #call method' end request.headers = headers request.body = parameters.to_json end) end |
#json_put(path:, parameters:) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/magicwrite/http.rb', line 24 def json_put(path:, parameters:) build_response(conn.put(uri(path: path)) do |request| if parameters[:stream].respond_to?(:call) request..on_data = to_json_stream(user_proc: parameters[:stream]) parameters[:stream] = true elsif parameters[:stream] raise ArgumentError, 'The stream parameter must be a Proc or have a #call method' end request.headers = headers request.body = parameters.to_json end) end |
#multipart_post(path:, parameters: nil) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/magicwrite/http.rb', line 38 def multipart_post(path:, parameters: nil) build_response(conn(multipart: true).post(uri(path: path)) do |request| request.headers = headers.merge({ 'Content-Type' => 'multipart/form-data' }) request.body = multipart_parameters(parameters) end) end |