social_profile 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ {"id":7505382,"id_str":"7505382","name":"Erik Michaels-Ober","screen_name":"sferik","location":"","description":"May contain forward-looking statements.","url":"https:\/\/t.co\/L2xIBazMPf","entities":{"url":{"urls":[{"url":"https:\/\/t.co\/L2xIBazMPf","expanded_url":"https:\/\/github.com\/sferik","display_url":"github.com\/sferik","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":4051,"friends_count":361,"listed_count":238,"created_at":"Mon Jul 16 12:59:01 +0000 2007","favourites_count":8976,"utc_offset":3600,"time_zone":"Berlin","geo_enabled":true,"verified":false,"statuses_count":13844,"lang":"en","status":{"created_at":"Wed Mar 19 00:50:35 +0000 2014","id":446086297866993665,"id_str":"446086297866993665","text":"RT @AntonWSJ: Okean Elzy, #Ukraine's biggest rock band, performed in Berlin tonight amid many \"Glory to Ukraine!\" chants http:\/\/t.co\/dkIF8X\u2026","source":"\u003ca href=\"http:\/\/itunes.apple.com\/us\/app\/twitter\/id409789998?mt=12\" rel=\"nofollow\"\u003eTwitter for Mac\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":{"created_at":"Tue Mar 18 23:56:08 +0000 2014","id":446072592227909632,"id_str":"446072592227909632","text":"Okean Elzy, #Ukraine's biggest rock band, performed in Berlin tonight amid many \"Glory to Ukraine!\" chants http:\/\/t.co\/dkIF8XvFyw","source":"\u003ca href=\"http:\/\/www.apple.com\" rel=\"nofollow\"\u003eiOS\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":4,"favorite_count":2,"entities":{"hashtags":[{"text":"Ukraine","indices":[12,20]}],"symbols":[],"urls":[],"user_mentions":[],"media":[{"id":446072592047538176,"id_str":"446072592047538176","indices":[107,129],"media_url":"http:\/\/pbs.twimg.com\/media\/BjDEqLkIAAAIpE4.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/BjDEqLkIAAAIpE4.jpg","url":"http:\/\/t.co\/dkIF8XvFyw","display_url":"pic.twitter.com\/dkIF8XvFyw","expanded_url":"http:\/\/twitter.com\/AntonWSJ\/status\/446072592227909632\/photo\/1","type":"photo","sizes":{"medium":{"w":600,"h":450,"resize":"fit"},"large":{"w":1024,"h":768,"resize":"fit"},"thumb":{"w":150,"h":150,"resize":"crop"},"small":{"w":340,"h":255,"resize":"fit"}}}]},"favorited":true,"retweeted":true,"possibly_sensitive":false,"lang":"en"},"retweet_count":4,"favorite_count":0,"entities":{"hashtags":[{"text":"Ukraine","indices":[26,34]}],"symbols":[],"urls":[],"user_mentions":[{"screen_name":"AntonWSJ","name":"Anton Troianovski","id":76773876,"id_str":"76773876","indices":[3,12]}],"media":[{"id":446072592047538176,"id_str":"446072592047538176","indices":[139,140],"media_url":"http:\/\/pbs.twimg.com\/media\/BjDEqLkIAAAIpE4.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/BjDEqLkIAAAIpE4.jpg","url":"http:\/\/t.co\/dkIF8XvFyw","display_url":"pic.twitter.com\/dkIF8XvFyw","expanded_url":"http:\/\/twitter.com\/AntonWSJ\/status\/446072592227909632\/photo\/1","type":"photo","sizes":{"medium":{"w":600,"h":450,"resize":"fit"},"large":{"w":1024,"h":768,"resize":"fit"},"thumb":{"w":150,"h":150,"resize":"crop"},"small":{"w":340,"h":255,"resize":"fit"}}}]},"favorited":true,"retweeted":true,"possibly_sensitive":false,"lang":"en"},"contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/pbs.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_image_url_https":"https:\/\/pbs.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/378800000757402331\/d8dfba561e2e94112a737f17e7d138ca_normal.jpeg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/378800000757402331\/d8dfba561e2e94112a737f17e7d138ca_normal.jpeg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/7505382\/1385736840","profile_link_color":"0084B4","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false,"suspended":false,"needs_phone_verification":false}
@@ -0,0 +1 @@
1
+ {"token_type":"bearer","access_token":"AAAA%2FAAA%3DAAAAAAAA"}
@@ -0,0 +1,14 @@
1
+ {
2
+ "response": [
3
+ {
4
+ "uid":"1",
5
+ "first_name":"Павел",
6
+ "last_name":"Дуров",
7
+ "photo":"http:\/\/cs109.vkontakte.ru\/u00001\/c_df2abf56.jpg",
8
+ "counters": {
9
+ "friends": 230,
10
+ "followers": 10
11
+ }
12
+ }
13
+ ]
14
+ }
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  require 'spec_helper'
3
2
 
4
3
  describe SocialProfile::People::Facebook do
@@ -7,6 +6,10 @@ describe SocialProfile::People::Facebook do
7
6
  end
8
7
 
9
8
  context "facebook" do
9
+ before :all do
10
+ # FbGraph.debug!
11
+ end
12
+
10
13
  before(:each) do
11
14
  @user = SocialProfile::Person.get(:facebook, "100000730417342", "abc")
12
15
  end
@@ -14,5 +17,83 @@ describe SocialProfile::People::Facebook do
14
17
  it "should be a facebook profile" do
15
18
  @user.should be_a(SocialProfile::People::Facebook)
16
19
  end
20
+
21
+ it "should response to friends_count" do
22
+ mock_fql SocialProfile::People::Facebook::FRIENDS_FQL, SocialProfile.root_path.join('spec/mock_json/facebook/friends_count.json'), :access_token => "abc" do
23
+ @user.friends_count.should > 0
24
+ end
25
+ end
26
+
27
+ it "should response to followers_count" do
28
+ stub_request(:get, "https://graph.facebook.com/me/subscribers?access_token=abc&limit=1").
29
+ to_return(:status => 200, :body => fixture("facebook/followers.json"))
30
+
31
+ @user.followers_count.should == 14
32
+ end
33
+
34
+ it "should response to first_post_exists?" do
35
+ _sql = SocialProfile::People::Facebook::FIRST_POST_FQL.gsub('{date}', '1293832800')
36
+
37
+ mock_fql _sql, SocialProfile.root_path.join('spec/mock_json/facebook/first_post.json'), :access_token => "abc" do
38
+ @user.first_post_exists?(2011).should > 0
39
+ end
40
+ end
41
+
42
+ it "should response to last_posts" do
43
+ fields = SocialProfile::People::Facebook::LAST_POSTS_FIELDS.join(",")
44
+
45
+ stub_request(:get, "https://graph.facebook.com/me/feed?access_token=abc&fields=#{fields}&limit=600").
46
+ to_return(:status => 200, :body => fixture("facebook/last_posts.json"))
47
+
48
+ posts = @user.last_posts(600)
49
+
50
+ posts.should be_a(Array)
51
+ posts.size.should == 239
52
+ end
53
+
54
+ it "should response to last_posts by days (with 3 request to facebook api)" do
55
+ fields = SocialProfile::People::Facebook::LAST_POSTS_FIELDS.join(",")
56
+ fields2 = fields.gsub('.fields(created_time)', '')
57
+
58
+ stub_request(:get, "https://graph.facebook.com/me/feed?access_token=abc&fields=#{fields}&limit=5").
59
+ to_return(:status => 200, :body => fixture("facebook/last_5_posts.json"))
60
+ stub_request(:get, "https://graph.facebook.com/me/feed?access_token=abc&fields=#{fields2}&limit=5&until=1394475325").
61
+ to_return(:status => 200, :body => fixture("facebook/last_5_posts_page_2.json"))
62
+ stub_request(:get, "https://graph.facebook.com/me/feed?access_token=abc&fields=#{fields2}&limit=5&until=1394439420").
63
+ to_return(:status => 200, :body => fixture("facebook/last_5_posts_page_3.json"))
64
+
65
+ posts = @user.last_post_by_days(10, :limit => 5, :date_end => DateTime.new(2014, 3, 15))
66
+
67
+ posts.should be_a(Array)
68
+ posts.size.should == 13
69
+ end
70
+
71
+ it "should get big data from last_posts" do
72
+ fields = ["comments.limit(1000).fields(created_time,from).summary(true)",
73
+ "likes.limit(1000).fields(id).summary(true)",
74
+ "shares",
75
+ "status_type"]
76
+
77
+ stub_request(:get, "https://graph.facebook.com/me/feed?access_token=abc&fields=#{fields.join(',')}&limit=1000").
78
+ to_return(:status => 200, :body => fixture("facebook/last_posts_big.json"))
79
+ stub_request(:get, "https://graph.facebook.com/me/feed?access_token=abc&fields=#{fields.join(',')}&limit=1000&until=1394789304").
80
+ to_return(:status => 200, :body => fixture("facebook/last_posts_big2.json"))
81
+
82
+ posts = @user.last_post_by_days(30, :limit => 1000, :date_end => DateTime.new(2014, 4, 6), :fields => fields)
83
+
84
+ posts.should be_a(Array)
85
+ posts.size.should == 56
86
+ posts.select {|p| p.raw_attributes["status_type"] == "shared_story"}.size.should == 13
87
+ end
88
+
89
+ it "should get friends list" do
90
+ stub_request(:get, "https://graph.facebook.com/me/friends?access_token=abc&limit=100000").
91
+ to_return(:status => 200, :body => fixture("facebook/friends.json"))
92
+
93
+ friends = @user.friends(:limit => 100000)
94
+
95
+ friends.should be_a(Array)
96
+ friends.size.should == 4343
97
+ end
17
98
  end
18
99
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe SocialProfile::People::Twitter do
4
+ it "should be a Module" do
5
+ SocialProfile::People.should be_a(Module)
6
+ end
7
+
8
+ context "twitter" do
9
+ before(:each) do
10
+ @user = SocialProfile::Person.get(:twitter, "123456", "abc", :api_key => "111", :api_secret => "222", :token_secret => "333")
11
+ stub_request(:post, "https://api.twitter.com/oauth2/token").with(:body => {'grant_type' => 'client_credentials'}).
12
+ to_return(:body => fixture("twitter/token.json"), :headers => {:content_type => 'application/json; charset=utf-8'})
13
+ stub_request(:get, "https://api.twitter.com/1.1/account/verify_credentials.json").
14
+ to_return(:body => fixture('twitter/auth.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
15
+ end
16
+
17
+ it "should be a twitter profile" do
18
+ @user.should be_a(SocialProfile::People::Twitter)
19
+ end
20
+
21
+ it "should response to friends_count" do
22
+ @user.friends_count.should == 4051
23
+ end
24
+ end
25
+ end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  require 'spec_helper'
3
2
 
4
3
  describe SocialProfile::People::Vkontakte do
@@ -6,13 +5,19 @@ describe SocialProfile::People::Vkontakte do
6
5
  SocialProfile::People.should be_a(Module)
7
6
  end
8
7
 
9
- context "facebook" do
8
+ context "vkontakte" do
10
9
  before(:each) do
11
10
  @user = SocialProfile::Person.get(:vkontakte, "123456789", "abc")
11
+ stub_request(:get, "https://api.vk.com/method/users.get?access_token=abc&fields=counters&uids=123456789").
12
+ to_return(:status => 200, :body => File.read(SocialProfile.root_path.join('spec/mock_json/vkontakte/friends_count.json')))
12
13
  end
13
14
 
14
- it "should be a facebook profile" do
15
+ it "should be a vkontakte profile" do
15
16
  @user.should be_a(SocialProfile::People::Vkontakte)
16
17
  end
18
+
19
+ it "should response to friends_count" do
20
+ @user.friends_count.should > 0
21
+ end
17
22
  end
18
23
  end
@@ -19,7 +19,7 @@ describe SocialProfile::Providers::Facebook do
19
19
  it "should parse profile" do
20
20
  @profile.name.should == "Pavel Galeta"
21
21
  @profile.email.should == "email@gmail.com"
22
- @profile.picture_url.should == "http://profile.ak.fbcdn.net/hprofile-ak-prn1/41634_100000730417342_973_n.jpg"
22
+ # @profile.picture_url.should == "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/t5.0-1/1116992_100000730417342_336985489_n.jpg"
23
23
  @profile.gender.should == 2
24
24
  @profile.profile_url.should == "http://www.facebook.com/pavel.galeta"
25
25
  @profile.works.should == []
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe SocialProfile::Providers::Instagram do
4
+ it "should be a Module" do
5
+ SocialProfile::Providers.should be_a(Module)
6
+ end
7
+
8
+ context "instagram" do
9
+ before(:each) do
10
+ hash = {"provider" => "instagram","uid" => "31973911","info" => {"nickname" => "pavel_galeta","name" => "pavel galeta","location" => "Anytown, USA","image" => "http://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png","description" => "a very normal guy.","urls" => {"Website" => nil,"Twitter" => "https://twitter.com/johnqpublic"}},"credentials" => {"token" => "a1b2c3d4...", "secret" => "abcdef1234"},"extra" => {"access_token" => "", "raw_info" => {"username" => "pavel_galeta", "bio" => "", "website" => "", "profile_picture" => "http://images.ak.instagram.com/profiles/anonymousUser.jpg", "full_name" => "pavel galeta", "counts" => { "media" => 62, "followed_by" => 30, "follows" => 34}, "id" => "31973911"}}}
11
+ @profile = SocialProfile.get(hash)
12
+ end
13
+
14
+ it "should be a instagram profile" do
15
+ @profile.should be_a(SocialProfile::Providers::Instagram)
16
+ end
17
+
18
+ it "should parse profile" do
19
+ @profile.name.should == "pavel galeta"
20
+ @profile.friends_count.should == 30
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe SocialProfile::Providers::Twitter do
4
+ it "should be a Module" do
5
+ SocialProfile::Providers.should be_a(Module)
6
+ end
7
+
8
+ context "twitter" do
9
+ before(:each) do
10
+ hash = {"provider" => "twitter","uid" => "123456","info" => {"nickname" => "johnqpublic","name" => "John Q Public","location" => "Anytown, USA","image" => "http://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png","description" => "a very normal guy.","urls" => {"Website" => nil,"Twitter" => "https://twitter.com/johnqpublic"}},"credentials" => {"token" => "a1b2c3d4...", "secret" => "abcdef1234"},"extra" => {"access_token" => "", "raw_info" => {"name" => "John Q Public","listed_count" => 0,"profile_sidebar_border_color" => "181A1E","url" => nil,"lang" => "en","statuses_count" => 129,"profile_image_url" => "http://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png","profile_background_image_url_https" => "https://twimg0-a.akamaihd.net/profile_background_images/229171796/pattern_036.gif","location" => "Anytown, USA","time_zone" => "Chicago","follow_request_sent" => false,"id" => 123456,"profile_background_tile" => true,"profile_sidebar_fill_color" => "666666","followers_count" => 1,"default_profile_image" => false,"screen_name" => "","following" => false,"utc_offset" => -3600,"verified" => false,"favourites_count" => 0,"profile_background_color" => "1A1B1F","is_translator" => false,"friends_count" => 1,"notifications" => false,"geo_enabled" => true,"profile_background_image_url" => "http://twimg0-a.akamaihd.net/profile_background_images/229171796/pattern_036.gif","protected" => false,"description" => "a very normal guy.","profile_link_color" => "2FC2EF","created_at" => "Thu Jul 4 00:00:00 +0000 2013","id_str" => "123456","profile_image_url_https" => "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png","default_profile" => false,"profile_use_background_image" => false,"entities" => {"description" => {"urls" => []}},"profile_text_color" => "666666","contributors_enabled" => false}}}
11
+ @profile = SocialProfile.get(hash)
12
+ end
13
+
14
+ it "should be a twitter profile" do
15
+ @profile.should be_a(SocialProfile::Providers::Twitter)
16
+ end
17
+
18
+ it "should parse profile" do
19
+ @profile.name.should == "John Q Public"
20
+ @profile.friends_count.should == 1
21
+ end
22
+ end
23
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
- # encoding: utf-8
2
1
  require "rspec"
3
2
  require "social_profile"
3
+ require 'fb_graph/mock'
4
+
5
+ include FbGraph::Mock
4
6
 
5
7
  # Load support files
6
8
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
@@ -11,6 +13,15 @@ RSpec.configure do |config|
11
13
  require 'rspec/expectations'
12
14
  config.include RSpec::Matchers
13
15
 
16
+ WebMock.allow_net_connect!
17
+
14
18
  # == Mock Framework
15
19
  config.mock_with :rspec
20
+
21
+ config.after(:all) do
22
+ end
23
+ end
24
+
25
+ def fixture(file)
26
+ File.read(SocialProfile.root_path.join('spec/mock_json', file))
16
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_profile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-24 00:00:00.000000000 Z
12
+ date: 2014-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -75,6 +75,22 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: twitter
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
78
94
  - !ruby/object:Gem::Dependency
79
95
  name: httpclient
80
96
  requirement: !ruby/object:Gem::Requirement
@@ -122,18 +138,37 @@ files:
122
138
  - Rakefile
123
139
  - lib/social_profile.rb
124
140
  - lib/social_profile/people/facebook.rb
141
+ - lib/social_profile/people/twitter.rb
125
142
  - lib/social_profile/people/vkontakte.rb
126
143
  - lib/social_profile/person.rb
127
144
  - lib/social_profile/providers/base.rb
128
145
  - lib/social_profile/providers/facebook.rb
146
+ - lib/social_profile/providers/instagram.rb
147
+ - lib/social_profile/providers/twitter.rb
129
148
  - lib/social_profile/providers/vkontakte.rb
130
149
  - lib/social_profile/response.rb
131
150
  - lib/social_profile/utils.rb
132
151
  - lib/social_profile/version.rb
133
152
  - social_profile.gemspec
153
+ - spec/mock_json/facebook/first_post.json
154
+ - spec/mock_json/facebook/followers.json
155
+ - spec/mock_json/facebook/friends.json
156
+ - spec/mock_json/facebook/friends_count.json
157
+ - spec/mock_json/facebook/last_5_posts.json
158
+ - spec/mock_json/facebook/last_5_posts_page_2.json
159
+ - spec/mock_json/facebook/last_5_posts_page_3.json
160
+ - spec/mock_json/facebook/last_posts.json
161
+ - spec/mock_json/facebook/last_posts_big.json
162
+ - spec/mock_json/facebook/last_posts_big2.json
163
+ - spec/mock_json/twitter/auth.json
164
+ - spec/mock_json/twitter/token.json
165
+ - spec/mock_json/vkontakte/friends_count.json
134
166
  - spec/people/facebook_spec.rb
167
+ - spec/people/twitter_spec.rb
135
168
  - spec/people/vkontakte_spec.rb
136
169
  - spec/providers/facebook_spec.rb
170
+ - spec/providers/instagram_spec.rb
171
+ - spec/providers/twitter_spec.rb
137
172
  - spec/providers/vkontakte_spec.rb
138
173
  - spec/spec_helper.rb
139
174
  homepage: https://github.com/galetahub/social_profile
@@ -162,8 +197,24 @@ signing_key:
162
197
  specification_version: 3
163
198
  summary: Wrapper for Omniauth profile hash
164
199
  test_files:
200
+ - spec/mock_json/facebook/first_post.json
201
+ - spec/mock_json/facebook/followers.json
202
+ - spec/mock_json/facebook/friends.json
203
+ - spec/mock_json/facebook/friends_count.json
204
+ - spec/mock_json/facebook/last_5_posts.json
205
+ - spec/mock_json/facebook/last_5_posts_page_2.json
206
+ - spec/mock_json/facebook/last_5_posts_page_3.json
207
+ - spec/mock_json/facebook/last_posts.json
208
+ - spec/mock_json/facebook/last_posts_big.json
209
+ - spec/mock_json/facebook/last_posts_big2.json
210
+ - spec/mock_json/twitter/auth.json
211
+ - spec/mock_json/twitter/token.json
212
+ - spec/mock_json/vkontakte/friends_count.json
165
213
  - spec/people/facebook_spec.rb
214
+ - spec/people/twitter_spec.rb
166
215
  - spec/people/vkontakte_spec.rb
167
216
  - spec/providers/facebook_spec.rb
217
+ - spec/providers/instagram_spec.rb
218
+ - spec/providers/twitter_spec.rb
168
219
  - spec/providers/vkontakte_spec.rb
169
220
  - spec/spec_helper.rb