Class: Hinoki::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/hinoki/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(host = nil, port = nil, user = nil, pass = nil) ⇒ Connection

Returns a new instance of Connection.



10
11
12
13
14
15
# File 'lib/hinoki/connection.rb', line 10

def initialize(host=nil, port=nil, user=nil, pass=nil)
  @config = Hinoki::Config.new
  @config.user = user if user
  @config.pass = pass if pass
  @http = Net::HTTP.new(host || @config.host, port || @config.port)
end

Instance Method Details

#delete(path) ⇒ Object

Wrapper around Net::HTTP.delete



28
29
30
# File 'lib/hinoki/connection.rb', line 28

def delete(path)
  request(Net::HTTP::Delete.new(path))
end

#get(path) ⇒ Object

Wrapper around Net::HTTP.get



18
19
20
# File 'lib/hinoki/connection.rb', line 18

def get(path)
  request(Net::HTTP::Get.new(path))
end

#post(path) ⇒ Object

Wrapper around Net::HTTP.post



23
24
25
# File 'lib/hinoki/connection.rb', line 23

def post(path)
  request(Net::HTTP::Post.new(path))
end

#request(req) ⇒ Object



32
33
34
35
36
37
# File 'lib/hinoki/connection.rb', line 32

def request(req)
  if @config.user && @config.pass
    req.basic_auth(@config.user, @config.pass)
  end
  return interpret_response(@http.request(req))
end