Skip to content

Instantly share code, notes, and snippets.

@lastk
Forked from kurko/gist:2407768
Created April 17, 2012 17:58
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 lastk/2407839 to your computer and use it in GitHub Desktop.
Save lastk/2407839 to your computer and use it in GitHub Desktop.
class PostCommitmentContext
#how we're using ruby/rails I thought in something like a rubygem and have a 'config' file in other place.
twitterable[:twitterFollower,:twitterPoster]
def initialize(params)
@params = params
end
def save
@post = Post.new(@params)
if @post.save
# @post is probably ActiveRecord, so there's nothing to extend
twitter.post(@post.body)
end
end
def save_comment
@comment = Comment.new(@params)
# ... instantiates Model
if @comment.save
twitter.follow(@comment.twitter_nickname)
end
end
end
class PostsController < ActionController::Base
def create
@context = PostCommitmentContext.new(params[:posts])
if @context.save
# redirect
# ...
end
end
end
class Twitter
def initialize(user)
@twitter = Twitter::API.login(user[:login], user[:password]) # fake API class
end
end
module TwitterPoster
def post(body)
# calls Twitter API
end
def parse_tweet_body
# ...
end
# other methods related to posting on Twitter
end
module TwitterFollower
def follow(body)
# calls Twitter API
end
# other methods related to following on Twitter
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment