Skip to content

Instantly share code, notes, and snippets.

@myobie
Created December 23, 2008 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myobie/39401 to your computer and use it in GitHub Desktop.
Save myobie/39401 to your computer and use it in GitHub Desktop.
### just post a string to a url, and we can figure out what type of post it is
chat_string = "Me: Hello
You: Hello back
Me: I need to get this blog done
Me: Like now
You: Yeah, you do
You: It really has been a while
Me: OK, that's enough from you"
quote_string = "Source: Me
> This should be a quote."
article_string = "I am so happy that this works
=============================
This should be an article."
review_string = "Rating: 1.5
Toaster
======="
r2dstring = "Rating: 0
Item: Motorola Phone"
link_string = "URL: yahoo.com"
quote2_string = "> This should be a quote."
### the big finale
PostType.auto_detect(chat_string) # => #<Chat:0x10c3acc @content={:type=>"Chat", :slug=>"mehelloyouhello-backmei-need-to-get-this-blog-donemelike-nowyouyeah-you-doyouit-really-has-been-a-whilemeok-that-s-enough-from-you", :transcript=>[{:me=>"Hello"}, {:you=>"Hello back"}, {:me=>"I need to get this blog done"}, {:me=>"Like now"}, {:you=>"Yeah, you do"}, {:you=>"It really has been a while"}, {:me=>"OK, that's enough from you"}]}>
PostType.auto_detect(quote_string) # => #<Quote:0x10bfad0 @content={:source=>"Me", :type=>"Quote", :quote=>"This should be a quote.", :slug=>"this-should-be-a-quote"}>
PostType.auto_detect(article_string) # => #<Article:0x10ba0f8 @content={:type=>"Article", :title=>"I am so happy that this works", :slug=>"i-am-so-happy-that-this-works", :body=>"<p>This should be an article.</p>"}>
PostType.auto_detect(review_string) # => #<Review:0x10b6390 @content={:type=>"Review", :slug=>"toaster", :item=>"Toaster", :rating=>1.5}>
PostType.auto_detect(r2dstring) # => #<Review:0x10b21dc @content={:type=>"Review", :slug=>"motorola-phone", :item=>"Motorola Phone", :rating=>0.0}>
PostType.auto_detect(quote2_string) # => #<Quote:0x10b056c @content={:type=>"Quote", :quote=>"This should be a quote.", :slug=>"this-should-be-a-quote"}>
PostType.auto_detect(link_string) # => #<Link:0x10ae85c @content={:type=>"Link", :url=>"http://yahoo.com", :title=>"Yahoo!", :slug=>"yahoo"}>
### So imagine how easy it could be to create a TextMate action to POST the current document
### to your-blog.com/posts and then have it turned into a tumblr style post depending on the
### content.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment