Skip to content

Commit

Permalink
Removed active support and switched to echoe for gem management.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Dec 23, 2008
1 parent 906d34d commit fbb7925
Show file tree
Hide file tree
Showing 24 changed files with 115 additions and 1,928 deletions.
File renamed without changes.
File renamed without changes.
23 changes: 7 additions & 16 deletions Manifest.txt → Manifest
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
History.txt
License.txt
Manifest.txt
README.txt
Rakefile
bin/twitter
config/hoe.rb
config/requirements.rb
examples/blocks.rb
examples/direct_messages.rb
examples/favorites.rb
Expand All @@ -20,9 +13,8 @@ examples/sent_messages.rb
examples/timeline.rb
examples/twitter.rb
examples/verify_credentials.rb
lib/twitter.rb
History
lib/twitter/base.rb
lib/twitter/cli.rb
lib/twitter/cli/config.rb
lib/twitter/cli/helpers.rb
lib/twitter/cli/migrations/20080722194500_create_accounts.rb
Expand All @@ -32,17 +24,19 @@ lib/twitter/cli/migrations/20080722214606_create_configurations.rb
lib/twitter/cli/models/account.rb
lib/twitter/cli/models/configuration.rb
lib/twitter/cli/models/tweet.rb
lib/twitter/cli.rb
lib/twitter/direct_message.rb
lib/twitter/easy_class_maker.rb
lib/twitter/rate_limit_status.rb
lib/twitter/search.rb
lib/twitter/status.rb
lib/twitter/user.rb
lib/twitter/version.rb
script/destroy
script/generate
script/txt2html
setup.rb
lib/twitter.rb
License
Manifest
Rakefile
README
spec/base_spec.rb
spec/cli/helper_spec.rb
spec/direct_message_spec.rb
Expand All @@ -62,9 +56,6 @@ spec/spec.opts
spec/spec_helper.rb
spec/status_spec.rb
spec/user_spec.rb
tasks/deployment.rake
tasks/environment.rake
tasks/website.rake
twitter.gemspec
website/css/common.css
website/images/terminal_output.png
Expand Down
File renamed without changes.
44 changes: 41 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
require 'config/requirements'
require 'config/hoe' # setup Hoe + all gem configuration
ProjectName = 'twitter'
WebsitePath = "[email protected]:/var/www/gforge-projects/#{ProjectName}"

Dir['tasks/**/*.rake'].each { |rake| load rake }
require 'rubygems'
require 'rake'
require 'echoe'
require 'spec/rake/spectask'
require "lib/#{ProjectName}/version"

Echoe.new(ProjectName, Twitter::Version) do |p|
p.description = "a command line interface for twitter, also a library which wraps the twitter api"
p.url = "http://#{ProjectName}.rubyforge.org"
p.author = "John Nunemaker"
p.email = "[email protected]"
p.extra_deps = [['hpricot', '>= 0.6'], ['activesupport', '>= 2.1'], ['httparty', '>= 0.2.4']]
p.need_tar_gz = false
p.docs_host = WebsitePath
end

desc 'Upload website files to rubyforge'
task :website do
sh %{rsync -av website/ #{WebsitePath}}
Rake::Task['website_docs'].invoke
end

task :website_docs do
Rake::Task['redocs'].invoke
sh %{rsync -av doc/ #{WebsitePath}/docs}
end

desc 'Preps the gem for a new release'
task :prepare do
%w[manifest build_gemspec].each do |task|
Rake::Task[task].invoke
end
end

Rake::Task[:default].prerequisites.clear
task :default => :spec
Spec::Rake::SpecTask.new do |t|
t.spec_files = FileList["spec/**/*_spec.rb"]
end
8 changes: 1 addition & 7 deletions bin/twitter
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,5 @@ if ARGV[0] && ARGV[0] == 'd' && !STDIN.tty?
ARGV[2] = "#{STDIN.read}#{ARGV[2]}"
end

require 'rubygems'

gem 'main', '>= 2.8.2'
gem 'highline', '>= 1.4.0'
gem 'activerecord', '>= 2.1'

require 'twitter'
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'twitter'))
require 'twitter/cli'
72 changes: 0 additions & 72 deletions config/hoe.rb

This file was deleted.

17 changes: 0 additions & 17 deletions config/requirements.rb

This file was deleted.

10 changes: 8 additions & 2 deletions lib/twitter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
%w(uri cgi net/http yaml rubygems hpricot active_support).each { |f| require f }
require 'uri'
require 'cgi'
require 'net/http'
require 'yaml'
require 'time'
require 'rubygems'
require 'hpricot'

$:.unshift(File.join(File.dirname(__FILE__)))
$:.unshift(File.dirname(__FILE__))
require 'twitter/version'
require 'twitter/easy_class_maker'
require 'twitter/base'
Expand Down
17 changes: 11 additions & 6 deletions lib/twitter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def users(doc)
#
# ie: call(:public_timeline, :auth => false)
def call(method, options={})
options.reverse_merge!({ :auth => true, :args => {} })
options = { :auth => true, :args => {} }.merge(options)
# Following line needed as lite=false doesn't work in the API: http://tinyurl.com/yo3h5d
options[:args].delete(:lite) unless options[:args][:lite]
args = options.delete(:args)
Expand All @@ -193,11 +193,12 @@ def call(method, options={})

# Makes a request to twitter.
def request(path, options={})
options.reverse_merge!({
options = {
:headers => { "User-Agent" => @config[:email] },
:method => :get
})
unless options[:since].blank?
:method => :get,
}.merge(options)

unless options[:since].nil?
since = options[:since].kind_of?(Date) ? options[:since].strftime('%a, %d-%b-%y %T GMT') : options[:since].to_s
options[:headers]["If-Modified-Since"] = since
end
Expand Down Expand Up @@ -233,7 +234,11 @@ def request(path, options={})

# Given a path and a hash, build a full path with the hash turned into a query string
def build_path(path, options)
path += "?#{options.to_query}" unless options.blank?
unless options.nil?
query = options.inject('') { |str, h| str += "#{CGI.escape(h[0].to_s)}=#{CGI.escape(h[1].to_s)}&"; str }
path += "?#{query}"
end

path
end

Expand Down
6 changes: 4 additions & 2 deletions lib/twitter/cli.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require 'rubygems'

gem 'main', '>= 2.8.2'
gem 'highline', '>= 1.4.0'
gem 'activerecord', '>= 2.1'
gem 'sqlite3-ruby', '>= 1.2.1'

require 'main'
require 'highline/import'
require 'activerecord'
Expand Down Expand Up @@ -280,7 +282,7 @@ def run
do_work do
timeline = params['timeline'].value == 'me' ? 'user' : params['timeline'].value
options, since_id = {}, Configuration["#{timeline}_since_id"]
options[:since_id] = since_id if !since_id.blank? && !params['force'].given?
options[:since_id] = since_id if !since_id.nil? && !params['force'].given?
cache = [:friends, :user].include?(timeline)
collection = base.timeline(timeline.to_sym, options)
output_tweets(collection, {:cache => cache, :since_prefix => timeline})
Expand All @@ -297,7 +299,7 @@ def run
def run
do_work do
options, since_id = {}, Configuration["replies_since_id"]
options[:since_id] = since_id if !since_id.blank? && !params['force'].given?
options[:since_id] = since_id if !since_id.nil? && !params['force'].given?
collection = base.replies(options)
output_tweets(collection, {:since_prefix => 'replies'})
end
Expand Down
22 changes: 16 additions & 6 deletions lib/twitter/cli/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,34 @@ class NoActiveAccount < StandardError; end
class NoAccounts < StandardError; end

def output_tweets(collection, options={})
options.reverse_merge!({
options = {
:cache => false,
:since_prefix => '',
:empty_msg => 'Nothing new since your last check.'
})
}.merge(options)

if collection.size > 0
justify = collection.collect { |s| s.user.screen_name }.max { |a,b| a.length <=> b.length }.length rescue 0
indention = ' ' * (justify + 3)
say("\n#{indention}#{collection.size} new tweet(s) found.\n\n")
collection.each do |s|
Tweet.create_from_tweet(current_account, s) if options[:cache]

occurred_at = Time.parse(s.created_at).strftime('On %b %d at %l:%M%P')
formatted_time = '-' * occurred_at.length + "\n#{indention}#{occurred_at}"
formatted_name = s.user.screen_name.rjust(justify + 1)
formatted_msg = ''
s.text.split(' ').in_groups_of(6, false) { |row| formatted_msg += row.join(' ') + "\n#{indention}" }
say "#{CGI::unescapeHTML(formatted_name)}: #{CGI::unescapeHTML(formatted_msg)}#{formatted_time}\n\n"

s.text.split(' ').each_with_index do |word, idx|
formatted_msg += "#{word} "

sixth_word = idx != 0 && idx % 6 == 0
formatted_msg += "\n#{indention}" if sixth_word
end

say "#{CGI::unescapeHTML(formatted_name)}: #{CGI::unescapeHTML(formatted_msg)}\n#{indention}#{formatted_time}\n\n"
end

Configuration["#{options[:since_prefix]}_since_id"] = collection.first.id
else
say(options[:empty_msg])
Expand All @@ -35,7 +45,7 @@ def base(username=current_account.username, password=current_account.password)

def current_account
@current_account ||= Account.active
raise Account.count == 0 ? NoAccounts : NoActiveAccount if @current_account.blank?
raise Account.count == 0 ? NoAccounts : NoActiveAccount if @current_account.nil?
@current_account
end

Expand All @@ -44,7 +54,7 @@ def attempt_import(&block)
if File.exists?(tweet_file)
say '.twitter file found, attempting import...'
config = YAML::load(File.read(tweet_file))
if !config['email'].blank? && !config['password'].blank?
if !config['email'].nil? && !config['password'].nil?
Account.add(:username => config['email'], :password => config['password'])
say 'Account imported'
block.call if block_given?
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Search

def initialize(q=nil)
clear
containing(q) unless q.blank?
containing(q) if q && q.strip != ''
end

def from(user)
Expand Down
8 changes: 1 addition & 7 deletions lib/twitter/version.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
module Twitter #:nodoc:
module VERSION #:nodoc:
MAJOR = 0
MINOR = 3
TINY = 8

STRING = [MAJOR, MINOR, TINY].join('.')
end
Version = '0.4.0'
end
Empty file removed log/debug.log
Empty file.
14 changes: 0 additions & 14 deletions script/destroy

This file was deleted.

Loading

0 comments on commit fbb7925

Please sign in to comment.