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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a83a641108791a5a3691a56ccae188dbb41762ac
4
- data.tar.gz: 92d8d426440bcaf8dae90b22aa8a1cfa35f99112
3
+ metadata.gz: 67e756e9a5226e0a5993f3659270a04034ccae3d
4
+ data.tar.gz: 82f7eadc1bac46efc939d79ab6d84264cc248603
5
5
  SHA512:
6
- metadata.gz: 72c516252444d1331c5de0e09281261db8de3d43a8440e1dd042b576c0e449ae82f7a2875811fe3fb0a50a84d89528c90501789fa0f61b531b2ec537e2fd0187
7
- data.tar.gz: 2e3d64e0477a01912e63de74b43c7347303d30d3f550f37f8e01fed06c83fbae3343f68262634c4ecb66fa24252b531588b9081aeb260b608c457ca2b24a16cc
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
- # or with authorization
45
- twitter = TwitterCache::Client.new(access_token: 'token', access_token_secret: 'secre
46
- t')
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)
@@ -3,10 +3,12 @@ require 'twitter'
3
3
  module TwitterCache
4
4
  class Client
5
5
  include TwitterCache::Helpers
6
- attr_reader :tokens
6
+ attr_accessor :access_token, :access_token_secret
7
7
 
8
- def initialize(tokens = nil)
9
- @tokens = tokens
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.dup.merge(tokens))
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
@@ -1,3 +1,3 @@
1
1
  module TwitterCache
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - masarakki