Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
Backport to 1.8.
Browse files Browse the repository at this point in the history
  • Loading branch information
rummelonp committed Jan 8, 2012
1 parent 9be202e commit 69d356e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 48 deletions.
3 changes: 2 additions & 1 deletion lib/tumblife/client.rb
Expand Up @@ -37,7 +37,8 @@ class Client < API
send http_method, path % args, params
end
else
define_method method_name do |params = {}|
define_method method_name do |*args|
params = args.first || {}
send http_method, path, params
end
end
Expand Down
14 changes: 7 additions & 7 deletions spec/tumblife/api_spec.rb
Expand Up @@ -5,12 +5,12 @@
describe Tumblife::API do
def create_response(status, msg)
Hashie::Mash.new({
body: {
meta: {
status: status,
msg: msg
:body => {
:meta => {
:status => status,
:msg => msg
},
response: {}
:response => {}
}.to_json
})
end
Expand All @@ -27,13 +27,13 @@ def create_response(status, msg)
it 'should get' do
@api.should_receive(:access_token).and_return(@token)
@token.should_receive(:get).with('/path/to?key1=param1&key2=param2', @api.header).and_return(create_response(200, 'OK'))
@api.get('/path/to', key1: 'param1', key2: 'param2')
@api.get('/path/to', :key1 => 'param1', :key2 => 'param2')
end

it 'should post' do
@api.should_receive(:access_token).and_return(@token)
@token.should_receive(:post).with('/path/to', {'key1' => 'param1', 'key2' => 'param2'}, @api.header).and_return(create_response(200, 'OK'))
@api.post('/path/to', key1: 'param1', key2: 'param2')
@api.post('/path/to', :key1 => 'param1', :key2 => 'param2')
end
end

Expand Down
80 changes: 40 additions & 40 deletions spec/tumblife/client_spec.rb
Expand Up @@ -16,29 +16,29 @@

context :api do
it 'should respond to info' do
@client.should_receive(:get).with('/v2/blog/mitukiii.tumblr.com/info', api_key: @api_key)
@client.should_receive(:get).with('/v2/blog/mitukiii.tumblr.com/info', :api_key => @api_key)
@client.info 'mitukiii.tumblr.com'
end

it 'should respond to avatar' do
@client.should_receive(:get).with('/v2/blog/mitukiii.tumblr.com/avatar', {})
@client.avatar 'mitukiii.tumblr.com'
@client.should_receive(:get).with('/v2/blog/mitukiii.tumblr.com/avatar', size: 512)
@client.avatar 'mitukiii.tumblr.com', size: 512
@client.should_receive(:get).with('/v2/blog/mitukiii.tumblr.com/avatar', :size => 512)
@client.avatar 'mitukiii.tumblr.com', :size => 512
end

it 'should respond to followers' do
@client.should_receive(:get).with('/v2/blog/mitukiii.tumblr.com/followers', {})
@client.followers 'mitukiii.tumblr.com'
@client.should_receive(:get).with('/v2/blog/mitukiii.tumblr.com/followers', limit: 10)
@client.followers 'mitukiii.tumblr.com', limit: 10
@client.should_receive(:get).with('/v2/blog/mitukiii.tumblr.com/followers', :limit => 10)
@client.followers 'mitukiii.tumblr.com', :limit => 10
end

it 'should respond to posts' do
@client.should_receive(:get).with('/v2/blog/mitukiii.tumblr.com/posts', api_key: @api_key)
@client.should_receive(:get).with('/v2/blog/mitukiii.tumblr.com/posts', :api_key => @api_key)
@client.posts 'mitukiii.tumblr.com'
@client.should_receive(:get).with('/v2/blog/mitukiii.tumblr.com/posts', api_key: @api_key, type: :photo)
@client.posts 'mitukiii.tumblr.com', type: :photo
@client.should_receive(:get).with('/v2/blog/mitukiii.tumblr.com/posts', :api_key => @api_key, :type => :photo)
@client.posts 'mitukiii.tumblr.com', :type => :photo
end

it 'should respond to queue' do
Expand All @@ -57,68 +57,68 @@
end

it 'should respond to create_post' do
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post', type: :text, body: 'text')
@client.create_post 'mitukiii.tumblr.com', type: :text, body: 'text'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post', type: :photo, source: 'http://example.com/photo.png')
@client.create_post 'mitukiii.tumblr.com', type: :photo, source: 'http://example.com/photo.png'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post', type: :quote, quote: 'quote')
@client.create_post 'mitukiii.tumblr.com', type: :quote, quote: 'quote'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post', type: :link, url: 'http://example.com/')
@client.create_post 'mitukiii.tumblr.com', type: :link, url: 'http://example.com/'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post', type: :chat, conversation: 'conversation')
@client.create_post 'mitukiii.tumblr.com', type: :chat, conversation: 'conversation'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post', type: :audio, external_url: 'http://example.com/audio.mp3')
@client.create_post 'mitukiii.tumblr.com', type: :audio, external_url: 'http://example.com/audio.mp3'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post', type: :video, embed: '<embed>code</embed>')
@client.create_post 'mitukiii.tumblr.com', type: :video, embed: '<embed>code</embed>'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post', :type => :text, :body => 'text')
@client.create_post 'mitukiii.tumblr.com', :type => :text, :body => 'text'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post', :type => :photo, :source => 'http://example.com/photo.png')
@client.create_post 'mitukiii.tumblr.com', :type => :photo, :source => 'http://example.com/photo.png'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post', :type => :quote, :quote => 'quote')
@client.create_post 'mitukiii.tumblr.com', :type => :quote, :quote => 'quote'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post', :type => :link, :url => 'http://example.com/')
@client.create_post 'mitukiii.tumblr.com', :type => :link, :url => 'http://example.com/'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post', :type => :chat, :conversation => 'conversation')
@client.create_post 'mitukiii.tumblr.com', :type => :chat, :conversation => 'conversation'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post', :type => :audio, :external_url => 'http://example.com/audio.mp3')
@client.create_post 'mitukiii.tumblr.com', :type => :audio, :external_url => 'http://example.com/audio.mp3'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post', :type => :video, :embed => '<embed>code</embed>')
@client.create_post 'mitukiii.tumblr.com', :type => :video, :embed => '<embed>code</embed>'
end

it 'should respond to edit_post' do
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post/edit', id: 123456789, type: :text, body: 'new text')
@client.edit_post 'mitukiii.tumblr.com', id: 123456789, type: :text, body: 'new text'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post/edit', :id => 123456789, :type => :text, :body => 'new text')
@client.edit_post 'mitukiii.tumblr.com', :id => 123456789, :type => :text, :body => 'new text'
end

it 'should respond to reblog' do
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post/reblog', id: 123456789, reblog_key: 'abcdefg')
@client.reblog_post 'mitukiii.tumblr.com', id: 123456789, reblog_key: 'abcdefg'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post/reblog', id: 123456789, reblog_key: 'abcdefg', comment: 'comment')
@client.reblog_post 'mitukiii.tumblr.com', id: 123456789, reblog_key: 'abcdefg', comment: 'comment'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post/reblog', :id => 123456789, :reblog_key => 'abcdefg')
@client.reblog_post 'mitukiii.tumblr.com', :id => 123456789, :reblog_key => 'abcdefg'
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post/reblog', :id => 123456789, :reblog_key => 'abcdefg', :comment => 'comment')
@client.reblog_post 'mitukiii.tumblr.com', :id => 123456789, :reblog_key => 'abcdefg', :comment => 'comment'
end

it 'should respond to delete' do
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post/delete', id: 123456789)
@client.delete_post 'mitukiii.tumblr.com', id: 123456789
@client.should_receive(:post).with('/v2/blog/mitukiii.tumblr.com/post/delete', :id => 123456789)
@client.delete_post 'mitukiii.tumblr.com', :id => 123456789
end

it 'should respond to dashboard' do
@client.should_receive(:get).with('/v2/user/dashboard', {})
@client.dashboard
@client.should_receive(:get).with('/v2/user/dashboard', type: :photo)
@client.dashboard type: :photo
@client.should_receive(:get).with('/v2/user/dashboard', :type => :photo)
@client.dashboard :type => :photo
end

it 'should respond to likes' do
@client.should_receive(:get).with('/v2/user/likes', {})
@client.likes
@client.should_receive(:get).with('/v2/user/likes', limit: 10)
@client.likes limit: 10
@client.should_receive(:get).with('/v2/user/likes', :limit => 10)
@client.likes :limit => 10
end

it 'should respond to following' do
@client.should_receive(:get).with('/v2/user/following', {})
@client.following
@client.should_receive(:get).with('/v2/user/following', limit: 10)
@client.following limit: 10
@client.should_receive(:get).with('/v2/user/following', :limit => 10)
@client.following :limit => 10
end

it 'should respond to follow' do
@client.should_receive(:post).with('/v2/user/follow', url: 'mitukiii.tumblr.com')
@client.follow url: 'mitukiii.tumblr.com'
@client.should_receive(:post).with('/v2/user/follow', :url => 'mitukiii.tumblr.com')
@client.follow :url => 'mitukiii.tumblr.com'
end

it 'should respond to unfollow' do
@client.should_receive(:post).with('/v2/user/unfollow', url: 'mitukiii.tumblr.com')
@client.unfollow url: 'mitukiii.tumblr.com'
@client.should_receive(:post).with('/v2/user/unfollow', :url => 'mitukiii.tumblr.com')
@client.unfollow :url => 'mitukiii.tumblr.com'
end

it 'should respond to info_user' do
Expand Down

0 comments on commit 69d356e

Please sign in to comment.