Skip to content

Commit

Permalink
Implement direct_message method
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Oct 16, 2011
1 parent a1dfa23 commit edd6f28
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/twitter/client/direct_messages.rb
Expand Up @@ -8,6 +8,7 @@ module DirectMessages
# Returns the 20 most recent direct messages sent to the authenticating user
#
# @see https://dev.twitter.com/docs/api/1/get/direct_messages
# @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
# @rate_limited Yes
# @requires_authentication Yes
# @param options [Hash] A customizable set of options.
Expand All @@ -29,6 +30,7 @@ def direct_messages(options={})
# Returns the 20 most recent direct messages sent by the authenticating user
#
# @see https://dev.twitter.com/docs/api/1/get/direct_messages/sent
# @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
# @rate_limited Yes
# @requires_authentication Yes
# @param options [Hash] A customizable set of options.
Expand All @@ -50,7 +52,7 @@ def direct_messages_sent(options={})
# Destroys a direct message
#
# @see https://dev.twitter.com/docs/api/1/post/direct_messages/destroy/:id
# @note The authenticating user must be the recipient of the specified direct message.
# @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
# @rate_limited No
# @requires_authentication Yes
# @param id [Integer] The ID of the direct message to delete.
Expand Down Expand Up @@ -86,6 +88,22 @@ def direct_message_create(user, text, options={})
end
alias :d :direct_message_create

# Returns a single direct message, specified by id.
#
# @see https://dev.twitter.com/docs/api/1/get/direct_messages/show/%3Aid
# @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
# @rate_limited Yes
# @requires_authentication Yes
# @param id [Integer] The ID of the direct message to retrieve.
# @param options [Hash] A customizable set of options.
# @return [Twitter::DirectMessage] The requested message.
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @example Return the direct message with the id 1825786345
# Twitter.direct_message(1825786345)
def direct_message(id, options={})
direct_message = get("/1/direct_messages/show/#{id}.json", options)
Twitter::DirectMessage.new(direct_message)
end
end
end
end
17 changes: 17 additions & 0 deletions spec/twitter/client/direct_messages_spec.rb
Expand Up @@ -78,4 +78,21 @@
end
end

describe ".direct_message" do
before do
stub_get("/1/direct_messages/show/1825786345.json").
to_return(:body => fixture("direct_message.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should get the correct resource" do
@client.direct_message(1825786345)
a_get("/1/direct_messages/show/1825786345.json").
should have_been_made
end
it "should return the 20 most recent direct messages sent to the authenticating user" do
direct_messages = @client.direct_message(1825786345)
direct_messages.should be_an Twitter::DirectMessage
direct_messages.sender.name.should == "Erik Michaels-Ober"
end
end

end

0 comments on commit edd6f28

Please sign in to comment.