Class: Miby::HTTP

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

Overview

Mibyで利用するのhttpメソッドを提供します。 接続するホストのアドレスやプロキシの設定は Miby::Config で設定します。

使い方

実行したい処理をブロックで渡します。ブロック内で利用できるメソッドは Net::HTTPと同じです。

http_response =  HTTP.new.connection {|http|
  http.get(path)
  ...
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = Config.new) ⇒ HTTP

Returns a new instance of HTTP.



17
18
19
20
21
22
# File 'lib/http.rb', line 17

def initialize(config = Config.new)
  @http_address = config.http_address
  @http_port = config.http_port
  @proxy_addr = config.proxy_addr
  @proxy_port = config.proxy_port
end

Instance Attribute Details

#http_addressObject (readonly)

Returns the value of attribute http_address.



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

def http_address
  @http_address
end

#http_portObject (readonly)

Returns the value of attribute http_port.



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

def http_port
  @http_port
end

#proxy_addrObject (readonly)

Returns the value of attribute proxy_addr.



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

def proxy_addr
  @proxy_addr
end

#proxy_portObject (readonly)

Returns the value of attribute proxy_port.



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

def proxy_port
  @proxy_port
end

Instance Method Details

#connection(&block) ⇒ Object

ホスト @http_address に接続しブロックをを実行します。 成功した場合は Net::HTTPResponse のインスタンスを返します。



27
28
29
30
# File 'lib/http.rb', line 27

def connection(&block)
  puts "connection : #@http_address, #@http_port, #@proxy_addr, #@proxy_port" if $VERBOSE
  Net::HTTP.start(@http_address, @http_port, @proxy_addr, @proxy_port, &block)
end