social_count 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjA5NjhjYTc4ZWY5NmEzZmY5NTNiOGUwMWExMWJhM2FiMGFlYWNkYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Nzc0NzdjZGI4ZWRkNjNiZDNiZjM0MGY0YzNjZDEwMDNjMjEyMmU0Mg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTQ0MDAzYTAyNzliNjI0NTM2NGRjMzM2OWFiN2Y1NTgwYWMxMGI1MjEyMDMy
|
10
|
+
NDJkMzU0M2NjZGY1NzIxYjU3YzRmOGU5ODg0Y2ZjNzBjYjAxNjQwMWFlMmJi
|
11
|
+
OTIxMjEwOTYxMDE5YjRhZTA1MmUwOGI3NTQxM2M0NWYzYzEzNTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzliODBmZDkxYmU1ZjYxYjdjNWFlZDI2MzgxODkyZDMxNmNkZWZhOTk5YWNj
|
14
|
+
NWMyMTViYWVhNTJlZjkyMDQ3ZmZmODA5ZmNhMWZhNjY1MTdmNWI5MzQxOGU2
|
15
|
+
ZTUwMGZkNzlkZWNjMDk4NDQxNGYxYWRlZjU5ZDg5ZTNiNTUyMmM=
|
data/lib/social_count/error.rb
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
module SocialCount
|
2
2
|
class Error < StandardError
|
3
3
|
end
|
4
|
+
class TwitterApiError < Error
|
5
|
+
attr_reader :code
|
6
|
+
def initialize(msg, code)
|
7
|
+
@code = code.is_a?(Array) ? code.join(", ") : code
|
8
|
+
super(msg)
|
9
|
+
end
|
10
|
+
def to_s
|
11
|
+
"Code(s): #{code}\nSee code explanations at https://dev.twitter.com/docs/error-codes-responses"
|
12
|
+
end
|
13
|
+
end
|
4
14
|
end
|
@@ -13,9 +13,13 @@ module SocialCount
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def follower_count
|
16
|
+
return unless valid?
|
16
17
|
response = self.class.access_token.request(:get, follower_count_url)
|
17
|
-
JSON.parse(response.body)
|
18
|
+
response = JSON.parse(response.body)
|
19
|
+
raise SocialCount::TwitterApiError.new("Twitter API returned the following errors: #{response["errors"]}", response["errors"].collect{|e| e["code"]}) if response["errors"]
|
20
|
+
response["followers_count"]
|
18
21
|
end
|
22
|
+
|
19
23
|
private
|
20
24
|
def follower_count_url
|
21
25
|
@follower_count_url ||= "#{API_DOMAIN}/1.1/users/show.json?screen_name=#{URI.escape(name)}"
|
data/lib/social_count/version.rb
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
module SocialCount
|
4
|
+
class TwitterUser
|
5
|
+
class << self
|
6
|
+
def reset_credentials
|
7
|
+
@token_hash = nil
|
8
|
+
@access_token = nil
|
9
|
+
@credentials = nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
3
15
|
describe SocialCount::TwitterUser do
|
4
16
|
before(:all) do
|
5
17
|
SocialCount.credentials = TestCredentials::INSTANCE
|
@@ -48,4 +60,20 @@ describe SocialCount::TwitterUser do
|
|
48
60
|
non_existent_user.follower_count.should be_nil
|
49
61
|
end
|
50
62
|
end
|
63
|
+
|
64
|
+
describe "expired credentials" do
|
65
|
+
before(:all) do
|
66
|
+
@old_credentials = SocialCount.credentials
|
67
|
+
SocialCount::TwitterUser.reset_credentials
|
68
|
+
SocialCount.credentials = TestCredentials::EXPIRED_CREDENTIALS
|
69
|
+
@twitter = SocialCount::TwitterUser.new(username)
|
70
|
+
end
|
71
|
+
it "should raise an exception" do
|
72
|
+
expect{@twitter.follower_count}.to raise_error(SocialCount::TwitterApiError, "Code(s): 89\nSee code explanations at https://dev.twitter.com/docs/error-codes-responses")
|
73
|
+
end
|
74
|
+
after(:all) do
|
75
|
+
SocialCount.credentials = @old_credentials
|
76
|
+
SocialCount::TwitterUser.reset_credentials
|
77
|
+
end
|
78
|
+
end
|
51
79
|
end
|
@@ -8,4 +8,12 @@ class TestCredentials
|
|
8
8
|
'MY_FACEBOOK_APP_ID',
|
9
9
|
'MY_FACEBOOK_APP_SECRET'
|
10
10
|
)
|
11
|
+
EXPIRED_CREDENTIALS = TestCredentials.new(
|
12
|
+
'MY_TWITTER_CONSUMER_KEY', # Same as above
|
13
|
+
'MY_TWITTER_CONSUMER_SECRET', # Same as above
|
14
|
+
'ANYTHING_RANDOM_STRING_HERE',
|
15
|
+
'ANOTHER_RANDOM_STRING_HERE',
|
16
|
+
'MY_FACEBOOK_APP_ID', # Same as above
|
17
|
+
'MY_FACEBOOK_APP_SECRET', # Same as above
|
18
|
+
)
|
11
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_count
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isaac Betesh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|