social_media_parser 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -5
- data/Rakefile +3 -0
- data/lib/social_media_parser/{social_media/provider.rb → provider/base.rb} +3 -3
- data/lib/social_media_parser/{social_media → provider}/facebook.rb +3 -3
- data/lib/social_media_parser/provider/github.rb +12 -0
- data/lib/social_media_parser/{social_media → provider}/google.rb +3 -3
- data/lib/social_media_parser/provider/instagram.rb +11 -0
- data/lib/social_media_parser/provider/pinterest.rb +11 -0
- data/lib/social_media_parser/{social_media → provider}/twitter.rb +3 -3
- data/lib/social_media_parser/{social_media → provider}/youtube.rb +3 -3
- data/lib/social_media_parser/version.rb +1 -1
- data/lib/social_media_parser.rb +3 -3
- data/social_media_parser.gemspec +3 -3
- data/spec/social_media_parser/{social_media → provider}/facebook_spec.rb +1 -1
- data/spec/social_media_parser/{social_media → provider}/github_spec.rb +1 -1
- data/spec/social_media_parser/{social_media → provider}/google_spec.rb +1 -1
- data/spec/social_media_parser/{social_media → provider}/instagram_spec.rb +1 -1
- data/spec/social_media_parser/{social_media → provider}/pinterest_spec.rb +1 -1
- data/spec/social_media_parser/{social_media → provider}/twitter_spec.rb +1 -1
- data/spec/social_media_parser/{social_media → provider}/youtube_spec.rb +1 -1
- data/spec/social_media_parser_spec.rb +4 -4
- metadata +32 -32
- data/lib/social_media_parser/social_media/github.rb +0 -12
- data/lib/social_media_parser/social_media/instagram.rb +0 -12
- data/lib/social_media_parser/social_media/pinterest.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 118b227b802b71eb23147a919b5757067a7a24f7
|
4
|
+
data.tar.gz: 71fb3bb95e7224290f8df62f307bb15417b2fad8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0d244c23a4389fdcc05a2292d3f12dce90bece65a6ae801fdabde663d79dcc88eb0618b8290002ab110003863fd138517e60e4fed2ecaa1eb7a67f12c801f07
|
7
|
+
data.tar.gz: 97735b8243a2feaa95435e51b8aaca3541aedebbe7ec246af9e538e9be673295d78e9e6e5b58a6e4bf808bc569b4011a20052fccd011d48409475ec84dca247c
|
data/README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
Parse social media attributes from url or construct url from attributes.
|
4
4
|
|
5
|
+
[![Code Climate](https://codeclimate.com/github/mynewsdesk/social_media_parser/badges/gpa.svg)](https://codeclimate.com/github/mynewsdesk/social_media_parser)
|
6
|
+
[![Build Status](https://semaphoreapp.com/api/v1/projects/488b1479-a701-4807-956c-a0a513308163/237493/badge.png)](https://semaphoreapp.com/mynewsdesk/social_media_parser)
|
7
|
+
|
5
8
|
## Installation
|
6
9
|
|
7
10
|
Add this line to your application's Gemfile:
|
@@ -20,9 +23,9 @@ Or install it yourself as:
|
|
20
23
|
|
21
24
|
## Usage
|
22
25
|
|
23
|
-
```
|
26
|
+
```ruby
|
24
27
|
parser = SocialMediaParser.parse "https://www.facebook.com/teamcoco"
|
25
|
-
=> #<SocialMediaParser::
|
28
|
+
=> #<SocialMediaParser::Provider::Facebook:0x007fe014ef0f78 @url="https://www.facebook.com/teamcoco">
|
26
29
|
|
27
30
|
parser.username
|
28
31
|
=> "teamcoco"
|
@@ -36,8 +39,13 @@ parser.url
|
|
36
39
|
|
37
40
|
`SocialMediaParser#parse` accepts either a url string or a hash, that accepts
|
38
41
|
|
39
|
-
```
|
40
|
-
{
|
42
|
+
```ruby
|
43
|
+
{
|
44
|
+
username: "teamcoco",
|
45
|
+
provider: "facebook",
|
46
|
+
url: "https://www.facebook.com/teamcoco",
|
47
|
+
url_or_username: "teamcoco"
|
48
|
+
}
|
41
49
|
```
|
42
50
|
|
43
51
|
The `url_or_username` option can be used when you're not sure of the input, like the screenshot below for instance. This gem is built to take user input directly.
|
@@ -47,7 +55,7 @@ The `url_or_username` option can be used when you're not sure of the input, like
|
|
47
55
|
|
48
56
|
If the input provided isn't enough for SocialMediaParser to figure out which provider it is, it returns a `SocialMediaParser::Link` object instead.
|
49
57
|
|
50
|
-
```
|
58
|
+
```ruby
|
51
59
|
link = SocialMediaParser.parse "www.ruby-lang.org/en/"
|
52
60
|
=> #<SocialMediaParser::Link:0x007fe014fd8350 @url="https://www.ruby-lang.org/en/">
|
53
61
|
|
data/Rakefile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'social_media_parser/link'
|
2
2
|
|
3
3
|
module SocialMediaParser
|
4
|
-
module
|
5
|
-
class
|
4
|
+
module Provider
|
5
|
+
class Base < ::SocialMediaParser::Link
|
6
6
|
PROVIDERS = ['facebook', 'github', 'google', 'instagram', 'pinterest', 'twitter', 'youtube']
|
7
7
|
|
8
8
|
def self.parse(attributes)
|
9
9
|
PROVIDERS.map do |provider|
|
10
|
-
Object.const_get("SocialMediaParser").const_get("
|
10
|
+
Object.const_get("SocialMediaParser").const_get("Provider").const_get(provider.capitalize).new(attributes)
|
11
11
|
end.select(&:valid?).first or
|
12
12
|
::SocialMediaParser::Link.new(attributes)
|
13
13
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'social_media_parser/
|
1
|
+
require 'social_media_parser/provider/base'
|
2
2
|
|
3
3
|
module SocialMediaParser
|
4
|
-
module
|
5
|
-
class Facebook <
|
4
|
+
module Provider
|
5
|
+
class Facebook < Base
|
6
6
|
URL_REGEX = /(?:(?:http|https):\/\/)?(?:www.)?facebook.com\/(?:(?:\w)*#!\/)?(?:pages\/[\w\-]*)?(?:[?\d\-]*\/)?(?:profile.php\?id=(?=\d.*))?([\w\-\.]*)?/i
|
7
7
|
|
8
8
|
def provider
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'social_media_parser/
|
1
|
+
require 'social_media_parser/provider/base'
|
2
2
|
|
3
3
|
module SocialMediaParser
|
4
|
-
module
|
5
|
-
class Google <
|
4
|
+
module Provider
|
5
|
+
class Google < Base
|
6
6
|
URL_REGEX = /(?:(?:http|https):\/\/)plus.google.com\/?(?:u\/\d{1,}\/|)(?:\+|)([\w\-\.\%]{1,})/i
|
7
7
|
|
8
8
|
def provider
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'social_media_parser/
|
1
|
+
require 'social_media_parser/provider/base'
|
2
2
|
|
3
3
|
module SocialMediaParser
|
4
|
-
module
|
5
|
-
class Twitter <
|
4
|
+
module Provider
|
5
|
+
class Twitter < Base
|
6
6
|
URL_REGEX = /(?:(?:http|https):\/\/)?(?:www.)?twitter.com\/(?:(?:\w)*#!\/)?(\w*)/i
|
7
7
|
|
8
8
|
def provider
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'social_media_parser/
|
1
|
+
require 'social_media_parser/provider/base'
|
2
2
|
|
3
3
|
module SocialMediaParser
|
4
|
-
module
|
5
|
-
class Youtube <
|
4
|
+
module Provider
|
5
|
+
class Youtube < Base
|
6
6
|
URL_REGEX = /(?:(?:http|https):\/\/)?(?:www.)?youtube\.com\/(?:user\/)([\w\-\.]{1,})/i
|
7
7
|
|
8
8
|
def provider
|
data/lib/social_media_parser.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require '
|
2
|
-
Dir[File.join(File.dirname(__FILE__), 'social_media_parser', '
|
1
|
+
require 'uri'
|
2
|
+
Dir[File.join(File.dirname(__FILE__), 'social_media_parser', 'provider', '*.rb')].each {|file| require file }
|
3
3
|
|
4
4
|
module SocialMediaParser
|
5
5
|
def self.parse(attrs)
|
6
6
|
if attrs.is_a? String
|
7
7
|
return parse(url: attrs)
|
8
8
|
end
|
9
|
-
|
9
|
+
Provider::Base.parse(attrs)
|
10
10
|
end
|
11
11
|
end
|
data/social_media_parser.gemspec
CHANGED
@@ -17,8 +17,8 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "public_suffix", "~> 1.4
|
20
|
+
spec.add_dependency "public_suffix", "~> 1.4"
|
21
21
|
|
22
|
-
spec.add_development_dependency "rspec", "~> 3.0
|
23
|
-
spec.add_development_dependency "pry"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
24
24
|
end
|
@@ -7,7 +7,7 @@ describe SocialMediaParser do
|
|
7
7
|
let(:profile_attributes) { {url: "https://www.facebook.com/teamcoco"} }
|
8
8
|
|
9
9
|
it "returns a Facebook object" do
|
10
|
-
expect(parser).to be_a SocialMediaParser::
|
10
|
+
expect(parser).to be_a SocialMediaParser::Provider::Facebook
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -7,7 +7,7 @@ describe SocialMediaParser do
|
|
7
7
|
let(:profile_attributes) { {url: "https://github.com/mynewsdesk"} }
|
8
8
|
|
9
9
|
it "returns a Github object" do
|
10
|
-
expect(parser).to be_a SocialMediaParser::
|
10
|
+
expect(parser).to be_a SocialMediaParser::Provider::Github
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -7,7 +7,7 @@ describe SocialMediaParser do
|
|
7
7
|
let(:profile_attributes) { {url: "https://plus.google.com/+TeamCoco"} }
|
8
8
|
|
9
9
|
it "returns a Google object" do
|
10
|
-
expect(parser).to be_a SocialMediaParser::
|
10
|
+
expect(parser).to be_a SocialMediaParser::Provider::Google
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -7,7 +7,7 @@ describe SocialMediaParser do
|
|
7
7
|
let(:profile_attributes) { {url: "https://instagram.com/jimmykimmellive"} }
|
8
8
|
|
9
9
|
it "returns a Instagram object" do
|
10
|
-
expect(parser).to be_a SocialMediaParser::
|
10
|
+
expect(parser).to be_a SocialMediaParser::Provider::Instagram
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -7,7 +7,7 @@ describe SocialMediaParser do
|
|
7
7
|
let(:profile_attributes) { {url: "https://pinterest.com/fallontonight"} }
|
8
8
|
|
9
9
|
it "returns a Pinterest object" do
|
10
|
-
expect(parser).to be_a SocialMediaParser::
|
10
|
+
expect(parser).to be_a SocialMediaParser::Provider::Pinterest
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -7,7 +7,7 @@ describe SocialMediaParser do
|
|
7
7
|
let(:profile_attributes) { {url: "https://www.twitter.com/TheDailyShow"} }
|
8
8
|
|
9
9
|
it "returns a Twitter object" do
|
10
|
-
expect(parser).to be_a SocialMediaParser::
|
10
|
+
expect(parser).to be_a SocialMediaParser::Provider::Twitter
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -7,7 +7,7 @@ describe SocialMediaParser do
|
|
7
7
|
let(:profile_attributes) { {url: "https://www.youtube.com/user/TeamCoco"} }
|
8
8
|
|
9
9
|
it "returns a Youtube object" do
|
10
|
-
expect(parser).to be_a SocialMediaParser::
|
10
|
+
expect(parser).to be_a SocialMediaParser::Provider::Youtube
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -5,14 +5,14 @@ describe SocialMediaParser do
|
|
5
5
|
let(:profile_attributes){ {url: "https://twitter.com/StephenAtHome", provider: 'twitter'} }
|
6
6
|
|
7
7
|
it "returns a Twitter instance" do
|
8
|
-
expect(described_class.parse(profile_attributes)).to be_a SocialMediaParser::
|
8
|
+
expect(described_class.parse(profile_attributes)).to be_a SocialMediaParser::Provider::Twitter
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "string key hash" do
|
12
12
|
let(:profile_attributes){ {"url" => "https://twitter.com/StephenAtHome", "provider" => "twitter"} }
|
13
13
|
|
14
14
|
it "still works" do
|
15
|
-
expect(described_class.parse(profile_attributes)).to be_a SocialMediaParser::
|
15
|
+
expect(described_class.parse(profile_attributes)).to be_a SocialMediaParser::Provider::Twitter
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -20,7 +20,7 @@ describe SocialMediaParser do
|
|
20
20
|
let(:profile_attributes){ {"url" => "https://twitter.com/StephenAtHome", "provider" => "Twitter"} }
|
21
21
|
|
22
22
|
it "still works" do
|
23
|
-
expect(described_class.parse(profile_attributes)).to be_a SocialMediaParser::
|
23
|
+
expect(described_class.parse(profile_attributes)).to be_a SocialMediaParser::Provider::Twitter
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -28,7 +28,7 @@ describe SocialMediaParser do
|
|
28
28
|
let(:profile_attributes){ "https://twitter.com/StephenAtHome" }
|
29
29
|
|
30
30
|
it "still works" do
|
31
|
-
expect(described_class.parse(profile_attributes)).to be_a SocialMediaParser::
|
31
|
+
expect(described_class.parse(profile_attributes)).to be_a SocialMediaParser::Provider::Twitter
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
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.1
|
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: 2014-09-
|
13
|
+
date: 2014-09-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: public_suffix
|
@@ -18,42 +18,42 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.4
|
21
|
+
version: '1.4'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 1.4
|
28
|
+
version: '1.4'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: rspec
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - "~>"
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 3.0
|
35
|
+
version: '3.0'
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 3.0
|
42
|
+
version: '3.0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: pry
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- - "
|
47
|
+
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '0'
|
49
|
+
version: '0.10'
|
50
50
|
type: :development
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - "
|
54
|
+
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '0'
|
56
|
+
version: '0.10'
|
57
57
|
description:
|
58
58
|
email:
|
59
59
|
- dev@mynewsdesk.com
|
@@ -68,24 +68,24 @@ files:
|
|
68
68
|
- Rakefile
|
69
69
|
- lib/social_media_parser.rb
|
70
70
|
- lib/social_media_parser/link.rb
|
71
|
-
- lib/social_media_parser/
|
72
|
-
- lib/social_media_parser/
|
73
|
-
- lib/social_media_parser/
|
74
|
-
- lib/social_media_parser/
|
75
|
-
- lib/social_media_parser/
|
76
|
-
- lib/social_media_parser/
|
77
|
-
- lib/social_media_parser/
|
78
|
-
- lib/social_media_parser/
|
71
|
+
- lib/social_media_parser/provider/base.rb
|
72
|
+
- lib/social_media_parser/provider/facebook.rb
|
73
|
+
- lib/social_media_parser/provider/github.rb
|
74
|
+
- lib/social_media_parser/provider/google.rb
|
75
|
+
- lib/social_media_parser/provider/instagram.rb
|
76
|
+
- lib/social_media_parser/provider/pinterest.rb
|
77
|
+
- lib/social_media_parser/provider/twitter.rb
|
78
|
+
- lib/social_media_parser/provider/youtube.rb
|
79
79
|
- lib/social_media_parser/version.rb
|
80
80
|
- social_media_parser.gemspec
|
81
81
|
- spec/social_media_parser/link_spec.rb
|
82
|
-
- spec/social_media_parser/
|
83
|
-
- spec/social_media_parser/
|
84
|
-
- spec/social_media_parser/
|
85
|
-
- spec/social_media_parser/
|
86
|
-
- spec/social_media_parser/
|
87
|
-
- spec/social_media_parser/
|
88
|
-
- spec/social_media_parser/
|
82
|
+
- spec/social_media_parser/provider/facebook_spec.rb
|
83
|
+
- spec/social_media_parser/provider/github_spec.rb
|
84
|
+
- spec/social_media_parser/provider/google_spec.rb
|
85
|
+
- spec/social_media_parser/provider/instagram_spec.rb
|
86
|
+
- spec/social_media_parser/provider/pinterest_spec.rb
|
87
|
+
- spec/social_media_parser/provider/twitter_spec.rb
|
88
|
+
- spec/social_media_parser/provider/youtube_spec.rb
|
89
89
|
- spec/social_media_parser_spec.rb
|
90
90
|
- spec/spec_helper.rb
|
91
91
|
homepage: http://devcorner.mynewsdesk.com
|
@@ -114,12 +114,12 @@ specification_version: 4
|
|
114
114
|
summary: Parse social media attributes from url or construct url from attributes
|
115
115
|
test_files:
|
116
116
|
- spec/social_media_parser/link_spec.rb
|
117
|
-
- spec/social_media_parser/
|
118
|
-
- spec/social_media_parser/
|
119
|
-
- spec/social_media_parser/
|
120
|
-
- spec/social_media_parser/
|
121
|
-
- spec/social_media_parser/
|
122
|
-
- spec/social_media_parser/
|
123
|
-
- spec/social_media_parser/
|
117
|
+
- spec/social_media_parser/provider/facebook_spec.rb
|
118
|
+
- spec/social_media_parser/provider/github_spec.rb
|
119
|
+
- spec/social_media_parser/provider/google_spec.rb
|
120
|
+
- spec/social_media_parser/provider/instagram_spec.rb
|
121
|
+
- spec/social_media_parser/provider/pinterest_spec.rb
|
122
|
+
- spec/social_media_parser/provider/twitter_spec.rb
|
123
|
+
- spec/social_media_parser/provider/youtube_spec.rb
|
124
124
|
- spec/social_media_parser_spec.rb
|
125
125
|
- spec/spec_helper.rb
|