Sha256: 802aac5fd11de66b3c53ca84e2eb4a00f666b40fe8a82d5394bc5169fb8ab37a

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require 'liquid'
require 'models/post'
require 'models/app_config'
require 'twitter'
require 'twitter/tweet'
require 'file_helper'

class BaseTweetCommand
  attr_reader :file_helper

  TWEET_LAYOUT = <<-LAYOUT
---
title: tweet {{tweet.id}}
timestamp: {{tweet.timestamp}}
layout: tweet
tweet: {{tweet.url}}
---

{{tweet.content}}
LAYOUT

  def initialize
    @file_helper = FileHelper.new(Dir.pwd)
  end

  protected
  def app_config
    @config ||= AppConfig.new(file_helper.read_file("_config.yml"))
  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

  def persist_tweet(tweet)
    file_helper.new_file("_posts/tweet-#{tweet.id}.md",
                          Liquid::Template.parse(TWEET_LAYOUT).render({
                            'tweet' => {
                              'content' => tweet.text,
                              'id' => tweet.id,
                              'url' => tweet.uri.to_s,
                              'timestamp' => DateTime.parse(tweet.created_at.to_s)
                            }
                          }))
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ignoramos-1.1.0 lib/commands/base_tweet_command.rb