Last active
December 20, 2015 07:48
-
-
Save kgrz/6095520 to your computer and use it in GitHub Desktop.
Upton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
module Upton | |
class Uri | |
attr_accessor :login_params | |
def initialize(url, &blk) | |
@u = URI(url) | |
if block_given? | |
yield self | |
end | |
end | |
def to_s | |
u.to_s | |
end | |
def scheme | |
u.scheme | |
end | |
def host | |
u.host | |
end | |
def path | |
u.path | |
end | |
def port | |
u.port | |
end | |
def query | |
u.query | |
end | |
def inspect | |
{ | |
:scheme => scheme, | |
:host => host, | |
:path => path, | |
:port => port, | |
:query => query, | |
:url => url, | |
} | |
end | |
alias_method :url, :to_s | |
alias_method :uri, :to_s | |
private | |
def u | |
@u | |
end | |
end | |
end | |
__END__ | |
Upton::Uri.new("http://google.com") | |
u = Upton::Uri.new("http://google.com") do |i| | |
i.login_params = { :uid => "userID", :pass => "password" } | |
end | |
u.login_params #=> {:uid => "userID", :pass => "password" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment