Class: Zoid::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/zoid/agent.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}, &connection_builder) ⇒ Agent

Returns a new instance of Agent.



7
8
9
10
11
12
# File 'lib/zoid/agent.rb', line 7

def initialize(url, options = {}, &connection_builder)
  @url = url

  @options = options
  @builder = connection_builder
end

Instance Method Details

#delete(path, params = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/zoid/agent.rb', line 62

def delete(path, params = {})
  response = connection.delete do |request|
    request.path = path
    request.headers['Content-Type'] = "application/json"
    request.body = params

    yield if block_given?
  end

  Zoid::Response.new(response.status, response.body)
end

#get(path, params = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/zoid/agent.rb', line 14

def get(path, params = {})
  response = connection.get do |request|
    request.path = path
    request.headers['Content-Type'] = "application/json"
    request.params = params

    yield if block_given?
  end

  Zoid::Response.new(response.status, response.body)
end

#patch(path, params = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/zoid/agent.rb', line 50

def patch(path, params = {})
  response = connection.patch do |request|
    request.path = path
    request.headers['Content-Type'] = "application/json"
    request.body = params

    yield if block_given?
  end

  Zoid::Response.new(response.status, response.body)
end

#post(path, params = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/zoid/agent.rb', line 26

def post(path, params = {})
  response = connection.post do |request|
    request.path = path
    request.headers['Content-Type'] = "application/json"
    request.body = params

    yield if block_given?
  end

  Zoid::Response.new(response.status, response.body)
end

#put(path, params = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/zoid/agent.rb', line 38

def put(path, params = {})
  response = connection.put do |request|
    request.path = path
    request.headers['Content-Type'] = "application/json"
    request.body = params

    yield if block_given?
  end

  Zoid::Response.new(response.status, response.body)
end