facebook_dialog 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use default@facebook_dialog --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in facebook_dialog.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ begin
5
+ require 'rspec/core/rake_task'
6
+
7
+ desc "Run specs"
8
+ RSpec::Core::RakeTask.new do |t|
9
+ end
10
+
11
+ rescue LoadError
12
+ puts "RSpec is not installed"
13
+ end
14
+
data/Readme.md ADDED
@@ -0,0 +1,24 @@
1
+ #Facebook Dialog
2
+
3
+ A utility that makes it easy to integrate progressively enhanced facebook dialogs
4
+
5
+ ```@ruby
6
+ FacebookDialog.api_key = "<your app_id/api key>"
7
+
8
+ #in a Rails View
9
+ <%= link_to "Share on Facebook" FacebookDialog::Feed.new({
10
+ redirect_uri: "http://www.example.com",
11
+ caption: "Something pretty awesome",
12
+ description: "Zomg! You won't believe what I found on the web."
13
+ }),
14
+ id: "share_on_facebook" %>
15
+
16
+ <%= facebook_js %>
17
+ <%= javascript_tag do %>
18
+ <%= fb_init_js %>
19
+ $("#share_on_facebook").click(function(e){
20
+ FB.ui(<%== Facebook::TopicShareUrl.new(resource).to_json %>);
21
+ });
22
+ <%- end -%>
23
+ ```
24
+
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/facebook_dialog/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Dan Pickett"]
6
+ gem.email = ["dpickett@enlightsolutions.com"]
7
+ gem.description = %q{A utility for building progressively enhanced Facebook dialogs}
8
+ gem.summary = %q{Use ActiveModel serialization to keep html and javascript FB dialogs DRY}
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "facebook_dialog"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = FacebookDialog::VERSION
17
+
18
+ gem.add_dependency "rack"
19
+ gem.add_dependency "activemodel"
20
+ gem.add_dependency "configatron"
21
+ gem.add_dependency "rake"
22
+
23
+ gem.add_development_dependency "rspec"
24
+ end
25
+
@@ -0,0 +1,51 @@
1
+ module FacebookDialog
2
+ class Feed
3
+ FACEBOOK_BASE_URL = "http://www.facebook.com/dialog/feed"
4
+ include ActiveModel::Serializers::JSON
5
+ self.include_root_in_json = false
6
+
7
+ DEFAULTS = {
8
+ display: "popup"
9
+ }
10
+
11
+ #options
12
+ #redirect_uri
13
+ #display
14
+ #from
15
+ #to
16
+ #message
17
+ #link
18
+ #picture
19
+ #source
20
+ #name
21
+ #caption
22
+ #description
23
+ #properties
24
+ #actions
25
+ #ref
26
+ def initialize(options = {})
27
+ @options = options
28
+ end
29
+
30
+ def url
31
+ "#{FACEBOOK_BASE_URL}?#{Rack::Utils.build_query(query)}"
32
+ end
33
+
34
+ def query
35
+ to_h.merge({
36
+ redirect_uri: @options[:redirect_uri] || @options[:link],
37
+ display: @options[:display] || "popup"
38
+ })
39
+ end
40
+
41
+ def serializable_hash(options = {})
42
+ to_h.merge({method: :feed})
43
+ end
44
+
45
+ HTML_ONLY_KEYS = [:redirect_uri, :display]
46
+ def to_h
47
+ @options.reject{|key, value| HTML_ONLY_KEYS.include?(key) }
48
+ end
49
+ end
50
+ end
51
+
@@ -0,0 +1,7 @@
1
+ module FacebookDialog
2
+ class Railtie < Rails::Railtie
3
+ ActiveSupport.on_load(:action_controller) do
4
+ helper FacebookDialog::ScriptHelper
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module FacebookDialog
2
+ module ScriptHelper
3
+ def facebook_js
4
+ content_tag(:div, "", id: "fb-root") +
5
+ javascript_include_tag('http://connect.facebook.net/en_US/all.js')
6
+ end
7
+
8
+ def fb_init_js
9
+ "FB.init({
10
+ appId: '#{FacebookDialog.api_key}',
11
+ status: true,
12
+ cookies: true
13
+ });".html_safe
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,4 @@
1
+ module FacebookDialog
2
+ VERSION = "0.0.1"
3
+ end
4
+
@@ -0,0 +1,18 @@
1
+ require "rack/utils"
2
+ require "active_model"
3
+ require "configatron"
4
+
5
+ require "facebook_dialog/version"
6
+ require "facebook_dialog/feed"
7
+
8
+ module FacebookDialog
9
+ def self.api_key
10
+ configatron.facebook_dialog.api_key
11
+ end
12
+
13
+ def self.api_key=(api_key)
14
+ configatron.facebook_dialog.api_key = api_key
15
+ end
16
+ end
17
+
18
+ require "facebook_dialog/railtie" if defined?(Rails)
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe FacebookDialog::Feed do
4
+ let(:redirect_uri) { "http://www.example.com" }
5
+ let(:title) { "Title! With. Special Characters" }
6
+ let(:caption) { "A Caption" }
7
+ let(:description) { "A description" }
8
+ let(:api_key) { "An Api Key" }
9
+
10
+ before(:each) do
11
+ FacebookDialog.api_key = api_key
12
+ end
13
+
14
+ subject do
15
+ FacebookDialog::Feed.new({
16
+ redirect_uri: redirect_uri,
17
+ title: title,
18
+ caption: caption,
19
+ description: description
20
+ })
21
+ end
22
+
23
+ its(:url) { should include(Rack::Utils.escape(redirect_uri)) }
24
+ its(:url) { should include(Rack::Utils.escape(title)) }
25
+ its(:url) { should include(Rack::Utils.escape(description)) }
26
+ its(:url) { should include(Rack::Utils.escape(caption)) }
27
+
28
+ its(:url) { should include("facebook.com") }
29
+
30
+ it "omits the redirect uri from the serialized hash" do
31
+ subject.serializable_hash.keys.should_not include(:redirect_uri)
32
+ end
33
+
34
+ it "omits the display from the serialized hash" do
35
+ subject.serializable_hash.keys.should_not include(:display)
36
+ end
37
+ end
38
+
@@ -0,0 +1,3 @@
1
+ require 'rspec'
2
+ require 'facebook_dialog'
3
+
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: facebook_dialog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dan Pickett
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-16 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ requirement: &2156198440 !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: *2156198440
25
+ - !ruby/object:Gem::Dependency
26
+ name: activemodel
27
+ requirement: &2156197860 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2156197860
36
+ - !ruby/object:Gem::Dependency
37
+ name: configatron
38
+ requirement: &2156197340 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2156197340
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &2156196800 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *2156196800
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &2156196060 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2156196060
69
+ description: A utility for building progressively enhanced Facebook dialogs
70
+ email:
71
+ - dpickett@enlightsolutions.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - .rvmrc
79
+ - Gemfile
80
+ - Rakefile
81
+ - Readme.md
82
+ - facebook_dialog.gemspec
83
+ - lib/facebook_dialog.rb
84
+ - lib/facebook_dialog/feed.rb
85
+ - lib/facebook_dialog/railtie.rb
86
+ - lib/facebook_dialog/script_helper.rb
87
+ - lib/facebook_dialog/version.rb
88
+ - spec/facebook_dialog/feed_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: ''
91
+ licenses: []
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ segments:
103
+ - 0
104
+ hash: -128552961892435604
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ segments:
112
+ - 0
113
+ hash: -128552961892435604
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 1.8.6
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Use ActiveModel serialization to keep html and javascript FB dialogs DRY
120
+ test_files:
121
+ - spec/facebook_dialog/feed_spec.rb
122
+ - spec/spec_helper.rb