Skip to content

Commit

Permalink
code sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
lancejpollard committed Aug 10, 2010
1 parent 2996e7d commit 4e9e5dd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 44 deletions.
8 changes: 4 additions & 4 deletions README.markdown
Expand Up @@ -45,7 +45,7 @@ It treats everything as a `Post`. A post has these properties:
- `categories`: Category for the post. Most services allow 1 category, some up to 4. These are specific to the service.
- `vote`: Vote for the post, either "up", "down", or "none" (or 1, 0, -1). Only if applicable to the service.
- `rating`: Rating for the post, 1-5, if applicable.
- `private`: Whether the service is public or private (0 == public, 1 == private)
- `privacy`: Whether the service is public or private (0 || "public", 1 || "private")
- `state`: Status of the post, either "published", "draft", "submitted", or "queued".
- `kind`: The type of post, either post, link, quote, comment, image, video, audio, or answer.
- `format`: The format of your post content, either "plain", "html", "markdown", "textile", or any code (ruby, c, php, etc.).
Expand All @@ -57,12 +57,12 @@ Each service requires different things, which are determined by the `validates_p
1. Microblogging (twitter, yahoo meme, google buzz, identica)
2. Tumblelogging (tumblr, posterous)
3. Blogging (large posts)
4. Bookmarking
5. Code Sharing (gist, snipplr, dzone snippets, pastie, snipt, pastebin)
4. Bookmarking (delicious, diigo, mixx, newsvine, reddit, digg...)
5. Code Sharing (gist, snipplr, dzone snippets, snipt)

## How it works

Everything is built around [Mechanize](http://mechanize.rubyforge.org/mechanize/GUIDE_rdoc.html) and [Nokogiri](http://nokogiri.org/tutorials/parsing_an_html_xml_document.html), both led by [Aaron Patterson](http://tenderlovemaking.com/).
Everything is built around [Mechanize](http://mechanize.rubyforge.org/mechanize/GUIDE_rdoc.html) and [Nokogiri](http://nokogiri.org/tutorials/parsing_an_html_xml_document.html), both led by [Aaron Patterson](http://tenderlovemaking.com/) (watch [Yehuda's "How to do the Impossible video"](http://www.youtube.com/watch?v=mo-lMdQMsdw)).

Many social bookmarking services do not have API's in order to prevent spammers from ruining their system. But what about for those of us that actually create content several times a day and want automation? We're out of luck.

Expand Down
6 changes: 4 additions & 2 deletions lib/ubiquitously/post.rb
@@ -1,6 +1,6 @@
module Ubiquitously
class Post
attr_accessor :url, :title, :description, :tags, :categories, :user, :page, :posts
attr_accessor :url, :title, :description, :tags, :categories, :user, :page, :posts, :format, :extension

def initialize(attributes = {})
attributes.each do |key, value|
Expand Down Expand Up @@ -39,7 +39,9 @@ def postables(*services)
:title => self.title,
:description => self.description,
:tags => self.tags,
:categories => self.categories
:categories => self.categories,
:format => self.format,
:extension => self.extension
)
end
end.uniq
Expand Down
32 changes: 0 additions & 32 deletions lib/ubiquitously/services/

This file was deleted.

17 changes: 14 additions & 3 deletions lib/ubiquitously/services/base.rb
Expand Up @@ -41,14 +41,14 @@ class Post

attr_accessor :title, :url, :description, :tags, :categories
# some sites check to see if you're posting duplicate content!
attr_accessor :image, :rating, :private, :vote, :status, :must_be_unique, :captcha
attr_accessor :image, :rating, :privacy, :vote, :status, :must_be_unique, :captcha
attr_accessor :service_url, :user
# the application that automates! ("Posted by TweetMeme")
attr_accessor :source, :source_url
# kind == regular, link, quote, photo, conversation, video, audio, answer
attr_accessor :kind
# plain, html, markdown
attr_accessor :format
attr_accessor :format, :extension
# max 55 chars, for custom url if possible
attr_accessor :slug
# published, draft, submission, queue
Expand All @@ -59,7 +59,10 @@ def initialize(attributes = {})

raise 'please give me a user' if self.user.blank?

self.format ||= "plain"
self.format ||= "text"
self.privacy = 0 if self.privacy.nil?
self.categories ||= []
self.tags ||= []

# for httparty
@auth = {:username => user.username_for(self), :password => user.password_for(self)}
Expand Down Expand Up @@ -111,6 +114,14 @@ def tokenize
}
end

def private?
privacy == 1 || privacy == "1" || privacy == "private"
end

def public?
privacy == 0 || privacy == "0" || privacy == "public"
end

class << self
def submit_to(url = nil)
@submit_to = url if url
Expand Down
4 changes: 2 additions & 2 deletions lib/ubiquitously/services/tumblr.rb
Expand Up @@ -18,10 +18,10 @@ def save(options = {})
:query => {
:email => user.username,
:password => user.password,
:type =>
:type => "link",
:name => token[:title],
:url => token[:url],
:description => token[:description]
:description => token[:description],
:tags => token[:tags],
}
})
Expand Down
8 changes: 7 additions & 1 deletion lib/ubiquitously/user.rb
Expand Up @@ -63,9 +63,15 @@ def save_cookies(path = self.cookies_path)
end

def has_cookie_for(service)
name = service_cookie_name(service.to_s)
!self.agent.cookie_jar.jar.keys.detect do |domain|
domain.downcase =~ /#{service.to_s.gsub("_", "_?")}/
domain.downcase =~ /#{name}/
end.blank?
end

def service_cookie_name(service)
return service.gsub("_", "_?") unless service == "dzone_snippets"
return "dzone"
end
end
end

0 comments on commit 4e9e5dd

Please sign in to comment.