Class: Tr3llo::RemoteServer
- Inherits:
-
Object
- Object
- Tr3llo::RemoteServer
- Defined in:
- lib/3llo/remote_server.rb
Defined Under Namespace
Classes: RequestError
Constant Summary collapse
- EXPECTED_CODES =
["200"].freeze
Instance Attribute Summary collapse
-
#endpoint_url ⇒ Object
readonly
Returns the value of attribute endpoint_url.
Instance Method Summary collapse
- #delete(req_path, req_headers, payload, expected_codes = EXPECTED_CODES) ⇒ Object
- #get(req_path, req_headers, expected_codes = EXPECTED_CODES) ⇒ Object
-
#initialize(endpoint_url) ⇒ RemoteServer
constructor
A new instance of RemoteServer.
- #post(req_path, req_headers, payload, expected_codes = EXPECTED_CODES) ⇒ Object
- #put(req_path, req_headers, payload, expected_codes = EXPECTED_CODES) ⇒ Object
Constructor Details
#initialize(endpoint_url) ⇒ RemoteServer
Returns a new instance of RemoteServer.
24 25 26 |
# File 'lib/3llo/remote_server.rb', line 24 def initialize(endpoint_url) @endpoint_url = endpoint_url end |
Instance Attribute Details
#endpoint_url ⇒ Object (readonly)
Returns the value of attribute endpoint_url.
5 6 7 |
# File 'lib/3llo/remote_server.rb', line 5 def endpoint_url @endpoint_url end |
Instance Method Details
#delete(req_path, req_headers, payload, expected_codes = EXPECTED_CODES) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/3llo/remote_server.rb', line 63 def delete(req_path, req_headers, payload, expected_codes = EXPECTED_CODES) req_uri = build_request_uri(req_path) req_headers = { "Accept" => "application/json", "Content-Type" => "application/json" }.merge(req_headers) request = Net::HTTP::Delete.new(req_uri, req_headers) request.body = JSON.dump(payload) dispatch(request, expected_codes) end |
#get(req_path, req_headers, expected_codes = EXPECTED_CODES) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/3llo/remote_server.rb', line 28 def get(req_path, req_headers, expected_codes = EXPECTED_CODES) req_uri = build_request_uri(req_path) req_headers = {"accept" => "application/json"}.merge(req_headers) dispatch(Net::HTTP::Get.new(req_uri, req_headers), expected_codes) end |
#post(req_path, req_headers, payload, expected_codes = EXPECTED_CODES) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/3llo/remote_server.rb', line 35 def post(req_path, req_headers, payload, expected_codes = EXPECTED_CODES) req_uri = build_request_uri(req_path) req_headers = { "accept" => "application/json", "content-type" => "application/json" }.merge(req_headers) request = Net::HTTP::Post.new(req_uri, req_headers) request.body = JSON.dump(payload) dispatch(request, expected_codes) end |
#put(req_path, req_headers, payload, expected_codes = EXPECTED_CODES) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/3llo/remote_server.rb', line 49 def put(req_path, req_headers, payload, expected_codes = EXPECTED_CODES) req_uri = build_request_uri(req_path) req_headers = { "Accept" => "application/json", "Content-Type" => "application/json" }.merge(req_headers) request = Net::HTTP::Put.new(req_uri, req_headers) request.body = JSON.dump(payload) dispatch(request, expected_codes) end |