Skip to content

Commit df4e2a8

Browse files
committed
Fix to default location
1 parent ab4b93b commit df4e2a8

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

lib/t/cli.rb

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ def open(user)
521521

522522
desc "reply TWEET_ID MESSAGE", "Post your Tweet as a reply directed at another person."
523523
method_option "all", :aliases => "-a", :type => :boolean, :default => false, :desc => "Reply to all users mentioned in the Tweet."
524-
method_option "location", :aliases => "-l", :type => :string, :default => nil, :desc => "Add location information. If the optional 'latitude,longitude' parameter is not supplied, looks up location by IP address."
524+
method_option "location", :aliases => "-l", :type => :string, :default => "location", :desc => "Add location information. If the optional 'latitude,longitude' parameter is not supplied, looks up location by IP address."
525525
def reply(status_id, message)
526526
status = client.status(status_id.to_i, :include_my_retweet => false)
527527
users = Array(status.from_user)
@@ -532,7 +532,7 @@ def reply(status_id, message)
532532
require 't/core_ext/string'
533533
users.map!(&:prepend_at)
534534
opts = {:in_reply_to_status_id => status.id, :trim_user => true}
535-
opts = add_location(options, opts)
535+
add_location!(options, opts)
536536
reply = client.update("#{users.join(' ')} #{message}", opts)
537537
say "Reply posted by @#{@rcfile.active_profile[0]} to #{users.join(' ')}."
538538
say
@@ -739,13 +739,12 @@ def unfollow(user, *users)
739739
end
740740

741741
desc "update [MESSAGE]", "Post a Tweet."
742-
method_option "location", :aliases => "-l", :type => :string, :default => nil, :desc => "Add location information. If the optional 'latitude,longitude' parameter is not supplied, looks up location by IP address."
742+
method_option "location", :aliases => "-l", :type => :string, :default => "location", :desc => "Add location information. If the optional 'latitude,longitude' parameter is not supplied, looks up location by IP address."
743743
method_option "file", :aliases => "-f", :type => :string, :desc => "The path to an image to attach to your tweet."
744744
def update(message=nil)
745745
message = T::Editor.gets if message.nil? || message.empty?
746746
opts = {:trim_user => true}
747-
opts = add_location(options, opts)
748-
747+
add_location!(options, opts)
749748
status = if options['file']
750749
client.update_with_media(message, File.new(File.expand_path(options['file'])), opts)
751750
else
@@ -870,14 +869,11 @@ def pin_auth_parameters
870869
{:oauth_callback => 'oob'}
871870
end
872871

873-
def add_location(options, opts)
874-
unless options['location'].nil?
875-
lat, lng = options['location'].strip.empty? ?
876-
[location.lat, location.lng] :
877-
options['location'].split(',').map(&:to_f)
872+
def add_location!(options, opts)
873+
if options['location']
874+
lat, lng = options['location'] == 'location' ? [location.lat, location.lng] : options['location'].split(',').map(&:to_f)
878875
opts.merge!(:lat => lat, :long => lng)
879876
end
880-
opts
881877
end
882878

883879
def location

spec/cli_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,7 +2048,7 @@
20482048
end
20492049
context "--location" do
20502050
before do
2051-
@cli.options = @cli.options.merge("location" => '')
2051+
@cli.options = @cli.options.merge("location" => "location")
20522052
stub_get("/1.1/statuses/show/263813522369159169.json").with(:query => {:include_my_retweet => "false"}).to_return(:body => fixture("status_with_mention.json"))
20532053
stub_post("/1.1/statuses/update.json").with(:body => {:in_reply_to_status_id => "263813522369159169", :status => "@joshfrench Testing", :lat => "37.76969909668", :long => "-122.39330291748", :trim_user => "true"}).to_return(:body => fixture("status.json"))
20542054
end
@@ -3087,9 +3087,9 @@
30873087
expect($stdout.string.split("\n").first).to eq "Tweet posted by @testcli."
30883088
end
30893089
end
3090-
context "with just location" do
3090+
context "--location" do
30913091
before do
3092-
@cli.options = @cli.options.merge("location" => '')
3092+
@cli.options = @cli.options.merge("location" => "location")
30933093
stub_post("/1.1/statuses/update.json").with(:body => {:status => "Testing", :lat => "37.76969909668", :long => "-122.39330291748", :trim_user => "true"}).to_return(:body => fixture("status.json"))
30943094
end
30953095
it "requests the correct resource" do
@@ -3103,7 +3103,7 @@
31033103
expect($stdout.string.split("\n").first).to eq "Tweet posted by @testcli."
31043104
end
31053105
end
3106-
context "with location, latitude and longitude" do
3106+
context "--location 'latitude,longitude'" do
31073107
before do
31083108
@cli.options = @cli.options.merge("location" => "41.03132,28.9869")
31093109
stub_post("/1.1/statuses/update.json").with(:body => {:status => "Testing", :lat => "41.03132", :long => "28.9869", :trim_user => "true"}).to_return(:body => fixture("status.json"))

0 commit comments

Comments
 (0)