Module: Misty::HTTP::Request
- Included in:
- Client
- Defined in:
- lib/misty/http/request.rb
Instance Method Summary collapse
- #decode?(response) ⇒ Boolean
- #http(request) ⇒ Object
- #http_copy(path, headers) ⇒ Object
- #http_delete(path, headers) ⇒ Object
- #http_get(path, headers) ⇒ Object
- #http_head(path, headers) ⇒ Object
- #http_options(path, headers) ⇒ Object
- #http_patch(path, headers, data) ⇒ Object
- #http_post(path, headers, data) ⇒ Object
- #http_put(path, headers, data) ⇒ Object
- #http_to_s(path, headers, data = nil) ⇒ Object
Instance Method Details
#decode?(response) ⇒ Boolean
4 5 6 7 8 9 10 |
# File 'lib/misty/http/request.rb', line 4 def decode?(response) if @config.content_type != :json && response.code =~ /2??/ && !response.is_a?(Net::HTTPNoContent) \ && !response.is_a?(Net::HTTPResetContent) && response.header["content-type"] \ && response.header["content-type"].include?("application/json") true end end |
#http(request) ⇒ Object
12 13 14 15 16 |
# File 'lib/misty/http/request.rb', line 12 def http(request) response = @http.request(request) response.body = JSON.load(response.body) if decode?(response) response end |
#http_copy(path, headers) ⇒ Object
24 25 26 27 28 |
# File 'lib/misty/http/request.rb', line 24 def http_copy(path, headers) @config.log.info(http_to_s(path, headers)) request = Net::HTTP::Copy.new(path, headers) http(request) end |
#http_delete(path, headers) ⇒ Object
18 19 20 21 22 |
# File 'lib/misty/http/request.rb', line 18 def http_delete(path, headers) @config.log.info(http_to_s(path, headers)) request = Net::HTTP::Delete.new(path, headers) http(request) end |
#http_get(path, headers) ⇒ Object
30 31 32 33 34 |
# File 'lib/misty/http/request.rb', line 30 def http_get(path, headers) @config.log.info(http_to_s(path, headers)) request = Net::HTTP::Get.new(path, headers) http(request) end |
#http_head(path, headers) ⇒ Object
36 37 38 39 40 |
# File 'lib/misty/http/request.rb', line 36 def http_head(path, headers) @config.log.info(http_to_s(path, headers)) request = Net::HTTP::Head.new(path, headers) http(request) end |
#http_options(path, headers) ⇒ Object
42 43 44 45 46 |
# File 'lib/misty/http/request.rb', line 42 def (path, headers) @config.log.info(http_to_s(path, headers)) request = Net::HTTP::Options.new(path, headers) http(request) end |
#http_patch(path, headers, data) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/misty/http/request.rb', line 48 def http_patch(path, headers, data) @config.log.info(http_to_s(path, headers, data)) request = Net::HTTP::Patch.new(path, headers) request.body = Misty.to_json(data) http(request) end |
#http_post(path, headers, data) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/misty/http/request.rb', line 55 def http_post(path, headers, data) @config.log.info(http_to_s(path, headers, data)) request = Net::HTTP::Post.new(path, headers) request.body = Misty.to_json(data) http(request) end |
#http_put(path, headers, data) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/misty/http/request.rb', line 62 def http_put(path, headers, data) @config.log.info(http_to_s(path, headers, data)) request = Net::HTTP::Put.new(path, headers) request.body = Misty.to_json(data) http(request) end |
#http_to_s(path, headers, data = nil) ⇒ Object
69 70 71 72 |
# File 'lib/misty/http/request.rb', line 69 def http_to_s(path, headers, data = nil) log = "base_url='#{@uri.host}:#{@uri.port}', path='#{path}', header=#{headers}" log << ", data='#{data}'" if data end |