moomerman-twitter_oauth 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -1,4 +1,4 @@
1
- h1. Twitter OAuth client library for Ruby
1
+ h1. Twitter OAuth REST API client library for Ruby
2
2
 
3
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
4
 
@@ -6,6 +6,10 @@ See [sinitter](http://github.com/moomerman/sinitter/tree/master) for a full webs
6
6
 
7
7
  h2. Unauthorized request example
8
8
 
9
+ The Twitter API can be called to make public requests without needing any client credentials.
10
+ Most methods will not work in this mode but some of them do. An example to retrieve the public details
11
+ about a Twitter user is below.
12
+
9
13
  <pre><code>client = TwitterOAuth::Client.new
10
14
 
11
15
  puts client.show('twitter')
@@ -14,10 +18,16 @@ puts client.show('twitter')
14
18
 
15
19
  h2. Authorized request example
16
20
 
17
- <pre><code>TwitterOAuth::Client::CLIENT_KEY = 'YOUR-CONSUMER-KEY'
18
- TwitterOAuth::Client::CLIENT_SECRET = 'YOUR-CONSUMER-SECRET'
21
+ To use the full power of the Twitter API you need to authorize your application and a valid Twitter user via OAuth.
22
+ An example showing how to update the status of an authorized user is below.
23
+
24
+ Firstly we need to create an instance of the client with your application client credentials you have been given by Twitter
25
+ when you set up your application.
19
26
 
20
- client = TwitterOAuth::Client.new
27
+ <pre><code>client = TwitterOAuth::Client.new(
28
+ :consumer_key => 'YOUR_APP_CONSUMER_KEY',
29
+ :consumer_secret => 'YOURA_APP_CONSUMER_SECRET'
30
+ )
21
31
  request_token = client.request_token
22
32
 
23
33
  request_token.authorize_url
@@ -25,7 +35,7 @@ request_token.authorize_url
25
35
  </code></pre>
26
36
 
27
37
  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.
38
+ the request token (usually in the session) for later. The code continues below assuming the user has authorized your application.
29
39
 
30
40
  <pre><code>access_token = client.authorize(
31
41
  request_token.token,
@@ -38,10 +48,15 @@ client.authorized?
38
48
  client.update('checking out the twitter_oauth library') # sends a twitter status update
39
49
  </code></pre>
40
50
 
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.
51
+ 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. When you create an instance of the client you can just pass in the access token and secret that you have stored.
42
52
 
43
- <pre><code>access_token = @user.access_token # assuming user ivar
44
- client = TwitterOAuth::Client.new(:token => access_token.token, :secret => access_token.secret)
53
+ <pre><code>access_token = @user.access_token # assuming @user
54
+ client = TwitterOAuth::Client.new(
55
+ :consumer_key => 'YOUR_CONSUMER_KEY',
56
+ :consumer_secret => 'YOUR-CONSUMER-SECRET',
57
+ :token => access_token.token,
58
+ :secret => access_token.secret
59
+ )
45
60
 
46
61
  client.authorized?
47
62
  => true
@@ -4,9 +4,10 @@ require 'twitter_oauth/direct_messages'
4
4
 
5
5
  module TwitterOAuth
6
6
  class Client
7
-
7
+
8
8
  def initialize(options = {})
9
- @username = options[:username]
9
+ @consumer_key = options[:consumer_key]
10
+ @consumer_secret = options[:consumer_secret]
10
11
  @token = options[:token]
11
12
  @secret = options[:secret]
12
13
  end
@@ -21,7 +22,7 @@ module TwitterOAuth
21
22
  @access_token
22
23
  end
23
24
 
24
- def show(username = @username)
25
+ def show(username)
25
26
  oauth_response = access_token.get("/users/show/#{username}.json")
26
27
  JSON.parse(oauth_response.body)
27
28
  end
@@ -33,8 +34,8 @@ module TwitterOAuth
33
34
  private
34
35
  def consumer
35
36
  @consumer ||= OAuth::Consumer.new(
36
- CLIENT_KEY,
37
- CLIENT_SECRET,
37
+ @consumer_key,
38
+ @consumer_secret,
38
39
  { :site=>"http://twitter.com" }
39
40
  )
40
41
  end
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.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Taylor