social_feed_agregator 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f548b461c4328280e0e85046aaf241f6f9083659
4
- data.tar.gz: 2ba8f7d20acf36b32c6f20ff1ed511eac17bfeac
3
+ metadata.gz: c4fc4e3a81aaea74d2dad456924b6b2a69ad9ef1
4
+ data.tar.gz: 3317654c2c16a115b8c4b3c0149e34588abc4070
5
5
  SHA512:
6
- metadata.gz: 064e1ccde9755477090af8a13fc159d5d6ab6d245e98882c06e48fede8a11fef2b1b22e8e86397ba21ebc39bf24c0996a6203721279f55994899372744bcf03c
7
- data.tar.gz: fc042377bbaf949625ed7fca328b8f4dd2fbee676cf3267eb41c47f310f65d9a5428aa98e24820225a2d59ea1d8d361c18d8ce8090acb5195428ac1e5a60a857
6
+ metadata.gz: 3be704d71ae0522f84e4533b48173eb5544b0e39cc9d8c57dab75785363e0a3ac8e30938b29285c4db61b0ee1c2adbba72d81b08e0b196709f7415e5d38703fe
7
+ data.tar.gz: d708b5279a83931fdebff98007f79acdcce61f26637dba650284a68873f22c4b2abe6d4ae47f1e815c1052e6db7408135813786fb9e35d2e2c186c4882620a44
data/README.md CHANGED
@@ -18,7 +18,49 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ ## 1. Create reader for some social service (available Facebook, Twitter, Pinterest)
22
+
23
+ fb = SFA::Facebook.new ({
24
+ facebook_app_id: "FACEBOOK_APP_ID",
25
+ facebook_app_secret: "FACEBOOK_APP_SECRET",
26
+ facebook_user_name: "FACEBOOK_USER_NAME"
27
+ })
28
+
29
+ tw = SFA::Twitter.new ({
30
+ twitter_consumer_key: "TWITTER_CONSUMER_KEY",
31
+ twitter_consumer_secret: "TWITTER_CONSUMER_SECRET",
32
+ twitter_oauth_token: "TWITTER_OAUTH_TOKEN",
33
+ twitter_oauth_token_secret: "TWITTER_OAUTH_TOKEN_SECRET",
34
+ twitter_user_name: "TWITTER_USER_NAME"
35
+ })
36
+
37
+ pins = SFA::Pinterest.new ({
38
+ pinterest_user_name: "PINTEREST_USER_NAME"
39
+ })
40
+
41
+
42
+ ## 2. Get data
43
+
44
+ res = []
45
+
46
+ # Default 25
47
+ fb.get_feeds(count: 2) do |feed|
48
+ res << feed
49
+ end
50
+
51
+ # Default 25
52
+ tw.get_feeds(count: 2) do |feed|
53
+ res << feed
54
+ end
55
+
56
+ # Default 25
57
+ pins.get_feeds(count: 2) do |feed|
58
+ res << feed
59
+ end
60
+
61
+ res.sort!{|a, b| a.created_at <=> b.created_at}
62
+
63
+ res.to_json
22
64
 
23
65
  ## Contributing
24
66
 
@@ -0,0 +1,7 @@
1
+ class BaseReader
2
+ def initialize(options={})
3
+ end
4
+
5
+ def get_feeds(options={})
6
+ end
7
+ end
@@ -1,12 +1,14 @@
1
+ require "social_feed_agregator/base_reader"
1
2
  require "social_feed_agregator/feed"
2
3
  require "koala"
3
4
 
4
5
  module SocialFeedAgregator
5
- class FacebookReader
6
+ class FacebookReader < BaseReader
6
7
 
7
8
  attr_accessor :app_id, :app_secret, :name
8
9
 
9
10
  def initialize(options={})
11
+ super(options)
10
12
  options.replace(SocialFeedAgregator.default_options.merge(options))
11
13
 
12
14
  @name = options[:facebook_user_name]
@@ -15,15 +17,25 @@ module SocialFeedAgregator
15
17
  end
16
18
 
17
19
  def get_feeds(options={})
20
+ super(options)
18
21
  @name = options[:name] if options[:name]
22
+ count = options[:count] || 25
19
23
 
20
24
  oauth = Koala::Facebook::OAuth.new(@app_id, @app_secret)
21
25
  graph = Koala::Facebook::API.new oauth.get_app_access_token
22
26
  posts = graph.get_connections(@name, "posts")
23
27
 
28
+ feeds, i, count_per_request, items = [], 0, 25, 0
29
+
30
+ parts = (count.to_f / count_per_request).ceil
31
+
24
32
  begin
25
- posts.map do |post|
26
- Feed.new ({
33
+ i+=1
34
+ posts.each do |post|
35
+ items+=1
36
+ break if items > count
37
+
38
+ feed = Feed.new({
27
39
  feed_type: :facebook,
28
40
  feed_id: post['id'],
29
41
 
@@ -39,13 +51,16 @@ module SocialFeedAgregator
39
51
  caption: post['caption'],
40
52
  story: post['story'],
41
53
  message: post['message'],
42
- created_at: post["created_time" ],
54
+ created_at: DateTime.parse(post["created_time"]),
43
55
  type: post['type']
44
56
  })
45
- end
46
- end while not posts = posts.next_page
47
57
 
48
- end
49
-
58
+ block_given? ? yield(feed) : feeds << feed
59
+
60
+ end
61
+ end while (posts = posts.next_page) && (i < parts)
62
+ feeds
63
+ end
50
64
  end
65
+ Facebook = FacebookReader
51
66
  end
@@ -0,0 +1,49 @@
1
+ require "social_feed_agregator/base_reader"
2
+ require "social_feed_agregator/feed"
3
+
4
+ module SocialFeedAgregator
5
+ class PinterestReader < BaseReader
6
+
7
+ attr_accessor :name
8
+
9
+ def initialize(options={})
10
+ super(options)
11
+ options.replace(SocialFeedAgregator.default_options.merge(options))
12
+ @name = options[:pinterest_user_name]
13
+ end
14
+
15
+ def get_feeds(options={})
16
+ super(options)
17
+ @name = options[:name] if options[:name]
18
+ count = options[:count] || 25
19
+
20
+ feeds, items = [], 0
21
+
22
+ doc = Nokogiri::XML(RestClient.get("http://pinterest.com/#{@name}/feed.rss?page=2"))
23
+
24
+ doc.xpath('//item').each do |item|
25
+ items += 1
26
+ break if items > count
27
+ desc = item.xpath('description').inner_text.match(/src="(\S+)".+<p>(.+)<\/p>/)
28
+
29
+ feed = Feed.new ({
30
+ feed_type: :pinterest,
31
+ feed_id: item.xpath('guid').inner_text.match(/\d+/)[0].to_s,
32
+
33
+ user_id: @name,
34
+ user_name: @name,
35
+
36
+ name: item.xpath('title').inner_text,
37
+ permalink: item.xpath('link').inner_text,
38
+ picture_url: desc[1],
39
+ description: desc[2],
40
+ created_at: DateTime.parse(item.xpath('pubDate').inner_text), #.strftime("%Y-%m-%d %H:%M:%S")
41
+ })
42
+
43
+ block_given? ? yield(feed) : feeds << feed
44
+ end
45
+ feeds
46
+ end
47
+ end
48
+ Pinterest = PinterestReader
49
+ end
@@ -1,8 +1,9 @@
1
+ require "social_feed_agregator/base_reader"
1
2
  require "social_feed_agregator/feed"
2
3
  require "twitter"
3
4
 
4
5
  module SocialFeedAgregator
5
- class TwitterReader
6
+ class TwitterReader < BaseReader
6
7
 
7
8
  attr_accessor :consumer_key,
8
9
  :consumer_secret,
@@ -11,6 +12,7 @@ module SocialFeedAgregator
11
12
  :twitter_name
12
13
 
13
14
  def initialize(options={})
15
+ super(options)
14
16
  options.replace(SocialFeedAgregator.default_options.merge(options))
15
17
 
16
18
  @consumer_key = options[:twitter_consumer_key]
@@ -18,11 +20,13 @@ module SocialFeedAgregator
18
20
  @oauth_token = options[:twitter_oauth_token]
19
21
  @token_secret = options[:twitter_oauth_token_secret]
20
22
  @name = options[:twitter_user_name]
23
+
21
24
  end
22
25
 
23
26
  def get_feeds(options={})
27
+ super(options)
24
28
  @name = options[:name] if options[:name]
25
- count = options[:count] if options[:count]
29
+ count = options[:count] || 25
26
30
 
27
31
  client = ::Twitter.configure do |config|
28
32
  config.consumer_key = @consumer_key
@@ -31,47 +35,58 @@ module SocialFeedAgregator
31
35
  config.oauth_token_secret = @token_secret
32
36
  end
33
37
 
34
- statuses = client.user_timeline(@name, {count: count})
35
-
36
- statuses.map do |status|
37
- tweet_type = 'status'
38
- picture_url = ''
39
- link = ''
40
-
41
- if status.entities?
42
38
 
43
- if status.media.any?
44
- photo_entity = status.media.first
45
- tweet_type = 'photo'
46
- picture_url = photo_entity.media_url
47
- end
39
+ feeds, i = [], 0
40
+ count_per_request = 200 #::Twitter::REST::API::Timelines::MAX_TWEETS_PER_REQUEST
48
41
 
49
- if status.urls.any?
50
- url_entity = status.urls.first
51
- tweet_type = 'link'
52
- link = url_entity.url
53
- end
42
+ opts = {count: count < count_per_request ? count : count_per_request}
54
43
 
55
- end
44
+ parts = (count.to_f / count_per_request).ceil
56
45
 
46
+ while (statuses = client.user_timeline(@name, opts)) && i < parts do
47
+ i+=1
57
48
 
58
- Feed.new ({
59
- feed_type: :twitter,
60
- feed_id: status.id.to_s,
49
+ statuses.each do |status|
50
+ tweet_type, picture_url, link = 'status', '', ''
51
+
52
+ if status.entities?
53
+ if status.media.any?
54
+ photo_entity = status.media.first
55
+ tweet_type = 'photo'
56
+ picture_url = photo_entity.media_url
57
+ end
61
58
 
62
- user_id: status.user.id,
63
- user_name: status.user.screen_name,
64
-
65
- permalink: "https://twitter.com/#{status.user.screen_name}/status/#{status.id}", #status.url,
66
- message: status.text,
67
- created_at: status.created_at,
59
+ if status.urls.any?
60
+ url_entity = status.urls.first
61
+ tweet_type = 'link'
62
+ link = url_entity.url
63
+ end
64
+ end
65
+
66
+ feed = Feed.new({
67
+ feed_type: :twitter,
68
+ feed_id: status.id.to_s,
68
69
 
69
- type: tweet_type,
70
- picture_url: picture_url,
71
- link: link
72
- })
73
- end
70
+ user_id: status.user.id,
71
+ user_name: status.user.screen_name,
72
+
73
+ permalink: "https://twitter.com/#{status.user.screen_name}/status/#{status.id}", #status.url,
74
+ message: status.text,
75
+ created_at: status.created_at,
74
76
 
77
+ type: tweet_type,
78
+ picture_url: picture_url,
79
+ link: link
80
+ })
81
+
82
+ block_given? ? yield(feed) : feeds << feed
83
+
84
+ new_count = count - count_per_request * i
85
+ opts[:count] = new_count < count_per_request ? new_count : count_per_request
86
+ opts[:max_id] = status.id.to_s
87
+ end
88
+ end
89
+ feeds
75
90
  end
76
91
 
77
92
  end
@@ -1,3 +1,3 @@
1
1
  module SocialFeedAgregator
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require "social_feed_agregator/version"
2
2
  require "social_feed_agregator/facebook_reader"
3
3
  require "social_feed_agregator/twitter_reader"
4
+ require "social_feed_agregator/pinterest_reader"
4
5
 
5
6
  module SocialFeedAgregator
6
7
  @default_options = {}
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["eus@appfellas.co"]
11
11
  spec.description = %q{Social Feed Agregator}
12
12
  spec.summary = %q{Social Feed Agregator}
13
- spec.homepage = ""
13
+ spec.homepage = "http://appfellas.nl"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -22,5 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
 
24
24
  spec.add_dependency("koala", "~> 1.6.0")
25
- spec.add_dependency("twitter", "= 4.6.2")
25
+ spec.add_dependency("twitter", "~> 4.6.2")
26
+ spec.add_dependency("rest-client", "1.6.7")
27
+ spec.add_dependency("nokogiri", "~> 1.6.0")
26
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_feed_agregator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Sobolev
@@ -56,16 +56,44 @@ dependencies:
56
56
  name: twitter
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 4.6.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '='
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: 4.6.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: rest-client
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.6.7
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.6.7
83
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.6.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.6.0
69
97
  description: Social Feed Agregator
70
98
  email:
71
99
  - eus@appfellas.co
@@ -79,12 +107,14 @@ files:
79
107
  - README.md
80
108
  - Rakefile
81
109
  - lib/social_feed_agregator.rb
110
+ - lib/social_feed_agregator/base_reader.rb
82
111
  - lib/social_feed_agregator/facebook_reader.rb
83
112
  - lib/social_feed_agregator/feed.rb
113
+ - lib/social_feed_agregator/pinterest_reader.rb
84
114
  - lib/social_feed_agregator/twitter_reader.rb
85
115
  - lib/social_feed_agregator/version.rb
86
116
  - social_feed_agregator.gemspec
87
- homepage: ''
117
+ homepage: http://appfellas.nl
88
118
  licenses:
89
119
  - MIT
90
120
  metadata: {}