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

#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

#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