t 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/t/cli.rb +8 -2
- data/lib/t/rcfile.rb +18 -1
- data/lib/t/set.rb +17 -2
- data/lib/t/version.rb +2 -2
- data/spec/cli_spec.rb +28 -2
- data/spec/fixtures/{xml.gp → geoplugin.xml} +0 -0
- data/spec/fixtures/long.png +0 -0
- data/spec/fixtures/me.jpg +0 -0
- data/spec/fixtures/we_concept_bg2.png +0 -0
- data/spec/helper.rb +8 -8
- data/spec/set_spec.rb +54 -2
- metadata +10 -4
data/lib/t/cli.rb
CHANGED
@@ -608,8 +608,9 @@ module T
|
|
608
608
|
map %w(rts) => :retweets
|
609
609
|
|
610
610
|
desc "ruler", "Prints a 140-character ruler"
|
611
|
+
method_option "indent", :aliases => "-i", :type => :numeric, :default => 0, :desc => "The number of space to print before the ruler."
|
611
612
|
def ruler
|
612
|
-
say "----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|"
|
613
|
+
say "#{' ' * options['indent'].to_i}----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|"
|
613
614
|
end
|
614
615
|
|
615
616
|
desc "status STATUS_ID", "Retrieves detailed information about a Tweet."
|
@@ -752,10 +753,15 @@ module T
|
|
752
753
|
|
753
754
|
desc "update MESSAGE", "Post a Tweet."
|
754
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."
|
755
757
|
def update(message)
|
756
758
|
opts = {:trim_user => true}
|
757
759
|
opts.merge!(:lat => location.lat, :long => location.lng) if options['location']
|
758
|
-
status =
|
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
|
759
765
|
say "Tweet posted by @#{@rcfile.active_profile[0]}."
|
760
766
|
say
|
761
767
|
say "Run `#{File.basename($0)} delete status #{status.id}` to delete."
|
data/lib/t/rcfile.rb
CHANGED
@@ -12,7 +12,24 @@ module T
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def [](username)
|
15
|
-
profiles[username]
|
15
|
+
profiles[find(username)]
|
16
|
+
end
|
17
|
+
|
18
|
+
def find(username)
|
19
|
+
possibilities = Array(find_case_insensitive_match(username) || find_case_insensitive_possibilities(username))
|
20
|
+
if possibilities.size == 1
|
21
|
+
possibilities.first
|
22
|
+
else
|
23
|
+
raise ArgumentError, "Username #{username} is #{possibilities.size < 1 ? 'not found.' : 'ambiguous, matching ' + possibilities.join(', ')}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def find_case_insensitive_match(username)
|
28
|
+
profiles.keys.detect { |u| username.downcase == u.downcase }
|
29
|
+
end
|
30
|
+
|
31
|
+
def find_case_insensitive_possibilities(username)
|
32
|
+
profiles.keys.select { |u| username.downcase == u.downcase[0, username.length] }
|
16
33
|
end
|
17
34
|
|
18
35
|
def []=(username, profile)
|
data/lib/t/set.rb
CHANGED
@@ -19,8 +19,8 @@ module T
|
|
19
19
|
screen_name = screen_name.strip_ats
|
20
20
|
@rcfile.path = options['profile'] if options['profile']
|
21
21
|
consumer_key = @rcfile[screen_name].keys.last if consumer_key.nil?
|
22
|
-
@rcfile.active_profile = {'username' => screen_name, 'consumer_key' => consumer_key}
|
23
|
-
say "Active account has been updated."
|
22
|
+
@rcfile.active_profile = {'username' => @rcfile[screen_name][consumer_key]["username"], 'consumer_key' => consumer_key}
|
23
|
+
say "Active account has been updated to #{@rcfile.active_profile[0]}."
|
24
24
|
end
|
25
25
|
map %w(default) => :active
|
26
26
|
|
@@ -48,6 +48,21 @@ module T
|
|
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)
|
data/lib/t/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
@@ -2357,7 +2357,7 @@ Hourly limit,Remaining hits,Reset time
|
|
2357
2357
|
stub_request(:get, "http://checkip.dyndns.org/").
|
2358
2358
|
to_return(:body => fixture("checkip.html"), :headers => {:content_type => "text/html"})
|
2359
2359
|
stub_request(:get, "http://www.geoplugin.net/xml.gp?ip=50.131.22.169").
|
2360
|
-
to_return(:body => fixture("xml
|
2360
|
+
to_return(:body => fixture("geoplugin.xml"), :headers => {:content_type => "application/xml"})
|
2361
2361
|
end
|
2362
2362
|
it "should request the correct resource" do
|
2363
2363
|
@cli.reply("55709764298092545", "Testing")
|
@@ -2705,6 +2705,16 @@ ID Posted at Screen name Text
|
|
2705
2705
|
$stdout.string.chomp.size.should == 140
|
2706
2706
|
$stdout.string.chomp.should == "----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|"
|
2707
2707
|
end
|
2708
|
+
context "with indentation" do
|
2709
|
+
before do
|
2710
|
+
@cli.options = @cli.options.merge("indent" => 2)
|
2711
|
+
end
|
2712
|
+
it "should have the correct output" do
|
2713
|
+
@cli.ruler
|
2714
|
+
$stdout.string.chomp.size.should == 142
|
2715
|
+
$stdout.string.chomp.should == " ----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|"
|
2716
|
+
end
|
2717
|
+
end
|
2708
2718
|
end
|
2709
2719
|
|
2710
2720
|
describe "#status" do
|
@@ -3485,7 +3495,7 @@ WOEID Parent ID Type Name Country
|
|
3485
3495
|
stub_request(:get, "http://checkip.dyndns.org/").
|
3486
3496
|
to_return(:body => fixture("checkip.html"), :headers => {:content_type => "text/html"})
|
3487
3497
|
stub_request(:get, "http://www.geoplugin.net/xml.gp?ip=50.131.22.169").
|
3488
|
-
to_return(:body => fixture("xml
|
3498
|
+
to_return(:body => fixture("geoplugin.xml"), :headers => {:content_type => "application/xml"})
|
3489
3499
|
end
|
3490
3500
|
it "should request the correct resource" do
|
3491
3501
|
@cli.update("Testing")
|
@@ -3501,6 +3511,22 @@ WOEID Parent ID Type Name Country
|
|
3501
3511
|
@cli.update("Testing")
|
3502
3512
|
$stdout.string.split("\n").first.should == "Tweet posted by @testcli."
|
3503
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
|
3504
3530
|
end
|
3505
3531
|
|
3506
3532
|
describe "#users" do
|
File without changes
|
Binary file
|
Binary file
|
Binary file
|
data/spec/helper.rb
CHANGED
@@ -12,35 +12,35 @@ require 'rspec'
|
|
12
12
|
require 'timecop'
|
13
13
|
require 'webmock/rspec'
|
14
14
|
|
15
|
-
def a_delete(path, 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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
43
|
+
def stub_put(path, endpoint='https://api.twitter.com')
|
44
44
|
stub_request(:put, endpoint + path)
|
45
45
|
end
|
46
46
|
|
data/spec/set_spec.rb
CHANGED
@@ -20,11 +20,29 @@ describe T::Set do
|
|
20
20
|
|
21
21
|
describe "#active" do
|
22
22
|
before do
|
23
|
-
@set.options = @set.options.merge("profile" => fixture_path + "/.
|
23
|
+
@set.options = @set.options.merge("profile" => fixture_path + "/.trc_set")
|
24
24
|
end
|
25
25
|
it "should have the correct output" do
|
26
26
|
@set.active("testcli", "abc123")
|
27
|
-
$stdout.string.chomp.should == "Active account has been updated."
|
27
|
+
$stdout.string.chomp.should == "Active account has been updated to testcli."
|
28
|
+
end
|
29
|
+
it "should accept an account name without a consumer key" do
|
30
|
+
@set.active("testcli")
|
31
|
+
$stdout.string.chomp.should == "Active account has been updated to testcli."
|
32
|
+
end
|
33
|
+
it "should be case insensitive" do
|
34
|
+
@set.active("TestCLI", "abc123")
|
35
|
+
$stdout.string.chomp.should == "Active account has been updated to testcli."
|
36
|
+
end
|
37
|
+
it "should raise an error if username is ambiguous" do
|
38
|
+
lambda do
|
39
|
+
@set.active("test", "abc123")
|
40
|
+
end.should raise_error(ArgumentError, /Username test is ambiguous/)
|
41
|
+
end
|
42
|
+
it "should raise an error if the username is not found" do
|
43
|
+
lambda do
|
44
|
+
@set.active("clitest")
|
45
|
+
end.should raise_error(ArgumentError, /Username clitest is not found/)
|
28
46
|
end
|
29
47
|
end
|
30
48
|
|
@@ -104,6 +122,40 @@ describe T::Set do
|
|
104
122
|
end
|
105
123
|
end
|
106
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
|
+
|
107
159
|
describe "#url" do
|
108
160
|
before do
|
109
161
|
@set.options = @set.options.merge("profile" => fixture_path + "/.trc")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: t
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: launchy
|
@@ -315,9 +315,12 @@ files:
|
|
315
315
|
- spec/fixtures/followers_ids.json
|
316
316
|
- spec/fixtures/friends_ids.json
|
317
317
|
- spec/fixtures/gem.json
|
318
|
+
- spec/fixtures/geoplugin.xml
|
318
319
|
- spec/fixtures/list.json
|
319
320
|
- spec/fixtures/lists.json
|
320
321
|
- spec/fixtures/locations.json
|
322
|
+
- spec/fixtures/long.png
|
323
|
+
- spec/fixtures/me.jpg
|
321
324
|
- spec/fixtures/not_found.json
|
322
325
|
- spec/fixtures/rate_limit_status.json
|
323
326
|
- spec/fixtures/recommendations.json
|
@@ -337,7 +340,7 @@ files:
|
|
337
340
|
- spec/fixtures/true.json
|
338
341
|
- spec/fixtures/users.json
|
339
342
|
- spec/fixtures/users_list.json
|
340
|
-
- spec/fixtures/
|
343
|
+
- spec/fixtures/we_concept_bg2.png
|
341
344
|
- spec/helper.rb
|
342
345
|
- spec/list_spec.rb
|
343
346
|
- spec/rcfile_spec.rb
|
@@ -384,9 +387,12 @@ test_files:
|
|
384
387
|
- spec/fixtures/followers_ids.json
|
385
388
|
- spec/fixtures/friends_ids.json
|
386
389
|
- spec/fixtures/gem.json
|
390
|
+
- spec/fixtures/geoplugin.xml
|
387
391
|
- spec/fixtures/list.json
|
388
392
|
- spec/fixtures/lists.json
|
389
393
|
- spec/fixtures/locations.json
|
394
|
+
- spec/fixtures/long.png
|
395
|
+
- spec/fixtures/me.jpg
|
390
396
|
- spec/fixtures/not_found.json
|
391
397
|
- spec/fixtures/rate_limit_status.json
|
392
398
|
- spec/fixtures/recommendations.json
|
@@ -406,7 +412,7 @@ test_files:
|
|
406
412
|
- spec/fixtures/true.json
|
407
413
|
- spec/fixtures/users.json
|
408
414
|
- spec/fixtures/users_list.json
|
409
|
-
- spec/fixtures/
|
415
|
+
- spec/fixtures/we_concept_bg2.png
|
410
416
|
- spec/helper.rb
|
411
417
|
- spec/list_spec.rb
|
412
418
|
- spec/rcfile_spec.rb
|