File tree 1 file changed +35
-0
lines changed
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ require 'rubygems'
2
+ require 'oauth'
3
+ require 'json'
4
+
5
+ consumer_key = OAuth ::Consumer . new (
6
+ "j5oWVtmbD3MnrGtRk0jMOEI4z" ,
7
+ "VfoxZbtrTjeSPVOkuzsmjUB8c6TmIHKsZIZr83MSo0CpN1x72F" )
8
+ access_token = OAuth ::Token . new (
9
+ "704876576337477636-9wsUP6ZuWHsbpHhnSyiOQIkoxd5OalJ" ,
10
+ "IZ06WkLDpmCzvLXf6tTKVYl893xPIV39PK7wUCHovf8qc" )
11
+
12
+ baseurl = "https://api.twitter.com"
13
+ path = "/1.1/statuses/update.json"
14
+ address = URI ( "#{ baseurl } #{ path } " )
15
+ request = Net ::HTTP ::Post . new address . request_uri
16
+ request . set_form_data (
17
+ "status" => "This tweet was sent using twit.rb" ,
18
+ )
19
+
20
+ http = Net ::HTTP . new address . host , address . port
21
+ http . use_ssl = true
22
+ http . verify_mode = OpenSSL ::SSL ::VERIFY_PEER
23
+
24
+ request . oauth! http , consumer_key , access_token
25
+ http . start
26
+ response = http . request request
27
+
28
+ tweet = nil
29
+ if response . code == '200' then
30
+ tweet = JSON . parse ( response . body )
31
+ puts "Successfully sent #{ tweet [ "text" ] } "
32
+ else
33
+ puts "Could not send the Tweet! " +
34
+ "Code:#{ response . code } Body:#{ response . body } "
35
+ end
You can’t perform that action at this time.
0 commit comments