social-url 1.0.3 → 1.1.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
  SHA1:
3
- metadata.gz: 7da8ae1fb196885bceeb75aa9eb759b2caddfe15
4
- data.tar.gz: 86a3f78bca01f19e012f867eb609fef26ea186f0
3
+ metadata.gz: d011ff092db1bcb067cf63d00f8a35fdf86f1e1d
4
+ data.tar.gz: b025ef99deda02e311090322bd760145a5dd8b4d
5
5
  SHA512:
6
- metadata.gz: 1b8fddbee83d030ad5f4a403b529519e068ccde7c949900c19f3d1400204487db3373326e6cad7086a84c1d47377c4a5c7b7d7ff879a3d2552e90805195e3f91
7
- data.tar.gz: 894ce18765a86b740e7dafd4490eb1abc53f4a06ce96c0b042b145beb32786f608348cc6b20c909a11c70e04d5accd12923a24d97d26ece2c8aecf8341712746
6
+ metadata.gz: 887b9b1c38a8b8cc65e3f44112435a753bd646ded8671b53734addc91f4d197c6eecbbc94f025770e0f5ce3d815c065d9e7f5fc0b66ab88791153659067314ec
7
+ data.tar.gz: 884439c80675cd43bd6e6e7e44c08670f3ff12c161064ecbef43e03745cb8e42cf6cf0d8356134ff91537d0b410575bdb277337d347c373bacef3cfbe2a7071e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- social-url (1.0.2)
4
+ social-url (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,7 +12,7 @@ GEM
12
12
  docile (1.1.5)
13
13
  ffi (1.9.10)
14
14
  formatador (0.2.5)
15
- guard (2.12.8)
15
+ guard (2.13.0)
16
16
  formatador (>= 0.2.4)
17
17
  listen (>= 2.7, <= 4.0)
18
18
  lumberjack (~> 1.0)
@@ -26,14 +26,14 @@ GEM
26
26
  guard-compat (~> 1.2)
27
27
  minitest (>= 3.0)
28
28
  json (1.8.3)
29
- listen (3.0.2)
29
+ listen (3.0.3)
30
30
  rb-fsevent (>= 0.9.3)
31
31
  rb-inotify (>= 0.9)
32
32
  lumberjack (1.0.9)
33
33
  method_source (0.8.2)
34
34
  minitest (5.7.0)
35
35
  nenv (0.2.0)
36
- notiffany (0.0.6)
36
+ notiffany (0.0.7)
37
37
  nenv (~> 0.1)
38
38
  shellany (~> 0.0)
39
39
  pry (0.10.1)
@@ -58,7 +58,7 @@ PLATFORMS
58
58
 
59
59
  DEPENDENCIES
60
60
  codeclimate-test-reporter (~> 0.4)
61
- guard (~> 2.12)
61
+ guard (~> 2)
62
62
  guard-minitest (~> 2.4)
63
63
  rake (~> 10.4)
64
64
  simplecov (~> 0.9)
data/README.md CHANGED
@@ -1,14 +1,20 @@
1
1
  # social-url
2
2
 
3
- A simple gem to generate social media sharing links.
3
+ A simple gem to generate social media sharing URLs.
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/social-url.svg)](http://badge.fury.io/rb/social-url) [![Code Climate](https://codeclimate.com/github/richardvenneman/social-url/badges/gpa.svg)](https://codeclimate.com/github/richardvenneman/social-url) [![Dependency Status](https://gemnasium.com/richardvenneman/social-url.svg)](https://gemnasium.com/richardvenneman/social-url) [![Test Coverage](https://codeclimate.com/github/richardvenneman/social-url/badges/coverage.svg)](https://codeclimate.com/github/richardvenneman/social-url/coverage) [![Build Status](http://img.shields.io/travis/richardvenneman/social-url.svg)](https://travis-ci.org/richardvenneman/social-url)
5
+ [![Gem](https://img.shields.io/gem/v/social-url.svg?style=flat-square)](http://rubygems.org/gems/social-url)
6
+ [![Build Status](https://img.shields.io/travis/richardvenneman/social-url/master.svg?style=flat-square)](https://travis-ci.org/richardvenneman/social-url)
7
+ [![Gemnasium](https://img.shields.io/gemnasium/richardvenneman/social-url.svg?style=flat-square)](https://gemnasium.com/richardvenneman/social-url)
8
+ [![Code Climate](https://img.shields.io/codeclimate/github/richardvenneman/social-url.svg?style=flat-square)](https://codeclimate.com/github/richardvenneman/social-url)
9
+ [![Test Coverage](https://img.shields.io/codeclimate/coverage/github/richardvenneman/social-url.svg?style=flat-square)](https://codeclimate.com/github/richardvenneman/social-url/coverage)
6
10
 
7
11
  Supported networks: Google+, Facebook, Pinterest, Twitter.
8
12
 
9
13
  ## Introduction
10
14
 
11
- This gem was created to help quickly set up sharing links for web pages. This should help you create simple and fast sharing links to social media networks as opposed to performance-heavy third-party sharing widgets.
15
+ This gem was created to help you create social media sharing URLs. Create a message once and make it sharable on multiple networks with each their own specific parameters.
16
+
17
+ Use this to create fast sharing links as opposed to performance-heavy third-party sharing widgets.
12
18
 
13
19
  Read more about [Responsible Social Share Links](https://jonsuh.com/blog/social-share-links) (by [@jonsuh](https://github.com/jonsuh)).
14
20
 
@@ -24,16 +30,6 @@ Run the `bundle install` in your terminal command to install it.
24
30
 
25
31
  ## Usage
26
32
 
27
- The gem exposes two classes `SocialUrl` and `SocialUrl::Message`. The `SocialUrl` class provides normalization functionality for URL parameters and exposes the available networks:
28
-
29
- ```ruby
30
- SocialUrl.networks #=> [:facebook, :google, :twitter, ...]
31
-
32
- SocialUrl.normalize_string('Hello World') #=> 'Hello%20World'
33
- SocialUrl.normalize_array(%w(nature sunset)) #=> 'nature,sunset'
34
- SocialUrl.normalize_array(['twitter:Twitter News', 'twitterapi:Twitter API News']) #=> 'twitter%3ATwitter%20News,twitterapi%3ATwitter%20API%20News'
35
- ```
36
-
37
33
  Setup a new message to share on social networks using the `Message` class:
38
34
 
39
35
  ```ruby
@@ -42,28 +38,39 @@ message = SocialUrl::Message.new({
42
38
  url: 'http://example.com',
43
39
  hashtags: %w(nature sunset)
44
40
  })
41
+ ```
45
42
 
46
- # Use the network methods to easily get sharing URLs
43
+ Use the message's network methods to get the sharing URLs:
47
44
 
45
+ - `facebook_url`
46
+ - `google_url`
47
+ - `pinterest_url`
48
+ - `twitter_url`
49
+
50
+ ```ruby
48
51
  message.twitter_url #=> 'https://twitter.com/intent/tweet/?text=Hello%20World&url=http%3A%2F%2Fexample.com&hashtags=nature,sunset'
49
52
  message.facebook_url #=> 'https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com'
50
53
  ...
51
54
  ```
52
55
 
53
- ## TODO
56
+ The `SocialUrl` class provides normalization functionality for URL parameters and exposes the available networks:
54
57
 
55
- This gem is a work-in-progress. Planned features:
58
+ ```ruby
59
+ SocialUrl.networks #=> [:facebook, :google, :twitter, ...]
56
60
 
57
- - Raise on missing required network parameters
58
- - Ruby on Rails ActionView helpers
59
- - Add missing networks
61
+ SocialUrl.normalize_string('Hello World') #=> 'Hello%20World'
62
+ SocialUrl.normalize_array(%w(nature sunset)) #=> 'nature,sunset'
63
+ SocialUrl.normalize_array(['twitter:Twitter News', 'twitterapi:Twitter API News']) #=> 'twitter%3ATwitter%20News,twitterapi%3ATwitter%20API%20News'
64
+ ```
60
65
 
61
66
  ## Contributing
62
67
 
63
- Everyone is encouraged to help improve this project. Here are a few ways you can help:
68
+ 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:
69
+
70
+ 1. Create `lib/social_url/mynetwork.rb` and `test/lib/social_url/mynetwork_test.rb`
71
+ 2. Add tests and implementation (take a look at the current networks)
72
+ 3. In `lib/social_url.rb`, add a require statement and add `:mynetwork` to the `NETWORKS` constant
73
+
74
+ ## License
64
75
 
65
- - Report bugs
66
- - Fix bugs and submit pull requests
67
- - Write, clarify, or fix documentation
68
- - Suggest or add new features
69
- - Write missing tests
76
+ This library is released under the [MIT License](http://www.opensource.org/licenses/MIT).
@@ -31,8 +31,13 @@ module SocialUrl
31
31
  options.each do |key, value|
32
32
  next unless value
33
33
 
34
- opts[key] = normalize_string(value) if value.is_a?(String)
35
- opts[key] = normalize_array(value) if value.is_a?(Array)
34
+ if key == :hashtags
35
+ opts[key] = normalize_hashtags(value)
36
+ elsif value.is_a?(String)
37
+ opts[key] = normalize_string(value)
38
+ elsif value.is_a?(Array)
39
+ opts[key] = normalize_array(value)
40
+ end
36
41
  end
37
42
 
38
43
  normalize_keys(opts)
@@ -48,6 +53,12 @@ module SocialUrl
48
53
  opts
49
54
  end
50
55
 
56
+ def normalize_hashtags(array)
57
+ array.collect do |value|
58
+ value.delete(' ')
59
+ end.join(',')
60
+ end
61
+
51
62
  def normalize_string(string)
52
63
  ERB::Util.url_encode(string)
53
64
  end
@@ -1,3 +1,3 @@
1
1
  module SocialUrl
2
- VERSION = '1.0.3'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.test_files = Dir['test/**/*']
18
18
 
19
19
  s.add_development_dependency 'rake', '~> 10.4'
20
- s.add_development_dependency 'guard', '~> 2.12'
20
+ s.add_development_dependency 'guard', '~> 2'
21
21
  s.add_development_dependency 'guard-minitest', '~> 2.4'
22
22
  s.add_development_dependency 'simplecov', '~> 0.9'
23
23
  s.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
@@ -6,7 +6,7 @@ module SocialUrl
6
6
  @options = {
7
7
  text: 'Hello World',
8
8
  url: 'http://example.com',
9
- hashtags: %w(nature sunset),
9
+ hashtags: ['nature', 'sunset', 'Multi Word HashTag'],
10
10
  via: 'twitterdev',
11
11
  related: ['twitter:Twitter News', 'twitterapi:Twitter API News']
12
12
  }
@@ -16,7 +16,7 @@ module SocialUrl
16
16
  opts = SocialUrl.normalize(@options)
17
17
  url = ['https://twitter.com/intent/tweet/?text=Hello%20World',
18
18
  '&url=http%3A%2F%2Fexample.com',
19
- '&hashtags=nature,sunset',
19
+ '&hashtags=nature,sunset,MultiWordHashTag',
20
20
  '&via=twitterdev',
21
21
  '&related=twitter%3ATwitter%20News,twitterapi%3ATwitter%20API%20News'].join
22
22
 
@@ -42,6 +42,13 @@ class SocialUrlTest < Minitest::Test
42
42
  assert_equal complex_text, SocialUrl.normalize_array(complex_array)
43
43
  end
44
44
 
45
+ def test_hashtag_normalization
46
+ array = ['Multi Word HashTag', 'nature']
47
+ text = 'MultiWordHashTag,nature'
48
+
49
+ assert_equal text, SocialUrl.normalize_hashtags(array)
50
+ end
51
+
45
52
  def test_normalization
46
53
  assert_equal @normalized_options, SocialUrl.normalize(@options)
47
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social-url
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Venneman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-11 00:00:00.000000000 Z
11
+ date: 2015-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.12'
33
+ version: '2'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.12'
40
+ version: '2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: guard-minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -105,7 +105,6 @@ files:
105
105
  - lib/social_url/pinterest.rb
106
106
  - lib/social_url/twitter.rb
107
107
  - lib/social_url/version.rb
108
- - social-url-1.0.1.gem
109
108
  - social-url.gemspec
110
109
  - test/lib/social_url/facebook_test.rb
111
110
  - test/lib/social_url/google_test.rb
Binary file