Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
update api URL and support proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Wei Feng committed Jan 2, 2013
1 parent 8d62c32 commit e852747
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/prowl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ class MissingAPIKey < RuntimeError; end
class TooManyAPIKeys < RuntimeError; end
class PriorityOutOfRange < RuntimeError; end

API_URL = "https://prowl.weks.net:443/publicapi"
API_URL = "https://api.prowlapp.com/publicapi"
MAX_API_KEYS = 5
PRIORITY_RANGE = -2..2

def initialize(defaults = {})
@defaults = defaults
end

def set_proxy(addr, port)
@proxy_addr = addr
@proxy_port = port
end

def add(params = {})
perform("add", params)
Expand Down Expand Up @@ -66,9 +71,9 @@ def perform(action, params = {})
end

uri = URI.parse("#{API_URL}/#{action}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

proxy = Net::HTTP::Proxy(@proxy_addr, @proxy_port)
http = proxy.start(uri.host, :use_ssl => true, :verify_mode => OpenSSL::SSL::VERIFY_NONE)

request = Net::HTTP::Get.new(uri.request_uri + "?" + params.map {|k, v| "#{k}=#{CGI.escape(v.to_s)}"}.join("&"))
response = http.request(request)
Expand All @@ -82,4 +87,4 @@ def perform(action, params = {})

p Prowl.add(:apikey => api_key, :application => "Fishes", :event => "silly", :description => "Awwawaw.", :priority => 1)
p Prowl.verify(api_key)
end
end

0 comments on commit e852747

Please sign in to comment.