social_count 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.rspec +1 -0
- data/lib/social_count/api_base.rb +3 -0
- data/lib/social_count/error.rb +4 -0
- data/lib/social_count/facebook_user.rb +1 -1
- data/lib/social_count/version.rb +1 -1
- data/lib/social_count.rb +7 -3
- data/social_count.gemspec +1 -0
- data/spec/social_count/credentials_spec.rb +33 -3
- data/spec/social_count/facebook_user_spec.rb +17 -0
- data/spec/social_count/twitter_user_spec.rb +9 -0
- data/spec/support/test_credentials.rb +0 -1
- metadata +21 -23
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NWQ5ZjM0MWZmYmU1YWIyZTNiMGI4YTBkNzhkZGQ3OGY1NTM2YTYxNQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MzY0ZTRiYjIyOGNlY2JiZmE2M2M5MDk3MDhmYjFlYzFkZDFhNjMxOA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZjRmMDYxYWFmZmEzZmU5YWQ1YzhkYzE4MTU2NmFjZGE0MTNiYzBkMzg2Zjk4
|
10
|
+
MTRjZDdkY2FmNWE3NTZlMzFkZjc2MzQwYmRlMGYzNjYyZjg1MzdmNWYwMGRl
|
11
|
+
OGRkOWFiNTYyNDU1MGZlNGI2MDAwOGY1NjJlYjI5OGI0ODU5MzY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NmVmYTA2NWU4ZjZkMmVmYzNkN2Y4YzViYTIzNmE2NTY5ZmMyNzQwZTJkOTQy
|
14
|
+
ZjY4OWU0YmVhZDcwNmNkZTYzNWFlZjFkMzJhZjk4NzNjNWEzZDQyYzdjMjc1
|
15
|
+
YzBkYTA3MjlmOWY1OThhMDFlYWNmNGVlOTYxMTg0OWU5YjdhN2U=
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'net/http'
|
2
|
+
require 'active_support/core_ext/object/blank'
|
3
|
+
require 'social_count/error'
|
2
4
|
|
3
5
|
module SocialCount
|
4
6
|
class ApiBase
|
5
7
|
attr_reader :name
|
6
8
|
def initialize(name)
|
9
|
+
raise SocialCount::Error, "#{self.class}#name cannot be blank" if name.blank?
|
7
10
|
@name = name
|
8
11
|
end
|
9
12
|
class << self
|
data/lib/social_count/version.rb
CHANGED
data/lib/social_count.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
+
require 'active_support/core_ext/object/blank'
|
1
2
|
require "social_count/version"
|
3
|
+
require "social_count/error"
|
2
4
|
require "social_count/facebook_user"
|
3
5
|
require "social_count/twitter_user"
|
4
6
|
|
5
7
|
module SocialCount
|
6
8
|
REQUIRED_CREDENTIALS = [:twitter_consumer_key, :twitter_consumer_secret, :twitter_oauth_token, :twitter_oauth_token_secret, :fb_app_id, :fb_app_secret]
|
7
|
-
class Error < StandardError; end
|
8
9
|
class Credentials
|
9
|
-
|
10
|
+
attr_accessor *REQUIRED_CREDENTIALS
|
10
11
|
end
|
11
12
|
class << self
|
12
13
|
def credentials
|
@@ -20,7 +21,10 @@ module SocialCount
|
|
20
21
|
end
|
21
22
|
private
|
22
23
|
def validate_credentials(_credentials)
|
23
|
-
REQUIRED_CREDENTIALS.each
|
24
|
+
REQUIRED_CREDENTIALS.each do |attr|
|
25
|
+
raise SocialCount::Error, "SocialCount.credentials must respond to #{attr}" unless _credentials.respond_to?(attr.to_s)
|
26
|
+
raise SocialCount::Error, "SocialCount.credentials.#{attr} cannot be blank" if _credentials.__send__(attr.to_s).blank?
|
27
|
+
end
|
24
28
|
end
|
25
29
|
end
|
26
30
|
end
|
data/social_count.gemspec
CHANGED
@@ -13,16 +13,39 @@ def credentials_without(attr)
|
|
13
13
|
SocialCount::REQUIRED_CREDENTIALS.dup.tap { |a| a.delete(attr) }
|
14
14
|
end
|
15
15
|
|
16
|
+
def class_that_doesnt_respond_to(credential)
|
17
|
+
Class.new do
|
18
|
+
attributes = credentials_without(credential)
|
19
|
+
attributes.each do |a|
|
20
|
+
define_method(a) { '123' }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def class_that_responds_with_x_to(credential, x)
|
26
|
+
Class.new(class_that_doesnt_respond_to(credential)) do
|
27
|
+
define_method(credential) { x }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
16
31
|
describe SocialCount::Credentials do
|
17
32
|
SocialCount::REQUIRED_CREDENTIALS.each do |credential|
|
18
33
|
it "should require credentials to have a #{credential}" do
|
19
|
-
credentials =
|
34
|
+
credentials = class_that_doesnt_respond_to(credential)
|
20
35
|
expect{SocialCount.credentials = credentials.new}.to raise_error(SocialCount::Error, "SocialCount.credentials must respond to #{credential}")
|
21
36
|
end
|
37
|
+
it "should not allow #{credential} to be nil" do
|
38
|
+
credentials = class_that_responds_with_x_to(credential, nil)
|
39
|
+
expect{SocialCount.credentials = credentials.new}.to raise_error(SocialCount::Error, "SocialCount.credentials.#{credential} cannot be blank")
|
40
|
+
end
|
41
|
+
it "should not allow #{credential} to be an empty string" do
|
42
|
+
credentials = class_that_responds_with_x_to(credential, '')
|
43
|
+
expect{SocialCount.credentials = credentials.new}.to raise_error(SocialCount::Error, "SocialCount.credentials.#{credential} cannot be blank")
|
44
|
+
end
|
22
45
|
end
|
23
46
|
|
24
47
|
it "shouldn't change state when an exception is raised" do
|
25
|
-
credentials =
|
48
|
+
credentials = class_that_doesnt_respond_to(:twitter_consumer_secret)
|
26
49
|
SocialCount.reset_credentials
|
27
50
|
expect{SocialCount.credentials = credentials.new}.to raise_error(SocialCount::Error, "SocialCount.credentials must respond to twitter_consumer_secret")
|
28
51
|
expect(SocialCount.instance_variable_get("@credentials")).to be_nil
|
@@ -34,6 +57,13 @@ describe SocialCount::Credentials do
|
|
34
57
|
end
|
35
58
|
|
36
59
|
it "can be a SocialCount::Credentials instance" do
|
37
|
-
|
60
|
+
s = SocialCount::Credentials.new
|
61
|
+
s.twitter_consumer_key = "1"
|
62
|
+
s.twitter_consumer_secret = "1"
|
63
|
+
s.twitter_oauth_token = "1"
|
64
|
+
s.twitter_oauth_token_secret = "1"
|
65
|
+
s.fb_app_id = "1"
|
66
|
+
s.fb_app_secret = "1"
|
67
|
+
expect{SocialCount.credentials = s}.to_not raise_error
|
38
68
|
end
|
39
69
|
end
|
@@ -11,6 +11,7 @@ describe SocialCount::FacebookUser do
|
|
11
11
|
def access_token_did_not_match_specified_format
|
12
12
|
@access_token_did_not_match_specified_format ||= "Facebook Access Token #{@access_token} did not match specified format"
|
13
13
|
end
|
14
|
+
|
14
15
|
describe "class methods" do
|
15
16
|
it "should receive an access token" do
|
16
17
|
@access_token = SocialCount::FacebookUser.access_token.split("|")
|
@@ -19,6 +20,17 @@ describe SocialCount::FacebookUser do
|
|
19
20
|
@access_token[1].should match(/[_A-Za-z0-9]{27}/), access_token_did_not_match_specified_format
|
20
21
|
end
|
21
22
|
end
|
23
|
+
|
24
|
+
describe "name" do
|
25
|
+
it "cannot be an empty string" do
|
26
|
+
expect{SocialCount::TwitterUser.new('')}.to raise_error(SocialCount::Error, "SocialCount::TwitterUser#name cannot be blank")
|
27
|
+
end
|
28
|
+
it "cannot be nil" do
|
29
|
+
expect{SocialCount::TwitterUser.new(nil)}.to raise_error(SocialCount::Error, "SocialCount::TwitterUser#name cannot be blank")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
22
34
|
describe "user that supports following" do
|
23
35
|
before(:all) do
|
24
36
|
@facebook = SocialCount::FacebookUser.new(username)
|
@@ -46,6 +58,7 @@ describe SocialCount::FacebookUser do
|
|
46
58
|
@facebook.friend_count.should be_nil
|
47
59
|
end
|
48
60
|
end
|
61
|
+
|
49
62
|
describe "user that supports friending" do
|
50
63
|
before(:all) do
|
51
64
|
@facebook = SocialCount::FacebookUser.new('jose.valim')
|
@@ -59,6 +72,7 @@ describe SocialCount::FacebookUser do
|
|
59
72
|
@facebook.follower_count.should be_nil
|
60
73
|
end
|
61
74
|
end
|
75
|
+
|
62
76
|
describe "non-existent user" do
|
63
77
|
def non_existent_user
|
64
78
|
SocialCount::FacebookUser.new("george_orwell")
|
@@ -78,5 +92,8 @@ describe SocialCount::FacebookUser do
|
|
78
92
|
it "should have nil friend_count" do
|
79
93
|
non_existent_user.friend_count.should be_nil
|
80
94
|
end
|
95
|
+
it "should have nil follower_count" do
|
96
|
+
non_existent_user.follower_count.should be_nil
|
97
|
+
end
|
81
98
|
end
|
82
99
|
end
|
@@ -8,6 +8,15 @@ describe SocialCount::TwitterUser do
|
|
8
8
|
@username ||= 'tsa'
|
9
9
|
end
|
10
10
|
|
11
|
+
describe "name" do
|
12
|
+
it "cannot be an empty string" do
|
13
|
+
expect{SocialCount::TwitterUser.new('')}.to raise_error(SocialCount::Error, "SocialCount::TwitterUser#name cannot be blank")
|
14
|
+
end
|
15
|
+
it "cannot be nil" do
|
16
|
+
expect{SocialCount::TwitterUser.new(nil)}.to raise_error(SocialCount::Error, "SocialCount::TwitterUser#name cannot be blank")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
11
20
|
describe "existent user" do
|
12
21
|
before(:each) do
|
13
22
|
@twitter = SocialCount::TwitterUser.new(username)
|
@@ -6,7 +6,6 @@ class TestCredentials
|
|
6
6
|
credentials_file = File.expand_path("#{__FILE__}/../credentials.rb")
|
7
7
|
unless File.exists?(credentials_file)
|
8
8
|
puts "Please configure your Facebook and Twitter application credentials by copying #{credentials_file}.example to #{credentials_file} and configuring the required values there appropriately."
|
9
|
-
puts "Then comment out the 'exit' line in #{File.expand_path(__FILE__)} before running rspec."
|
10
9
|
exit
|
11
10
|
end
|
12
11
|
end
|
metadata
CHANGED
@@ -1,20 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_count
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Isaac Betesh
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-03 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
14
27
|
- !ruby/object:Gem::Dependency
|
15
28
|
name: fb_graph
|
16
29
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
30
|
requirements:
|
19
31
|
- - ! '>='
|
20
32
|
- !ruby/object:Gem::Version
|
@@ -22,7 +34,6 @@ dependencies:
|
|
22
34
|
type: :runtime
|
23
35
|
prerelease: false
|
24
36
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
37
|
requirements:
|
27
38
|
- - ! '>='
|
28
39
|
- !ruby/object:Gem::Version
|
@@ -30,7 +41,6 @@ dependencies:
|
|
30
41
|
- !ruby/object:Gem::Dependency
|
31
42
|
name: twitter_oauth
|
32
43
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
44
|
requirements:
|
35
45
|
- - ~>
|
36
46
|
- !ruby/object:Gem::Version
|
@@ -38,7 +48,6 @@ dependencies:
|
|
38
48
|
type: :runtime
|
39
49
|
prerelease: false
|
40
50
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
51
|
requirements:
|
43
52
|
- - ~>
|
44
53
|
- !ruby/object:Gem::Version
|
@@ -46,7 +55,6 @@ dependencies:
|
|
46
55
|
- !ruby/object:Gem::Dependency
|
47
56
|
name: bundler
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
58
|
requirements:
|
51
59
|
- - ~>
|
52
60
|
- !ruby/object:Gem::Version
|
@@ -54,7 +62,6 @@ dependencies:
|
|
54
62
|
type: :development
|
55
63
|
prerelease: false
|
56
64
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
65
|
requirements:
|
59
66
|
- - ~>
|
60
67
|
- !ruby/object:Gem::Version
|
@@ -62,7 +69,6 @@ dependencies:
|
|
62
69
|
- !ruby/object:Gem::Dependency
|
63
70
|
name: rake
|
64
71
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
72
|
requirements:
|
67
73
|
- - ! '>='
|
68
74
|
- !ruby/object:Gem::Version
|
@@ -70,7 +76,6 @@ dependencies:
|
|
70
76
|
type: :development
|
71
77
|
prerelease: false
|
72
78
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
79
|
requirements:
|
75
80
|
- - ! '>='
|
76
81
|
- !ruby/object:Gem::Version
|
@@ -78,7 +83,6 @@ dependencies:
|
|
78
83
|
- !ruby/object:Gem::Dependency
|
79
84
|
name: rspec
|
80
85
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
86
|
requirements:
|
83
87
|
- - ! '>='
|
84
88
|
- !ruby/object:Gem::Version
|
@@ -86,7 +90,6 @@ dependencies:
|
|
86
90
|
type: :development
|
87
91
|
prerelease: false
|
88
92
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
93
|
requirements:
|
91
94
|
- - ! '>='
|
92
95
|
- !ruby/object:Gem::Version
|
@@ -100,12 +103,14 @@ extensions: []
|
|
100
103
|
extra_rdoc_files: []
|
101
104
|
files:
|
102
105
|
- .gitignore
|
106
|
+
- .rspec
|
103
107
|
- Gemfile
|
104
108
|
- LICENSE.txt
|
105
109
|
- README.md
|
106
110
|
- Rakefile
|
107
111
|
- lib/social_count.rb
|
108
112
|
- lib/social_count/api_base.rb
|
113
|
+
- lib/social_count/error.rb
|
109
114
|
- lib/social_count/facebook_user.rb
|
110
115
|
- lib/social_count/twitter_user.rb
|
111
116
|
- lib/social_count/version.rb
|
@@ -119,33 +124,26 @@ files:
|
|
119
124
|
homepage: https://github.com/betesh/social_count
|
120
125
|
licenses:
|
121
126
|
- MIT
|
127
|
+
metadata: {}
|
122
128
|
post_install_message:
|
123
129
|
rdoc_options: []
|
124
130
|
require_paths:
|
125
131
|
- lib
|
126
132
|
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
-
none: false
|
128
133
|
requirements:
|
129
134
|
- - ! '>='
|
130
135
|
- !ruby/object:Gem::Version
|
131
136
|
version: '0'
|
132
|
-
segments:
|
133
|
-
- 0
|
134
|
-
hash: 1024359385876280514
|
135
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
-
none: false
|
137
138
|
requirements:
|
138
139
|
- - ! '>='
|
139
140
|
- !ruby/object:Gem::Version
|
140
141
|
version: '0'
|
141
|
-
segments:
|
142
|
-
- 0
|
143
|
-
hash: 1024359385876280514
|
144
142
|
requirements: []
|
145
143
|
rubyforge_project:
|
146
|
-
rubygems_version: 1.
|
144
|
+
rubygems_version: 2.1.5
|
147
145
|
signing_key:
|
148
|
-
specification_version:
|
146
|
+
specification_version: 4
|
149
147
|
summary: ! '# SocialCount This gem is an incredibly ligh-weight wrapper for finding
|
150
148
|
how many facebook friends and twitter followers someone has. ## Installation gem
|
151
149
|
''social_count'' # In your Gemfile $ gem install social_count # Install locally ##
|