moomerman-twitter_oauth 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.textile ADDED
@@ -0,0 +1,48 @@
1
+ h1. Twitter OAuth client library for Ruby
2
+
3
+ To make authorized requests with the client library you'll need to [create a Twitter OAuth Application](http://twitter.com/oauth_clients/new).
4
+
5
+ See [sinitter](http://github.com/moomerman/sinitter/tree/master) for a full website integration example.
6
+
7
+ h2. Unauthorized request example
8
+
9
+ <pre><code>client = TwitterOAuth::Client.new
10
+
11
+ puts client.show('twitter')
12
+ => => {"status"=>{"truncated"=>false, "favorited"=>false, "text"=>"Update on service issues http://tinyurl.com/ca872j", "id"=>1357776683, "in_reply_to_user_id"=>nil, "in_reply_to_status_id"=>nil, "source"=>"<a href=\"http://twitterfeed.com\">twitterfeed</a>", "created_at"=>"Fri Mar 20 01:17:35 +0000 2009"}, "name"=>"Twitter", "profile_sidebar_fill_color"=>"CDFFFF", "profile_sidebar_border_color"=>"8a6447", "profile_background_tile"=>false, "profile_link_color"=>"0000ff", "url"=>"http://twitter.com", "favourites_count"=>0, "id"=>783214, "description"=>"Always wondering what everyone's doing.", "profile_text_color"=>"000000", "protected"=>false, "utc_offset"=>-28800, "screen_name"=>"twitter", "profile_background_color"=>"9ae4e8", "time_zone"=>"Pacific Time (US & Canada)", "followers_count"=>469150, "profile_background_image_url"=>"http://static.twitter.com/images/themes/theme1/bg.gif", "friends_count"=>30, "statuses_count"=>290, "location"=>"San Francisco, CA", "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/75075164/twitter_bird_profile_normal.png", "created_at"=>"Tue Feb 20 14:35:54 +0000 2007"}
13
+ </code></pre>
14
+
15
+ h2. Authorized request example
16
+
17
+ <pre><code>TwitterOAuth::Client::CLIENT_KEY = 'YOUR-CONSUMER-KEY'
18
+ TwitterOAuth::Client::CLIENT_SECRET = 'YOUR-CONSUMER-SECRET'
19
+
20
+ client = TwitterOAuth::Client.new
21
+ request_token = client.request_token
22
+
23
+ request_token.authorize_url
24
+ => http://twitter.com/oauth/authorize?oauth_token=TOKEN
25
+ </code></pre>
26
+
27
+ In your application your user would be redirected to Twitter to authorize the application at this point. You'll need to store
28
+ the request token (usually in the session) for later.
29
+
30
+ <pre><code>access_token = client.authorize(
31
+ request_token.token,
32
+ request_token.secret
33
+ )
34
+
35
+ client.authorized?
36
+ => true
37
+
38
+ client.update('checking out the twitter_oauth library') # sends a twitter status update
39
+ </code></pre>
40
+
41
+ Now if you keep hold of the access_token (usually in the database) for this user you won't need to re-authorize them next time.
42
+
43
+ <pre><code>access_token = @user.access_token # assuming user ivar
44
+ client = TwitterOAuth::Client.new(:token => access_token.token, :secret => access_token.secret)
45
+
46
+ client.authorized?
47
+ => true
48
+ </code></pre>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moomerman-twitter_oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Taylor
@@ -41,10 +41,9 @@ extensions: []
41
41
  extra_rdoc_files: []
42
42
 
43
43
  files:
44
- - README.md
44
+ - README.textile
45
45
  - lib/twitter_oauth
46
46
  - lib/twitter_oauth.rb
47
- - lib/twitter_oauth/client.rb
48
47
  has_rdoc: false
49
48
  homepage: http://github.com/moomerman/twitter_oauth
50
49
  post_install_message:
data/README.md DELETED
@@ -1,7 +0,0 @@
1
- = Twitter OAuth Client for Ruby
2
-
3
- TwitterOAuth::Client::CLIENT_KEY = 'xxxx'
4
- TwitterOAuth::Client::CLIENT_SECRET = 'xxxx'
5
-
6
- client = TwitterOAuth::Client.new
7
- puts client.show('moomerman')
@@ -1,63 +0,0 @@
1
- module TwitterOAuth
2
- class Client
3
-
4
- def initialize(options = {})
5
- @username = options[:username]
6
- @token = options[:token]
7
- @secret = options[:secret]
8
- end
9
-
10
- def login(token, secret)
11
- request_token = OAuth::RequestToken.new(
12
- consumer, token, secret
13
- )
14
- @access_token = request_token.get_access_token
15
- @token = @access_token.token
16
- @secret = @access_token.secret
17
- @access_token
18
- end
19
-
20
- def show(username = @username)
21
- oauth_response = access_token.get("/users/show/#{username}.json")
22
- JSON.parse(oauth_response.body)
23
- end
24
-
25
- def authorized?
26
- oauth_response = access_token.get('/account/verify_credentials.json')
27
- return oauth_response.class == Net::HTTPOK
28
- end
29
-
30
- def friends
31
- oauth_response = access_token.get('/statuses/friends_timeline.json')
32
- JSON.parse(oauth_response.body)
33
- end
34
-
35
- def update(message)
36
- oauth_response = access_token.post('/statuses/update.json', :status => message)
37
- JSON.parse(oauth_response.body)
38
- end
39
-
40
- def message(user, text)
41
- oauth_response = access_token.post('/direct_messages/new.format', :user => user, :text => text)
42
- JSON.parse(oauth_response.body)
43
- end
44
-
45
- def request_token
46
- consumer.get_request_token
47
- end
48
-
49
- private
50
- def consumer
51
- @consumer ||= OAuth::Consumer.new(
52
- CLIENT_KEY,
53
- CLIENT_SECRET,
54
- { :site=>"http://twitter.com" }
55
- )
56
- end
57
-
58
- def access_token
59
- @access_token ||= OAuth::AccessToken.new(consumer, @token, @secret)
60
- end
61
- end
62
- end
63
-