social_butterfly 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,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in social_butterfly.gemspec
4
+ gemspec
data/README ADDED
@@ -0,0 +1 @@
1
+ # social_butterfly
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ require "social_butterfly/version"
2
+ require "social_butterfly/services"
3
+
4
+ module SocialButterfly
5
+ end
@@ -0,0 +1,14 @@
1
+ require 'open-uri'
2
+ require 'json'
3
+
4
+ class SocialButterfly::AbstractService
5
+
6
+ def self.share(content, service_options={})
7
+ puts "You must override the share(content, service_options) method."
8
+ end
9
+
10
+ def self.track(content, service_options={})
11
+ puts "You must override the track(content, service_options) method."
12
+ end
13
+
14
+ end
@@ -0,0 +1,8 @@
1
+ require 'social_butterfly/services/facebook_service'
2
+ require 'social_butterfly/services/google_plus_service'
3
+ require 'social_butterfly/services/twitter_service'
4
+
5
+ module SocialButterfly
6
+ module Services
7
+ end
8
+ end
@@ -0,0 +1,22 @@
1
+ require 'social_butterfly/abstract_service'
2
+
3
+ module SocialButterfly::Services
4
+ class FacebookService < SocialButterfly::AbstractService
5
+ def self.share_button_url(content, service_options={})
6
+ "https://www.facebook.com/sharer/sharer.php?u=#{content[:url]}"
7
+ end
8
+
9
+ def self.track(content, service_options={})
10
+ url = "http://graph.facebook.com/#{content[:url]}"
11
+ stats = {}
12
+ result = JSON.parse(open(url).read)
13
+
14
+ if result.present? && result['shares'].present?
15
+ stats[:shares] = result['shares']
16
+ else
17
+ stats[:shares] = 0
18
+ end
19
+ stats
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ require 'social_butterfly/abstract_service'
2
+ require 'curb'
3
+
4
+ module SocialButterfly::Services
5
+ class GooglePlusService < SocialButterfly::AbstractService
6
+ def self.share_button_url(content, service_options={})
7
+ "https://plus.google.com/share?url=" + content[:url]
8
+ end
9
+
10
+ def self.track(content, service_options={})
11
+ stats = {}
12
+ jsonstring = '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' + content[:url] +'","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]'
13
+ c = Curl::Easy.http_post("https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ", jsonstring) do |curl|
14
+ curl.headers['Accept'] = 'application/json'
15
+ curl.headers['Content-Type'] = 'application/json'
16
+ curl.headers['Api-Version'] = '2.2'
17
+ end
18
+
19
+ response = JSON.parse(c.body_str)
20
+ if response[0]['error'] == nil
21
+ stats[:shares] = 0
22
+ else
23
+ stats[:shares] = response[0]['result']['metadata']['globalCounts']['count'].round
24
+ end
25
+ stats
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ require 'social_butterfly/abstract_service'
2
+
3
+ module SocialButterfly::Services
4
+ class TwitterService < SocialButterfly::AbstractService
5
+ def self.share_button_url(content, service_options={})
6
+ "http://twitter.com/share?" +
7
+ "url=" + content[:url] +
8
+ "&text=" + content[:text] +
9
+ "&via=" + service_options[:via] +
10
+ "&count=none"
11
+ end
12
+
13
+ def self.track(content, service_options={})
14
+ url = "http://urls.api.twitter.com/1/urls/count.json?url=#{content[:url]}"
15
+ stats = {}
16
+ result = JSON.parse(open(url).read)
17
+
18
+ if result.present? && result['count'].present?
19
+ stats[:shares] = result['count']
20
+ else
21
+ stats[:shares] = 0
22
+ end
23
+ stats
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module SocialButterfly
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "social_butterfly/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "social_butterfly"
7
+ s.version = SocialButterfly::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Kevin Elliott"]
10
+ s.email = ["kevin@welikeinc.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Now your content can be as popular as Cher in Clueless}
13
+ s.description = %q{Share and track content on social networks in Ruby.}
14
+
15
+ s.rubyforge_project = "social_butterfly"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ # specify any dependencies here; for example:
23
+ # s.add_development_dependency "rspec"
24
+ # s.add_runtime_dependency "rest-client"
25
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: social_butterfly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kevin Elliott
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-04 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Share and track content on social networks in Ruby.
15
+ email:
16
+ - kevin@welikeinc.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - README
24
+ - Rakefile
25
+ - lib/social_butterfly.rb
26
+ - lib/social_butterfly/abstract_service.rb
27
+ - lib/social_butterfly/services.rb
28
+ - lib/social_butterfly/services/facebook_service.rb
29
+ - lib/social_butterfly/services/google_plus_service.rb
30
+ - lib/social_butterfly/services/twitter_service.rb
31
+ - lib/social_butterfly/version.rb
32
+ - social_butterfly.gemspec
33
+ homepage: ''
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project: social_butterfly
53
+ rubygems_version: 1.8.10
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Now your content can be as popular as Cher in Clueless
57
+ test_files: []