Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for images

Closes #57.
  • Loading branch information...
commit 155a56d575cea679dcfed4731ac29c858b775eaf 1 parent 01c8cd4
@sferik authored
View
7 lib/t/cli.rb
@@ -753,10 +753,15 @@ def unfollow(user, *users)
desc "update MESSAGE", "Post a Tweet."
method_option "location", :aliases => "-l", :type => :boolean, :default => false
+ method_option "file", :aliases => "-f", :type => :string, :desc => "The path to an image to attach to your tweet."
def update(message)
opts = {:trim_user => true}
opts.merge!(:lat => location.lat, :long => location.lng) if options['location']
- status = client.update(message, opts)
+ status = if options['file']
+ client.update_with_media(message, File.new(File.expand_path(options['file'])), opts)
+ else
+ client.update(message, opts)
+ end
say "Tweet posted by @#{@rcfile.active_profile[0]}."
say
say "Run `#{File.basename($0)} delete status #{status.id}` to delete."
View
15 lib/t/set.rb
@@ -48,6 +48,21 @@ def name(name)
say "@#{@rcfile.active_profile[0]}'s name has been updated."
end
+ desc "profile_background_image FILE", "Sets the background image on your Twitter profile."
+ method_option "tile", :aliases => "-t", :type => :boolean, :default => false, :desc => "Whether or not to tile the background image."
+ def profile_background_image(file)
+ client.update_profile_background_image(File.new(File.expand_path(file)), :tile => options['tile'], :skip_status => true)
+ say "@#{@rcfile.active_profile[0]}'s background image has been updated."
+ end
+ map %w(background background_image) => :profile_background_image
+
+ desc "profile_image FILE", "Sets the image on your Twitter profile."
+ def profile_image(file)
+ client.update_profile_image(File.new(File.expand_path(file)))
+ say "@#{@rcfile.active_profile[0]}'s image has been updated."
+ end
+ map %w(avatar image) => :profile_image
+
desc "url URL", "Sets the URL field on your profile."
def url(url)
client.update_profile(:url => url)
View
16 spec/cli_spec.rb
@@ -3511,6 +3511,22 @@
@cli.update("Testing")
$stdout.string.split("\n").first.should == "Tweet posted by @testcli."
end
+ context "with file" do
+ before do
+ @cli.options = @cli.options.merge("file" => fixture_path + "/long.png")
+ stub_post("/1/statuses/update_with_media.json", "https://upload.twitter.com").
+ to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "should request the correct resource" do
+ @cli.update("Testing")
+ a_post("/1/statuses/update_with_media.json", "https://upload.twitter.com").
+ should have_been_made
+ end
+ it "should have the correct output" do
+ @cli.update("Testing")
+ $stdout.string.split("\n").first.should == "Tweet posted by @testcli."
+ end
+ end
end
describe "#users" do
View
BIN  spec/fixtures/long.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  spec/fixtures/me.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  spec/fixtures/we_concept_bg2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
16 spec/helper.rb
@@ -12,35 +12,35 @@
require 'timecop'
require 'webmock/rspec'
-def a_delete(path, endpoint=Twitter.endpoint)
+def a_delete(path, endpoint='https://api.twitter.com')
a_request(:delete, endpoint + path)
end
-def a_get(path, endpoint=Twitter.endpoint)
+def a_get(path, endpoint='https://api.twitter.com')
a_request(:get, endpoint + path)
end
-def a_post(path, endpoint=Twitter.endpoint)
+def a_post(path, endpoint='https://api.twitter.com')
a_request(:post, endpoint + path)
end
-def a_put(path, endpoint=Twitter.endpoint)
+def a_put(path, endpoint='https://api.twitter.com')
a_request(:put, endpoint + path)
end
-def stub_delete(path, endpoint=Twitter.endpoint)
+def stub_delete(path, endpoint='https://api.twitter.com')
stub_request(:delete, endpoint + path)
end
-def stub_get(path, endpoint=Twitter.endpoint)
+def stub_get(path, endpoint='https://api.twitter.com')
stub_request(:get, endpoint + path)
end
-def stub_post(path, endpoint=Twitter.endpoint)
+def stub_post(path, endpoint='https://api.twitter.com')
stub_request(:post, endpoint + path)
end
-def stub_put(path, endpoint=Twitter.endpoint)
+def stub_put(path, endpoint='https://api.twitter.com')
stub_request(:put, endpoint + path)
end
View
34 spec/set_spec.rb
@@ -122,6 +122,40 @@
end
end
+ describe "#profile_background_image" do
+ before do
+ @set.options = @set.options.merge("profile" => fixture_path + "/.trc")
+ stub_post("/1/account/update_profile_background_image.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "should request the correct resource" do
+ @set.profile_background_image(fixture_path + "/we_concept_bg2.png")
+ a_post("/1/account/update_profile_background_image.json").
+ should have_been_made
+ end
+ it "should have the correct output" do
+ @set.profile_background_image(fixture_path + "/we_concept_bg2.png")
+ $stdout.string.chomp.should == "@testcli's background image has been updated."
+ end
+ end
+
+ describe "#profile_image" do
+ before do
+ @set.options = @set.options.merge("profile" => fixture_path + "/.trc")
+ stub_post("/1/account/update_profile_image.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "should request the correct resource" do
+ @set.profile_image(fixture_path + "/me.jpg")
+ a_post("/1/account/update_profile_image.json").
+ should have_been_made
+ end
+ it "should have the correct output" do
+ @set.profile_image(fixture_path + "/me.jpg")
+ $stdout.string.chomp.should == "@testcli's image has been updated."
+ end
+ end
+
describe "#url" do
before do
@set.options = @set.options.merge("profile" => fixture_path + "/.trc")
Please sign in to comment.
Something went wrong with that request. Please try again.