socialoud 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2011 - Endel Dreyer
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.
21
+
data/lib/socialoud.rb ADDED
@@ -0,0 +1,4 @@
1
+ $: << 'lib'
2
+
3
+ require 'socialoud/socialoud'
4
+ require 'socialoud/services'
@@ -0,0 +1,33 @@
1
+ module Socialoud
2
+ module Services
3
+ class Base
4
+ attr_reader :data, :aggregator
5
+
6
+ def initialize(data, aggr = nil)
7
+ @data = data
8
+ @aggregator = aggr
9
+ end
10
+
11
+ def setup!
12
+ end
13
+
14
+ def set(key, value)
15
+ @data[key] = value
16
+ end
17
+
18
+ def method_missing(method, *args)
19
+ if args.length > 0
20
+ @data[method.to_s].send(args.shift, *args)
21
+ else
22
+ @data[method.to_s]
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ require 'socialoud/services/twitter'
30
+ require 'socialoud/services/facebook'
31
+ require 'socialoud/services/github'
32
+ require 'socialoud/services/linkedin'
33
+ require 'socialoud/services/gravatar'
@@ -0,0 +1,16 @@
1
+ module Socialoud
2
+ module Services
3
+ class Facebook < Base
4
+ def setup!
5
+ end
6
+
7
+ #
8
+ # TODO: add more methods to this service
9
+ #
10
+
11
+ def profile_url
12
+ "http://www.facebook.com.br/#{@data}"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,31 @@
1
+ require 'octopi'
2
+
3
+ module Socialoud
4
+ module Services
5
+ class Github < Base
6
+ attr_reader :user
7
+
8
+ def repositories
9
+ Octopi::Repository.find(:user => @data)
10
+ end
11
+
12
+ def profile_url
13
+ "http://github.com/#{@data}"
14
+ end
15
+
16
+ def method_missing(method, *args)
17
+ fetch_user!
18
+ if args.length > 0
19
+ @user.send(method, *args)
20
+ else
21
+ @user.send(method)
22
+ end
23
+ end
24
+
25
+ private
26
+ def fetch_user!
27
+ @user ||= Octopi::User.find(@data)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ require 'digest/md5'
2
+
3
+ module Socialoud
4
+ module Services
5
+ class Gravatar < Base
6
+ def setup!
7
+ @hash = Digest::MD5.hexdigest(@data)
8
+ end
9
+
10
+ def email
11
+ @data
12
+ end
13
+
14
+ def image(size = 200)
15
+ "http://www.gravatar.com/avatar/#{@hash}?s=#{size}"
16
+ end
17
+
18
+ def profile_url
19
+ "http://www.gravatar.com/#{@hash}"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,53 @@
1
+ require 'nokogiri'
2
+ require 'httparty'
3
+
4
+ module Socialoud
5
+ module Services
6
+ #
7
+ # LinkedIn service class doesn't use official API calls to avoid superfluous authentication
8
+ #
9
+ class Linkedin < Base
10
+ def setup!
11
+ @page = Nokogiri::HTML.parse(HTTParty.get(@data['url']).response.body)
12
+ end
13
+
14
+ def profile_url
15
+ @data['url']
16
+ end
17
+
18
+ def full_name
19
+ clean_str!(@page.css('#name .full-name').inner_text)
20
+ end
21
+
22
+ def first_name
23
+ clean_str!(@page.css('#name .given-name').inner_text)
24
+ end
25
+
26
+ def family_name
27
+ clean_str!(@page.css('#name .family-name').inner_text)
28
+ end
29
+
30
+ def headline
31
+ clean_str!(@page.css('.headline-title.title').inner_text)
32
+ end
33
+
34
+ def current
35
+ clean_str!(@page.css('.summary-current ul.current li').inner_html.strip.gsub(/<\/?[^>]*>/, ""))
36
+ end
37
+
38
+ # Returns an Array of skills
39
+ def skills
40
+ @page.css('ol#skills-list li a').collect {|a| a.inner_text.gsub(/\n/,'').strip }
41
+ end
42
+
43
+ def summary
44
+ clean_str!(@page.css('p.description.summary').inner_html)
45
+ end
46
+
47
+ protected
48
+ def clean_str!(str)
49
+ str.gsub(/ +/, ' ').strip
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,78 @@
1
+ require 'twitter'
2
+
3
+ module Socialoud
4
+ module Services
5
+ class Twitter < Base
6
+ attr_reader :user
7
+
8
+ def setup!
9
+ @username = @data['user'] || @data
10
+ @client = ::Twitter::Client.new
11
+ end
12
+
13
+ def profile_url
14
+ "http://twitter.com/#{@username}"
15
+ end
16
+
17
+ def last_tweet
18
+ last_tweets = @client.user_timeline(@data, {:count => 5})
19
+ (last_tweets.select {|t| t['text'].index('@') != 0 }.first || last_tweets.first)['text']
20
+ end
21
+
22
+ #
23
+ # Allow to retrieve each user attribute by aggr.twitter.attribute.
24
+ #
25
+ # Examples:
26
+ # aggr.twitter.is_translator
27
+ # aggr.twitter.profile_background_image_url_https
28
+ # aggr.twitter.profile_text_color
29
+ # aggr.twitter.followers_count
30
+ # aggr.twitter.protected
31
+ # aggr.twitter.default_profile
32
+ # aggr.twitter.follow_request_sent
33
+ # aggr.twitter.profile_background_image_url
34
+ # aggr.twitter.friends_count
35
+ # aggr.twitter.name
36
+ # aggr.twitter.id_str
37
+ # aggr.twitter.profile_link_color
38
+ # aggr.twitter.lang
39
+ # aggr.twitter.utc_offset
40
+ # aggr.twitter.created_at
41
+ # aggr.twitter.profile_image_url_https
42
+ # aggr.twitter.description
43
+ # aggr.twitter.profile_background_color
44
+ # aggr.twitter.listed_count
45
+ # aggr.twitter.notifications
46
+ # aggr.twitter.profile_background_tile
47
+ # aggr.twitter.show_all_inline_media
48
+ # aggr.twitter.contributors_enabled
49
+ # aggr.twitter.favourites_count
50
+ # aggr.twitter.profile_sidebar_fill_color
51
+ # aggr.twitter.verified
52
+ # aggr.twitter.profile_image_url
53
+ # aggr.twitter.following
54
+ # aggr.twitter.time_zone
55
+ # aggr.twitter.profile_sidebar_border_color
56
+ # aggr.twitter.location
57
+ # aggr.twitter.screen_name
58
+ # aggr.twitter.default_profile_image
59
+ # aggr.twitter.id
60
+ # aggr.twitter.statuses_count
61
+ # aggr.twitter.geo_enabled
62
+ # aggr.twitter.profile_use_background_image
63
+ # aggr.twitter.url
64
+ #
65
+
66
+ def method_missing(method, *args)
67
+ fetch_user!
68
+ @user[method.to_s]
69
+ end
70
+
71
+ private
72
+ def fetch_user!
73
+ @user ||= ::Twitter.user(@username)
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,40 @@
1
+ require 'yaml'
2
+
3
+ module Socialoud
4
+ class Client
5
+ attr_accessor :services
6
+
7
+ def self.configure(data)
8
+ aggr = Client.new
9
+ hash = data.is_a?(Hash) ? data : YAML.load_file(data)
10
+
11
+ services = {}
12
+ hash['services'].each_pair do |service, config|
13
+ service_const = Socialoud::Services.const_get("#{service[0..0].upcase}#{service[1..-1]}")
14
+ services[service] = service_const.new(config, aggr)
15
+ end
16
+ services.each do |name, instance|
17
+ aggr.services[name.to_sym] = instance
18
+ instance.setup!
19
+ end
20
+ aggr
21
+ end
22
+
23
+ def add_service!(name, instance)
24
+ services[name] = instance
25
+ instance.setup!
26
+ end
27
+
28
+ def method_missing(method, *args)
29
+ if args.length > 0
30
+ @services[method].send(args.shift, *args)
31
+ else
32
+ @services[method]
33
+ end
34
+ end
35
+
36
+ def initialize(services = {})
37
+ @services = services
38
+ end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: socialoud
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.1
6
+ platform: ruby
7
+ authors:
8
+ - Endel Dreyer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-10-12 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: twitter
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 1.7.2
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: octopi
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 0.4.5
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: nokogiri
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.5.0
46
+ type: :runtime
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: httparty
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 0.8.0
57
+ type: :runtime
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: sinatra
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 1.3.1
68
+ type: :runtime
69
+ version_requirements: *id005
70
+ description: " Simple social aggregation written in Ruby.\n With this gem you can create your custom social network overview.\n"
71
+ email: endel.dreyer@gmail.com
72
+ executables: []
73
+
74
+ extensions: []
75
+
76
+ extra_rdoc_files: []
77
+
78
+ files:
79
+ - LICENSE
80
+ - lib/socialoud/services/facebook.rb
81
+ - lib/socialoud/services/github.rb
82
+ - lib/socialoud/services/gravatar.rb
83
+ - lib/socialoud/services/linkedin.rb
84
+ - lib/socialoud/services/twitter.rb
85
+ - lib/socialoud/services.rb
86
+ - lib/socialoud/socialoud.rb
87
+ - lib/socialoud.rb
88
+ homepage: http://github.com/endel/socialoud
89
+ licenses: []
90
+
91
+ post_install_message:
92
+ rdoc_options: []
93
+
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
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: "0"
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.8.11
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: Simple social aggregation tool written in Ruby.
115
+ test_files: []
116
+