ids_please 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7a7f6fccaaba4b6781ce2efc944781496bb20d55
4
+ data.tar.gz: 92ebfb30ccbd70b0476f8196aad9ff0c0155b950
5
+ SHA512:
6
+ metadata.gz: db2c5ad5731b75c06739015a460bbaf8d7994111449111eee7e063a40a0f779e0f202603dc86bb88a05b54d18d397c30539a4d1725221a5d0717d2adc7d139ae
7
+ data.tar.gz: 65364ce2928331f1856fe662829634bfa9ee501630ae1459fd7f3a0cecee2b3f5f1a0c902a5468866e02135baab3e9efbafa871f33034c7e6b57ad88fc46930a
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+ Gemfile.lock
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Alexey Gaziev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ ids_please
2
+ ==========
3
+
4
+ Helps to get ids or screen names from links to social network accounts
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ desc 'Run all tests by default'
7
+ task :default => :spec
8
+
9
+ require 'rspec/core/rake_task'
10
+ RSpec::Core::RakeTask.new do |t|
11
+ t.rspec_opts = ["--color", '--format doc']
12
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ids_please'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "ids_please"
8
+ s.version = IdsPlease::VERSION
9
+ s.authors = ["gazay"]
10
+ s.description = %q{Helps to get ids or screen names from links to social network accounts}
11
+ s.summary = %q{Helps to get ids or screen names from links to social network accounts}
12
+ s.licenses = ['MIT']
13
+ s.email = "alex.gaziev@gmail.com"
14
+ s.extra_rdoc_files = ["LICENSE"]
15
+ s.rdoc_options = ["--charset=UTF-8"]
16
+ s.homepage = "http://github.com/gazay/ids_please"
17
+ s.require_paths = ["lib"]
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.add_development_dependency 'rake'
21
+ s.add_development_dependency 'rspec'
22
+ s.add_development_dependency 'byebug'
23
+ end
@@ -0,0 +1,15 @@
1
+ class IdsPlease::BaseParser
2
+
3
+ def self.network_name
4
+ self.name.split('::').last
5
+ end
6
+
7
+ def self.parse(links)
8
+ links.map { |l| parse_link(l) }.compact
9
+ end
10
+
11
+ def self.parse_link(link)
12
+ link.path.split('/')[1]
13
+ end
14
+
15
+ end
@@ -0,0 +1,16 @@
1
+ class IdsPlease::Facebook < IdsPlease::BaseParser
2
+
3
+ MASK = /fb\.me|fb\.com|facebook/i
4
+
5
+ def self.parse_link(link)
6
+ if link.query && !link.query.empty?
7
+ query = CGI.parse(link.query)
8
+ query['id'].first if query.keys.include?('id')
9
+ elsif link.path =~ /\/pages\//
10
+ link.path.split('/').last
11
+ else
12
+ link.path.split('/')[1]
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,18 @@
1
+ class IdsPlease::GooglePlus < IdsPlease::BaseParser
2
+
3
+ MASK = /google/i
4
+
5
+ def self.parse(links)
6
+ links.map { |l| parse_link(l) }.compact
7
+ end
8
+
9
+ def self.parse_link(link)
10
+ if link.host == 'google.com'
11
+ link.path.split('/')[1]
12
+ else
13
+ matched = link.path.match(/\/(\d{2,})\//)
14
+ matched[1] if matched
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,5 @@
1
+ class IdsPlease::Instagram < IdsPlease::BaseParser
2
+
3
+ MASK = /instagr/i
4
+
5
+ end
@@ -0,0 +1,13 @@
1
+ class IdsPlease::Odnoklassniki < IdsPlease::BaseParser
2
+
3
+ MASK = /odnoklassniki/i
4
+
5
+ def self.parse_link(link)
6
+ if link.path =~ /\/profile\//
7
+ link.path.split('/').last
8
+ elsif link.path.split('/').size == 2
9
+ link.path.split('/').last
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,5 @@
1
+ class IdsPlease::Soundcloud < IdsPlease::BaseParser
2
+
3
+ MASK = /snd\.cc|soundcloud/i
4
+
5
+ end
@@ -0,0 +1,16 @@
1
+ class IdsPlease::Tumblr < IdsPlease::BaseParser
2
+
3
+ MASK = /tumblr/i
4
+
5
+ def self.parse(links)
6
+ links.map do |link|
7
+ next if link.host.sub('.tumblr.com', '') == link.host
8
+ parse_link(link)
9
+ end.compact
10
+ end
11
+
12
+ def self.parse_link(link)
13
+ link.host.sub('.tumblr.com', '')
14
+ end
15
+
16
+ end
@@ -0,0 +1,14 @@
1
+ class IdsPlease::Twitter < IdsPlease::BaseParser
2
+
3
+ MASK = /twitter/i
4
+
5
+ def self.parse_link(link)
6
+ if link.path =~ /%23!/
7
+ id = link.path.sub(/\A\/%23!\//, '')
8
+ id.split(/[\/\?#]/).first
9
+ else
10
+ link.path.split('/')[1]
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,5 @@
1
+ class IdsPlease::Vimeo < IdsPlease::BaseParser
2
+
3
+ MASK = /vimeo/i
4
+
5
+ end
@@ -0,0 +1,18 @@
1
+ class IdsPlease::Vkontakte < IdsPlease::BaseParser
2
+
3
+ MASK = /vk\.com|vkontakte/i
4
+
5
+ def self.parse(links)
6
+ links.map { |l| parse_link(l) }.compact
7
+ end
8
+
9
+ def self.parse_link(link)
10
+ if link.path =~ /id|club/
11
+ id = link.path.sub(/\A\/id|\A\/club/, '')
12
+ id.split(/[\/\?#]/).first
13
+ else
14
+ link.path.split('/')[1]
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,13 @@
1
+ class IdsPlease::Youtube < IdsPlease::BaseParser
2
+
3
+ MASK = /youtu\.be|youtube/i
4
+
5
+ def self.parse_link(link)
6
+ if link.path =~ /channels/
7
+ link.path.split('/')[2]
8
+ else
9
+ link.path.split('/')[1]
10
+ end
11
+ end
12
+
13
+ end
data/lib/ids_please.rb ADDED
@@ -0,0 +1,68 @@
1
+ require 'uri'
2
+ require 'cgi'
3
+
4
+ class IdsPlease
5
+
6
+ VERSION = '0.0.1'
7
+
8
+ attr_accessor :original, :recognized, :unrecognized, :options, :parsed
9
+
10
+ SOCIAL_NETWORKS = %w(
11
+ GooglePlus
12
+ Vkontakte
13
+ Twitter
14
+ Facebook
15
+ Instagram
16
+ Soundcloud
17
+ Vimeo
18
+ Youtube
19
+ Odnoklassniki
20
+ Tumblr
21
+ )
22
+
23
+ def initialize(*args)
24
+ duped_args = args.dup
25
+ @options = duped_args.pop if duped_args.last.is_a?(Hash)
26
+ @original = duped_args
27
+ end
28
+
29
+ def recognize
30
+ @recognized = {}
31
+ @unrecognized = []
32
+ original.each { |l| recognize_link(l) }
33
+ end
34
+
35
+ def parse
36
+ recognize
37
+ @parsed = {}
38
+ recognized.each do |klass_name, links|
39
+ @parsed[klass_name] ||= []
40
+ @parsed[klass_name] += parser(klass_name).parse(links)
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def recognize_link(link)
47
+ network, handle = nil
48
+ link = "http://#{link}" unless link =~ /\Ahttps?:\/\//
49
+ parsed_link = URI(URI.encode(link))
50
+ SOCIAL_NETWORKS.each do |network|
51
+ if parsed_link.host =~ parser(network)::MASK
52
+ recognized[network] ||= []
53
+ recognized[network] << parsed_link
54
+ return
55
+ end
56
+ end
57
+ unrecognized << link
58
+ end
59
+
60
+ def parser(name)
61
+ "IdsPlease::#{name}".split('::').inject(Module) do |acc, val|
62
+ acc.const_get(val)
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ Dir[File.dirname(__FILE__) + '/ids_please/*.rb'].each {|file| require file }
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe IdsPlease do
4
+
5
+ describe 'recognize' do
6
+ recognazible_links = %w(
7
+ https://www.facebook.com/fb_acc
8
+ http://instagram.com/inst_acc
9
+ http://vk.com/vk_acc
10
+ https://twitter.com/twi_acc
11
+ https://vimeo.com/vimeo_acc
12
+ https://plus.google.com/2/u/b/12341234/1234/asdfasd
13
+ https://soundcloud.com/sc_acc
14
+ https://youtube.com/channels/yb_acc
15
+ http://tumblr-acc.tumblr.com
16
+ )
17
+
18
+ not_recognazible_links = %w(
19
+ http://fucebook.com/not_recognized
20
+ http://vka.com/not_recognized
21
+ )
22
+
23
+ it 'not recognizes wrong links' do
24
+ recognizer = IdsPlease.new(*not_recognazible_links)
25
+ recognizer.recognize
26
+ expect(recognizer.recognized.values.flatten.count).to eq(0)
27
+ end
28
+
29
+ context 'recognize social networks properly' do
30
+ before :each do
31
+ @recognizer = IdsPlease.new(*recognazible_links)
32
+ @recognizer.parse
33
+ end
34
+
35
+ it 'recognizes social links' do
36
+ expect(@recognizer.recognized.values.flatten.count).to eq(recognazible_links.count)
37
+ end
38
+
39
+ it 'get right id from facebook link' do
40
+ expect(@recognizer.parsed['Facebook'].first).to eq('fb_acc')
41
+ end
42
+
43
+ it 'get right id from instagram link' do
44
+ expect(@recognizer.parsed['Instagram'].first).to eq('inst_acc')
45
+ end
46
+
47
+ it 'get right id from vk link' do
48
+ expect(@recognizer.parsed['Vkontakte'].first).to eq('vk_acc')
49
+ end
50
+
51
+ it 'get right id from twitter link' do
52
+ expect(@recognizer.parsed['Twitter'].first).to eq('twi_acc')
53
+ end
54
+
55
+ it 'get right id from vimeo link' do
56
+ expect(@recognizer.parsed['Vimeo'].first).to eq('vimeo_acc')
57
+ end
58
+
59
+ it 'get right id from google+ link' do
60
+ expect(@recognizer.parsed['GooglePlus'].first).to eq('12341234')
61
+ end
62
+
63
+ it 'get right id from soundcloud link' do
64
+ expect(@recognizer.parsed['Soundcloud'].first).to eq('sc_acc')
65
+ end
66
+
67
+ it 'get right id from youtube link' do
68
+ expect(@recognizer.parsed['Youtube'].first).to eq('yb_acc')
69
+ end
70
+
71
+ it 'get right id from tumblr link' do
72
+ expect(@recognizer.parsed['Tumblr'].first).to eq('tumblr-acc')
73
+ end
74
+
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,2 @@
1
+ require 'ids_please'
2
+ require 'byebug'
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ids_please
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - gazay
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Helps to get ids or screen names from links to social network accounts
56
+ email: alex.gaziev@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files:
60
+ - LICENSE
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - ids_please.gemspec
68
+ - lib/ids_please.rb
69
+ - lib/ids_please/base_parser.rb
70
+ - lib/ids_please/facebook.rb
71
+ - lib/ids_please/google_plus.rb
72
+ - lib/ids_please/instagram.rb
73
+ - lib/ids_please/odnoklassniki.rb
74
+ - lib/ids_please/soundcloud.rb
75
+ - lib/ids_please/tumblr.rb
76
+ - lib/ids_please/twitter.rb
77
+ - lib/ids_please/vimeo.rb
78
+ - lib/ids_please/vkontakte.rb
79
+ - lib/ids_please/youtube.rb
80
+ - spec/ids_please/basic_spec.rb
81
+ - spec/spec_helper.rb
82
+ homepage: http://github.com/gazay/ids_please
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options:
88
+ - "--charset=UTF-8"
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.2.2
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Helps to get ids or screen names from links to social network accounts
107
+ test_files:
108
+ - spec/ids_please/basic_spec.rb
109
+ - spec/spec_helper.rb