Skip to content

Commit

Permalink
Fixed a few methods that require post now on twitter. Refactored meth…
Browse files Browse the repository at this point in the history
…ods not using #request to use it. Made form_data work in #request for post requests. Bumped version. [#10 state:resolved]
  • Loading branch information
jnunemaker committed Aug 11, 2008
1 parent 9277e83 commit 8a802c4
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 31 deletions.
7 changes: 7 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
0.3.6 - August 11, 2008
* Fixed a few more methods that required post.
* Refactored the remaining methods that were not using #request to use it.

0.3.5 - August 4, 2008
* Removed sqlite-ruby 1.2.2 as a dependency due to install issues on linux

0.3.4 - August 3, 2008
* Added search support

Expand Down
1 change: 1 addition & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ examples/friends_followers.rb
examples/friendships.rb
examples/identica_timeline.rb
examples/location.rb
examples/posting.rb
examples/replies.rb
examples/search.rb
examples/sent_messages.rb
Expand Down
28 changes: 15 additions & 13 deletions examples/direct_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@

puts 'SINCE'
twitter.direct_messages(:since => Time.now - 5.day).each do |s|
puts "- #{s.text}"
puts "- #{s.id} #{s.text}"
end
puts
puts

puts 'SINCE_ID'
twitter.direct_messages(:since_id => 33505386).each do |s|
puts "- #{s.text}"
end
puts
puts
# puts 'SINCE_ID'
# twitter.direct_messages(:since_id => 33505386).each do |s|
# puts "- #{s.text}"
# end
# puts
# puts
#
# puts 'PAGE'
# twitter.direct_messages(:page => 1).each do |s|
# puts "- #{s.text}"
# end
# puts
# puts

puts 'PAGE'
twitter.direct_messages(:page => 1).each do |s|
puts "- #{s.text}"
end
puts
puts
# puts twitter.destroy_direct_message(34489057).inspect
9 changes: 9 additions & 0 deletions examples/posting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'rubygems'
require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
config = YAML::load(open(ENV['HOME'] + '/.twitter'))

twitter = Twitter::Base.new(config['email'], config['password'])
puts twitter.post("This is a test from the example file").inspect

# sending a direct message
# puts twitter.d('jnunemaker', 'this is a test').inspect
19 changes: 6 additions & 13 deletions lib/twitter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,12 @@ def sent_messages(options={})

# destroys a give direct message by id if the auth user is a recipient
def destroy_direct_message(id)
request("direct_messages/destroy/#{id}.xml", :auth => true)
DirectMessage.new_from_xml(request("direct_messages/destroy/#{id}.xml", :auth => true, :method => :post))
end

# Sends a direct message <code>text</code> to <code>user</code>
def d(user, text)
url = URI.parse("http://#{@api_host}/direct_messages/new.xml")
req = Net::HTTP::Post.new(url.path)
req.basic_auth(@config[:email], @config[:password])
req.set_form_data({'text' => text, 'user' => user})
response = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
DirectMessage.new_from_xml(parse(response.body).at('direct_message'))
DirectMessage.new_from_xml(request('direct_messages/new.xml', :auth => true, :method => :post, :form_data => {'text' => text, 'user' => user}))
end

# Befriends id_or_screenname for the auth user
Expand Down Expand Up @@ -164,12 +159,7 @@ def unblock(id)
def post(status, options={})
form_data = {'status' => status}
form_data.merge({'source' => options[:source]}) if options[:source]
url = URI.parse("http://#{@api_host}/statuses/update.xml")
req = Net::HTTP::Post.new(url.path)
req.basic_auth(@config[:email], @config[:password])
req.set_form_data(form_data)
response = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
Status.new_from_xml(parse(response.body).at('status'))
Status.new_from_xml(request('statuses/update.xml', :auth => true, :method => :post, :form_data => form_data))
end
alias :update :post

Expand Down Expand Up @@ -219,6 +209,9 @@ def request(path, options={})
klass = Net::HTTP.const_get options[:method].to_s.downcase.capitalize
req = klass.new("#{uri.path}/#{path}", options[:headers])
req.basic_auth(@config[:email], @config[:password]) if options[:auth]
if options[:method].to_s == 'post' && options[:form_data]
req.set_form_data(options[:form_data])
end
http.request(req)
end
rescue => error
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Twitter #:nodoc:
module VERSION #:nodoc:
MAJOR = 0
MINOR = 3
TINY = 5
TINY = 6

STRING = [MAJOR, MINOR, TINY].join('.')
end
Expand Down
9 changes: 9 additions & 0 deletions tasks/deployment.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
desc 'Preps the gem for a new release'
task :prep_for_release do
require 'rio'
Rake::Task['manifest:refresh'].invoke
gemspec = %x[rake debug_gem]
lines = gemspec.split("\n")
rio('twitter.gemspec') < lines[1, lines.length-1].join("\n")
end

desc 'Release the website and new gem version'
task :deploy => [:check_version, :website, :release] do
puts "Remember to create SVN tag:"
Expand Down
8 changes: 4 additions & 4 deletions twitter.gemspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Gem::Specification.new do |s|
s.name = %q{twitter}
s.version = "0.3.5"
s.version = "0.3.6"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["John Nunemaker"]
s.date = %q{2008-08-04}
s.date = %q{2008-08-11}
s.default_executable = %q{twitter}
s.description = %q{a command line interface for twitter, also a library which wraps the twitter api}
s.email = %q{[email protected]}
s.executables = ["twitter"]
s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "README.txt"]
s.files = ["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", "examples/friends_followers.rb", "examples/friendships.rb", "examples/identica_timeline.rb", "examples/location.rb", "examples/replies.rb", "examples/search.rb", "examples/sent_messages.rb", "examples/timeline.rb", "examples/twitter.rb", "examples/verify_credentials.rb", "lib/twitter.rb", "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", "lib/twitter/cli/migrations/20080722194508_create_tweets.rb", "lib/twitter/cli/migrations/20080722214605_add_account_id_to_tweets.rb", "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/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", "spec/base_spec.rb", "spec/cli/helper_spec.rb", "spec/direct_message_spec.rb", "spec/fixtures/followers.xml", "spec/fixtures/friends.xml", "spec/fixtures/friends_for.xml", "spec/fixtures/friends_lite.xml", "spec/fixtures/friends_timeline.xml", "spec/fixtures/public_timeline.xml", "spec/fixtures/rate_limit_status.xml", "spec/fixtures/search_results.json", "spec/fixtures/status.xml", "spec/fixtures/user.xml", "spec/fixtures/user_timeline.xml", "spec/search_spec.rb", "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", "website/index.html"]
s.files = ["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", "examples/friends_followers.rb", "examples/friendships.rb", "examples/identica_timeline.rb", "examples/location.rb", "examples/posting.rb", "examples/replies.rb", "examples/search.rb", "examples/sent_messages.rb", "examples/timeline.rb", "examples/twitter.rb", "examples/verify_credentials.rb", "lib/twitter.rb", "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", "lib/twitter/cli/migrations/20080722194508_create_tweets.rb", "lib/twitter/cli/migrations/20080722214605_add_account_id_to_tweets.rb", "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/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", "spec/base_spec.rb", "spec/cli/helper_spec.rb", "spec/direct_message_spec.rb", "spec/fixtures/followers.xml", "spec/fixtures/friends.xml", "spec/fixtures/friends_for.xml", "spec/fixtures/friends_lite.xml", "spec/fixtures/friends_timeline.xml", "spec/fixtures/public_timeline.xml", "spec/fixtures/rate_limit_status.xml", "spec/fixtures/search_results.json", "spec/fixtures/status.xml", "spec/fixtures/user.xml", "spec/fixtures/user_timeline.xml", "spec/search_spec.rb", "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", "website/index.html"]
s.has_rdoc = true
s.homepage = %q{http://twitter.rubyforge.org}
s.rdoc_options = ["--main", "README.txt"]
Expand Down Expand Up @@ -46,4 +46,4 @@ Gem::Specification.new do |s|
s.add_dependency(%q<activerecord>, [">= 2.1"])
s.add_dependency(%q<httparty>, [">= 0.1.0"])
end
end
end

2 comments on commit 8a802c4

@thehack
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK then, how do you make it work with sqlite3 on linux?

@jnunemaker
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can install it with a package manager. I did on a version of ubuntu not too long ago for a project.

Please sign in to comment.