lib/commands/tweet_command.rb in ignoramos-1.0.1 vs lib/commands/tweet_command.rb in ignoramos-1.1.0
- old
+ new
@@ -1,64 +1,12 @@
-require 'liquid'
-require 'fileutils'
-require 'models/post'
-require 'models/app_config'
-require 'twitter'
-require 'twitter/tweet'
+require 'commands/base_tweet_command'
-class TweetCommand
- LAYOUT = <<-LAYOUT
----
-title: tweet {{tweet.id}}
-timestamp: {{tweet.timestamp}}
-layout: tweet
-tweet: {{tweet.url}}
----
-
-{{tweet.content}}
-LAYOUT
-
+class TweetCommand < BaseTweetCommand
def initialize(tweet)
+ super()
@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
+ persist_tweet(twitter.update(@tweet))
end
end