Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add get tweet example and post example

  • Loading branch information...
commit b61213a5835d0a48036fb835e2d60b5814e12a16 1 parent 7cf4104
@matsumoto-r authored
View
2  example/example.rb
@@ -4,7 +4,7 @@
ACCESS_TOKEN_SECRET = ''
API_URL = 'http://api.twitter.com/1.1/statuses/update.json'
-tweet = "hello twitter world from mruby-oauht"
+tweet = "happy new year from mruby-oauth"
ex_headers = {'Content-Type' => 'application/x-www-form-urlencoded'}
twitter = OAuth.new(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
response = twitter.post(API_URL, {:status => tweet}, ex_headers)
View
17 example/tweet_post.rb
@@ -0,0 +1,17 @@
+CONSUMER_KEY = ''
+CONSUMER_SECRET = ''
+ACCESS_TOKEN = ''
+ACCESS_TOKEN_SECRET = ''
+API_URL = 'http://api.twitter.com/1.1/statuses/update.json'
+
+tweet = "happy new year from mruby-oauth"
+ex_headers = {'Content-Type' => 'application/x-www-form-urlencoded'}
+twitter = OAuth.new(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
+response = twitter.post(API_URL, {:status => tweet}, ex_headers)
+
+if response.code.to_i == 200
+ puts "tweet success: #{tweet}"
+else
+ puts "tweet failed: #{tweet}: bellow response"
+ p response
+end
View
16 example/tweet_timeline.rb
@@ -0,0 +1,16 @@
+CONSUMER_KEY = ''
+CONSUMER_SECRET = ''
+ACCESS_TOKEN = ''
+ACCESS_TOKEN_SECRET = ''
+GET_API_URL = 'http://api.twitter.com/1.1/statuses/user_timeline.json?count=1'
+
+twitter = OAuth.new(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
+response = twitter.get(GET_API_URL)
+
+if response.code.to_i == 200
+ data = JSON::parse(response.body)
+ puts "#{data[0]["user"]["screen_name"]}'s tweet: #{data[0]["text"]}"
+else
+ puts response.body
+ raise "Request failed: " + response.code.to_s
+end
View
7 mrblib/oauth.rb
@@ -22,7 +22,7 @@ def request(method, url, body = nil, headers = {})
request['Authorization'] = auth_header(method, url, request["body"])
request['User-Agent'] = USER_AGENT
host = url.host.to_sym.to_s
- p request_uri, request
+ p method, request_uri, request
SimpleHttp.new(host, url.port).request(method, request_uri, request)
end
def auth_header(method, url, body)
@@ -79,8 +79,9 @@ def signature_base_url(url)
str += url.host
str += ":" + url.port if url.port
str += url.path if url.path
- str += "?" + url.query if url.query
- p str
+ #str += "?" + url.query if url.query
+ p ["sigbature_base_url", str]
+ str
end
def normalize_parameters(parameters, body, query)
parameters = encode_parameters(parameters, nil)
Please sign in to comment.
Something went wrong with that request. Please try again.