social_media_parser 0.1.2 → 0.1.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 687546e59538c94db3004a13e5387bb4cbc8e1d1
|
4
|
+
data.tar.gz: 5473d30a7cd613c66724bab5a1121135a1479484
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c500399a21c4c3db56b4d219f5661bd7104eae77176c70ef7d3bd6e8a08405c8e18c9d1a6057efc51be085d39134807b573d8ddc8c03f157d4748a7526736427
|
7
|
+
data.tar.gz: 0d482a6656c9bf1caf46b68f23c4e4aaec937654fb2040af8da70dccaebff88b9b3b4886f99ce3905df520bce5753b16fcf6aac8ef2281dabf18f41ce141d9a0
|
data/README.md
CHANGED
@@ -2,9 +2,10 @@
|
|
2
2
|
|
3
3
|
Parse social media attributes from url or construct url from attributes.
|
4
4
|
|
5
|
-
[![
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/social_media_parser.svg)](http://badge.fury.io/rb/social_media_parser)
|
6
6
|
[![Code Climate](https://codeclimate.com/github/mynewsdesk/social_media_parser/badges/gpa.svg)](https://codeclimate.com/github/mynewsdesk/social_media_parser)
|
7
7
|
[![Test Coverage](https://codeclimate.com/github/mynewsdesk/social_media_parser/badges/coverage.svg)](https://codeclimate.com/github/mynewsdesk/social_media_parser)
|
8
|
+
[![Build Status](https://semaphoreapp.com/api/v1/projects/488b1479-a701-4807-956c-a0a513308163/237493/badge.png)](https://semaphoreapp.com/mynewsdesk/social_media_parser)
|
8
9
|
|
9
10
|
## Installation
|
10
11
|
|
@@ -4,13 +4,10 @@ require 'uri'
|
|
4
4
|
module SocialMediaParser
|
5
5
|
module Provider
|
6
6
|
class Base < ::SocialMediaParser::Link
|
7
|
-
PROVIDERS = ['facebook', 'github', 'google', 'instagram', 'pinterest', 'twitter', 'youtube']
|
8
|
-
|
9
7
|
def self.parse(attributes)
|
10
|
-
|
11
|
-
|
12
|
-
end.
|
13
|
-
::SocialMediaParser::Link.new(attributes)
|
8
|
+
providers.map do |provider|
|
9
|
+
eval("SocialMediaParser::Provider::#{provider.capitalize}").new(attributes)
|
10
|
+
end.find(&:valid?) or ::SocialMediaParser::Link.new(attributes)
|
14
11
|
end
|
15
12
|
|
16
13
|
def username
|
@@ -36,14 +33,20 @@ module SocialMediaParser
|
|
36
33
|
|
37
34
|
private
|
38
35
|
|
39
|
-
# Common social media url format, like
|
40
|
-
# Overwrite this in subclasses when
|
41
|
-
# doesn't look like this
|
36
|
+
# Common social media url format, like http(s)://(www.)[provider].com/[username]
|
37
|
+
# Overwrite this in subclasses when url formatting is different
|
42
38
|
def parse_username_from_url
|
43
39
|
URI.parse(url_from_attributes).path.split("/")[1]
|
44
40
|
rescue URI::BadURIError, URI::InvalidURIError
|
45
41
|
nil
|
46
42
|
end
|
43
|
+
|
44
|
+
# Does a file name lookup in the providers/ folder and outputs all file
|
45
|
+
# names, except for this base file
|
46
|
+
def self.providers
|
47
|
+
@providers ||= Dir.entries("lib/social_media_parser/provider/")
|
48
|
+
.reject{|f| File.directory? f }.map{|s| s.gsub(".rb", "")} - ["base"]
|
49
|
+
end
|
47
50
|
end
|
48
51
|
end
|
49
52
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'social_media_parser/provider/base'
|
2
|
+
|
3
|
+
module SocialMediaParser
|
4
|
+
module Provider
|
5
|
+
class Linkedin < Base
|
6
|
+
URL_REGEX = /(?:(?:http|https):\/\/)?(?:www.|[a-z]{2}.)?linkedin.com\/in\/([\w]*)/i
|
7
|
+
|
8
|
+
def provider
|
9
|
+
"linkedin"
|
10
|
+
end
|
11
|
+
|
12
|
+
def url
|
13
|
+
"https://www.linkedin.com/in/#{username}"
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def parse_username_from_url
|
19
|
+
URL_REGEX.match(url_from_attributes).to_a[1]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SocialMediaParser do
|
4
|
+
let(:parser){ described_class.parse profile_attributes }
|
5
|
+
|
6
|
+
context "correct class" do
|
7
|
+
let(:profile_attributes) { {url: "https://www.linkedin.com/in/conanobrien"} }
|
8
|
+
|
9
|
+
it "returns a Linkedin object" do
|
10
|
+
expect(parser).to be_a SocialMediaParser::Provider::Linkedin
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "with linkedin as provider and username as url_or_username" do
|
15
|
+
let(:profile_attributes){ {url_or_username: "conanobrien", provider: "linkedin"} }
|
16
|
+
|
17
|
+
it "returns the parsed attributes" do
|
18
|
+
expect(parser.url).to eq "https://www.linkedin.com/in/conanobrien"
|
19
|
+
expect(parser.provider).to eq "linkedin"
|
20
|
+
expect(parser.username).to eq "conanobrien"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with linkedin as provider and username as url_or_username" do
|
25
|
+
let(:profile_attributes){ {url_or_username: "www.linkedin.com/in/williamhgates", provider: "linkedin"} }
|
26
|
+
|
27
|
+
it "returns the parsed attributes" do
|
28
|
+
expect(parser.url).to eq "https://www.linkedin.com/in/williamhgates"
|
29
|
+
expect(parser.provider).to eq "linkedin"
|
30
|
+
expect(parser.username).to eq "williamhgates"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with linkedin url and provider" do
|
35
|
+
let(:profile_attributes){ {url: "http://linkedin.com/in/barackobama", provider: "linkedin"} }
|
36
|
+
|
37
|
+
it "returns the parsed attributes" do
|
38
|
+
expect(parser.url).to eq "https://www.linkedin.com/in/barackobama"
|
39
|
+
expect(parser.provider).to eq "linkedin"
|
40
|
+
expect(parser.username).to eq "barackobama"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "url variations" do
|
45
|
+
it "parses username from url without trailing slash" do
|
46
|
+
parser = described_class.parse "http://linkedin.com/in/barackobama"
|
47
|
+
expect(parser.username).to eq "barackobama"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "parses username from url with www" do
|
51
|
+
parser = described_class.parse "http://linkedin.com/in/conanobrien/"
|
52
|
+
expect(parser.username).to eq "conanobrien"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "parses username from url without http" do
|
56
|
+
parser = described_class.parse "linkedin.com/in/williamhgates/"
|
57
|
+
expect(parser.username).to eq "williamhgates"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "parses username from country subdomain urls without http" do
|
61
|
+
parser = described_class.parse "se.linkedin.com/in/markusnordin"
|
62
|
+
expect(parser.username).to eq "markusnordin"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "parses username from country subdomain urls with http" do
|
66
|
+
parser = described_class.parse "http://se.linkedin.com/in/markusnordin"
|
67
|
+
expect(parser.username).to eq "markusnordin"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "doesn't parse old public profile urls" do
|
71
|
+
parser = described_class.parse "www.linkedin.com/pub/cameron-diaz/6b/328/111"
|
72
|
+
expect(parser.username).to eq nil
|
73
|
+
expect(parser).to be_a SocialMediaParser::Link
|
74
|
+
end
|
75
|
+
|
76
|
+
it "doesn't parse old public profile urls with country subdomain" do
|
77
|
+
parser = described_class.parse "ua.linkedin.com/pub/mila-kunis/55/4a2/3b5/en"
|
78
|
+
expect(parser.username).to eq nil
|
79
|
+
expect(parser).to be_a SocialMediaParser::Link
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_media_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Nordin
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: public_suffix
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- lib/social_media_parser/provider/github.rb
|
74
74
|
- lib/social_media_parser/provider/google.rb
|
75
75
|
- lib/social_media_parser/provider/instagram.rb
|
76
|
+
- lib/social_media_parser/provider/linkedin.rb
|
76
77
|
- lib/social_media_parser/provider/pinterest.rb
|
77
78
|
- lib/social_media_parser/provider/twitter.rb
|
78
79
|
- lib/social_media_parser/provider/youtube.rb
|
@@ -83,6 +84,7 @@ files:
|
|
83
84
|
- spec/social_media_parser/provider/github_spec.rb
|
84
85
|
- spec/social_media_parser/provider/google_spec.rb
|
85
86
|
- spec/social_media_parser/provider/instagram_spec.rb
|
87
|
+
- spec/social_media_parser/provider/linkedin_spec.rb
|
86
88
|
- spec/social_media_parser/provider/pinterest_spec.rb
|
87
89
|
- spec/social_media_parser/provider/twitter_spec.rb
|
88
90
|
- spec/social_media_parser/provider/youtube_spec.rb
|
@@ -108,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
110
|
version: '0'
|
109
111
|
requirements: []
|
110
112
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.4.
|
113
|
+
rubygems_version: 2.4.5
|
112
114
|
signing_key:
|
113
115
|
specification_version: 4
|
114
116
|
summary: Parse social media attributes from url or construct url from attributes
|
@@ -118,6 +120,7 @@ test_files:
|
|
118
120
|
- spec/social_media_parser/provider/github_spec.rb
|
119
121
|
- spec/social_media_parser/provider/google_spec.rb
|
120
122
|
- spec/social_media_parser/provider/instagram_spec.rb
|
123
|
+
- spec/social_media_parser/provider/linkedin_spec.rb
|
121
124
|
- spec/social_media_parser/provider/pinterest_spec.rb
|
122
125
|
- spec/social_media_parser/provider/twitter_spec.rb
|
123
126
|
- spec/social_media_parser/provider/youtube_spec.rb
|