ids_please 1.0.6 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71c43f0f021c3e31d48e900162f1cdbb0bcb0591
4
- data.tar.gz: 7feef5dcfdf2a0ff1a5076b5802a1ffcb85bf4fa
3
+ metadata.gz: 95672c43728eb68bbbf5fbf8917e049120e8c7c6
4
+ data.tar.gz: aab2241d2583ec30a539d87f6d4b3403ab5f1266
5
5
  SHA512:
6
- metadata.gz: 0606463138c74600656f3402032d7322f49ed838eb5e7ecd95345284f72e5f8b6b3595e887b549d5a05deb507bbfe22f658c2916a94560dbb7728f71237ff0ec
7
- data.tar.gz: 2dc7643226c2792d33a094c165b4101298ce04d23955a353f94c5e7e46ed83754a19bacd79894df0108b09bd7c7123830b7965b847408becb3b14e1f217cc9e8
6
+ metadata.gz: 1859ae23f350b2ca328afbc0b51e58b95b0b1ec4f351025abb2a6f6f8a5d48f92d65b6dea16ebd608e8d9cb316c8358246ac34bafa92b30c2ccf88843b6f7e2d
7
+ data.tar.gz: 8b5f4496318b59e43504a1981e40ed7c107800e14994abf5ab66d571cd5407914a891c7292eca1aed240af678f93164bafaafda50126d13f71ef97685cf6d1b8
data/README.md CHANGED
@@ -46,16 +46,24 @@ puts ids.unrecognized # => ["http://some-unknown-network.com/gazay"]
46
46
 
47
47
  Social networks supported at the moment:
48
48
 
49
- * Facebook
50
- * Twitter
51
- * Instagram
52
- * Soundcloud
53
- * GooglePlus
54
- * Youtube
55
- * Tumblr
56
- * Vimeo
57
- * Vkontakte
58
- * Odnoklassniki
49
+ * [Facebook](https://www.facebook.com)
50
+ * [Twitter](https://twitter.com)
51
+ * [Instagram](http://instagram.com)
52
+ * [Soundcloud](http://soundcloud.com)
53
+ * [GooglePlus](https://plus.google.com)
54
+ * [Youtube](http://www.youtube.com)
55
+ * [Tumblr](http://tumblr.com)
56
+ * [Vimeo](http://vimeo.com)
57
+ * [Pinterest](http://pinterest.com)
58
+ * [Blogger](http://blogger.com)
59
+ * [Reddit](http://reddit.com)
60
+ * [Ameba](http://ameblo.jp)
61
+ * [Linkedin](http://linkedin.com)
62
+ * [Livejournal](http://livejournal.com)
63
+ * [Hi5](http://hi5.com)
64
+ * [Vkontakte](http://vk.com)
65
+ * [Odnoklassniki](http://odnoklassniki.ru)
66
+ * [Moikrug](https://moikrug.ru)
59
67
 
60
68
  ## Contributors
61
69
 
data/lib/ids_please.rb CHANGED
@@ -4,6 +4,13 @@ require_relative 'ids_please/base_parser'
4
4
  require_relative 'ids_please/facebook'
5
5
  require_relative 'ids_please/google_plus'
6
6
  require_relative 'ids_please/instagram'
7
+ require_relative 'ids_please/blogger'
8
+ require_relative 'ids_please/ameba'
9
+ require_relative 'ids_please/hi5'
10
+ require_relative 'ids_please/livejournal'
11
+ require_relative 'ids_please/linkedin'
12
+ require_relative 'ids_please/pinterest'
13
+ require_relative 'ids_please/reddit'
7
14
  require_relative 'ids_please/twitter'
8
15
  require_relative 'ids_please/tumblr'
9
16
  require_relative 'ids_please/vimeo'
@@ -11,12 +18,13 @@ require_relative 'ids_please/youtube'
11
18
  require_relative 'ids_please/soundcloud'
12
19
  require_relative 'ids_please/vkontakte'
13
20
  require_relative 'ids_please/odnoklassniki'
21
+ require_relative 'ids_please/moikrug'
14
22
 
15
23
  class IdsPlease
16
24
 
17
- VERSION = '1.0.6'
25
+ VERSION = '1.1.0'
18
26
 
19
- attr_accessor :original, :recognized, :unrecognized, :parsed
27
+ attr_accessor :original, :unrecognized, :parsed
20
28
 
21
29
  SOCIAL_NETWORKS = [
22
30
  IdsPlease::GooglePlus,
@@ -24,11 +32,19 @@ class IdsPlease
24
32
  IdsPlease::Twitter,
25
33
  IdsPlease::Facebook,
26
34
  IdsPlease::Instagram,
35
+ IdsPlease::Blogger,
36
+ IdsPlease::Ameba,
37
+ IdsPlease::Hi5,
38
+ IdsPlease::Linkedin,
39
+ IdsPlease::Livejournal,
40
+ IdsPlease::Reddit,
41
+ IdsPlease::Pinterest,
27
42
  IdsPlease::Soundcloud,
28
43
  IdsPlease::Vimeo,
29
44
  IdsPlease::Youtube,
30
45
  IdsPlease::Odnoklassniki,
31
- IdsPlease::Tumblr
46
+ IdsPlease::Tumblr,
47
+ IdsPlease::Moikrug
32
48
  ]
33
49
 
34
50
  def initialize(*args)
@@ -42,14 +58,15 @@ class IdsPlease
42
58
  original.each { |l| recognize_link(l) }
43
59
  end
44
60
 
61
+ def recognized
62
+ Hash[@recognized.map { |parser, links| [ parser.to_sym, links ] }]
63
+ end
64
+
45
65
  def parse
46
66
  recognize
47
- @parsed = {}
48
- recognized.each do |network_sym, links|
49
- parser = SOCIAL_NETWORKS.find { |sn| sn.to_sym == network_sym }
50
-
51
- @parsed[network_sym] ||= []
52
- @parsed[network_sym] += parser.parse(links)
67
+ @parsed = Hash.new { |hash, parser| hash[parser.to_sym] = [] }
68
+ @recognized.each do |parser, links|
69
+ @parsed[parser].concat parser.parse(links)
53
70
  end
54
71
  end
55
72
 
@@ -60,8 +77,8 @@ class IdsPlease
60
77
  parsed_link = URI(URI.encode(link))
61
78
  SOCIAL_NETWORKS.each do |network|
62
79
  if parsed_link.host =~ network::MASK
63
- recognized[network.to_sym] ||= []
64
- recognized[network.to_sym] << parsed_link
80
+ @recognized[network] ||= []
81
+ @recognized[network] << parsed_link
65
82
  return
66
83
  end
67
84
  end
@@ -0,0 +1,7 @@
1
+ class IdsPlease
2
+ class Ameba < IdsPlease::BaseParser
3
+
4
+ MASK = /ameblo/i
5
+
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ class IdsPlease
2
+ class Blogger < IdsPlease::BaseParser
3
+
4
+ MASK = /blogspot|blogger/i
5
+
6
+ def self.parse(links)
7
+ links.map do |link|
8
+ parse_link(link)
9
+ end.compact
10
+ end
11
+
12
+ def self.parse_link(link)
13
+ query = CGI.parse(link.query) if link.query && !link.query.empty?
14
+
15
+ if query && !query['blogID'].empty?
16
+ query['blogID'].first.split('#').first
17
+ else
18
+ return if link.host.sub('.blogspot.com', '') == link.host
19
+ link.host.sub('.blogspot.com', '')
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+
@@ -3,6 +3,8 @@ class IdsPlease
3
3
 
4
4
  MASK = /fb\.me|fb\.com|facebook/i
5
5
 
6
+ private
7
+
6
8
  def self.parse_link(link)
7
9
  query = CGI.parse(link.query) if link.query && !link.query.empty?
8
10
 
@@ -0,0 +1,19 @@
1
+ class IdsPlease
2
+ class Hi5 < IdsPlease::BaseParser
3
+
4
+ MASK = /hi5/i
5
+
6
+ private
7
+
8
+ def self.parse_link(link)
9
+ query = CGI.parse(link.query) if link.query && !link.query.empty?
10
+
11
+ if query && !query['uid'].empty?
12
+ query['uid'].first
13
+ else
14
+ link.path.split('/')[1]
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ class IdsPlease
2
+ class Linkedin < IdsPlease::BaseParser
3
+
4
+ MASK = /linkedin/i
5
+
6
+ private
7
+
8
+ def self.parse_link(link)
9
+ query = CGI.parse(link.query) if link.query && !link.query.empty?
10
+
11
+ if query && !query['id'].empty?
12
+ query['id'].first
13
+ elsif link.path =~ /\/pub\//
14
+ link.path.split('/')[2]
15
+ end
16
+ end
17
+
18
+
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ class IdsPlease
2
+ class Livejournal < IdsPlease::BaseParser
3
+
4
+ MASK = /livejournal/i
5
+
6
+ private
7
+
8
+ def self.parse_link(link)
9
+ parsed = link.host.sub('.livejournal.com', '')
10
+ parsed = link.host.split('.livejournal').first if parsed == link.host
11
+ return if parsed == link.host
12
+ parsed
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ class IdsPlease
2
+ class Moikrug < IdsPlease::BaseParser
3
+
4
+ MASK = /moikrug/i
5
+
6
+ def self.parse(links)
7
+ links.map do |link|
8
+ next if link.host.sub('.moikrug.ru', '') == link.host
9
+ parse_link(link)
10
+ end.compact
11
+ end
12
+
13
+ private
14
+
15
+ def self.parse_link(link)
16
+ link.host.sub('.moikrug.ru', '')
17
+ end
18
+
19
+ end
20
+ end
@@ -3,6 +3,8 @@ class IdsPlease
3
3
 
4
4
  MASK = /odnoklassniki/i
5
5
 
6
+ private
7
+
6
8
  def self.parse_link(link)
7
9
  if matched = link.path.match(/\/(\d{2,})/)
8
10
  matched[1]
@@ -0,0 +1,7 @@
1
+ class IdsPlease
2
+ class Pinterest < IdsPlease::BaseParser
3
+
4
+ MASK = /pinterest/i
5
+
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ class IdsPlease
2
+ class Reddit < IdsPlease::BaseParser
3
+
4
+ MASK = /reddit/i
5
+
6
+ private
7
+
8
+ def self.parse_link(link)
9
+ link.path.split('/')[2]
10
+ end
11
+
12
+ end
13
+ end
@@ -3,14 +3,10 @@ class IdsPlease
3
3
 
4
4
  MASK = /tumblr/i
5
5
 
6
- def self.parse(links)
7
- links.map do |link|
8
- next if link.host.sub('.tumblr.com', '') == link.host
9
- parse_link(link)
10
- end.compact
11
- end
6
+ private
12
7
 
13
8
  def self.parse_link(link)
9
+ return if link.host.sub('.tumblr.com', '') == link.host
14
10
  link.host.sub('.tumblr.com', '')
15
11
  end
16
12
 
@@ -3,6 +3,8 @@ class IdsPlease
3
3
 
4
4
  MASK = /twitter/i
5
5
 
6
+ private
7
+
6
8
  def self.parse_link(link)
7
9
  if link.path =~ /%23!/
8
10
  id = link.path.sub(/\A\/%23!\//, '')
@@ -7,6 +7,8 @@ class IdsPlease
7
7
  links.map { |l| parse_link(l) }.compact
8
8
  end
9
9
 
10
+ private
11
+
10
12
  def self.parse_link(link)
11
13
  if link.path =~ /id|club/
12
14
  id = link.path.sub(/\A\/id|\A\/club/, '')
@@ -3,6 +3,8 @@ class IdsPlease
3
3
 
4
4
  MASK = /youtu\.be|youtube/i
5
5
 
6
+ private
7
+
6
8
  def self.parse_link(link)
7
9
  if link.path =~ /channels|user/
8
10
  link.path.split('/')[2]
@@ -2,64 +2,185 @@ require 'spec_helper'
2
2
 
3
3
  describe IdsPlease do
4
4
 
5
+ recognazible_links = %w(
6
+ https://www.facebook.com/fb_acc
7
+ https://www.facebook.com/fb_acc2<U+200>
8
+ http://instagram.com/inst_acc
9
+ http://hi5.com/hi5_acc
10
+ http://www.hi5.com/profile.html?uid=12341234
11
+ http://pinterest.com/pinterest_acc
12
+ http://blogger-acc.blogspot.com
13
+ http://livejournal-acc.livejournal.com
14
+ http://livejournal-acc2.livejournal.ru
15
+ https://www.blogger.com/blogger.g?blogID=12341234#overview/src=dashboard
16
+ http://vk.com/vk_acc
17
+ http://linkedin.com/pub/linkedin_acc
18
+ http://www.linkedin.com/profile/view?id=12341234&trk=nav_responsive_tab_profile
19
+ http://Ameblo.jp/ameba_acc
20
+ http://reddit.com/user/reddit_acc
21
+ https://twitter.com/twi_acc
22
+ https://vimeo.com/vimeo_acc
23
+ https://plus.google.com/12341234
24
+ https://plus.google.com/+VladimirBokov
25
+ https://soundcloud.com/sc_acc
26
+ https://youtube.com/channels/yb_acc
27
+ http://tumblr-acc.tumblr.com
28
+ http://odnoklassniki.com/profile/12341234/about
29
+ http://odnoklassniki.com/group/43214321/about?some=123
30
+ http://moikrug-acc.moikrug.ru
31
+ )
32
+
33
+ not_recognazible_links = %w(
34
+ http://fucebook.com/not_recognized
35
+ http://vka.com/not_recognized
36
+ )
37
+
38
+ not_parseble_links = %w(
39
+ http://vk.com
40
+ http://soundcloud.com
41
+ )
42
+
5
43
  describe 'recognize' do
6
- recognazible_links = %w(
7
- https://www.facebook.com/fb_acc
8
- https://www.facebook.com/fb_acc2<U+200>
9
- http://instagram.com/inst_acc
10
- http://vk.com/vk_acc
11
- https://twitter.com/twi_acc
12
- https://vimeo.com/vimeo_acc
13
- https://plus.google.com/12341234
14
- https://plus.google.com/+VladimirBokov
15
- https://soundcloud.com/sc_acc
16
- https://youtube.com/channels/yb_acc
17
- http://tumblr-acc.tumblr.com
18
- http://odnoklassniki.com/profile/12341234/about
19
- http://odnoklassniki.com/group/43214321/about?some=123
20
- )
21
-
22
- not_recognazible_links = %w(
23
- http://fucebook.com/not_recognized
24
- http://vka.com/not_recognized
25
- )
26
-
27
- not_parseble_links = %w(
28
- http://vk.com
29
- http://soundcloud.com
30
- )
31
44
 
32
45
  it 'not recognizes wrong links' do
33
46
  recognizer = IdsPlease.new(*not_recognazible_links)
34
47
  recognizer.recognize
35
48
  expect(recognizer.recognized.values.flatten.count).to eq(0)
49
+ expect(recognizer.unrecognized).to eq(not_recognazible_links)
50
+ end
51
+
52
+ context 'recognize social networks properly' do
53
+ before :each do
54
+ @recognizer = IdsPlease.new(*recognazible_links)
55
+ @recognizer.parse
56
+ end
57
+
58
+ it 'recognizes social links' do
59
+ expect(@recognizer.recognized.values.flatten.count).to eq(recognazible_links.count)
60
+ end
61
+
62
+ it 'recognizes facebook link' do
63
+ expect(@recognizer.recognized[:facebook].count).to eq(2)
64
+ end
65
+
66
+ it 'recognizes hi5 link' do
67
+ expect(@recognizer.recognized[:hi5].count).to eq(2)
68
+ end
69
+
70
+ it 'recognizes linkedin link' do
71
+ expect(@recognizer.recognized[:linkedin].count).to eq(2)
72
+ end
73
+
74
+ it 'recognizes livejournal link' do
75
+ expect(@recognizer.recognized[:livejournal].count).to eq(2)
76
+ end
77
+
78
+ it 'recognizes instagram link' do
79
+ expect(@recognizer.recognized[:instagram].count).to eq(1)
80
+ end
81
+
82
+ it 'recognizes reddit link' do
83
+ expect(@recognizer.recognized[:reddit].count).to eq(1)
84
+ end
85
+
86
+ it 'recognizes blogger link' do
87
+ expect(@recognizer.recognized[:blogger].count).to eq(2)
88
+ end
89
+
90
+ it 'recognizes pinterest link' do
91
+ expect(@recognizer.recognized[:pinterest].count).to eq(1)
92
+ end
93
+
94
+ it 'recognizes vk link' do
95
+ expect(@recognizer.recognized[:vkontakte].count).to eq(1)
96
+ end
97
+
98
+ it 'recognizes twitter link' do
99
+ expect(@recognizer.recognized[:twitter].count).to eq(1)
100
+ end
101
+
102
+ it 'recognizes vimeo link' do
103
+ expect(@recognizer.recognized[:vimeo].count).to eq(1)
104
+ end
105
+
106
+ it 'recognizes google+ link' do
107
+ expect(@recognizer.recognized[:google_plus].count).to eq(2)
108
+ end
109
+
110
+ it 'recognizes soundcloud link' do
111
+ expect(@recognizer.recognized[:soundcloud].count).to eq(1)
112
+ end
113
+
114
+ it 'recognizes youtube link' do
115
+ expect(@recognizer.recognized[:youtube].count).to eq(1)
116
+ end
117
+
118
+ it 'recognizes ameba link' do
119
+ expect(@recognizer.recognized[:ameba].count).to eq(1)
120
+ end
121
+
122
+ it 'recognizes tumblr link' do
123
+ expect(@recognizer.recognized[:tumblr].count).to eq(1)
124
+ end
125
+
126
+ it 'recognizes odnoklassniki link' do
127
+ expect(@recognizer.recognized[:odnoklassniki].count).to eq(2)
128
+ end
129
+
130
+ it 'recognizes moikrug link' do
131
+ expect(@recognizer.recognized[:moikrug].count).to eq(1)
132
+ end
133
+
36
134
  end
37
135
 
136
+ end
137
+
138
+ describe 'parse' do
139
+
38
140
  it 'not parse wrong links' do
39
141
  @recognizer = IdsPlease.new(*not_parseble_links)
40
142
  @recognizer.parse
41
143
  expect(@recognizer.parsed[:vkontakte]).to eq([])
42
144
  expect(@recognizer.parsed[:soundcloud]).to eq([])
145
+ expect(@recognizer.unrecognized).to eq([])
43
146
  end
44
147
 
45
- context 'recognize social networks properly' do
148
+ it 'contains the original passed args' do
149
+ @recognizer = IdsPlease.new(*not_parseble_links)
150
+ @recognizer.parse
151
+ expect(@recognizer.original).to eq(not_parseble_links)
152
+ end
153
+
154
+ context 'parse social networks properly' do
46
155
  before :each do
47
156
  @recognizer = IdsPlease.new(*recognazible_links)
48
157
  @recognizer.parse
49
158
  end
50
159
 
51
- it 'recognizes social links' do
52
- expect(@recognizer.recognized.values.flatten.count).to eq(recognazible_links.count)
160
+ it 'parses social links' do
161
+ expect(@recognizer.parsed.values.flatten.count).to eq(recognazible_links.count)
53
162
  end
54
163
 
55
164
  it 'get right id from facebook link' do
56
165
  expect(@recognizer.parsed[:facebook]).to eq(['fb_acc', 'fb_acc2'])
57
166
  end
58
167
 
168
+ it 'get right id from linkedin link' do
169
+ expect(@recognizer.parsed[:linkedin]).to eq(['linkedin_acc', '12341234'])
170
+ end
171
+
59
172
  it 'get right id from instagram link' do
60
173
  expect(@recognizer.parsed[:instagram].first).to eq('inst_acc')
61
174
  end
62
175
 
176
+ it 'get right id from pinterest link' do
177
+ expect(@recognizer.parsed[:pinterest].first).to eq('pinterest_acc')
178
+ end
179
+
180
+ it 'get right id from blogger link' do
181
+ expect(@recognizer.parsed[:blogger]).to eq(['blogger-acc', '12341234'])
182
+ end
183
+
63
184
  it 'get right id from vk link' do
64
185
  expect(@recognizer.parsed[:vkontakte].first).to eq('vk_acc')
65
186
  end
@@ -68,6 +189,10 @@ describe IdsPlease do
68
189
  expect(@recognizer.parsed[:twitter].first).to eq('twi_acc')
69
190
  end
70
191
 
192
+ it 'get right id from reddit link' do
193
+ expect(@recognizer.parsed[:reddit].first).to eq('reddit_acc')
194
+ end
195
+
71
196
  it 'get right id from vimeo link' do
72
197
  expect(@recognizer.parsed[:vimeo].first).to eq('vimeo_acc')
73
198
  end
@@ -76,6 +201,10 @@ describe IdsPlease do
76
201
  expect(@recognizer.parsed[:google_plus]).to eq(['12341234', '+VladimirBokov'])
77
202
  end
78
203
 
204
+ it 'get right id from hi5 link' do
205
+ expect(@recognizer.parsed[:hi5]).to eq(['hi5_acc', '12341234'])
206
+ end
207
+
79
208
  it 'get right id from soundcloud link' do
80
209
  expect(@recognizer.parsed[:soundcloud].first).to eq('sc_acc')
81
210
  end
@@ -84,16 +213,27 @@ describe IdsPlease do
84
213
  expect(@recognizer.parsed[:youtube].first).to eq('yb_acc')
85
214
  end
86
215
 
216
+ it 'get right id from ameba link' do
217
+ expect(@recognizer.parsed[:ameba].first).to eq('ameba_acc')
218
+ end
219
+
87
220
  it 'get right id from tumblr link' do
88
221
  expect(@recognizer.parsed[:tumblr].first).to eq('tumblr-acc')
89
222
  end
90
223
 
224
+ it 'get right id from livejournal link' do
225
+ expect(@recognizer.parsed[:livejournal]).to eq(['livejournal-acc', 'livejournal-acc2'])
226
+ end
227
+
91
228
  it 'get right id from odnoklassniki link' do
92
229
  expect(@recognizer.parsed[:odnoklassniki]).to eq(['12341234', '43214321'])
93
230
  end
94
231
 
95
- end
232
+ it 'get right id from moikrug link' do
233
+ expect(@recognizer.parsed[:moikrug].first).to eq('moikrug-acc')
234
+ end
96
235
 
236
+ end
97
237
  end
98
238
 
99
239
  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: 1.0.6
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gazay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-23 00:00:00.000000000 Z
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -66,11 +66,19 @@ files:
66
66
  - Rakefile
67
67
  - ids_please.gemspec
68
68
  - lib/ids_please.rb
69
+ - lib/ids_please/ameba.rb
69
70
  - lib/ids_please/base_parser.rb
71
+ - lib/ids_please/blogger.rb
70
72
  - lib/ids_please/facebook.rb
71
73
  - lib/ids_please/google_plus.rb
74
+ - lib/ids_please/hi5.rb
72
75
  - lib/ids_please/instagram.rb
76
+ - lib/ids_please/linkedin.rb
77
+ - lib/ids_please/livejournal.rb
78
+ - lib/ids_please/moikrug.rb
73
79
  - lib/ids_please/odnoklassniki.rb
80
+ - lib/ids_please/pinterest.rb
81
+ - lib/ids_please/reddit.rb
74
82
  - lib/ids_please/soundcloud.rb
75
83
  - lib/ids_please/tumblr.rb
76
84
  - lib/ids_please/twitter.rb