Class: Prowl::HttpAuthHandler
- Inherits:
-
Object
- Object
- Prowl::HttpAuthHandler
- Defined in:
- lib/prowl/http_auth_handler.rb
Constant Summary collapse
- API_URL =
URI.parse("https://prowl.weks.net:443/api/add_notification.php")
Instance Method Summary collapse
- #add(params) ⇒ Object
-
#initialize(username, password) ⇒ HttpAuthHandler
constructor
A new instance of HttpAuthHandler.
- #valid? ⇒ Boolean
Constructor Details
#initialize(username, password) ⇒ HttpAuthHandler
Returns a new instance of HttpAuthHandler.
5 6 7 |
# File 'lib/prowl/http_auth_handler.rb', line 5 def initialize(username, password) @username, @password = username, password end |
Instance Method Details
#add(params) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/prowl/http_auth_handler.rb', line 13 def add(params) http = Net::HTTP.new(API_URL.host, API_URL.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(API_URL.request_uri + "?" + params.map {|k, v| "#{k}=#{CGI.escape(v)}"}.join("&")) request.basic_auth @username, @password response = http.request(request) return response.code.to_i end |
#valid? ⇒ Boolean
9 10 11 |
# File 'lib/prowl/http_auth_handler.rb', line 9 def valid? raise RuntimeError, "The API doesn't provide a method for determining if a username/password is valid." end |