Class: RTwitter::OAuth
- Inherits:
-
Object
- Object
- RTwitter::OAuth
- Defined in:
- lib/RTwitter.rb
Defined Under Namespace
Classes: RTwitterException
Instance Attribute Summary collapse
-
#access_token(verifier) ⇒ Object
Returns the value of attribute access_token.
-
#access_token_secret ⇒ Object
Returns the value of attribute access_token_secret.
-
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
-
#consumer_key_secret ⇒ Object
Returns the value of attribute consumer_key_secret.
-
#screen_name ⇒ Object
Returns the value of attribute screen_name.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
-
#userAgent ⇒ Object
Returns the value of attribute userAgent.
Instance Method Summary collapse
- #get(endpoint, additional_params = Hash.new) ⇒ Object
-
#initialize(ck, cks, at = nil, ats = nil) ⇒ OAuth
constructor
A new instance of OAuth.
- #post(endpoint, additional_params = Hash.new) ⇒ Object
- #request_token(callback) ⇒ Object
- #streaming(endpoint, additional_params = Hash.new) ⇒ Object
Constructor Details
#initialize(ck, cks, at = nil, ats = nil) ⇒ OAuth
Returns a new instance of OAuth.
13 14 15 16 17 18 19 |
# File 'lib/RTwitter.rb', line 13 def initialize(ck ,cks ,at = nil ,ats = nil) @consumer_key = ck @consumer_key_secret = cks @access_token = at @access_token_secret = ats @userAgent = 'RTwitter' end |
Instance Attribute Details
#access_token(verifier) ⇒ Object
Returns the value of attribute access_token.
12 13 14 |
# File 'lib/RTwitter.rb', line 12 def access_token @access_token end |
#access_token_secret ⇒ Object
Returns the value of attribute access_token_secret.
12 13 14 |
# File 'lib/RTwitter.rb', line 12 def access_token_secret @access_token_secret end |
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
12 13 14 |
# File 'lib/RTwitter.rb', line 12 def consumer_key @consumer_key end |
#consumer_key_secret ⇒ Object
Returns the value of attribute consumer_key_secret.
12 13 14 |
# File 'lib/RTwitter.rb', line 12 def consumer_key_secret @consumer_key_secret end |
#screen_name ⇒ Object
Returns the value of attribute screen_name.
12 13 14 |
# File 'lib/RTwitter.rb', line 12 def screen_name @screen_name end |
#user_id ⇒ Object
Returns the value of attribute user_id.
12 13 14 |
# File 'lib/RTwitter.rb', line 12 def user_id @user_id end |
#userAgent ⇒ Object
Returns the value of attribute userAgent.
12 13 14 |
# File 'lib/RTwitter.rb', line 12 def userAgent @userAgent end |
Instance Method Details
#get(endpoint, additional_params = Hash.new) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/RTwitter.rb', line 83 def get(endpoint,additional_params = Hash.new) url = url(endpoint) header = signature('GET',url,additional_params) body = build_body(additional_params) response = get_request(url,body,header) return decode(response) end |
#post(endpoint, additional_params = Hash.new) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/RTwitter.rb', line 73 def post(endpoint,additional_params = Hash.new) url = url(endpoint) header = signature('POST',url,additional_params) body = build_body(additional_params) response = post_request(url,body,header) return decode(response) end |
#request_token(callback) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/RTwitter.rb', line 20 def request_token(callback) oauth_params = oauth oauth_params.delete('oauth_token') oauth_params['oauth_callback'] = callback base_params = Hash[oauth_params.sort] query = build_query(base_params) url = 'https://api.twitter.com/oauth/request_token' base = 'POST&' + escape(url) + '&' + escape(query) key = @consumer_key_secret + '&' oauth_params['oauth_signature'] = Base64.encode64(OpenSSL::HMAC.digest("sha1",key, base)).chomp header = {'Authorization' => 'OAuth ' + build_header(oauth_params),'User-Agent' => @userAgent} response = post_request(url,'',header) begin items = response.body.split('&') @request_token = items[0].split('=')[1] @request_token_secret = items[1].split('=')[1] return [@request_token,@request_token_secret] rescue raise RTwitterException,response.body end end |
#streaming(endpoint, additional_params = Hash.new) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/RTwitter.rb', line 93 def streaming(endpoint,additional_params = Hash.new) url = url(endpoint) header = signature('GET',url,additional_params) body = build_body(additional_params) buffer = '' streaming_request(url,body,header){|chunk| if buffer != '' chunk = buffer + chunk buffer = '' end begin status = JSON.parse(chunk) rescue buffer << chunk next end yield status } end |