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 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) 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 = 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) 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 = 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) 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 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

Private Instance Methods

build_url(path, id, name) click to toggle source
# File lib/tiny_client/remote_client.rb, line 56
def build_url(path, id, name)
  UrlBuilder.url(@config.url).path(path).path(id).path(name)
end