Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module PrivateGroupApi
- class Request
- attr_accessor :url,
- :username,
- :password,
- :listeners
- def initialize(url)
- self.url = url
- self.listners = {
- '200' => lambda {},
- '404' => lambda {},
- '500' => lambda {}
- }
- end
- def authenticate
- uri = URI.parse "#{url}?username=#{username}&password=#{password}"
- request = Net::HTTP::Get.new uri.path
- http = Net::HTTP.new uri.host, uri.port
- response = http.request request
- listener = listeners[response.code]
- listener.call
- end
- def on_failure(&block)
- listners['404'] = block
- end
- def on_error(&block)
- listners['500'] = block
- end
- end
- end
Add Comment
Please, Sign In to add comment