Class: Pastie::Paste

Inherits:
Object
  • Object
show all
Defined in:
lib/pastie-api/paste.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ Paste

Initializes a pastie from server html response


7
8
9
10
11
12
13
14
15
16
# File 'lib/pastie-api/paste.rb', line 7

def initialize(html)
  url = html.scan(/http:\/\/pastie.org\/pastes\/([\d]{1,})\/text(\?key=([A-Za-z\d]{1,}))?/)
  unless url.nil?
    url.flatten!
    @id = url[0] ; @key = url[2]
    @content = Request.fetch(raw_link)
  else
    raise 'Invalid html!'
  end
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content


4
5
6
# File 'lib/pastie-api/paste.rb', line 4

def content
  @content
end

#idObject (readonly)

Returns the value of attribute id


3
4
5
# File 'lib/pastie-api/paste.rb', line 3

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key


3
4
5
# File 'lib/pastie-api/paste.rb', line 3

def key
  @key
end

Instance Method Details

Return direct link to paste page


24
25
26
# File 'lib/pastie-api/paste.rb', line 24

def link
  BASE_URL + (private? ? "/private/#{@key}" : "/#{@id}")
end

#private?Boolean

Returns true if paste is private

Returns:

  • (Boolean)

29
30
31
# File 'lib/pastie-api/paste.rb', line 29

def private?
  !@key.nil?
end

Returns direct link to paste contents


19
20
21
# File 'lib/pastie-api/paste.rb', line 19

def raw_link
  BASE_URL + "/pastes/#{@id}/text" + (private? ? "?key=#{@key}" : '')
end