Skip to content

Commit

Permalink
Remove media endpoint
Browse files Browse the repository at this point in the history
In API v1.1, Twitter::API#update_with_media uses the default endpoint.

See: https://dev.twitter.com/discussions/10644?page=1#comment-22487
  • Loading branch information
sferik committed Sep 17, 2012
1 parent 3a4be52 commit e4a7015
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 34 deletions.
2 changes: 1 addition & 1 deletion lib/twitter/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/twitter/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -14,7 +14,6 @@ def keys
:oauth_token,
:oauth_token_secret,
:endpoint,
:media_endpoint,
:connection_options,
:identity_map,
:middleware,
Expand Down
6 changes: 0 additions & 6 deletions lib/twitter/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -79,11 +78,6 @@ def endpoint
ENDPOINT
end

# @return [String]
def media_endpoint
MEDIA_ENDPOINT
end

# @return [Hash]
def connection_options
CONNECTION_OPTIONS
Expand Down
32 changes: 16 additions & 16 deletions spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions spec/twitter/api/statuses_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions spec/twitter/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e4a7015

Please sign in to comment.