ids_please 2.2.5 → 2.3.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: 3ffc9292346271435345f61a1d78b0445ae9665a
4
- data.tar.gz: e804bf4bdc53f5b9fc6dad8cabac4a8896a3d45f
3
+ metadata.gz: c35bb69a59551448eae6824e7899412d17316913
4
+ data.tar.gz: 9eea7ffb29a6e31b774a79097fc7433acd6b3f65
5
5
  SHA512:
6
- metadata.gz: 2cf37f10598ec5c12cbb69a26dcc1b34d0419dffc0fa63095406032aec85c880e76d6d7e2fc1e5a2fbc811eab4aa1f4aade2ac8c490ae9ab7b7f84958de39d03
7
- data.tar.gz: fe7b94b2cc2218ef2667293499b44d43660653478743de11b80f06f76aa6b44c9439b43fd6fde24aed9c9ca55513aa6df7c3f9fd1a5ed196f80066be0121d8ee
6
+ metadata.gz: da397514835d00919f038b35b02baca683bb3696c3d75a52497ab95d4182cc574e36f4fbc2834e0fbedff50747418b9360c7fdf85282ceb035276fc2192473f7
7
+ data.tar.gz: c5f74ba3b93a4178407e0ba550325a665eba5da83d211547eea6e3a36844042267a6cf56ea42ad85f13a93a563fe9d2e8c85dac1c4f093e73df8f8a5602bca2f
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  .DS_Store
2
2
  *.gem
3
3
  *.rbc
4
+ .byebug_history
4
5
  /.config
5
6
  /coverage/
6
7
  /InstalledFiles
@@ -1,7 +1,6 @@
1
1
  class IdsPlease
2
2
  module Grabbers
3
3
  class Facebook < IdsPlease::Grabbers::Base
4
-
5
4
  def grab_link
6
5
  @network_id = find_network_id
7
6
  @avatar = find_avatar
@@ -35,9 +34,9 @@ class IdsPlease
35
34
  end
36
35
 
37
36
  def find_avatar
38
- CGI.unescapeHTML(
39
- find_by_regex(/profilePic\simg"\salt=[^=]+="([^"]+)/).encode('utf-8')
40
- )
37
+ _avatar = find_by_regex(/profilePic\simg"\salt=[^=]+="([^"]+)/) ||
38
+ find_by_regex(/id="entity_sidebar".+img".+src="([^"]+)/)
39
+ CGI.unescapeHTML(_avatar.gsub(/amp\;/, '').encode('utf-8')) if _avatar
41
40
  rescue => e
42
41
  record_error __method__, e.message
43
42
  return nil
@@ -61,7 +60,7 @@ class IdsPlease
61
60
  end
62
61
 
63
62
  def find_type
64
- find_by_regex(/type":"Person/) ? 'perosnal' : 'group'
63
+ find_by_regex(/type":"Person/) ? 'personal' : 'group'
65
64
  rescue => e
66
65
  record_error __method__, e.message
67
66
  return nil
@@ -31,7 +31,9 @@ class IdsPlease
31
31
  end
32
32
 
33
33
  def find_avatar
34
- "https:#{find_by_regex(/guidedhelpid="profile_photo"><img src="([^"]+)"/)}"
34
+ _avatar = find_by_regex(/meta itemprop="image" content="([^"]+)/).encode('utf-8')
35
+ _avatar = "http:#{_avatar}" unless _avatar =~ /\Ahttps?:\/\//
36
+ _avatar
35
37
  rescue => e
36
38
  record_error __method__, e.message
37
39
  return nil
@@ -30,21 +30,21 @@ class IdsPlease
30
30
  private
31
31
 
32
32
  def find_network_id
33
- find_by_regex(/"id":"(\d+)","biography"/)
33
+ find_by_regex(/"id":\s?"(\d+)"/)
34
34
  rescue => e
35
35
  record_error __method__, e.message
36
36
  return nil
37
37
  end
38
38
 
39
39
  def find_avatar
40
- find_by_regex(/"user":{.+"profile_pic_url":"([^"]+)"/).gsub('\\', '')
40
+ find_by_regex(/"user":\s?{.+"profile_pic_url":\s?"([^"]+)"/).gsub('\\', '')
41
41
  rescue => e
42
42
  record_error __method__, e.message
43
43
  return nil
44
44
  end
45
45
 
46
46
  def find_display_name
47
- _display_name = find_by_regex(/"user":{.+"full_name":"([^"]+)"/)
47
+ _display_name = find_by_regex(/"user":\s?{.+"full_name":\s?"([^"]+)"/)
48
48
  _display_name.gsub(/\\u([\da-fA-F]{4})/) { |_m|
49
49
  [Regexp.last_match(1)].pack('H*').unpack('n*').pack('U*')
50
50
  }
@@ -54,42 +54,42 @@ class IdsPlease
54
54
  end
55
55
 
56
56
  def find_username
57
- find_by_regex(/"user":{"username":"([^"]+)"/).to_s.gsub('\\', '')
57
+ find_by_regex(/"username":\s?"([^"]+)"/).to_s.gsub('\\', '')
58
58
  rescue => e
59
59
  record_error __method__, e.message
60
60
  return nil
61
61
  end
62
62
 
63
63
  def find_bio
64
- CGI.unescapeHTML(find_by_regex(/"biography":"([^"]+)"/).to_s).strip
64
+ CGI.unescapeHTML(find_by_regex(/"biography":\s?"([^"]+)"/).to_s).strip
65
65
  rescue => e
66
66
  record_error __method__, e.message
67
67
  return nil
68
68
  end
69
69
 
70
70
  def find_website
71
- CGI.unescapeHTML(find_by_regex(/"user":{.+"external_url":"([^"]+)"/).to_s.gsub('\\', '')).strip
71
+ CGI.unescapeHTML(find_by_regex(/"user":\s?{.+"external_url":\s?"([^"]+)"/).to_s.gsub('\\', '')).strip
72
72
  rescue => e
73
73
  record_error __method__, e.message
74
74
  return nil
75
75
  end
76
76
 
77
77
  def find_media
78
- find_by_regex(/"media":{"count":(\d+)/).to_i
78
+ find_by_regex(/"media":\s?{"count":\s?(\d+)/).to_i
79
79
  rescue => e
80
80
  record_error __method__, e.message
81
81
  return nil
82
82
  end
83
83
 
84
84
  def find_followed_by
85
- find_by_regex(/"followed_by":{"count":(\d+)/).to_i
85
+ find_by_regex(/"followed_by":\s?{"count":\s?(\d+)/).to_i
86
86
  rescue => e
87
87
  record_error __method__, e.message
88
88
  return nil
89
89
  end
90
90
 
91
91
  def find_follows
92
- find_by_regex(/"follows":{"count":(\d+)/).to_i
92
+ find_by_regex(/"follows":\s?{"count":\s?(\d+)/).to_i
93
93
  rescue => e
94
94
  record_error __method__, e.message
95
95
  return nil
@@ -2,28 +2,65 @@ class IdsPlease
2
2
  module Grabbers
3
3
  class Vkontakte < IdsPlease::Grabbers::Base
4
4
  def grab_link
5
- prepare_link
6
5
  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
6
  @page_source ||= open(link, 'User-Agent' => agent).read.encode('utf-8')
8
- @network_id = find_by_regex(/href="\/wall(-\d+)_/)
9
- @username = @link.to_s.split('vk.com/').last.gsub('/', '')
10
- @avatar = find_by_regex(/page_avatar.+\n.+src="([^"]+)/)
11
- @avatar = CGI.unescapeHTML(@avatar) if @avatar
12
- @display_name = find_by_regex(/page_name">([^<]+)/)
13
- @display_name = CGI.unescapeHTML(@display_name) if @display_name
7
+
8
+ @network_id = find_network_id
9
+ @username = find_username
10
+ @avatar = find_avatar
11
+ @display_name = find_display_name
12
+
14
13
  @data = {
15
- description: find_by_regex(/description" content="([^"]+)/)
14
+ description: find_description
16
15
  }
17
- @data[:description] = CGI.unescapeHTML(@data[:description]) if @data[:description]
18
16
  self
19
17
  rescue => e
20
18
  record_error __method__, e.message
21
19
  return self
22
20
  end
23
21
 
24
- def prepare_link
25
- id = @link.to_s.split('/').last
26
- @link = URI("https://new.vk.com/#{id}")
22
+ private
23
+
24
+ def find_avatar
25
+ CGI.unescapeHTML(
26
+ find_by_regex(/page_avatar_img" src="([^"]+)/) ||
27
+ find_by_regex(/<img src="([^"]+).+class="post_img"/)
28
+ )
29
+ rescue => e
30
+ record_error __method__, e.message
31
+ return nil
32
+ end
33
+
34
+ def find_network_id
35
+ find_by_regex(/href="\/wall(-\d+)_/)
36
+ rescue => e
37
+ record_error __method__, e.message
38
+ return nil
39
+ end
40
+
41
+ def find_display_name
42
+ CGI.unescapeHTML(
43
+ find_by_regex(/page_name">([^<]+)/)
44
+ )
45
+ rescue => e
46
+ record_error __method__, e.message
47
+ return nil
48
+ end
49
+
50
+ def find_username
51
+ @link.to_s.split('vk.com/').last.gsub('/', '')
52
+ rescue => e
53
+ record_error __method__, e.message
54
+ return nil
55
+ end
56
+
57
+ def find_description
58
+ CGI.unescapeHTML(
59
+ find_by_regex(/description" content="([^"]+)/)
60
+ )
61
+ rescue => e
62
+ record_error __method__, e.message
63
+ return nil
27
64
  end
28
65
  end
29
66
  end
@@ -1,5 +1,5 @@
1
1
  class IdsPlease
2
2
 
3
- VERSION = '2.2.5'
3
+ VERSION = '2.3.0'
4
4
 
5
5
  end
@@ -0,0 +1,144 @@
1
+ require 'spec_helper'
2
+
3
+ describe IdsPlease do
4
+ describe 'grab' do
5
+ context 'from external', external: true do
6
+ let!(:recognizer) do
7
+ recognizer = IdsPlease.new(*recognazible_links)
8
+ recognizer.grab
9
+ recognizer
10
+ end
11
+
12
+ let(:recognazible_links) do
13
+ %w(
14
+ https://twitter.com/amplifr
15
+ https://www.instagram.com/instagram/
16
+ https://my.mail.ru/community/test-group-102/
17
+ https://my.mail.ru/mail/gazay/
18
+ https://plus.google.com/+VladimirBokov
19
+ https://plus.google.com/communities/109254488709825102030
20
+ )
21
+ end
22
+
23
+ describe 'vk grabber' do
24
+ context 'vk public page' do
25
+ let(:grabbed) do
26
+ recognizer = IdsPlease.new('https://vk.com/amplifr')
27
+ recognizer.grab[:vkontakte].first
28
+ end
29
+
30
+ it "does return correct data set for public" do
31
+ expect(grabbed.errors).to be_empty
32
+ expect(URI.parse(grabbed.avatar)).to be_truthy
33
+ expect(grabbed.display_name).to be_truthy
34
+ expect(grabbed.username).to be_truthy
35
+ expect(grabbed.network_id).to be_truthy
36
+ expect(grabbed.link).to be_truthy
37
+ expect(grabbed.data).to be_truthy
38
+ end
39
+ end
40
+
41
+ context 'vk user page' do
42
+ let(:grabbed) do
43
+ recognizer = IdsPlease.new('https://vk.com/id1')
44
+ recognizer.grab[:vkontakte].first
45
+ end
46
+ it "does return correct data set for user page" do
47
+ expect(grabbed.errors).to be_empty
48
+ expect(URI.parse(grabbed.avatar)).to be_truthy
49
+ expect(grabbed.display_name).to be_truthy
50
+ expect(grabbed.username).to be_truthy
51
+ expect(grabbed.link).to be_truthy
52
+ expect(grabbed.data).to be_truthy
53
+ end
54
+ end
55
+ end
56
+
57
+ describe 'fb grabber' do
58
+ context 'fb public page' do
59
+ let(:grabbed) do
60
+ recognizer = IdsPlease.new('https://www.facebook.com/amplifr/')
61
+ recognizer.grab[:facebook].first
62
+ end
63
+
64
+ it "does return correct data set for public" do
65
+ expect(grabbed.errors).to be_empty
66
+ expect(URI.parse(grabbed.avatar)).to be_truthy
67
+ expect(grabbed.display_name).to be_truthy
68
+ expect(grabbed.username).to be_truthy
69
+ expect(grabbed.network_id).to be_truthy
70
+ expect(grabbed.link).to be_truthy
71
+ expect(grabbed.data).to be_truthy
72
+ expect(grabbed.data[:type]).to be_truthy
73
+ expect(grabbed.data[:description]).to be_truthy
74
+ end
75
+ end
76
+
77
+ context 'fb user page' do
78
+ let(:grabbed) do
79
+ recognizer = IdsPlease.new('https://www.facebook.com/zuck')
80
+ recognizer.grab[:facebook].first
81
+ end
82
+
83
+ it "does return correct data set for user page" do
84
+ expect(grabbed.errors).to be_empty
85
+ expect(URI.parse(grabbed.avatar)).to be_truthy
86
+ expect(grabbed.display_name).to be_truthy
87
+ expect(grabbed.username).to be_truthy
88
+ expect(grabbed.link).to be_truthy
89
+ expect(grabbed.data[:type]).to be_truthy
90
+ expect(grabbed.data[:description]).to be_truthy
91
+ end
92
+ end
93
+ end
94
+
95
+ it 'does return correct set of data for twitter' do
96
+ recognizer.grabbed[:twitter].each do |g|
97
+ expect(g.errors).to be_empty
98
+ expect(URI.parse(g.avatar)).to be_truthy
99
+ expect(g.display_name).to be_truthy
100
+ expect(g.username).to be_truthy
101
+ expect(g.link).to be_truthy
102
+ expect(g.network_id).to be_truthy
103
+ expect(g.data).to be_truthy
104
+ end
105
+ end
106
+
107
+ it 'does return correct set of data for instagram' do
108
+ recognizer.grabbed[:instagram].each do |g|
109
+ expect(g.errors).to be_empty
110
+ expect(URI.parse(g.avatar)).to be_truthy
111
+ expect(g.display_name).to be_truthy
112
+ expect(g.username).to be_truthy
113
+ expect(g.link).to be_truthy
114
+ expect(g.network_id).to be_truthy
115
+ expect(g.data).to be_truthy
116
+ end
117
+ end
118
+
119
+ it 'does return correct set of data for mail' do
120
+ recognizer.grabbed[:mail].each do |g|
121
+ expect(g.errors).to be_empty
122
+ expect(URI.parse(g.avatar)).to be_truthy
123
+ expect(g.display_name).to be_truthy
124
+ expect(g.username).to be_truthy
125
+ expect(g.link).to be_truthy
126
+ expect(g.network_id).to be_truthy
127
+ expect(g.data).to be_truthy
128
+ end
129
+ end
130
+
131
+ it 'does return correct set of data for google' do
132
+ recognizer.grabbed[:google].each do |g|
133
+ expect(g.errors).to be_empty
134
+ expect(URI.parse(g.avatar)).to be_truthy
135
+ expect(g.display_name).to be_truthy
136
+ expect(g.username).to be_truthy
137
+ expect(g.link).to be_truthy
138
+ expect(g.network_id).to be_truthy
139
+ expect(g.data).to be_truthy
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
@@ -1 +1,5 @@
1
1
  require 'ids_please'
2
+
3
+ RSpec.configure do |c|
4
+ c.filter_run_excluding external: true
5
+ end
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.2.5
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gazay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-10 00:00:00.000000000 Z
11
+ date: 2017-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -101,6 +101,7 @@ files:
101
101
  - lib/ids_please/parsers/youtube.rb
102
102
  - lib/ids_please/version.rb
103
103
  - spec/ids_please/basic_spec.rb
104
+ - spec/ids_please/grab_spec.rb
104
105
  - spec/spec_helper.rb
105
106
  homepage: http://github.com/gazay/ids_please
106
107
  licenses:
@@ -123,10 +124,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
124
  version: '0'
124
125
  requirements: []
125
126
  rubyforge_project:
126
- rubygems_version: 2.5.1
127
+ rubygems_version: 2.5.2
127
128
  signing_key:
128
129
  specification_version: 4
129
130
  summary: Helps to get ids or screen names from links to social network accounts
130
131
  test_files:
131
132
  - spec/ids_please/basic_spec.rb
133
+ - spec/ids_please/grab_spec.rb
132
134
  - spec/spec_helper.rb