social-url 1.1.1 → 1.2.0

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
  SHA256:
3
- metadata.gz: d2c6aa71b7cdf9b1f24a01a7145c3ef172a5503d6e7eca715b2cc7df1427740d
4
- data.tar.gz: 654f25781cc60e76bafaeb4b5020052ffc8b38841f152915c3646ba3499a46bb
3
+ metadata.gz: 87752f6be8be6cd96cf5bcff71d786ef8b8045abf66e1047b0fde61ed16c6b1c
4
+ data.tar.gz: db66035474aded4c69bb8ad7523af707145907d84432119cffba26c87f5a659e
5
5
  SHA512:
6
- metadata.gz: d0e4b062aa4797a7143ddf75f3838073cc9a1899574531de34e44e1062433b437410f79298fdb90b545c1d25f01f6de9b28c63927e505467295d34df2830e9af
7
- data.tar.gz: 3e0f5026ab62c48ac6ed78b9da15eeb8b108e5c6386ee5769b006cc7a27e49908dbcdd097a33e9f9b70445efbefbf2525c279337de996910fe573a16b1f018be
6
+ metadata.gz: 1ee71fcfb990e760259a4cbe1bcc6f3fc60043c64447b5f717912598599d683906bc07620f122492152f607ad3a27ed2e4317fa6bc422e4117ac7b6aa41b0b77
7
+ data.tar.gz: '0329c592b38c2bbeedb8a9823fae920b18733c8268d440ac503cd77b2bc6fc1ffab32f3944a7c11ba6494f29f5f01dbec2cdd6f8c837cc416cb1a5181f7a7417'
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # social-url
1
+ # social-url
2
2
 
3
3
  A simple gem to generate social media sharing URLs.
4
4
 
@@ -7,7 +7,7 @@ A simple gem to generate social media sharing URLs.
7
7
  [![Maintainability](https://api.codeclimate.com/v1/badges/18b840bd059f4e83442c/maintainability)](https://codeclimate.com/github/richardvenneman/social-url/maintainability)
8
8
  [![Test Coverage](https://api.codeclimate.com/v1/badges/18b840bd059f4e83442c/test_coverage)](https://codeclimate.com/github/richardvenneman/social-url/test_coverage)
9
9
 
10
- Supported networks: Google+, Facebook, Pinterest, Twitter.
10
+ Supported networks: Google+, Facebook, Pinterest, Twitter and `mailto:`.
11
11
 
12
12
  ## Introduction
13
13
 
@@ -17,18 +17,6 @@ Use this to create fast sharing links as opposed to performance-heavy third-part
17
17
 
18
18
  Read more about [Responsible Social Share Links](https://jonsuh.com/blog/social-share-links) (by [@jonsuh](https://github.com/jonsuh)).
19
19
 
20
- ## Installation
21
-
22
- This library is test with the following Rubies: 2.3.8, 2.4.5, 2.5.3.
23
-
24
- Add it to your Gemfile with:
25
-
26
- ```ruby
27
- gem 'social_url'
28
- ```
29
-
30
- Run the `bundle install` command in your terminal to install it.
31
-
32
20
  ## Usage
33
21
 
34
22
  Setup a new message to share on social networks using the `Message` class:
@@ -45,6 +33,7 @@ Use the message's network methods to get the sharing URLs:
45
33
 
46
34
  - `facebook_url`
47
35
  - `google_url`
36
+ - `mailto_url`
48
37
  - `pinterest_url`
49
38
  - `twitter_url`
50
39
 
@@ -54,6 +43,20 @@ message.facebook_url #=> 'https://www.facebook.com/sharer/sharer.php?u=http%3A%2
54
43
  ...
55
44
  ```
56
45
 
46
+ ### Parameters
47
+
48
+ This gem translates the options passed to the `SocialUrl::Message` into the correct parameters for each network. Supported options are:
49
+
50
+ | Network | Supported parameters |
51
+ | ------------- | -------------------- |
52
+ | Facebook | `url` (String) |
53
+ | Google | `url` (String) |
54
+ | mailto | `url` (String)<br>`text` (String) |
55
+ | Pinterest | `url` (String)<br>`text` (String)<br>`media` (String) |
56
+ | Twitter | `url` (String)<br>`text` (String)<br>`hashtags` (Array of Strings)<br>`via` (String)<br>`related` (Array of Strings) |
57
+
58
+ ### Utilities
59
+
57
60
  The `SocialUrl` class provides normalization functionality for URL parameters and exposes the available networks:
58
61
 
59
62
  ```ruby
@@ -64,13 +67,30 @@ SocialUrl.normalize_array(%w(nature sunset)) #=> 'nature,sunset'
64
67
  SocialUrl.normalize_array(['twitter:Twitter News', 'twitterapi:Twitter API News']) #=> 'twitter%3ATwitter%20News,twitterapi%3ATwitter%20API%20News'
65
68
  ```
66
69
 
70
+ ## Installation
71
+
72
+ This library is test with the following Rubies: 2.3.8, 2.4.5, 2.5.3.
73
+
74
+ Add this line to your application's Gemfile:
75
+
76
+ ```ruby
77
+ gem 'social-url'
78
+ ```
79
+
80
+ And then execute:
81
+
82
+ $ bundle
83
+
84
+ Or install it yourself as:
85
+
86
+ $ gem install social-url
87
+
67
88
  ## Contributing
68
89
 
69
90
  I'm happy to accept any pull requests for new networks. Adding a new network is relatively easy. Say you'd want to add `mynetwork` support:
70
91
 
71
- 1. Create `lib/social_url/mynetwork.rb` and `test/lib/social_url/mynetwork_test.rb`
92
+ 1. Create `lib/social_url/networks/mynetwork.rb` and `test/lib/social_url/networks/mynetwork_test.rb`
72
93
  2. Add tests and implementation (take a look at the current networks)
73
- 3. In `lib/social_url.rb`, add a require statement and add `:mynetwork` to the `NETWORKS` constant
74
94
 
75
95
  ## License
76
96
 
@@ -4,55 +4,33 @@ require "erb"
4
4
 
5
5
  require "social_url/errors"
6
6
  require "social_url/version"
7
-
8
7
  require "social_url/message"
9
- require "social_url/facebook"
10
- require "social_url/google"
11
- require "social_url/pinterest"
12
- require "social_url/twitter"
8
+ require "social_url/network"
9
+
10
+ NETWORKS = []
11
+ Dir[File.join(__dir__, "social_url", "networks", "*.rb")].each do |file|
12
+ require file
13
+ NETWORKS << /.+\/(.+).rb$/.match(file)[1].to_sym
14
+ end
13
15
 
14
16
  module SocialUrl
15
17
  include ERB::Util
16
18
 
17
19
  class << self
18
- NETWORKS = [:facebook, :google, :pinterest, :twitter]
19
- KEYS = {
20
- u: :url,
21
- url: :u,
22
- description: :text,
23
- text: :description
24
- }
25
-
26
20
  def networks
27
21
  NETWORKS
28
22
  end
29
23
 
30
- def normalize(options)
31
- opts = {}
32
-
33
- options.each do |key, value|
34
- next unless value
35
-
24
+ def normalize(params)
25
+ params.reject { |key, value| !value }.map do |key, value|
36
26
  if key == :hashtags
37
- opts[key] = normalize_hashtags(value)
27
+ [key, normalize_hashtags(value)]
38
28
  elsif value.is_a?(String)
39
- opts[key] = normalize_string(value)
29
+ [key, normalize_string(value)]
40
30
  elsif value.is_a?(Array)
41
- opts[key] = normalize_array(value)
31
+ [key, normalize_array(value)]
42
32
  end
43
- end
44
-
45
- normalize_keys(opts)
46
- end
47
-
48
- def normalize_keys(options)
49
- opts = options.dup
50
-
51
- options.each do |key, value|
52
- opts[KEYS[key]] = opts[key] if KEYS[key]
53
- end
54
-
55
- opts
33
+ end.to_h
56
34
  end
57
35
 
58
36
  def normalize_hashtags(array)
@@ -70,12 +48,5 @@ module SocialUrl
70
48
  ERB::Util.url_encode(value)
71
49
  end.join(",")
72
50
  end
73
-
74
- def filtered_params(options, params)
75
- params.collect do |param|
76
- next unless options[param]
77
- "#{param}=#{options[param]}"
78
- end.compact.join("&")
79
- end
80
51
  end
81
52
  end
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SocialUrl
4
+ class NotImplementedError < StandardError
5
+ end
6
+
4
7
  class UnsupportedNetworkError < StandardError
5
8
  end
6
9
  end
@@ -1,30 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module SocialUrl
4
- class Message
5
- def initialize(options)
6
- @options = SocialUrl.normalize(options)
3
+ class SocialUrl::Message
4
+ def initialize(params)
5
+ @params = SocialUrl.normalize(params)
7
6
 
8
- init_networks
9
- end
7
+ init_networks
8
+ end
10
9
 
11
- def method_missing(method)
12
- network = /(.+)_url/.match(method)
13
- return unless network
10
+ def method_missing(method)
11
+ network = /(.+)_url/.match(method)
12
+ return unless network
14
13
 
15
- networks = SocialUrl.networks.join(",")
16
- raise UnsupportedNetworkError,
17
- "Unsupported network '#{network[1]}'. Choose from: #{networks}."
18
- end
14
+ networks = SocialUrl.networks.join(", ")
15
+ raise SocialUrl::UnsupportedNetworkError,
16
+ "Unsupported network: '#{network[1]}'. Available networks: #{networks}."
17
+ end
19
18
 
20
- private
21
- def init_networks
22
- SocialUrl.networks.each do |network|
23
- self.class.send(:define_method, "#{network}_url") do
24
- klass = network.to_s.capitalize
25
- SocialUrl.const_get(klass).new(@options).url
26
- end
19
+ private
20
+ def init_networks
21
+ SocialUrl.networks.each do |network|
22
+ self.class.send(:define_method, "#{network}_url") do
23
+ klass = network.to_s.capitalize
24
+ SocialUrl::Networks.const_get(klass).new(@params).url
27
25
  end
28
26
  end
29
- end
27
+ end
30
28
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SocialUrl
4
+ module Networks
5
+ end
6
+
7
+ class Network
8
+ def initialize(params)
9
+ @original_params = params
10
+ end
11
+
12
+ def params
13
+ whitelisted_params.map do |key, value|
14
+ value.to_s << "=" << @original_params[key]
15
+ end.join("&")
16
+ end
17
+
18
+ def whitelisted_params
19
+ raise SocialUrl::NotImplementedError, "#{self.class.name} should implement #whitelisted_params"
20
+ end
21
+
22
+ def url
23
+ raise SocialUrl::NotImplementedError, "#{self.class.name} should implement #url"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SocialUrl::Networks::Facebook < SocialUrl::Network
4
+ def whitelisted_params
5
+ {
6
+ url: :u
7
+ }
8
+ end
9
+
10
+ def url
11
+ "https://www.facebook.com/sharer/sharer.php?#{params}"
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SocialUrl::Networks::Google < SocialUrl::Network
4
+ def whitelisted_params
5
+ {
6
+ url: :url
7
+ }
8
+ end
9
+
10
+ def url
11
+ "https://plus.google.com/share?#{params}"
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SocialUrl::Networks::Mailto < SocialUrl::Network
4
+ def whitelisted_params
5
+ {
6
+ url: :body,
7
+ text: :subject
8
+ }
9
+ end
10
+
11
+ def url
12
+ "mailto:?#{params}"
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SocialUrl::Networks::Pinterest < SocialUrl::Network
4
+ def whitelisted_params
5
+ {
6
+ url: :url,
7
+ text: :description,
8
+ media: :media
9
+ }
10
+ end
11
+
12
+ def url
13
+ "https://www.pinterest.com/pin/create/button/?#{params}"
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SocialUrl::Networks::Twitter < SocialUrl::Network
4
+ def whitelisted_params
5
+ {
6
+ text: :text,
7
+ url: :url,
8
+ hashtags: :hashtags,
9
+ via: :via,
10
+ related: :related
11
+ }
12
+ end
13
+
14
+ def url
15
+ "https://twitter.com/intent/tweet/?#{params}"
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SocialUrl
4
- VERSION = "1.1.1"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -2,45 +2,43 @@
2
2
 
3
3
  require "test_helper"
4
4
 
5
- module SocialUrl
6
- class MessageTest < Minitest::Test
7
- def setup
8
- @message = Message.new({})
9
- @complete_message = Message.new(
10
- text: "Hello World",
11
- url: "http://example.com",
12
- hashtags: %w(nature sunset),
13
- via: "twitterdev",
14
- related: ["twitter:Twitter News", "twitterapi:Twitter API News"]
15
- )
16
- end
5
+ class SocialUrl::MessageTest < Minitest::Test
6
+ def setup
7
+ @message = SocialUrl::Message.new({})
8
+ @complete_message = SocialUrl::Message.new(
9
+ text: "Hello World",
10
+ url: "http://example.com",
11
+ hashtags: %w(nature sunset),
12
+ via: "twitterdev",
13
+ related: ["twitter:Twitter News", "twitterapi:Twitter API News"]
14
+ )
15
+ end
17
16
 
18
- def teardown
19
- @message.destroy
20
- @complete_message.destroy
21
- end
17
+ def teardown
18
+ @message.destroy
19
+ @complete_message.destroy
20
+ end
22
21
 
23
- def test_exposes_network_methods
24
- SocialUrl.networks.each do |network|
25
- method = "#{network}_url".to_sym
26
- assert_respond_to @message, method
27
- end
22
+ def test_exposes_network_methods
23
+ SocialUrl.networks.each do |network|
24
+ method = "#{network}_url".to_sym
25
+ assert_respond_to @message, method
28
26
  end
27
+ end
29
28
 
30
- def test_throws_on_invalid_network
31
- assert_raises UnsupportedNetworkError do
32
- @message.derp_url
33
- end
29
+ def test_throws_on_invalid_network
30
+ assert_raises SocialUrl::UnsupportedNetworkError do
31
+ @message.derp_url
34
32
  end
33
+ end
35
34
 
36
- def test_network_url
37
- url = ["https://twitter.com/intent/tweet/?text=Hello%20World",
38
- "&url=http%3A%2F%2Fexample.com",
39
- "&hashtags=nature,sunset",
40
- "&via=twitterdev",
41
- "&related=twitter%3ATwitter%20News,twitterapi%3ATwitter%20API%20News"].join
35
+ def test_network_url
36
+ url = ["https://twitter.com/intent/tweet/?text=Hello%20World",
37
+ "&url=http%3A%2F%2Fexample.com",
38
+ "&hashtags=nature,sunset",
39
+ "&via=twitterdev",
40
+ "&related=twitter%3ATwitter%20News,twitterapi%3ATwitter%20API%20News"].join
42
41
 
43
- assert_equal url, @complete_message.twitter_url
44
- end
42
+ assert_equal url, @complete_message.twitter_url
45
43
  end
46
44
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class SocialUrl::NetworkTest < Minitest::Test
6
+ def setup
7
+ @network = SocialUrl::Network.new(
8
+ text: "Hello World",
9
+ url: "http://example.com"
10
+ )
11
+ end
12
+
13
+ def test_url_raises
14
+ assert_raises SocialUrl::NotImplementedError do
15
+ @network.url
16
+ end
17
+ end
18
+
19
+ def test_whitelisted_params_raises
20
+ assert_raises SocialUrl::NotImplementedError do
21
+ @network.whitelisted_params
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class SocialUrl::Networks::FacebookTest < Minitest::Test
6
+ def setup
7
+ @params = { url: "http://example.com" }
8
+ end
9
+
10
+ def test_url
11
+ params = SocialUrl.normalize(@params)
12
+ url = "https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com"
13
+
14
+ assert_equal url, SocialUrl::Networks::Facebook.new(params).url
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class SocialUrl::Networks::GoogleTest < Minitest::Test
6
+ def setup
7
+ @params = {
8
+ text: "Hello World",
9
+ url: "http://example.com"
10
+ }
11
+ end
12
+
13
+ def test_url
14
+ params = SocialUrl.normalize(@params)
15
+ url = "https://plus.google.com/share?url=http%3A%2F%2Fexample.com"
16
+
17
+ assert_equal url, SocialUrl::Networks::Google.new(params).url
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class SocialUrl::Networks::MailtoTest < Minitest::Test
6
+ def setup
7
+ @params = {
8
+ text: "Hello World",
9
+ url: "http://example.com"
10
+ }
11
+ end
12
+
13
+ def test_url
14
+ params = SocialUrl.normalize(@params)
15
+ url = "mailto:?body=http%3A%2F%2Fexample.com&subject=Hello%20World"
16
+
17
+ assert_equal url, SocialUrl::Networks::Mailto.new(params).url
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class SocialUrl::Networks::PinterestTest < Minitest::Test
6
+ def setup
7
+ @params = {
8
+ url: "http://www.flickr.com/photos/kentbrew/6851755809/",
9
+ text: "Next stop: Pinterest",
10
+ media: "http://farm8.staticflickr.com/7027/6851755809_df5b2051c9_z.jpg"
11
+ }
12
+ end
13
+
14
+ def test_url
15
+ params = SocialUrl.normalize(@params)
16
+ url = ["https://www.pinterest.com/pin/create/button/",
17
+ "?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F",
18
+ "&description=Next%20stop%3A%20Pinterest",
19
+ "&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg"].join
20
+
21
+ assert_equal url, SocialUrl::Networks::Pinterest.new(params).url
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class SocialUrl::Networks::TwitterTest < Minitest::Test
6
+ def setup
7
+ @params = {
8
+ text: "Hello World",
9
+ url: "http://example.com",
10
+ hashtags: ["nature", "sunset", "Multi Word HashTag"],
11
+ via: "twitterdev",
12
+ related: ["twitter:Twitter News", "twitterapi:Twitter API News"]
13
+ }
14
+ end
15
+
16
+ def test_url
17
+ params = SocialUrl.normalize(@params)
18
+ url = ["https://twitter.com/intent/tweet/?text=Hello%20World",
19
+ "&url=http%3A%2F%2Fexample.com",
20
+ "&hashtags=nature,sunset,MultiWordHashTag",
21
+ "&via=twitterdev",
22
+ "&related=twitter%3ATwitter%20News,twitterapi%3ATwitter%20API%20News"].join
23
+
24
+ assert_equal url, SocialUrl::Networks::Twitter.new(params).url
25
+ end
26
+ end
@@ -3,26 +3,6 @@
3
3
  require "test_helper"
4
4
 
5
5
  class SocialUrlTest < Minitest::Test
6
- def setup
7
- @options = {
8
- text: "Hello World",
9
- url: "http://example.com/",
10
- hashtags: %w(nature sunset),
11
- via: "twitterdev",
12
- related: ["twitter:Twitter News", "twitterapi:Twitter API News"]
13
- }
14
-
15
- @normalized_options = {
16
- text: "Hello%20World",
17
- description: "Hello%20World",
18
- u: "http%3A%2F%2Fexample.com%2F",
19
- url: "http%3A%2F%2Fexample.com%2F",
20
- hashtags: "nature,sunset",
21
- via: "twitterdev",
22
- related: "twitter%3ATwitter%20News,twitterapi%3ATwitter%20API%20News"
23
- }
24
- end
25
-
26
6
  def test_exposes_available_networks
27
7
  assert_kind_of Array, SocialUrl.networks
28
8
  assert_includes SocialUrl.networks, :twitter
@@ -50,15 +30,4 @@ class SocialUrlTest < Minitest::Test
50
30
 
51
31
  assert_equal text, SocialUrl.normalize_hashtags(array)
52
32
  end
53
-
54
- def test_normalization
55
- assert_equal @normalized_options, SocialUrl.normalize(@options)
56
- end
57
-
58
- def test_filtered_params
59
- filtered_params = "text=Hello%20World&url=http%3A%2F%2Fexample.com%2F"
60
- params = [:text, :url, :derp]
61
-
62
- assert_equal filtered_params, SocialUrl.filtered_params(@normalized_options, params)
63
- end
64
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social-url
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Venneman
@@ -87,18 +87,22 @@ files:
87
87
  - lib/social-url.rb
88
88
  - lib/social_url.rb
89
89
  - lib/social_url/errors.rb
90
- - lib/social_url/facebook.rb
91
- - lib/social_url/google.rb
92
90
  - lib/social_url/message.rb
93
- - lib/social_url/pinterest.rb
94
- - lib/social_url/twitter.rb
91
+ - lib/social_url/network.rb
92
+ - lib/social_url/networks/facebook.rb
93
+ - lib/social_url/networks/google.rb
94
+ - lib/social_url/networks/mailto.rb
95
+ - lib/social_url/networks/pinterest.rb
96
+ - lib/social_url/networks/twitter.rb
95
97
  - lib/social_url/version.rb
96
98
  - social-url.gemspec
97
- - test/lib/social_url/facebook_test.rb
98
- - test/lib/social_url/google_test.rb
99
99
  - test/lib/social_url/message_test.rb
100
- - test/lib/social_url/pinterest_test.rb
101
- - test/lib/social_url/twitter_test.rb
100
+ - test/lib/social_url/network_test.rb
101
+ - test/lib/social_url/networks/facebook_test.rb
102
+ - test/lib/social_url/networks/google_test.rb
103
+ - test/lib/social_url/networks/mailto_test.rb
104
+ - test/lib/social_url/networks/pinterest_test.rb
105
+ - test/lib/social_url/networks/twitter_test.rb
102
106
  - test/lib/social_url_test.rb
103
107
  - test/test_helper.rb
104
108
  homepage: https://github.com/richardvenneman/social-url
@@ -126,10 +130,12 @@ signing_key:
126
130
  specification_version: 4
127
131
  summary: Generates social media sharing links
128
132
  test_files:
129
- - test/lib/social_url/pinterest_test.rb
130
- - test/lib/social_url/google_test.rb
133
+ - test/lib/social_url/networks/pinterest_test.rb
134
+ - test/lib/social_url/networks/google_test.rb
135
+ - test/lib/social_url/networks/facebook_test.rb
136
+ - test/lib/social_url/networks/mailto_test.rb
137
+ - test/lib/social_url/networks/twitter_test.rb
138
+ - test/lib/social_url/network_test.rb
131
139
  - test/lib/social_url/message_test.rb
132
- - test/lib/social_url/facebook_test.rb
133
- - test/lib/social_url/twitter_test.rb
134
140
  - test/lib/social_url_test.rb
135
141
  - test/test_helper.rb
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SocialUrl
4
- class Facebook
5
- PARAMS = [:u]
6
-
7
- def initialize(options)
8
- @params = SocialUrl.filtered_params(options, PARAMS)
9
- end
10
-
11
- def url
12
- "https://www.facebook.com/sharer/sharer.php?#{@params}"
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SocialUrl
4
- class Google
5
- PARAMS = [:url]
6
-
7
- def initialize(options)
8
- @params = SocialUrl.filtered_params(options, PARAMS)
9
- end
10
-
11
- def url
12
- "https://plus.google.com/share?#{@params}"
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SocialUrl
4
- class Pinterest
5
- PARAMS = [:url, :media, :description]
6
-
7
- def initialize(options)
8
- @params = SocialUrl.filtered_params(options, PARAMS)
9
- end
10
-
11
- def url
12
- "https://www.pinterest.com/pin/create/button/?#{@params}"
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SocialUrl
4
- class Twitter
5
- PARAMS = [:text, :url, :hashtags, :via, :related]
6
-
7
- def initialize(options)
8
- @params = SocialUrl.filtered_params(options, PARAMS)
9
- end
10
-
11
- def url
12
- "https://twitter.com/intent/tweet/?#{@params}"
13
- end
14
- end
15
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SocialUrl
6
- class FacebookTest < Minitest::Test
7
- def setup
8
- @options = { url: "http://example.com" }
9
- end
10
-
11
- def test_url
12
- opts = SocialUrl.normalize(@options)
13
- url = "https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com"
14
-
15
- assert_equal url, Facebook.new(opts).url
16
- end
17
- end
18
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SocialUrl
6
- class GoogleTest < Minitest::Test
7
- def setup
8
- @options = {
9
- text: "Hello World",
10
- url: "http://example.com"
11
- }
12
- end
13
-
14
- def test_url
15
- opts = SocialUrl.normalize(@options)
16
- url = "https://plus.google.com/share?url=http%3A%2F%2Fexample.com"
17
-
18
- assert_equal url, Google.new(opts).url
19
- end
20
- end
21
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SocialUrl
6
- class PinterestTest < Minitest::Test
7
- def setup
8
- @options = {
9
- url: "http://www.flickr.com/photos/kentbrew/6851755809/",
10
- media: "http://farm8.staticflickr.com/7027/6851755809_df5b2051c9_z.jpg",
11
- description: "Next stop: Pinterest"
12
- }
13
- end
14
-
15
- def test_url
16
- opts = SocialUrl.normalize(@options)
17
- url = ["https://www.pinterest.com/pin/create/button/",
18
- "?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F",
19
- "&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg",
20
- "&description=Next%20stop%3A%20Pinterest"].join
21
-
22
- assert_equal url, Pinterest.new(opts).url
23
- end
24
- end
25
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module SocialUrl
6
- class TwitterTest < Minitest::Test
7
- def setup
8
- @options = {
9
- text: "Hello World",
10
- url: "http://example.com",
11
- hashtags: ["nature", "sunset", "Multi Word HashTag"],
12
- via: "twitterdev",
13
- related: ["twitter:Twitter News", "twitterapi:Twitter API News"]
14
- }
15
- end
16
-
17
- def test_url
18
- opts = SocialUrl.normalize(@options)
19
- url = ["https://twitter.com/intent/tweet/?text=Hello%20World",
20
- "&url=http%3A%2F%2Fexample.com",
21
- "&hashtags=nature,sunset,MultiWordHashTag",
22
- "&via=twitterdev",
23
- "&related=twitter%3ATwitter%20News,twitterapi%3ATwitter%20API%20News"].join
24
-
25
- assert_equal url, Twitter.new(opts).url
26
- end
27
- end
28
- end