Skip to content
This repository
Browse code

Add support for images

Closes #57.
  • Loading branch information...
commit 155a56d575cea679dcfed4731ac29c858b775eaf 1 parent 01c8cd4
Erik Michaels-Ober authored
7 lib/t/cli.rb
@@ -753,10 +753,15 @@ def unfollow(user, *users)
753 753
754 754 desc "update MESSAGE", "Post a Tweet."
755 755 method_option "location", :aliases => "-l", :type => :boolean, :default => false
  756 + method_option "file", :aliases => "-f", :type => :string, :desc => "The path to an image to attach to your tweet."
756 757 def update(message)
757 758 opts = {:trim_user => true}
758 759 opts.merge!(:lat => location.lat, :long => location.lng) if options['location']
759   - status = client.update(message, opts)
  760 + status = if options['file']
  761 + client.update_with_media(message, File.new(File.expand_path(options['file'])), opts)
  762 + else
  763 + client.update(message, opts)
  764 + end
760 765 say "Tweet posted by @#{@rcfile.active_profile[0]}."
761 766 say
762 767 say "Run `#{File.basename($0)} delete status #{status.id}` to delete."
15 lib/t/set.rb
@@ -48,6 +48,21 @@ def name(name)
48 48 say "@#{@rcfile.active_profile[0]}'s name has been updated."
49 49 end
50 50
  51 + desc "profile_background_image FILE", "Sets the background image on your Twitter profile."
  52 + method_option "tile", :aliases => "-t", :type => :boolean, :default => false, :desc => "Whether or not to tile the background image."
  53 + def profile_background_image(file)
  54 + client.update_profile_background_image(File.new(File.expand_path(file)), :tile => options['tile'], :skip_status => true)
  55 + say "@#{@rcfile.active_profile[0]}'s background image has been updated."
  56 + end
  57 + map %w(background background_image) => :profile_background_image
  58 +
  59 + desc "profile_image FILE", "Sets the image on your Twitter profile."
  60 + def profile_image(file)
  61 + client.update_profile_image(File.new(File.expand_path(file)))
  62 + say "@#{@rcfile.active_profile[0]}'s image has been updated."
  63 + end
  64 + map %w(avatar image) => :profile_image
  65 +
51 66 desc "url URL", "Sets the URL field on your profile."
52 67 def url(url)
53 68 client.update_profile(:url => url)
16 spec/cli_spec.rb
@@ -3511,6 +3511,22 @@
3511 3511 @cli.update("Testing")
3512 3512 $stdout.string.split("\n").first.should == "Tweet posted by @testcli."
3513 3513 end
  3514 + context "with file" do
  3515 + before do
  3516 + @cli.options = @cli.options.merge("file" => fixture_path + "/long.png")
  3517 + stub_post("/1/statuses/update_with_media.json", "https://upload.twitter.com").
  3518 + to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
  3519 + end
  3520 + it "should request the correct resource" do
  3521 + @cli.update("Testing")
  3522 + a_post("/1/statuses/update_with_media.json", "https://upload.twitter.com").
  3523 + should have_been_made
  3524 + end
  3525 + it "should have the correct output" do
  3526 + @cli.update("Testing")
  3527 + $stdout.string.split("\n").first.should == "Tweet posted by @testcli."
  3528 + end
  3529 + end
3514 3530 end
3515 3531
3516 3532 describe "#users" do
BIN  spec/fixtures/long.png
BIN  spec/fixtures/me.jpg
BIN  spec/fixtures/we_concept_bg2.png
16 spec/helper.rb
@@ -12,35 +12,35 @@
12 12 require 'timecop'
13 13 require 'webmock/rspec'
14 14
15   -def a_delete(path, endpoint=Twitter.endpoint)
  15 +def a_delete(path, endpoint='https://api.twitter.com')
16 16 a_request(:delete, endpoint + path)
17 17 end
18 18
19   -def a_get(path, endpoint=Twitter.endpoint)
  19 +def a_get(path, endpoint='https://api.twitter.com')
20 20 a_request(:get, endpoint + path)
21 21 end
22 22
23   -def a_post(path, endpoint=Twitter.endpoint)
  23 +def a_post(path, endpoint='https://api.twitter.com')
24 24 a_request(:post, endpoint + path)
25 25 end
26 26
27   -def a_put(path, endpoint=Twitter.endpoint)
  27 +def a_put(path, endpoint='https://api.twitter.com')
28 28 a_request(:put, endpoint + path)
29 29 end
30 30
31   -def stub_delete(path, endpoint=Twitter.endpoint)
  31 +def stub_delete(path, endpoint='https://api.twitter.com')
32 32 stub_request(:delete, endpoint + path)
33 33 end
34 34
35   -def stub_get(path, endpoint=Twitter.endpoint)
  35 +def stub_get(path, endpoint='https://api.twitter.com')
36 36 stub_request(:get, endpoint + path)
37 37 end
38 38
39   -def stub_post(path, endpoint=Twitter.endpoint)
  39 +def stub_post(path, endpoint='https://api.twitter.com')
40 40 stub_request(:post, endpoint + path)
41 41 end
42 42
43   -def stub_put(path, endpoint=Twitter.endpoint)
  43 +def stub_put(path, endpoint='https://api.twitter.com')
44 44 stub_request(:put, endpoint + path)
45 45 end
46 46
34 spec/set_spec.rb
@@ -122,6 +122,40 @@
122 122 end
123 123 end
124 124
  125 + describe "#profile_background_image" do
  126 + before do
  127 + @set.options = @set.options.merge("profile" => fixture_path + "/.trc")
  128 + stub_post("/1/account/update_profile_background_image.json").
  129 + to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
  130 + end
  131 + it "should request the correct resource" do
  132 + @set.profile_background_image(fixture_path + "/we_concept_bg2.png")
  133 + a_post("/1/account/update_profile_background_image.json").
  134 + should have_been_made
  135 + end
  136 + it "should have the correct output" do
  137 + @set.profile_background_image(fixture_path + "/we_concept_bg2.png")
  138 + $stdout.string.chomp.should == "@testcli's background image has been updated."
  139 + end
  140 + end
  141 +
  142 + describe "#profile_image" do
  143 + before do
  144 + @set.options = @set.options.merge("profile" => fixture_path + "/.trc")
  145 + stub_post("/1/account/update_profile_image.json").
  146 + to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
  147 + end
  148 + it "should request the correct resource" do
  149 + @set.profile_image(fixture_path + "/me.jpg")
  150 + a_post("/1/account/update_profile_image.json").
  151 + should have_been_made
  152 + end
  153 + it "should have the correct output" do
  154 + @set.profile_image(fixture_path + "/me.jpg")
  155 + $stdout.string.chomp.should == "@testcli's image has been updated."
  156 + end
  157 + end
  158 +
125 159 describe "#url" do
126 160 before do
127 161 @set.options = @set.options.merge("profile" => fixture_path + "/.trc")

0 comments on commit 155a56d

Please sign in to comment.
Something went wrong with that request. Please try again.