class TinyClient::RemoteClient
Remote Http client which delegates to the {CurbRequestor}.
Public Class Methods
new(config)
click to toggle source
# File lib/tiny_client/remote_client.rb, line 4 def initialize(config) @config = config end
Public Instance Methods
delete(path, id, name)
click to toggle source
DELETE /<path>/<id>.json
@raise [ResponseError] if the server respond with an error status (i.e 404, 500..) @return [Response]
# File lib/tiny_client/remote_client.rb, line 48 def delete(path, id, name) url = @config.url_for(path, id, name) 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)
click to toggle source
GET /<path>/<id>/<name>?<params>
@raise [ResponseError] if the server respond with an error status (i.e 404, 500..) @return [Response]
# File lib/tiny_client/remote_client.rb, line 11 def get(path, params, id, name) url = @config.url_for(path, id, name, params) 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)
click to toggle source
POST /<path>/<id>/<name>
@param [Hash] data @raise [ResponseError] if the server respond with an error status (i.e 404, 500..) @return [Response]
# File lib/tiny_client/remote_client.rb, line 23 def post(data, path, id, name) url = @config.url_for(path, id, name) verify_json(data) 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)
click to toggle source
PUT /<path>/<id>/<name>
@param [Hash] data the resource data @raise [ResponseError] if the server respond with an error status (i.e 404, 500..) @return [Response]
# File lib/tiny_client/remote_client.rb, line 36 def put(data, path, id, name) url = @config.url_for(path, id, name) verify_json(data) CurbRequestor.perform_put(url, { 'Accept' => 'application/json', 'Content-Type' => 'application/json' }.merge!(@config.headers), data.to_json, @config.connect_timeout, @config.verbose) end
Private Instance Methods
verify_json(data)
click to toggle source
# File lib/tiny_client/remote_client.rb, line 58 def verify_json(data) raise ArgumentError, 'data must respond to .to_json' unless data.respond_to? :to_json end