Permalink
Browse files

added d method for sending direct messages (jnewland)

git-svn-id: http://svn.addictedtonew.com/public/gems/twitter@73 fe7eae16-9a24-0410-a59d-9e59979e88be
  • Loading branch information...
1 parent 3025791 commit 139a820de0bcc97ece7e33435535985555231bc8 jnunemaker committed Jun 22, 2007
Showing with 12 additions and 12 deletions.
  1. +1 −0 CHANGELOG
  2. +11 −12 lib/twitter/base.rb
View
@@ -1,4 +1,5 @@
0.1.2 - to be released soon
+ * implemented d method to send direct messages (jnewland)
* fixed since argument in direct_messages method (jnewland)
0.1.1 - May 20, 2007
* hpricot 0.5+ now supported; just a bug fix (Ryan Waldron is the man!)
View
@@ -65,18 +65,17 @@ def direct_messages(since=nil)
(doc/:direct_message).inject([]) { |dms, dm| dms << DirectMessage.new_from_xml(dm); dms }
end
- # This api methods doesn't seem to be working
- # TODO: uncomment this when it is working
- # def d(user, msg)
- # url = URI.parse("http://#{@@api_url}/statuses/update.xml")
- #
- # req = Net::HTTP::Post.new(url.path)
- # req.basic_auth(@config[:email], @config[:password])
- # req.set_form_data({'user' => user, 'msg' => msg})
- #
- # response = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
- # puts response.message,response.body
- # end
+ #Sends a direct message to <code>text</code> to <code>user</code>
+ def d(user, text)
+ url = URI.parse("http://#{@@api_url}/direct_messages/new.xml")
+ req = Net::HTTP::Post.new(url.path)
+
+ req.basic_auth(@config[:email], @config[:password])
+ req.set_form_data({'text' => text, 'user' => user})
+
+ response = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
+ DirectMessage.new_from_xml(parse(response.body).at('direct_message'))
+ end
# Updates your twitter with whatever status string is passed in
def post(status)

0 comments on commit 139a820

Please sign in to comment.