From e4a70152b1a6f00299d3b659497c02adb791c18f Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Mon, 10 Sep 2012 10:18:10 -0700 Subject: [PATCH] Remove media endpoint In API v1.1, Twitter::API#update_with_media uses the default endpoint. See: https://dev.twitter.com/discussions/10644?page=1#comment-22487 --- lib/twitter/api.rb | 2 +- lib/twitter/configurable.rb | 3 +-- lib/twitter/default.rb | 6 ------ spec/helper.rb | 32 +++++++++++++++---------------- spec/twitter/api/statuses_spec.rb | 12 ++++++------ spec/twitter/client_spec.rb | 5 ++--- 6 files changed, 26 insertions(+), 34 deletions(-) diff --git a/lib/twitter/api.rb b/lib/twitter/api.rb index a2a966683..f9139c51d 100644 --- a/lib/twitter/api.rb +++ b/lib/twitter/api.rb @@ -1961,7 +1961,7 @@ def update(status, options={}) # @example Update the authenticating user's status # Twitter.update_with_media("I'm tweeting with @gem!", File.new('my_awesome_pic.jpeg')) def update_with_media(status, media, options={}) - object_from_response(Twitter::Tweet, :post, "/1.1/statuses/update_with_media.json", options.merge('media[]' => media, 'status' => status), :endpoint => @media_endpoint) + object_from_response(Twitter::Tweet, :post, "/1.1/statuses/update_with_media.json", options.merge('media[]' => media, 'status' => status)) end # Returns the top 10 trending topics for a specific WOEID diff --git a/lib/twitter/configurable.rb b/lib/twitter/configurable.rb index a8ac93428..f0de9abca 100644 --- a/lib/twitter/configurable.rb +++ b/lib/twitter/configurable.rb @@ -3,7 +3,7 @@ module Twitter module Configurable attr_writer :consumer_key, :consumer_secret, :oauth_token, :oauth_token_secret - attr_accessor :endpoint, :media_endpoint, :connection_options, :identity_map, :middleware + attr_accessor :endpoint, :connection_options, :identity_map, :middleware class << self @@ -14,7 +14,6 @@ def keys :oauth_token, :oauth_token_secret, :endpoint, - :media_endpoint, :connection_options, :identity_map, :middleware, diff --git a/lib/twitter/default.rb b/lib/twitter/default.rb index 888a176d8..0cc6d522e 100644 --- a/lib/twitter/default.rb +++ b/lib/twitter/default.rb @@ -11,7 +11,6 @@ module Twitter module Default ENDPOINT = 'https://api.twitter.com' unless defined? ENDPOINT - MEDIA_ENDPOINT = 'https://upload.twitter.com' unless defined? MEDIA_ENDPOINT CONNECTION_OPTIONS = { :headers => { :accept => 'application/json', @@ -79,11 +78,6 @@ def endpoint ENDPOINT end - # @return [String] - def media_endpoint - MEDIA_ENDPOINT - end - # @return [Hash] def connection_options CONNECTION_OPTIONS diff --git a/spec/helper.rb b/spec/helper.rb index c25054f68..5f9a3155f 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -12,36 +12,36 @@ require 'timecop' require 'webmock/rspec' -def a_delete(path, endpoint='https://api.twitter.com') - a_request(:delete, endpoint + path) +def a_delete(path) + a_request(:delete, 'https://api.twitter.com' + path) end -def a_get(path, endpoint='https://api.twitter.com') - a_request(:get, endpoint + path) +def a_get(path) + a_request(:get, 'https://api.twitter.com' + path) end -def a_post(path, endpoint='https://api.twitter.com') - a_request(:post, endpoint + path) +def a_post(path) + a_request(:post, 'https://api.twitter.com' + path) end -def a_put(path, endpoint='https://api.twitter.com') - a_request(:put, endpoint + path) +def a_put(path) + a_request(:put, 'https://api.twitter.com' + path) end -def stub_delete(path, endpoint='https://api.twitter.com') - stub_request(:delete, endpoint + path) +def stub_delete(path) + stub_request(:delete, 'https://api.twitter.com' + path) end -def stub_get(path, endpoint='https://api.twitter.com') - stub_request(:get, endpoint + path) +def stub_get(path) + stub_request(:get, 'https://api.twitter.com' + path) end -def stub_post(path, endpoint='https://api.twitter.com') - stub_request(:post, endpoint + path) +def stub_post(path) + stub_request(:post, 'https://api.twitter.com' + path) end -def stub_put(path, endpoint='https://api.twitter.com') - stub_request(:put, endpoint + path) +def stub_put(path) + stub_request(:put, 'https://api.twitter.com' + path) end def fixture_path diff --git a/spec/twitter/api/statuses_spec.rb b/spec/twitter/api/statuses_spec.rb index af5077cab..286c369c8 100644 --- a/spec/twitter/api/statuses_spec.rb +++ b/spec/twitter/api/statuses_spec.rb @@ -510,13 +510,13 @@ describe "#update_with_media" do before do - stub_post("/1.1/statuses/update_with_media.json", "https://upload.twitter.com"). + stub_post("/1.1/statuses/update_with_media.json"). to_return(:body => fixture("status_with_media.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end context "a gif image" do it "requests the correct resource" do @client.update_with_media("You always have options", fixture("pbjt.gif")) - a_post("/1.1/statuses/update_with_media.json", "https://upload.twitter.com"). + a_post("/1.1/statuses/update_with_media.json"). should have_been_made end it "returns a Tweet" do @@ -528,28 +528,28 @@ context "a jpe image" do it "requests the correct resource" do @client.update_with_media("You always have options", fixture("wildcomet2.jpe")) - a_post("/1.1/statuses/update_with_media.json", "https://upload.twitter.com"). + a_post("/1.1/statuses/update_with_media.json"). should have_been_made end end context "a jpeg image" do it "requests the correct resource" do @client.update_with_media("You always have options", fixture("me.jpeg")) - a_post("/1.1/statuses/update_with_media.json", "https://upload.twitter.com"). + a_post("/1.1/statuses/update_with_media.json"). should have_been_made end end context "a png image" do it "requests the correct resource" do @client.update_with_media("You always have options", fixture("we_concept_bg2.png")) - a_post("/1.1/statuses/update_with_media.json", "https://upload.twitter.com"). + a_post("/1.1/statuses/update_with_media.json"). should have_been_made end end context "a Tempfile" do it "requests the correct resource" do @client.update_with_media("You always have options", Tempfile.new("tmp")) - a_post("/1.1/statuses/update_with_media.json", "https://upload.twitter.com"). + a_post("/1.1/statuses/update_with_media.json"). should have_been_made end end diff --git a/spec/twitter/client_spec.rb b/spec/twitter/client_spec.rb index 824459c7e..94ac362e6 100644 --- a/spec/twitter/client_spec.rb +++ b/spec/twitter/client_spec.rb @@ -37,7 +37,6 @@ :consumer_key => 'CK', :consumer_secret => 'CS', :endpoint => 'http://tumblr.com/', - :media_endpoint => 'http://upload.twitter.com', :middleware => Proc.new{}, :oauth_token => 'OT', :oauth_token_secret => 'OS', @@ -140,10 +139,10 @@ should have_been_made end it "encodes none of the body when uploaded media is present" do - stub_post("/1.1/statuses/update_with_media.json", "https://upload.twitter.com"). + stub_post("/1.1/statuses/update_with_media.json"). to_return(:body => fixture("status_with_media.json"), :headers => {:content_type => "application/json; charset=utf-8"}) subject.update_with_media("Update", fixture("pbjt.gif")) - a_post("/1.1/statuses/update_with_media.json", "https://upload.twitter.com"). + a_post("/1.1/statuses/update_with_media.json"). should have_been_made end it "catches Faraday errors" do