social_butterfly 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,103 @@
1
+ = social_butterfly
2
+ {<img src="https://secure.travis-ci.org/kevinelliott/social_butterfly.png">}[http://travis-ci.org/kevinelliott/social_butterfly]
3
+
4
+ Share and track site content with social networks, for Ruby. ActionController/ActionView integration coming soon.
5
+
6
+ == About
7
+
8
+ There are a significant number of gems and snippets out there that enable some kind of social integration for your Ruby or Rails app, but they are typically overly complicated and tend to focus on authentication/authorization more than offering useful integrations with the social networks. Interacting with the social networks often ends up requiring custom code to query a remote graph and then process returned JSON responses. This approach is fine for scenarios where custom solutions are required.
9
+
10
+ But if you just want to snap on the ability to share some content on social networks and then track how well they are performing, that's where social_butterfly makes things easy. This library for Ruby exposes a simple API for interacting with various social networks, such as Facebook and Twitter, without requiring extensive custom code to integrate them into your applications.
11
+
12
+ This is not an authentication or authorization gem. It is focused on helping you add features to your site that will help to promote site content.
13
+
14
+ == Project Status
15
+
16
+ === In development.
17
+
18
+ The architecture and feature set is still being determined, though the gem is currently useful in limited capacities.
19
+
20
+ If you'd like to jump in and help out, please contact me and we can discuss. Otherwise, please do submit pull requests for bug fixes and minor feature enhancements.
21
+
22
+ == Installation
23
+
24
+ gem install social_butterfly
25
+
26
+ If you're going to use this with Rails or some other Ruby-based web framework, be sure to add the gem to your Gemfile and run bundle install.
27
+
28
+ == Example Implementations
29
+
30
+ The following sites have integrated this library and can give you an idea of how this library can be used.
31
+
32
+ {Vino Locale Wine Bar detail page at WineTribe}[http://winetribeapp.com/wine_bars/vino-locale-palo-alto/]
33
+
34
+ == How To Integrate
35
+
36
+ === Generate share URLs from a Model instance for attaching to buttons/links for Facebook, Google+ and Twitter
37
+
38
+ >> book = Book.find_by_name('Goldilocks and the Three Bears')
39
+ >> content = { :url => polymorphic_url(book) }
40
+ >> SocialButterfly::Services::FacebookService.share_button_url(content)
41
+ => 'https://www.facebook.com/sharer/sharer.php?u=http://mysite.dev/books/4'
42
+
43
+ >> SocialButterfly::Services::GooglePlusService.share_button_url(content)
44
+ => 'https://plus.google.com/share?url=http://mysite.dev/books/4'
45
+
46
+ >> options = { :via => 'kevinelliott' }
47
+ >> SocialButterfly::Services::TwitterService.share_button_url(content, options)
48
+ => 'http://twitter.com/share?url=http://mysite.dev/books/4&text=Check%20this%20out%20--%20&via=kevinelliott&count=none'
49
+
50
+ === Get Facebook share count for URL
51
+
52
+ >> content = { :url => 'http://winetribeapp.com/' }
53
+ => {:url=>"http://winetribeapp.com/"}
54
+ >> SocialButterfly::Services::FacebookService.track(content)
55
+ => {:shares=>2}
56
+
57
+ === Get Google+ share count for URL
58
+
59
+ >> SocialButterfly::Services::GooglePlusService.track(content)
60
+ => {:shares=>1}
61
+
62
+ === Get Twitter share count for URL
63
+
64
+ >> SocialButterfly::Services::TwitterService.track(content)
65
+ => {:shares=>3}
66
+
67
+ === Get share counts for all known services
68
+
69
+ >> SocialButterfly::Services.track(content)
70
+ => {:facebook=>{:shares=>2}, :google_plus=>{:shares=>1}, :twitter=>{:shares=>3}}
71
+
72
+
73
+ == Maintainer
74
+
75
+ * Kevin Elliott - http://kevinelliott.net - http://github.com/kevinelliott
76
+ * WeLike - http://www.welikeinc.com - http://github.com/welike
77
+
78
+ == Contributors
79
+
80
+ No one else has contributed yet, but they'll be acknowledged here once they do.
81
+
82
+ == License
83
+
84
+ (The MIT License)
85
+
86
+ Permission is hereby granted, free of charge, to any person obtaining
87
+ a copy of this software and associated documentation files (the
88
+ 'Software'), to deal in the Software without restriction, including
89
+ without limitation the rights to use, copy, modify, merge, publish,
90
+ distribute, sublicense, and/or sell copies of the Software, and to
91
+ permit persons to whom the Software is furnished to do so, subject to
92
+ the following conditions:
93
+
94
+ The above copyright notice and this permission notice shall be
95
+ included in all copies or substantial portions of the Software.
96
+
97
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
98
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
99
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
100
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
101
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
102
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
103
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,11 @@
1
+ <%= link_to( image_tag('social-facebook.png')+"Share on Facebook",
2
+ facebook_share_button_url( { :url => polymorphic_url(item) } )
3
+ ) %>
4
+ <span class="spacer">|</span>
5
+ <%= link_to( image_tag('social-twitter.png')+'Tweet It',
6
+ twitter_share_button_url( { :url => polymorphic_url(item) } )
7
+ ) %>
8
+ <span class="spacer">|</span>
9
+ <%= link_to( image_tag( 'social-gplus.png')+'Share on Google+',
10
+ google_plus_share_button_url( { :url => polymorphic_url(item) } )
11
+ ) %>
@@ -1,5 +1,63 @@
1
- require "social_butterfly/version"
2
- require "social_butterfly/services"
3
-
4
1
  module SocialButterfly
2
+ def self.frameworks
3
+ frameworks = []
4
+ case
5
+ when rails? then frameworks << 'rails'
6
+ end
7
+ frameworks
8
+ end
9
+
10
+ def self.load_framework!
11
+ show_warning if frameworks.empty?
12
+ frameworks.each do |framework|
13
+ begin
14
+ require framework
15
+ rescue NameError => e
16
+ raise "Failed to load framework #{framework.inspect}. Have you added it to Gemfile?"
17
+ end
18
+ end
19
+ end
20
+
21
+ def self.show_warning
22
+ $stderr.puts <<-EOC
23
+ warning: no framework detected.
24
+ would you check out if your Gemfile appropriately configured?
25
+ ---- e.g. ----
26
+ when Rails:
27
+ gem 'rails'
28
+ gem 'social_butterfly'
29
+
30
+ EOC
31
+ end
32
+
33
+ def self.load_social_butterfly!
34
+ require 'social_butterfly/version'
35
+ require 'social_butterfly/services'
36
+ require 'social_butterfly/helpers/social_butterfly_helper'
37
+ end
38
+
39
+ def self.hook!
40
+ load_framework!
41
+ load_social_butterfly!
42
+ require 'social_butterfly/hooks'
43
+ if rails?
44
+ require 'social_butterfly/rails/action_view_extension'
45
+ require 'social_butterfly/rails/railtie'
46
+ require 'social_butterfly/rails/engine'
47
+ else
48
+ SocialButterfly::Hooks.init!
49
+ end
50
+ end
51
+
52
+ def self.load!
53
+ hook!
54
+ end
55
+
56
+ private
57
+
58
+ def self.rails?
59
+ defined?(::Rails)
60
+ end
5
61
  end
62
+
63
+ SocialButterfly.load!
@@ -0,0 +1,2 @@
1
+ module SocialButterflyHelper
2
+ end
@@ -0,0 +1,9 @@
1
+ module SocialButterfly
2
+ class Hooks
3
+ def self.init!
4
+ ActiveSupport.on_load(:action_view) do
5
+ ::ActionView::Base.send :include, SocialButterfly::Rails::ActionViewExtension
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ require "social_butterfly/rails/acts_as_social_butterfly"
2
+ require "social_butterfly/rails/engine"
3
+
4
+ module SocialButterfly
5
+ module Rails
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ module SocialButterfly
2
+ module Rails
3
+ module ActionViewExtension
4
+ def facebook_share_button_url(content={}, options={})
5
+ content = { :text => '' }.merge(content)
6
+ options = { }.merge(options)
7
+ SocialButterfly::Services::FacebookService.share_button_url(content, options)
8
+ end
9
+
10
+ def google_plus_share_button_url(content={}, options={})
11
+ content = { :text => '' }.merge(content)
12
+ options = { }.merge(options)
13
+ SocialButterfly::Services::GooglePlusService.share_button_url(content, options)
14
+ end
15
+
16
+ def twitter_share_button_url(content={}, options={})
17
+ content = { :text => 'Check this out -- ' }.merge(content)
18
+ options = { :via => '' }.merge(options)
19
+ SocialButterfly::Services::TwitterService.share_button_url(content, options)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ module SocialButterfly::Rails::ActsAsSocialButterfly
2
+ def acts_as_social_butterfly
3
+ include InstanceMethods
4
+ end
5
+
6
+ module InstanceMethods
7
+ end
8
+ end
9
+ ActiveRecord::Base.extend SocialButterfly::Rails::ActsAsSocialButterfly
@@ -0,0 +1,15 @@
1
+ require "social_butterfly"
2
+ require "social_butterfly/rails"
3
+ require "rails"
4
+
5
+ module SocialButterfly
6
+ class Engine < ::Rails::Engine
7
+ initializer 'social_butterfly.ar_extensions', :before=>"action_controller.deprecated_routes" do |app|
8
+ ActiveRecord::Base.extend SocialButterfly::Rails::ActsAsSocialButterfly
9
+ end
10
+
11
+ config.to_prepare do
12
+ ActionView::Base.send(:include, SocialButterflyHelper)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module SocialButterfly
2
+ module Rails
3
+ class Railtie < ::Rails::Railtie #:nodoc:
4
+ initializer 'social_butterfly' do |app|
5
+ SocialButterfly::Hooks.init!
6
+ end
7
+ end
8
+ end
9
+ end
@@ -4,6 +4,12 @@ require 'social_butterfly/services/twitter_service'
4
4
 
5
5
  module SocialButterfly
6
6
  module Services
7
+ VALID_SERVICES = [
8
+ :facebook,
9
+ :google_plus,
10
+ :twitter
11
+ ]
12
+
7
13
  def self.track(content, options={})
8
14
  results = {}
9
15
  results[:facebook] = SocialButterfly::Services::FacebookService.track(content, options)
@@ -1,3 +1,3 @@
1
1
  module SocialButterfly
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Kevin Elliott"]
10
10
  s.email = ["kevin@welikeinc.com"]
11
- s.homepage = ""
11
+ s.homepage = "https://github.com/kevinelliott/social_butterfly"
12
12
  s.summary = %q{Now your content can be as popular as Cher in Clueless}
13
13
  s.description = %q{Share and track content on social networks in Ruby.}
14
14
 
@@ -17,9 +17,15 @@ Gem::Specification.new do |s|
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.extra_rdoc_files = ['README.rdoc']
20
21
  s.require_paths = ["lib"]
21
22
 
22
- # specify any dependencies here; for example:
23
- # s.add_development_dependency "rspec"
24
- # s.add_runtime_dependency "rest-client"
23
+ s.licenses = ['MIT']
24
+
25
+ %w{ activesupport actionpack railties }.each do |gem|
26
+ s.add_dependency gem, ['>= 3.0.0']
27
+ end
28
+ %w{ activerecord activemodel }.each do |gem|
29
+ s.add_development_dependency gem, ['>= 3.0.0']
30
+ end
25
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_butterfly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,28 +10,93 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-01-04 00:00:00.000000000Z
13
- dependencies: []
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &70165147292260 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70165147292260
25
+ - !ruby/object:Gem::Dependency
26
+ name: actionpack
27
+ requirement: &70165147291180 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70165147291180
36
+ - !ruby/object:Gem::Dependency
37
+ name: railties
38
+ requirement: &70165147290680 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 3.0.0
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70165147290680
47
+ - !ruby/object:Gem::Dependency
48
+ name: activerecord
49
+ requirement: &70165147289900 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70165147289900
58
+ - !ruby/object:Gem::Dependency
59
+ name: activemodel
60
+ requirement: &70165147289220 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 3.0.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70165147289220
14
69
  description: Share and track content on social networks in Ruby.
15
70
  email:
16
71
  - kevin@welikeinc.com
17
72
  executables: []
18
73
  extensions: []
19
- extra_rdoc_files: []
74
+ extra_rdoc_files:
75
+ - README.rdoc
20
76
  files:
21
77
  - .gitignore
22
78
  - Gemfile
23
- - README
79
+ - README.rdoc
24
80
  - Rakefile
81
+ - app/views/social_butterfly/_share_links.html.erb
25
82
  - lib/social_butterfly.rb
26
83
  - lib/social_butterfly/abstract_service.rb
84
+ - lib/social_butterfly/helpers/social_butterfly_helper.rb
85
+ - lib/social_butterfly/hooks.rb
86
+ - lib/social_butterfly/rails.rb
87
+ - lib/social_butterfly/rails/action_view_extension.rb
88
+ - lib/social_butterfly/rails/acts_as_social_butterfly.rb
89
+ - lib/social_butterfly/rails/engine.rb
90
+ - lib/social_butterfly/rails/railtie.rb
27
91
  - lib/social_butterfly/services.rb
28
92
  - lib/social_butterfly/services/facebook_service.rb
29
93
  - lib/social_butterfly/services/google_plus_service.rb
30
94
  - lib/social_butterfly/services/twitter_service.rb
31
95
  - lib/social_butterfly/version.rb
32
96
  - social_butterfly.gemspec
33
- homepage: ''
34
- licenses: []
97
+ homepage: https://github.com/kevinelliott/social_butterfly
98
+ licenses:
99
+ - MIT
35
100
  post_install_message:
36
101
  rdoc_options: []
37
102
  require_paths:
data/README DELETED
@@ -1 +0,0 @@
1
- # social_butterfly