Class: WebService

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

Direct Known Subclasses

CacheWarp

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#headersObject

Returns the value of attribute headers


4
5
6
# File 'lib/cachewarp/web_service.rb', line 4

def headers
  @headers
end

#uriObject

Returns the value of attribute uri


4
5
6
# File 'lib/cachewarp/web_service.rb', line 4

def uri
  @uri
end

Instance Method Details

#get(host, port, endpoint, headers) ⇒ Object


19
20
21
22
23
# File 'lib/cachewarp/web_service.rb', line 19

def get(host, port, endpoint, headers)
  request = Net::HTTP::Get.new(endpoint, headers)
  response = service_request(host, port, request)
  response
end

#get_uri(uri, headers) ⇒ Object


25
26
27
28
# File 'lib/cachewarp/web_service.rb', line 25

def get_uri uri, headers
  @uri = URI.parse(uri)
  get(@uri.host, @uri.port, @uri.path, headers)
end

#service_request(host, port, request, use_ssl = false) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cachewarp/web_service.rb', line 6

def service_request(host, port, request, use_ssl=false)
  begin
    http = Net::HTTP.new(host, port)
    if use_ssl
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
      http.use_ssl = true
    end
    http.start { |htttp| htttp.request(request) }
  rescue Exception => ex
    raise "Unable to fetch request. Check if site is up and running"
  end
end