Class: TinyClient::RemoteClient
- Inherits:
-
Object
- Object
- TinyClient::RemoteClient
- Defined in:
- lib/tiny_client/remote_client.rb
Overview
Remote Http client which delegates to the CurbRequestor.
Instance Method Summary collapse
-
#delete(path, id, name) ⇒ Response
DELETE /<path>/<id>.json.
-
#get(path, params, id, name) ⇒ Response
GET /<path>/<id>/<name>?<params>.
-
#initialize(config) ⇒ RemoteClient
constructor
A new instance of RemoteClient.
-
#post(data, path, id, name) ⇒ Response
POST /<path>/<id>/<name>.
-
#put(data, path, id, name) ⇒ Response
PUT /<path>/<id>/<name>.
Constructor Details
#initialize(config) ⇒ RemoteClient
Returns a new instance of RemoteClient
4 5 6 |
# File 'lib/tiny_client/remote_client.rb', line 4 def initialize(config) @config = config end |
Instance Method Details
#delete(path, id, name) ⇒ Response
DELETE /<path>/<id>.json
46 47 48 49 50 51 52 |
# File 'lib/tiny_client/remote_client.rb', line 46 def delete(path, id, name) url = build_url(path, id, name).build! CurbRequestor.perform_delete(url, { 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded' }.merge!(@config.headers), @config.connect_timeout, @config.verbose) end |
#get(path, params, id, name) ⇒ Response
GET /<path>/<id>/<name>?<params>
11 12 13 14 15 16 17 |
# File 'lib/tiny_client/remote_client.rb', line 11 def get(path, params, id, name) url = build_url(path, id, name).query(params).build! CurbRequestor.perform_get(url, { 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded' }.merge!(@config.headers), @config.connect_timeout, @config.verbose) end |
#post(data, path, id, name) ⇒ Response
POST /<path>/<id>/<name>
23 24 25 26 27 28 29 |
# File 'lib/tiny_client/remote_client.rb', line 23 def post(data, path, id, name) url = build_url(path, id, name).build! CurbRequestor.perform_post(url, { 'Accept' => 'application/json', 'Content-Type' => 'application/json' }.merge!(@config.headers), data.to_json, @config.connect_timeout, @config.verbose) end |
#put(data, path, id, name) ⇒ Response
PUT /<path>/<id>/<name>
35 36 37 38 39 40 41 |
# File 'lib/tiny_client/remote_client.rb', line 35 def put(data, path, id, name) url = build_url(path, id, name).build! CurbRequestor.perform_put(url, { 'Accept' => 'application/json', 'Content-Type' => 'application/json' }.merge!(@config.headers), data.to_json, @config.connect_timeout, @config.verbose) end |