Class: ThreeScale::Client::HTTPClient::NetHttpPersistent

Inherits:
BaseClient
  • Object
show all
Defined in:
lib/3scale/client/http_client.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseClient

#get_request, #post_request

Constructor Details

#initialize(host) ⇒ NetHttpPersistent

Returns a new instance of NetHttpPersistent.



68
69
70
71
72
# File 'lib/3scale/client/http_client.rb', line 68

def initialize(host)
  super
  @http = ::Net::HTTP::Persistent.new
  @protocol = 'http'
end

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
# File 'lib/3scale/client/http_client.rb', line 57

def self.available?
  prepare
  true
rescue LoadError
  false
end

.prepareObject



64
65
66
# File 'lib/3scale/client/http_client.rb', line 64

def self.prepare
  require 'net/http/persistent'
end

Instance Method Details

#full_uri(path) ⇒ Object



89
90
91
# File 'lib/3scale/client/http_client.rb', line 89

def full_uri(path)
  URI.join "#{@protocol}://#{@host}", path
end

#get(path) ⇒ Object



78
79
80
81
# File 'lib/3scale/client/http_client.rb', line 78

def get(path)
  uri = full_uri(path)
  @http.request(uri, get_request(path))
end

#post(path, payload) ⇒ Object



84
85
86
87
# File 'lib/3scale/client/http_client.rb', line 84

def post(path, payload)
  uri = full_uri(path)
  @http.request(uri, post_request(path, payload))
end

#ssl!Object



74
75
76
# File 'lib/3scale/client/http_client.rb', line 74

def ssl!
  @protocol = 'https'
end