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/nopaste/nopaste.rb,
lib/rpaste/pastebin/recent.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

VERSION =
'0.0.9'

Class Method Summary collapse

Class Method Details

.http_agent(opts = {}) ⇒ Object

Creates a new Mechanize agent with the given opts.

RPaste.http_agent
RPaste.http_agent(:user_agent_alias => 'Linux Mozilla')
RPaste.http_agent(:user_agent => 'wooden pants')

49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rpaste/rpaste.rb', line 49

def RPaste.http_agent(opts={})
  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

  return agent
end

.open(uri, opts = {}) ⇒ Object

Opens the uri with the given opts. The contents of the uri will be returned.

RPaste.open('http://www.hackety.org/')
RPaste.open('http://tenderlovemaking.com/',
  :user_agent_alias => 'Linux Mozilla')
RPaste.open('http://www.wired.com/', :user_agent => 'the future')

28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rpaste/rpaste.rb', line 28

def RPaste.open(uri,opts={})
  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

  return Kernel.open(uri,headers)
end

.user_agentObject

Returns the RPaste user-agent


8
9
10
# File 'lib/rpaste/rpaste.rb', line 8

def RPaste.user_agent
  @user_agent
end

.user_agent=(agent) ⇒ Object

Sets the RPaste user-agent to the specified agent.


15
16
17
# File 'lib/rpaste/rpaste.rb', line 15

def RPaste.user_agent=(agent)
  @user_agent = agent
end