-
-
Save lastk/2407839 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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