Sha256: 1ddc056e0c6b231fe16bd0bdfcada8fdc039ca986f1d07a00a381dc7cd63d64b
Contents?: true
Size: 1.46 KB
Versions: 2
Compression:
Stored size: 1.46 KB
Contents
require 'liquid' require 'fileutils' require 'models/post' require 'models/app_config' require 'twitter' require 'twitter/tweet' class TweetCommand LAYOUT = <<-LAYOUT --- title: tweet {{tweet.id}} timestamp: {{tweet.timestamp}} layout: tweet tweet: {{tweet.url}} --- {{tweet.content}} LAYOUT def initialize(tweet) @tweet = tweet @dir = Dir.pwd end def execute tweet = twitter.update(@tweet) new_file("_posts/tweet-#{tweet.id}.md", Liquid::Template.parse(LAYOUT).render({ 'tweet' => { 'content' => @tweet, 'id' => tweet.id, 'url' => tweet.uri.to_s, 'timestamp' => DateTime.now } })) end private def app_config @config ||= AppConfig.new(read_file("_config.yml")) end def new_file(filename, contents) new_post_file = File.new("#{@dir}/#{filename}", 'w') new_post_file.write(contents) new_post_file.close end def read_file(filename) File.open("#{@dir}/#{filename}", 'r') do |file| file.read() end end def twitter @twitter ||= Twitter::REST::Client.new do |config| config.consumer_key = "RerlMuPVgYySMdqvuaBeSw" config.consumer_secret = "Ccq3hS7fMplpjwCfvpVyPQXV6nPGGGonXSAdmi8ZIc" config.access_token = app_config.vars['twitter']['access_token'] config.access_token_secret = app_config.vars['twitter']['access_token_secret'] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ignoramos-1.0.1 | lib/commands/tweet_command.rb |
ignoramos-1.0.0 | lib/commands/tweet_command.rb |