Skip to content

Commit

Permalink
#19: return URL with scheme for Proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
nbulaj committed Apr 1, 2018
1 parent d9b7f1e commit 5560e27
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ Also you can call next instance methods for every Proxy object:
* `socks4?`
* `socks5?`
* `uri` (returns `URI::Generic` object)
* `url` (returns a formatted URL like "_http://IP:PORT_" )
* `url` (returns a formatted URL like "_IP:PORT_" or "_http://IP:PORT_" if `scheme: true` provided)

## Providers

Expand Down
11 changes: 9 additions & 2 deletions lib/proxy_fetcher/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,18 @@ def uri

# Returns <code>String</code> object with <i>addr:port</i> values of the proxy.
#
# @param scheme [Boolean]
# Indicates if URL must include proxy type
#
# @return [String]
# true if proxy connectable, otherwise false.
#
def url
"#{addr}:#{port}"
def url(scheme: false)
if scheme
URI::Generic.build(scheme: type, host: addr, port: port).to_s
else
URI::Generic.build(host: addr, port: port).to_s
end
end
end
end
4 changes: 4 additions & 0 deletions spec/proxy_fetcher/proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@
it 'returns URL' do
expect(proxy.url).to be_a(String)
end

it 'returns URL with schema' do
expect(proxy.url(scheme: true)).to include('://')
end
end

0 comments on commit 5560e27

Please sign in to comment.