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.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -5
  3. data/Rakefile +3 -0
  4. data/lib/social_media_parser/{social_media/provider.rb → provider/base.rb} +3 -3
  5. data/lib/social_media_parser/{social_media → provider}/facebook.rb +3 -3
  6. data/lib/social_media_parser/provider/github.rb +12 -0
  7. data/lib/social_media_parser/{social_media → provider}/google.rb +3 -3
  8. data/lib/social_media_parser/provider/instagram.rb +11 -0
  9. data/lib/social_media_parser/provider/pinterest.rb +11 -0
  10. data/lib/social_media_parser/{social_media → provider}/twitter.rb +3 -3
  11. data/lib/social_media_parser/{social_media → provider}/youtube.rb +3 -3
  12. data/lib/social_media_parser/version.rb +1 -1
  13. data/lib/social_media_parser.rb +3 -3
  14. data/social_media_parser.gemspec +3 -3
  15. data/spec/social_media_parser/{social_media → provider}/facebook_spec.rb +1 -1
  16. data/spec/social_media_parser/{social_media → provider}/github_spec.rb +1 -1
  17. data/spec/social_media_parser/{social_media → provider}/google_spec.rb +1 -1
  18. data/spec/social_media_parser/{social_media → provider}/instagram_spec.rb +1 -1
  19. data/spec/social_media_parser/{social_media → provider}/pinterest_spec.rb +1 -1
  20. data/spec/social_media_parser/{social_media → provider}/twitter_spec.rb +1 -1
  21. data/spec/social_media_parser/{social_media → provider}/youtube_spec.rb +1 -1
  22. data/spec/social_media_parser_spec.rb +4 -4
  23. metadata +32 -32
  24. data/lib/social_media_parser/social_media/github.rb +0 -12
  25. data/lib/social_media_parser/social_media/instagram.rb +0 -12
  26. 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: 846a6fdd025433f2116c000b3a70c564b5edc479
4
- data.tar.gz: 6fb70ea26a18a132fe49e68da6d25b1dde9f2213
3
+ metadata.gz: 118b227b802b71eb23147a919b5757067a7a24f7
4
+ data.tar.gz: 71fb3bb95e7224290f8df62f307bb15417b2fad8
5
5
  SHA512:
6
- metadata.gz: bf4bc7df352688cbdd8a5a4af09cb77e167fe0de54801699824e152d056034dc6bb394e07119603a615058b0426cd7c49d7f80a86ebd0c348ece4225bc402e99
7
- data.tar.gz: b55815fb373e7b9f70cd4f50fa6848a0850f639b253c64fbbbb1ebc0c750c86f6200d322add345c93b0b639bc341287de123293c0d7f6271620eaaa9a817562c
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::SocialMedia::Facebook:0x007fe014ef0f78 @url="https://www.facebook.com/teamcoco">
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
- {username: "teamcoco", provider: "facebook", url: "https://www.facebook.com/teamcoco", url_or_username: "teamcoco"}
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,2 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
@@ -1,13 +1,13 @@
1
1
  require 'social_media_parser/link'
2
2
 
3
3
  module SocialMediaParser
4
- module SocialMedia
5
- class Provider < ::SocialMediaParser::Link
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("SocialMedia").const_get(provider.capitalize).new(attributes)
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/social_media/provider'
1
+ require 'social_media_parser/provider/base'
2
2
 
3
3
  module SocialMediaParser
4
- module SocialMedia
5
- class Facebook < Provider
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
@@ -0,0 +1,12 @@
1
+ require 'social_media_parser/provider/base'
2
+
3
+ module SocialMediaParser
4
+ module Provider
5
+ class Github < Base
6
+
7
+ def provider
8
+ 'github'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,8 +1,8 @@
1
- require 'social_media_parser/social_media/provider'
1
+ require 'social_media_parser/provider/base'
2
2
 
3
3
  module SocialMediaParser
4
- module SocialMedia
5
- class Google < Provider
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
@@ -0,0 +1,11 @@
1
+ require 'social_media_parser/provider/base'
2
+
3
+ module SocialMediaParser
4
+ module Provider
5
+ class Instagram < Base
6
+ def provider
7
+ 'instagram'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'social_media_parser/provider/base'
2
+
3
+ module SocialMediaParser
4
+ module Provider
5
+ class Pinterest < Base
6
+ def provider
7
+ 'pinterest'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,8 +1,8 @@
1
- require 'social_media_parser/social_media/provider'
1
+ require 'social_media_parser/provider/base'
2
2
 
3
3
  module SocialMediaParser
4
- module SocialMedia
5
- class Twitter < Provider
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/social_media/provider'
1
+ require 'social_media_parser/provider/base'
2
2
 
3
3
  module SocialMediaParser
4
- module SocialMedia
5
- class Youtube < Provider
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
@@ -1,3 +1,3 @@
1
1
  module SocialMediaParser
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,11 +1,11 @@
1
- require 'ostruct'
2
- Dir[File.join(File.dirname(__FILE__), 'social_media_parser', 'social_media', '*.rb')].each {|file| require file }
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
- SocialMedia::Provider.parse(attrs)
9
+ Provider::Base.parse(attrs)
10
10
  end
11
11
  end
@@ -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.5"
20
+ spec.add_dependency "public_suffix", "~> 1.4"
21
21
 
22
- spec.add_development_dependency "rspec", "~> 3.0.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::SocialMedia::Facebook
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::SocialMedia::Github
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::SocialMedia::Google
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::SocialMedia::Instagram
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::SocialMedia::Pinterest
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::SocialMedia::Twitter
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::SocialMedia::Youtube
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::SocialMedia::Twitter
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::SocialMedia::Twitter
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::SocialMedia::Twitter
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::SocialMedia::Twitter
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.0
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-10 00:00:00.000000000 Z
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.5
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.5
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.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.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/social_media/facebook.rb
72
- - lib/social_media_parser/social_media/github.rb
73
- - lib/social_media_parser/social_media/google.rb
74
- - lib/social_media_parser/social_media/instagram.rb
75
- - lib/social_media_parser/social_media/pinterest.rb
76
- - lib/social_media_parser/social_media/provider.rb
77
- - lib/social_media_parser/social_media/twitter.rb
78
- - lib/social_media_parser/social_media/youtube.rb
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/social_media/facebook_spec.rb
83
- - spec/social_media_parser/social_media/github_spec.rb
84
- - spec/social_media_parser/social_media/google_spec.rb
85
- - spec/social_media_parser/social_media/instagram_spec.rb
86
- - spec/social_media_parser/social_media/pinterest_spec.rb
87
- - spec/social_media_parser/social_media/twitter_spec.rb
88
- - spec/social_media_parser/social_media/youtube_spec.rb
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/social_media/facebook_spec.rb
118
- - spec/social_media_parser/social_media/github_spec.rb
119
- - spec/social_media_parser/social_media/google_spec.rb
120
- - spec/social_media_parser/social_media/instagram_spec.rb
121
- - spec/social_media_parser/social_media/pinterest_spec.rb
122
- - spec/social_media_parser/social_media/twitter_spec.rb
123
- - spec/social_media_parser/social_media/youtube_spec.rb
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
@@ -1,12 +0,0 @@
1
- require 'social_media_parser/social_media/provider'
2
-
3
- module SocialMediaParser
4
- module SocialMedia
5
- class Github < Provider
6
-
7
- def provider
8
- 'github'
9
- end
10
- end
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- require 'social_media_parser/social_media/provider'
2
-
3
- module SocialMediaParser
4
- module SocialMedia
5
- class Instagram < Provider
6
-
7
- def provider
8
- 'instagram'
9
- end
10
- end
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- require 'social_media_parser/social_media/provider'
2
-
3
- module SocialMediaParser
4
- module SocialMedia
5
- class Pinterest < Provider
6
-
7
- def provider
8
- 'pinterest'
9
- end
10
- end
11
- end
12
- end