Permalink
Browse files

pastie.org -> wrttn.in

  • Loading branch information...
1 parent 722971f commit 190eb6f73314958e2b60e79ee1812583b5c4d3f5 @jasiek committed Jun 8, 2012
Showing with 32 additions and 3 deletions.
  1. +4 −3 lib/muzang-plugins/muzang-grep.rb
  2. +28 −0 lib/muzang-plugins/muzang-grep/wrttn_in.rb
@@ -1,6 +1,6 @@
require 'sqlite3'
require 'active_record'
-require 'pastie-api'
+require 'muzang-plugins/muzang-grep/wrttn_in'
class Grep
include Muzang::Plugins::Helpers
@@ -18,7 +18,7 @@ def self.like(channel, term)
end
def to_text
- ["## #{user} @ #{created_at}:", content, ''].join("\n")
+ ["### #{user} @ #{created_at}:", "> #{content}", ''].join("\n")
end
class Migration < ActiveRecord::Migration
@@ -97,6 +97,7 @@ def open_existing_database
def save_results(term, results)
content = ["Searched for '#{term}', found #{results.size} matches", '']
content += results.map(&:to_text)
- Pastie.create(content.join("\n"), false).link
+ content = content.join("\n")
+ WrttnIn.create(content).public_url
end
end
@@ -0,0 +1,28 @@
+require 'net/http'
+
+class WrttnIn
+ attr_reader :public_url, :content
+
+ 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
+
+ def initialize(id, content)
+ @public_url = "http://wrttn.in/#{id}"
+ @content = content
+ end
+end

0 comments on commit 190eb6f

Please sign in to comment.