Module: RPaste
- Defined in:
- lib/rpaste/paste.rb,
lib/rpaste/rpaste.rb,
lib/rpaste/version.rb,
lib/rpaste/metadata.rb,
lib/rpaste/result_set.rb,
lib/rpaste/nopaste/paste.rb,
lib/rpaste/nopaste/recent.rb,
lib/rpaste/pastebin/paste.rb,
lib/rpaste/nopaste/nopaste.rb,
lib/rpaste/nopaste/metadata.rb,
lib/rpaste/pastebin/metadata.rb,
lib/rpaste/pastebin/pastebin.rb,
lib/rpaste/nopaste/result_set.rb,
lib/rpaste/pastebin/result_set.rb
Defined Under Namespace
Modules: NoPaste, PasteBin Classes: Metadata, Paste, ResultSet
Constant Summary collapse
- COMMON_PROXY_PORT =
Common proxy port.
8080
- VERSION =
'0.1.0'
Class Method Summary collapse
-
.open_page(uri, options = {}) ⇒ Object
Similar to RPaste.open_uri but returns an Hpricot document.
-
.open_uri(uri, options = {}) ⇒ Object
Opens the uri with the given options.
-
.proxy ⇒ Object
Returns the
Hash
of proxy information. -
.proxy_uri(proxy_info = RPaste.proxy) ⇒ Object
Creates a HTTP URI based from the given proxy_info
Hash
. -
.user_agent ⇒ Object
Returns the RPaste User-Agent.
-
.user_agent=(agent) ⇒ Object
Sets the RPaste user-agent to the specified agent.
-
.user_agent_aliases ⇒ Object
Returns the supported Web User-Agent Aliases.
-
.web_agent(options = {}) ⇒ Object
Creates a new Mechanize agent with the given options.
Class Method Details
.open_page(uri, options = {}) ⇒ Object
Similar to RPaste.open_uri but returns an Hpricot document.
99 100 101 |
# File 'lib/rpaste/rpaste.rb', line 99 def RPaste.open_page(uri,={}) Hpricot(RPaste.open_uri(uri,)) end |
.open_uri(uri, options = {}) ⇒ Object
Opens the uri with the given options. The contents of the uri will be returned.
options may contain the following keys:
:user_agent_alias
-
The User-Agent Alias to use.
:user_agent
-
The User-Agent String to use.
:proxy
-
A
Hash
of proxy information which may contain the following keys::host
-
The proxy host.
:port
-
The proxy port.
:user
-
The user-name to login as.
:password
-
The password to login with.
RPaste.open_uri('http://www.hackety.org/')
RPaste.open_uri('http://tenderlovemaking.com/',
:user_agent_alias => 'Linux Mozilla')
RPaste.open_uri('http://www.wired.com/',
:user_agent => 'the future')
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rpaste/rpaste.rb', line 77 def RPaste.open_uri(uri,={}) headers = {} if opts[:user_agent_alias] headers['User-Agent'] = WWW::Mechanize::AGENT_ALIASES[opts[:user_agent_alias]] elsif opts[:user_agent] headers['User-Agent'] = opts[:user_agent] elsif RPaste.user_agent headers['User-Agent'] = RPaste.user_agent end proxy = ([:proxy] || GScraper.proxy) if proxy[:host] headers[:proxy] = GScraper.proxy_uri(proxy) end return Kernel.open(uri,headers) end |
.proxy ⇒ Object
Returns the Hash
of proxy information.
11 12 13 |
# File 'lib/rpaste/rpaste.rb', line 11 def RPaste.proxy @@rpaste_proxy ||= {:host => nil, :port => COMMON_PROXY_PORT, :user => nil, :pass => nil} end |
.proxy_uri(proxy_info = RPaste.proxy) ⇒ Object
Creates a HTTP URI based from the given proxy_info Hash
. The proxy_info hash defaults to Web.proxy, if not given.
proxy_info may contain the following keys:
:host
-
The proxy host.
:port
-
The proxy port. Defaults to COMMON_PROXY_PORT, if not specified.
:user
-
The user-name to login as.
:password
-
The password to login with.
26 27 28 29 30 31 32 33 |
# File 'lib/rpaste/rpaste.rb', line 26 def RPaste.proxy_uri(proxy_info=RPaste.proxy) if RPaste.proxy[:host] return URI::HTTP.build(:host => RPaste.proxy[:host], :port => RPaste.proxy[:port] || COMMON_PROXY_PORT, :userinfo => "#{RPaste.proxy[:user]}:#{RPaste.proxy[:password]}", :path => '/') end end |
.user_agent ⇒ Object
Returns the RPaste User-Agent
45 46 47 |
# File 'lib/rpaste/rpaste.rb', line 45 def RPaste.user_agent @@rpaste_user_agent ||= nil end |
.user_agent=(agent) ⇒ Object
Sets the RPaste user-agent to the specified agent.
52 53 54 |
# File 'lib/rpaste/rpaste.rb', line 52 def RPaste.user_agent=(agent) @@rpaste_user_agent = agent end |
.user_agent_aliases ⇒ Object
Returns the supported Web User-Agent Aliases.
38 39 40 |
# File 'lib/rpaste/rpaste.rb', line 38 def RPaste.user_agent_aliases WWW::Mechanize::AGENT_ALIASES end |
.web_agent(options = {}) ⇒ Object
Creates a new Mechanize agent with the given options.
options may contain the following keys:
:user_agent_alias
-
The User-Agent Alias to use.
:user_agent
-
The User-Agent String to use.
:proxy
-
A
Hash
of proxy information which may contain the following keys::host
-
The proxy host.
:port
-
The proxy port.
:user
-
The user-name to login as.
:password
-
The password to login with.
RPaste.web_agent
RPaste.web_agent(:user_agent_alias => 'Linux Mozilla')
RPaste.web_agent(:user_agent => 'wooden pants')
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/rpaste/rpaste.rb', line 120 def RPaste.web_agent(={}) agent = WWW::Mechanize.new if opts[:user_agent_alias] agent.user_agent_alias = opts[:user_agent_alias] elsif opts[:user_agent] agent.user_agent = opts[:user_agent] elsif RPaste.user_agent agent.user_agent = RPaste.user_agent end proxy = ([:proxy] || GScraper.proxy) if proxy[:host] agent.set_proxy(proxy[:host],proxy[:port],proxy[:user],proxy[:password]) end return agent end |