Class: WrttnIn

Inherits:
Object
  • Object
show all
Defined in:
lib/muzang-plugins/muzang-grep/wrttn_in.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, content) ⇒ WrttnIn

Returns a new instance of WrttnIn.



24
25
26
27
# File 'lib/muzang-plugins/muzang-grep/wrttn_in.rb', line 24

def initialize(id, content)
  @public_url = "http://wrttn.in/#{id}"
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



4
5
6
# File 'lib/muzang-plugins/muzang-grep/wrttn_in.rb', line 4

def content
  @content
end

#public_urlObject (readonly)

Returns the value of attribute public_url.



4
5
6
# File 'lib/muzang-plugins/muzang-grep/wrttn_in.rb', line 4

def public_url
  @public_url
end

Class Method Details

.create(content, markup = :markdown) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/muzang-plugins/muzang-grep/wrttn_in.rb', line 6

def self.create(content, markup = :markdown)
  post_data = {
    :content => content,
    :parser => markup
  }
  response = Net::HTTP.post_form(URI.parse('http://wrttn.in/create'), post_data)
  if response.kind_of?(Net::HTTPRedirection)
    response_body = Net::HTTP.get(URI.join('http://wrttn.in', response['Location']))
    if id = response_body.match(/<a href="\/(.*)" class="lab" target="_blank">public url<\/a>/)[1]
      self.new(id, content)
    else
      raise "Couldn't parse the response"
    end
  else
    raise "Couldn't create a post"
  end
end