Class: OpenAgent::Zone

Inherits:
Object
  • Object
show all
Defined in:
lib/openagent/zone.rb

Instance Method Summary collapse

Instance Method Details

#connectionObject



19
20
21
22
23
24
25
# File 'lib/openagent/zone.rb', line 19

def connection
  @connection ||= Net::HTTP.new(host, port).tap do |conn|
    ssl.configure(conn) if ssl
    conn.read_timeout = timeout if timeout
    conn.open_timeout = open_timeout if open_timeout
  end
end

#create_request(msg) ⇒ Object



43
44
45
46
47
48
# File 'lib/openagent/zone.rb', line 43

def create_request(msg)
  Net::HTTP::Post.new(path).tap do |post|
    post.body = msg.to_s
    post.content_type = "application/xml"
  end
end

#hostObject



31
32
33
# File 'lib/openagent/zone.rb', line 31

def host
  url.host
end

#pathObject



39
40
41
# File 'lib/openagent/zone.rb', line 39

def path
  url.path == "" ? "/" : url.path
end

#portObject



35
36
37
# File 'lib/openagent/zone.rb', line 35

def port
  url.port
end

#send_message(msg) ⇒ Object



54
55
56
# File 'lib/openagent/zone.rb', line 54

def send_message(msg)
  send_request(create_request(msg))
end

#send_request(request) ⇒ Object



50
51
52
# File 'lib/openagent/zone.rb', line 50

def send_request(request)
  connection.request(request)
end

#urlObject



27
28
29
# File 'lib/openagent/zone.rb', line 27

def url
  @url ||= URI.parse(uri)
end