Class: TinyClient::RemoteClient

Inherits:
Object
  • Object
show all
Defined in:
lib/tiny_client/remote_client.rb

Overview

Remote Http client which delegates to the CurbRequestor.

Instance Method Summary collapse

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

Returns:

Raises:

  • (ResponseError)

    if the server respond with an error status (i.e 404, 500..)



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>

Returns:

Raises:

  • (ResponseError)

    if the server respond with an error status (i.e 404, 500..)



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>

Parameters:

  • data (Hash)

Returns:

Raises:

  • (ResponseError)

    if the server respond with an error status (i.e 404, 500..)



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>

Parameters:

  • data (Hash)

    the resource data

Returns:

Raises:

  • (ResponseError)

    if the server respond with an error status (i.e 404, 500..)



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