Class: Alipan::HTTP

Inherits:
Object
  • Object
show all
Includes:
Common::Logging
Defined in:
lib/alipan/http.rb

Constant Summary collapse

DEFAULT_CONTENT_TYPE =
'application/json'
AUTH_HEADER =
'Authorization'
OPEN_TIMEOUT =
10
READ_TIMEOUT =
120

Constants included from Common::Logging

Common::Logging::MAX_NUM_LOG, Common::Logging::ROTATE_SIZE

Instance Method Summary collapse

Methods included from Common::Logging

#logger, set_log_file, set_log_level

Constructor Details

#initialize(config) ⇒ HTTP

Returns a new instance of HTTP.



15
16
17
# File 'lib/alipan/http.rb', line 15

def initialize(config)
      @config = config
end

Instance Method Details

#delete(resources = {}, http_options = {}, &block) ⇒ Object



35
36
37
# File 'lib/alipan/http.rb', line 35

def delete(resources = {}, http_options = {}, &block)
  do_request('DELETE', resources, http_options, &block)
end

#get(resources = {}, http_options = {}, &block) ⇒ Object



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

def get(resources = {}, http_options = {}, &block)
  do_request('GET', resources, http_options, &block)
end

#handle_response(r, &block) ⇒ Object



19
20
21
# File 'lib/alipan/http.rb', line 19

def handle_response(r, &block)
  r.read_body { |chunk| yield chunk }
end

#head(resources = {}, http_options = {}, &block) ⇒ Object



39
40
41
# File 'lib/alipan/http.rb', line 39

def head(resources = {}, http_options = {}, &block)
  do_request('HEAD', resources, http_options, &block)
end

#options(resources = {}, http_options = {}, &block) ⇒ Object



43
44
45
# File 'lib/alipan/http.rb', line 43

def options(resources = {}, http_options = {}, &block)
  do_request('OPTIONS', resources, http_options, &block)
end

#post(resources = {}, http_options = {}, &block) ⇒ Object



31
32
33
# File 'lib/alipan/http.rb', line 31

def post(resources = {}, http_options = {}, &block)
  do_request('POST', resources, http_options, &block)
end

#put(resources = {}, http_options = {}, &block) ⇒ Object



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

def put(resources = {}, http_options = {}, &block)
  do_request('PUT', resources, http_options, &block)
end