ids_please 2.1.2 → 2.2.0

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: 8da387525f9002e6b61c37a156ab3463eddc1f13
4
- data.tar.gz: 1b011d8e71246e51a912afc902b976d9e77bdcaa
3
+ metadata.gz: cbbb7fdc96da69f11a60cfbda149c1efc18cf3ec
4
+ data.tar.gz: a32ec832041c194f72d78aae0f410688edbd3239
5
5
  SHA512:
6
- metadata.gz: a40722b50e4e5105b965feb3ef03264bbde369bec2a5b9d52407111a618cc06e05c7a0eef3ca6fece82f1889f020752a74fa89a05b07b2f95fd28b7481fff18b
7
- data.tar.gz: 014973413f0ff8677839a3b82d7ba73896e4d345fdd33ed93b800f8bf91048b29db4918ceaa0f702d4c11226df9071a52cbb76f9f94b3ad7cea1a0e79c3a3e31
6
+ metadata.gz: e903c0a4695122ade18201fe6f33035644c2193cd13e1f950426da6ba98de85ccb4953f6aab4069288652b202441ed4992b09cd51e13ea34d544e8afe5060ed8
7
+ data.tar.gz: 94ef374b9075560bad7f53dd829d98a499f3b84d923de4392df9f77a07afeb628a723ef8e977b9fcde2323c94084da47d726e14791c08f3d81997d64905475da
data/README.md CHANGED
@@ -81,6 +81,7 @@ Social networks supported for grabbing at the moment:
81
81
  * [Instagram](http://instagram.com)
82
82
  * [Vkontakte](https://vk.com)
83
83
  * [Mailru](https://my.mail.ru)
84
+ * [GooglePlus](https://plus.google.com)
84
85
 
85
86
  ### Link parsing
86
87
 
@@ -8,7 +8,7 @@ class IdsPlease
8
8
  links.map { |l| self.new(l).grab_link }
9
9
  end
10
10
 
11
- attr_reader :avatar, :display_name, :username, :link, :page_source, :network_id, :data
11
+ attr_reader :avatar, :display_name, :username, :link, :page_source, :network_id, :data, :counts
12
12
 
13
13
  def initialize(link)
14
14
  @link = link
@@ -45,6 +45,9 @@ class IdsPlease
45
45
  to_s
46
46
  end
47
47
 
48
+ def page_source
49
+ @page_source ||= open(link).read
50
+ end
48
51
  end
49
52
  end
50
53
  end
@@ -3,27 +3,43 @@ class IdsPlease
3
3
  class Facebook < IdsPlease::Grabbers::Base
4
4
 
5
5
  def grab_link
6
- @page_source ||= open(link).read
7
- @network_id = @page_source.scan(/entity_id":"(\d+)"/).flatten.first
8
- @avatar = @page_source.scan(/og:image" content="([^"]+)"/).flatten.first
9
- @display_name = @page_source.scan(/og:title" content="([^"]+)"/).flatten.first
10
- @username = @page_source.scan(/og:url" content="[^"]+\/([^\/"]+)"/).flatten.first
11
- @avatar = CGI.unescapeHTML(@avatar.encode('utf-8')) if @avatar
6
+ @network_id = page_source.scan(/entity_id":"(\d+)"/).flatten.first
7
+ @avatar = page_source.scan(/og:image" content="([^"]+)"/).flatten.first
8
+ @display_name = page_source.scan(/og:title" content="([^"]+)"/).flatten.first
9
+ @username = page_source.scan(/og:url" content="[^"]+\/([^\/"]+)"/).flatten.first
10
+ @avatar = CGI.unescapeHTML(@avatar.encode('utf-8')) if @avatar
12
11
  @display_name = CGI.unescapeHTML(@display_name.encode('utf-8')) if @display_name
13
12
  @data = {}
14
13
  {
15
- type: @page_source.scan(/og:type" content="([^"]+)"/).flatten.first.encode('utf-8'),
16
- description: @page_source.scan(/og:description" content="([^"]+)"/).flatten.first.encode('utf-8')
14
+ type: page_source.scan(/og:type" content="([^"]+)"/).flatten.first.to_s.encode('utf-8'),
15
+ description: page_source.scan(/og:description" content="([^"]+)"/).flatten.first.to_s.encode('utf-8'),
17
16
  }.each do |k, v|
18
17
  next if v.nil? || v == ''
19
- @data[k] = CGI.unescapeHTML(v)
18
+ @data[k] = CGI.unescapeHTML(v).strip
20
19
  end
20
+ @counts = {
21
+ likes: likes,
22
+ visits: visits,
23
+ }.delete_if {|k,v| v.nil? }
21
24
  self
22
25
  rescue => e
23
26
  p e
24
27
  return self
25
28
  end
26
29
 
30
+ def likes
31
+ page_source.scan(/>([^"]+) <span class=".+">likes/).flatten.first.to_s.tr(',','').to_i
32
+ rescue => e
33
+ p e
34
+ return nil
35
+ end
36
+
37
+ def visits
38
+ page_source.scan(/likes.+>([^"]+)<\/span> <span class=".+">visits/).flatten.first.to_s.tr(',','').to_i
39
+ rescue => e
40
+ p e
41
+ return nil
42
+ end
27
43
  end
28
44
  end
29
45
  end
@@ -0,0 +1,25 @@
1
+ class IdsPlease
2
+ module Grabbers
3
+ class GooglePlus < IdsPlease::Grabbers::Base
4
+
5
+ def grab_link
6
+ @network_id = page_source.scan(/data-oid="(\d+)"/).flatten.first
7
+ @avatar = 'https:' + page_source.scan(/guidedhelpid="profile_photo"><img src="([^"]+)"/).flatten.first
8
+ @display_name = page_source.scan(/og:title" content="([^"]+)"/).flatten.first.gsub(' - Google+','')
9
+ @username = '+' + page_source.scan(/&quot;https:\/\/plus.google.com\/\+(.+?)&quot;/).flatten.first
10
+ @data = {
11
+ description: page_source.scan(/name="Description" content="([^"]+)">/).flatten.first.to_s.encode('utf-8')
12
+ }
13
+ @counts = {
14
+ followers: page_source.scan(/">([^"]+)<\/span> followers</).flatten.first.to_s.tr(',','').to_i,
15
+ views: page_source.scan(/">([^"]+)<\/span> views</).flatten.first.to_s.tr(',','').to_i,
16
+ }
17
+ self
18
+ rescue => e
19
+ p e
20
+ return self
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -5,29 +5,25 @@ class IdsPlease
5
5
  class Instagram < IdsPlease::Grabbers::Base
6
6
 
7
7
  def grab_link
8
- @page_source ||= open(link).read
9
- @network_id = @page_source.scan(/"user":{.+"id":"(\d+)"/).flatten.first
10
- @avatar = @page_source.scan(/"user":{.+"profile_picture":"([^"]+)"/).flatten.first.gsub('\\', '')
11
- @display_name = @page_source.scan(/"user":{.+"full_name":"([^"]+)"/).flatten.first
12
- @username = @page_source.scan(/"user":{.+"username":"([^"]+)"/).flatten.first.gsub('\\', '')
13
- counts = @page_source.scan(/"user":{.+"counts":({[^}]+})/).flatten.first
14
- counts = JSON.parse counts
15
- @data = {}
16
- {
17
- bio: @page_source.scan(/"user":{.+"bio":"([^"]+)"/).flatten.first,
18
- website: @page_source.scan(/"user":{.+"website":"([^"]+)"/).flatten.first.gsub('\\', ''),
19
- counts: counts
20
- }.each do |k, v|
21
- next if v.nil? || v == '' || !v.is_a?(String)
22
- @data[k] = v.gsub(/\\u([\da-fA-F]{4})/) {|m| [$1].pack("H*").unpack("n*").pack("U*")}
23
- end
8
+ @network_id = page_source.scan(/"user":{.+"id":"(\d+)"/).flatten.first
9
+ @avatar = page_source.scan(/"user":{.+"profile_pic_url":"([^"]+)"/).flatten.first.gsub('\\', '')
10
+ @display_name = page_source.scan(/"user":{.+"full_name":"([^"]+)"/).flatten.first
11
+ @username = page_source.scan(/"user":{"username":"([^"]+)"/).flatten.first.gsub('\\', '')
12
+ @data = {
13
+ bio: page_source.scan(/"biography":"([^"]+)"/).flatten.first,
14
+ website: page_source.scan(/"user":{.+"external_url":"([^"]+)"/).flatten.first.gsub('\\', ''),
15
+ }
16
+ @counts = {
17
+ media: page_source.scan(/"media":{"count":(\d+)/).flatten.first.to_i,
18
+ followed_by: page_source.scan(/"followed_by":{"count":(\d+)/).flatten.first.to_i,
19
+ follows: page_source.scan(/"follows":{"count":(\d+)/).flatten.first.to_i,
20
+ }
24
21
  @display_name = @display_name.gsub(/\\u([\da-fA-F]{4})/) {|m| [$1].pack("H*").unpack("n*").pack("U*")}
25
22
  self
26
23
  rescue => e
27
24
  p e
28
25
  return self
29
26
  end
30
-
31
27
  end
32
28
  end
33
29
  end
@@ -5,16 +5,16 @@ class IdsPlease
5
5
  class Mailru < IdsPlease::Grabbers::Base
6
6
 
7
7
  def grab_link
8
- @page_source ||= open(link).read.encode('utf-8')
9
- uid_url = "http://appsmail.ru/platform/#{link.split('/')[-2..-1].join('/')}"
10
- @network_id = JSON.parse(open(uid_url).read)['uid']
8
+ @page_source ||= open(link).read.encode('utf-8')
9
+ uid_url = "http://appsmail.ru/platform/#{link.split('/')[-2..-1].join('/')}"
10
+ @network_id = JSON.parse(open(uid_url).read)['uid']
11
11
  @username, type = get_name_and_type(link)
12
- @avatar = @page_source.scan(/profile__avatar" src="([^"]+)/).flatten.first
13
- @display_name = @page_source.scan(/h1.+title="([^"]+)/).flatten.first
14
- @display_name = CGI.unescapeHTML(@display_name) if @display_name
12
+ @avatar = page_source.scan(/profile__avatar" src="([^"]+)/).flatten.first
13
+ @display_name = page_source.scan(/h1.+title="([^"]+)/).flatten.first
14
+ @display_name = CGI.unescapeHTML(@display_name) if @display_name
15
15
  @data = {
16
16
  type: type,
17
- description: @page_source.scan(/profile__content_mainInfo" title="([^"]+)/).flatten.first
17
+ description: page_source.scan(/profile__content_mainInfo" title="([^"]+)/).flatten.first
18
18
  }
19
19
  @data[:description] = CGI.unescapeHTML(@data[:description]) if @data[:description]
20
20
  self
@@ -3,20 +3,26 @@ class IdsPlease
3
3
  class Twitter < IdsPlease::Grabbers::Base
4
4
 
5
5
  def grab_link
6
- @page_source ||= open(link).read
7
- @network_id = @page_source.scan(/data-user-id="(\d+)"/).flatten.first
8
- @avatar = @page_source.scan(/ProfileAvatar-image " src="([^"]+)"/).flatten.first
9
- @display_name = @page_source.scan(/ProfileHeaderCard-nameLink[^>]+>([^<]+)</).flatten.first
10
- @username = @page_source.scan(/<title>[^\(]+\(@([^\)]+)\)/).flatten.first
6
+ @network_id = page_source.scan(/data-user-id="(\d+)"/).flatten.first
7
+ @avatar = page_source.scan(/ProfileAvatar-image " src="([^"]+)"/).flatten.first
8
+ @display_name = page_source.scan(/ProfileHeaderCard-nameLink[^>]+>([^<]+)</).flatten.first
9
+ @username = page_source.scan(/<title>[^\(]+\(@([^\)]+)\)/).flatten.first
11
10
  @data = {}
12
11
  {
13
- description: @page_source.scan(/ProfileHeaderCard-bio[^>]+>([^<]+)</).flatten.first.encode('utf-8'),
14
- location: @page_source.scan(/ProfileHeaderCard-locationText[^>]+>([^<]+)</).flatten.first.encode('utf-8'),
15
- join_date: @page_source.scan(/ProfileHeaderCard-joinDateText[^>]+>([^<]+)</).flatten.first.encode('utf-8'),
12
+ description: page_source.scan(/ProfileHeaderCard-bio[^>]+>([^<]+)</).flatten.first.to_s.encode('utf-8'),
13
+ location: page_source.scan(/ProfileHeaderCard-locationText[^>]+>([^<]+)</).flatten.first.to_s.encode('utf-8'),
14
+ join_date: page_source.scan(/ProfileHeaderCard-joinDateText[^>]+>([^<]+)</).flatten.first.to_s.encode('utf-8'),
16
15
  }.each do |k, v|
17
16
  next if v.nil? || v == ''
18
- @data[k] = CGI.unescapeHTML(v)
17
+ @data[k] = CGI.unescapeHTML(v).strip
19
18
  end
19
+ @counts = {
20
+ tweets: page_source.scan(/statuses_count&quot;:(\d+),&quot;/).flatten.first.to_i,
21
+ following: page_source.scan(/friends_count&quot;:(\d+),&quot;/).flatten.first.to_i,
22
+ followers: page_source.scan(/followers_count&quot;:(\d+),&quot;/).flatten.first.to_i,
23
+ favorites: page_source.scan(/favourites_count&quot;:(\d+),&quot;/).flatten.first.to_i,
24
+ lists: page_source.scan(/listed_count&quot;:(\d+),&quot;/).flatten.first.to_i,
25
+ }
20
26
  self
21
27
  rescue => e
22
28
  p e
@@ -3,16 +3,16 @@ class IdsPlease
3
3
  class Vkontakte < IdsPlease::Grabbers::Base
4
4
 
5
5
  def grab_link
6
- agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36'
6
+ agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36'
7
7
  @page_source ||= open(link, 'User-Agent' => agent).read.encode('utf-8')
8
- @network_id = @page_source.scan(/href="\/wall(-\d+)_/).flatten.first
9
- @username = @link.to_s.split('vk.com/').last.gsub('/', '')
10
- @avatar = @page_source.scan(/page_avatar.+\n.+src="([^"]+)/).flatten.first
11
- @avatar = CGI.unescapeHTML(@avatar) if @avatar
12
- @display_name = @page_source.scan(/page_name">([^<]+)/).flatten.first
13
- @display_name = CGI.unescapeHTML(@display_name) if @display_name
8
+ @network_id = page_source.scan(/href="\/wall(-\d+)_/).flatten.first
9
+ @username = @link.to_s.split('vk.com/').last.gsub('/', '')
10
+ @avatar = page_source.scan(/page_avatar.+\n.+src="([^"]+)/).flatten.first
11
+ @avatar = CGI.unescapeHTML(@avatar) if @avatar
12
+ @display_name = page_source.scan(/page_name">([^<]+)/).flatten.first
13
+ @display_name = CGI.unescapeHTML(@display_name) if @display_name
14
14
  @data = {
15
- description: @page_source.scan(/description" content="([^"]+)/).flatten.first
15
+ description: page_source.scan(/description" content="([^"]+)/).flatten.first
16
16
  }
17
17
  @data[:description] = CGI.unescapeHTML(@data[:description]) if @data[:description]
18
18
  self
@@ -4,6 +4,7 @@ require_relative 'grabbers/vkontakte'
4
4
  require_relative 'grabbers/instagram'
5
5
  require_relative 'grabbers/twitter'
6
6
  require_relative 'grabbers/mailru'
7
+ require_relative 'grabbers/google_plus'
7
8
 
8
9
  class IdsPlease
9
10
  module Grabbers
@@ -14,6 +15,7 @@ class IdsPlease
14
15
  twitter: IdsPlease::Grabbers::Twitter,
15
16
  instagram: IdsPlease::Grabbers::Instagram,
16
17
  mailru: IdsPlease::Grabbers::Mailru,
18
+ google_plus: IdsPlease::Grabbers::GooglePlus,
17
19
  }
18
20
 
19
21
  def self.each
@@ -1,3 +1,3 @@
1
1
  class IdsPlease
2
- VERSION = '2.1.2'
2
+ VERSION = '2.2.0'
3
3
  end
@@ -4,7 +4,7 @@ describe IdsPlease do
4
4
 
5
5
  recognazible_links = %w(
6
6
  https://www.facebook.com/fb_acc
7
- https://www.facebook.com/fb_acc2<U+200>
7
+ https://facebook.com/fb_acc2<U+200>
8
8
  http://instagram.com/inst_acc
9
9
  http://hi5.com/hi5_acc
10
10
  http://www.hi5.com/profile.html?uid=12341234
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ids_please
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gazay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-13 00:00:00.000000000 Z
11
+ date: 2015-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -56,6 +56,7 @@ files:
56
56
  - lib/ids_please/grabbers.rb
57
57
  - lib/ids_please/grabbers/base.rb
58
58
  - lib/ids_please/grabbers/facebook.rb
59
+ - lib/ids_please/grabbers/google_plus.rb
59
60
  - lib/ids_please/grabbers/instagram.rb
60
61
  - lib/ids_please/grabbers/mailru.rb
61
62
  - lib/ids_please/grabbers/twitter.rb