facebook_share_link 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.md +43 -0
- data/lib/facebook_share_link/version.rb +3 -0
- data/lib/facebook_share_link.rb +29 -0
- data/spec/facebook_share_link_spec.rb +34 -0
- data/spec/spec_helper.rb +14 -0
- metadata +82 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Facebook Share Link
|
2
|
+
|
3
|
+
Builds a link to share something to Facebook based on the Facebook Feed Dialog: http://developers.facebook.com/docs/reference/dialogs/feed/
|
4
|
+
|
5
|
+
## Reason for being
|
6
|
+
|
7
|
+
I needed this to put facebook share links in emails where the javascript facebook dialogs aren't available.
|
8
|
+
|
9
|
+
## Install
|
10
|
+
|
11
|
+
<pre>gem install facebook_share_link</pre>
|
12
|
+
|
13
|
+
Or add <pre>gem 'facebook_share_link'</pre> to your Gemfile
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Mininum
|
18
|
+
|
19
|
+
<pre>
|
20
|
+
FacebookShareLink.link(
|
21
|
+
app_id: 11111111111,
|
22
|
+
redirect_uri: "http://yoursite.com/return")
|
23
|
+
</pre>
|
24
|
+
|
25
|
+
### Full usage
|
26
|
+
|
27
|
+
<pre>
|
28
|
+
FacebookShareLink.link(
|
29
|
+
app_id: 11111111,
|
30
|
+
link: "https://github.com/joshcrews",
|
31
|
+
description: "Josh Crews on Github",
|
32
|
+
message: "I just found Josh Crews on Github",
|
33
|
+
picture: "http://joshcrews.com/logo.png",
|
34
|
+
caption: "Josh Crews dot Com",
|
35
|
+
redirect_uri: "http://google.com/q=Josh Crews"
|
36
|
+
)
|
37
|
+
</pre>
|
38
|
+
|
39
|
+
#### Outputs
|
40
|
+
|
41
|
+
<pre>http://www.facebook.com/dialog/feed?app_id=11111111&caption=Josh+Crews+dot+Com&description=Josh+Crews+on+Github&link=https%3A%2F%2Fgithub.com%2Fjoshcrews&message=I+just+found+Josh+Crews+on+Github&picture=http%3A%2F%2Fjoshcrews.com%2Flogo.png&redirect_uri=http%3A%2F%2Fgoogle.com%2Fq%3DJosh+Crews</pre>
|
42
|
+
|
43
|
+
Note: that link won't work because that's a made up app_id
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module FacebookShareLink
|
2
|
+
|
3
|
+
def FacebookShareLink.link(options)
|
4
|
+
raise FacebookShareLinkError, 'Missing app_id' if options[:app_id].nil? || options[:app_id] == ""
|
5
|
+
raise FacebookShareLinkError, 'Missing redirect_uri' if options[:redirect_uri].nil? || options[:redirect_uri] == ""
|
6
|
+
|
7
|
+
facebook_dialog_path = "http://www.facebook.com/dialog/feed?"
|
8
|
+
|
9
|
+
queries = options.collect do |key, value|
|
10
|
+
to_query(key, value.to_s)
|
11
|
+
end.sort * '&'
|
12
|
+
|
13
|
+
facebook_dialog_path + queries
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
## FYI, copied and modded from Rails core
|
19
|
+
def FacebookShareLink.to_query(key, value)
|
20
|
+
require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
|
21
|
+
"#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
class FacebookShareLinkError < StandardError
|
27
|
+
end
|
28
|
+
|
29
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FacebookShareLink do
|
4
|
+
|
5
|
+
def standard_parameters
|
6
|
+
{
|
7
|
+
app_id: 11111111,
|
8
|
+
link: "https://github.com/joshcrews",
|
9
|
+
description: "Josh Crews on Github",
|
10
|
+
message: "I just found Josh Crews on Github",
|
11
|
+
picture: "http://joshcrews.com/logo.png",
|
12
|
+
caption: "Josh Crews dot Com",
|
13
|
+
redirect_uri: "http://google.com/q=Josh Crews"
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
it "builds a link to share on facebook" do
|
18
|
+
facebook_share_url = FacebookShareLink.link(standard_parameters)
|
19
|
+
facebook_share_url.should == "http://www.facebook.com/dialog/feed?app_id=11111111&caption=Josh+Crews+dot+Com&description=Josh+Crews+on+Github&link=https%3A%2F%2Fgithub.com%2Fjoshcrews&message=I+just+found+Josh+Crews+on+Github&picture=http%3A%2F%2Fjoshcrews.com%2Flogo.png&redirect_uri=http%3A%2F%2Fgoogle.com%2Fq%3DJosh+Crews"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "tells you if missing app_id" do
|
23
|
+
lambda do
|
24
|
+
facebook_share_url = FacebookShareLink.link(standard_parameters.merge(app_id: nil))
|
25
|
+
end.should raise_error(FacebookShareLinkError, 'Missing app_id')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "tells you if missing redirect_uri" do
|
29
|
+
lambda do
|
30
|
+
facebook_share_url = FacebookShareLink.link(standard_parameters.merge(redirect_uri: nil))
|
31
|
+
end.should raise_error(FacebookShareLinkError, 'Missing redirect_uri')
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require 'facebook_share_link'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: facebook_share_link
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josh Crews
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-21 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: &70136969928300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70136969928300
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70136969927600 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70136969927600
|
36
|
+
description: Great for adding share on Facebook links in emails
|
37
|
+
email:
|
38
|
+
- josh@joshcrews.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- lib/facebook_share_link/version.rb
|
44
|
+
- lib/facebook_share_link.rb
|
45
|
+
- MIT-LICENSE
|
46
|
+
- README.md
|
47
|
+
- spec/facebook_share_link_spec.rb
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
homepage: https://github.com/joshcrews/facebook_share_link
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
hash: -706711382868041378
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
hash: -706711382868041378
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.11
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Builds a URL to create a hyperlink to share something to facebook through
|
79
|
+
the Feed Dialog API
|
80
|
+
test_files:
|
81
|
+
- spec/facebook_share_link_spec.rb
|
82
|
+
- spec/spec_helper.rb
|