twitter-cache 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -3
- data/lib/twitter_cache/client.rb +15 -4
- data/lib/twitter_cache/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67e756e9a5226e0a5993f3659270a04034ccae3d
|
4
|
+
data.tar.gz: 82f7eadc1bac46efc939d79ab6d84264cc248603
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0139115cd127a1f20f29317487f5b84ad6489b85f1e1e96cfe651a92b9351a073aa264fbd157792f127d6a426f9f3d78add41b868500be3c9f1a605f8208b00d
|
7
|
+
data.tar.gz: 42f8ae1c30b9b24357c502c847642ea0779f1ea9b9c309ad362b2269d9d537052c6535b321a207a44f9c0ceda2bed7e99a38e04c204b4e87635d0ecdfc0ab074
|
data/README.md
CHANGED
@@ -39,12 +39,28 @@ end
|
|
39
39
|
|
40
40
|
### Usage
|
41
41
|
|
42
|
+
Unauthorized client:
|
43
|
+
|
42
44
|
```ruby
|
43
45
|
twitter = TwitterCache::Client.new
|
44
|
-
|
45
|
-
|
46
|
-
|
46
|
+
```
|
47
|
+
|
48
|
+
Authorized client:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
twitter = TwitterCache::Client.new(access_token: 'token', access_token_secret: 'secret')
|
52
|
+
|
53
|
+
# or with block
|
47
54
|
|
55
|
+
twitter = TwitterCache::Client.new do |c|
|
56
|
+
c.access_token = 'token'
|
57
|
+
c.access_token_secret = 'secret'
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
Get friends:
|
62
|
+
|
63
|
+
```ruby
|
48
64
|
# for authorized user
|
49
65
|
twitter.friends(per: 200, page: 1)
|
50
66
|
twitter.friends(per: 200, page: :randam)
|
data/lib/twitter_cache/client.rb
CHANGED
@@ -3,10 +3,12 @@ require 'twitter'
|
|
3
3
|
module TwitterCache
|
4
4
|
class Client
|
5
5
|
include TwitterCache::Helpers
|
6
|
-
|
6
|
+
attr_accessor :access_token, :access_token_secret
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
8
|
+
def initialize(access_token: nil, access_token_secret: nil)
|
9
|
+
@access_token = access_token
|
10
|
+
@access_token_secret = access_token_secret
|
11
|
+
yield(self) if block_given?
|
10
12
|
end
|
11
13
|
|
12
14
|
def user(id = current_id)
|
@@ -47,11 +49,20 @@ module TwitterCache
|
|
47
49
|
end
|
48
50
|
|
49
51
|
def twitter
|
50
|
-
@twitter ||= ::Twitter::REST::Client.new(config.twitter
|
52
|
+
@twitter ||= ::Twitter::REST::Client.new(config.twitter) do |conf|
|
53
|
+
if token_given?
|
54
|
+
conf.access_token = access_token
|
55
|
+
conf.access_token_secret = access_token_secret
|
56
|
+
end
|
57
|
+
end
|
51
58
|
end
|
52
59
|
|
53
60
|
protected
|
54
61
|
|
62
|
+
def token_given?
|
63
|
+
access_token && access_token_secret
|
64
|
+
end
|
65
|
+
|
55
66
|
def user_key(id)
|
56
67
|
"user:#{id}"
|
57
68
|
end
|