social_profile 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +15 -0
- data/lib/social_profile/people/facebook.rb +24 -0
- data/lib/social_profile/people/vkontakte.rb +90 -0
- data/lib/social_profile/person.rb +70 -0
- data/lib/social_profile/version.rb +1 -1
- data/lib/social_profile.rb +6 -0
- data/social_profile.gemspec +6 -1
- data/spec/people/facebook_spec.rb +18 -0
- data/spec/people/vkontakte_spec.rb +18 -0
- metadata +74 -3
data/README.md
CHANGED
@@ -18,6 +18,8 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
+
Parse auth hash:
|
22
|
+
|
21
23
|
``` ruby
|
22
24
|
profile = SocialProfile.get(auth_hash)
|
23
25
|
profile.picture_url # http://profile.ak.fbcdn.net/h..._4963049_s.jpg
|
@@ -26,6 +28,17 @@ profile.profile_url # http://www.facebook.com/develop.rails
|
|
26
28
|
profile.provider # facebook
|
27
29
|
```
|
28
30
|
|
31
|
+
Post photo to social album. If album dosn't exists, it's create new one:
|
32
|
+
|
33
|
+
``` ruby
|
34
|
+
user = SocialProfile::Person.get(:facebook, uid, access_token)
|
35
|
+
|
36
|
+
user.share_photo!(album_id, filepath, {
|
37
|
+
:album => {:title => "Site pictures"},
|
38
|
+
:photo => {:message => "Cool photo"}
|
39
|
+
})
|
40
|
+
|
41
|
+
```
|
29
42
|
|
30
43
|
## Contributing
|
31
44
|
|
@@ -34,3 +47,5 @@ profile.provider # facebook
|
|
34
47
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
48
|
4. Push to the branch (`git push origin my-new-feature`)
|
36
49
|
5. Create new Pull Request
|
50
|
+
|
51
|
+
Copyright (c) 2013 Fodojo, released under the MIT license
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "fb_graph"
|
3
|
+
|
4
|
+
module SocialProfile
|
5
|
+
module People
|
6
|
+
class Facebook < Person
|
7
|
+
# Find album by id
|
8
|
+
def fetch_album(album_id)
|
9
|
+
::FbGraph::Album.fetch(album_id, :access_token => access_token)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Create new album id
|
13
|
+
def album!(options = {})
|
14
|
+
user.album!(options)
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def user
|
20
|
+
@user ||= ::FbGraph::User.me(access_token)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "vkontakte"
|
3
|
+
require "httpclient"
|
4
|
+
require "multi_json"
|
5
|
+
|
6
|
+
module SocialProfile
|
7
|
+
module People
|
8
|
+
class Vkontakte < Person
|
9
|
+
# Find album by id
|
10
|
+
def fetch_album(album_id)
|
11
|
+
response = user.photos.getAlbums(:aids => album_id)
|
12
|
+
Album.new(response, user)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Create new album id
|
16
|
+
def album!(options = {})
|
17
|
+
response = user.photos.createAlbum(:title => options[:name], :description => options[:message])
|
18
|
+
Album.new(response, user)
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def user
|
24
|
+
@user ||= ::Vkontakte::App::User.new(uid, :access_token => access_token)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Album
|
29
|
+
|
30
|
+
def initialize(hash, target)
|
31
|
+
@hash = Array.wrap(hash["response"]).first || {}
|
32
|
+
@target = target
|
33
|
+
end
|
34
|
+
|
35
|
+
def http_client
|
36
|
+
@http_client ||= ::HTTPClient.new(:agent_name => 'SocialProfile robot/0.1')
|
37
|
+
end
|
38
|
+
|
39
|
+
# Get album id
|
40
|
+
def identifier
|
41
|
+
@hash['aid']
|
42
|
+
end
|
43
|
+
|
44
|
+
# Upload photo to album
|
45
|
+
#
|
46
|
+
# album.photo!(
|
47
|
+
# :source => File.new('/path/to/image')
|
48
|
+
# :message => "some photo info"
|
49
|
+
# )
|
50
|
+
#
|
51
|
+
# http://vk.com/developers.php?oid=-1&p=%D0%9F%D1%80%D0%BE%D1%86%D0%B5%D1%81%D1%81_%D0%B7%D0%B0%D0%B3%D1%80%D1%83%D0%B7%D0%BA%D0%B8_%D1%84%D0%B0%D0%B9%D0%BB%D0%BE%D0%B2_%D0%BD%D0%B0_%D1%81%D0%B5%D1%80%D0%B2%D0%B5%D1%80_%D0%92%D0%9A%D0%BE%D0%BD%D1%82%D0%B0%D0%BA%D1%82%D0%B5
|
52
|
+
#
|
53
|
+
def photo!(options)
|
54
|
+
return if identifier.nil?
|
55
|
+
|
56
|
+
if upload_url = find_upload_url
|
57
|
+
data = http_client.post(upload_url, 'file1' => options[:source])
|
58
|
+
parsed_response = MultiJson.decode(data.body)
|
59
|
+
|
60
|
+
@target.photos.save(parsed_response.merge('caption' => options[:message]))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def respond_to?(method_name)
|
65
|
+
@hash.has_key?(method_name.to_s) ? true : super
|
66
|
+
end
|
67
|
+
|
68
|
+
def method_missing(method_name, *args, &block)
|
69
|
+
if @hash.has_key?(method_name.to_s)
|
70
|
+
@hash[method_name.to_s]
|
71
|
+
else
|
72
|
+
super
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
protected
|
77
|
+
|
78
|
+
def find_upload_url
|
79
|
+
server = @target.photos.getUploadServer(:aid => identifier)
|
80
|
+
|
81
|
+
if server && server['response']
|
82
|
+
server['response']['upload_url']
|
83
|
+
else
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "social_profile/version"
|
3
|
+
|
4
|
+
module SocialProfile
|
5
|
+
class Person
|
6
|
+
attr_reader :uid, :access_token
|
7
|
+
|
8
|
+
def initialize(uid, access_token, options = {})
|
9
|
+
@uid = uid
|
10
|
+
@access_token = access_token
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.get(provider, uid, access_token, options = {})
|
15
|
+
return if provider.nil?
|
16
|
+
|
17
|
+
klass = case provider.to_s
|
18
|
+
when "facebook" then People::Facebook
|
19
|
+
when "vkontakte" then People::Vkontakte
|
20
|
+
else Person
|
21
|
+
end
|
22
|
+
|
23
|
+
klass.new(uid, access_token, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Find album by id
|
27
|
+
def fetch_album(album_id)
|
28
|
+
raise NotImplementedError("Subclasses should implement this!")
|
29
|
+
end
|
30
|
+
|
31
|
+
# Create new album id
|
32
|
+
def album!(options = {})
|
33
|
+
raise NotImplementedError("Subclasses should implement this!")
|
34
|
+
end
|
35
|
+
|
36
|
+
def find_album(album_id)
|
37
|
+
return if album_id.nil?
|
38
|
+
|
39
|
+
begin
|
40
|
+
fetch_album(album_id)
|
41
|
+
rescue Exception => e
|
42
|
+
return nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_or_create_album(album_id, options = {})
|
47
|
+
record = find_album(album_id)
|
48
|
+
record ||= album!(options)
|
49
|
+
record
|
50
|
+
end
|
51
|
+
|
52
|
+
def share_photo!(album_id, filepath, options = {})
|
53
|
+
album = find_or_create_album(album_id, options[:album])
|
54
|
+
|
55
|
+
data = {
|
56
|
+
:source => File.new(filepath)
|
57
|
+
}.merge(options[:photo] || {})
|
58
|
+
|
59
|
+
album.photo!(data)
|
60
|
+
end
|
61
|
+
|
62
|
+
def tag_object!(object, tags)
|
63
|
+
tags = Array.wrap(tags)
|
64
|
+
|
65
|
+
return if tags.empty? || object.nil?
|
66
|
+
|
67
|
+
object.tag!(:tags => tags)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/social_profile.rb
CHANGED
@@ -4,12 +4,18 @@ require "social_profile/version"
|
|
4
4
|
module SocialProfile
|
5
5
|
autoload :Utils, "social_profile/utils"
|
6
6
|
autoload :Response, "social_profile/response"
|
7
|
+
autoload :Person, "social_profile/person"
|
7
8
|
|
8
9
|
module Providers
|
9
10
|
autoload :Base, "social_profile/providers/base"
|
10
11
|
autoload :Facebook, "social_profile/providers/facebook"
|
11
12
|
autoload :Vkontakte, "social_profile/providers/vkontakte"
|
12
13
|
end
|
14
|
+
|
15
|
+
module People
|
16
|
+
autoload :Facebook, "social_profile/people/facebook"
|
17
|
+
autoload :Vkontakte, "social_profile/people/vkontakte"
|
18
|
+
end
|
13
19
|
|
14
20
|
def self.get(auth_hash, options = {})
|
15
21
|
provider = auth_hash["provider"].to_s.downcase if auth_hash && auth_hash["provider"]
|
data/social_profile.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = SocialProfile::VERSION
|
9
9
|
spec.authors = ["Igor Galeta"]
|
10
10
|
spec.email = ["galeta.igor@gmail.com"]
|
11
|
-
spec.description = %q{Wrapper for Omniauth profile hash}
|
11
|
+
spec.description = %q{Wrapper for Omniauth profile hash, post photo to album}
|
12
12
|
spec.summary = %q{Wrapper for Omniauth profile hash}
|
13
13
|
spec.homepage = "https://github.com/galetahub/social_profile"
|
14
14
|
spec.license = "MIT"
|
@@ -20,4 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "fb_graph"
|
25
|
+
spec.add_dependency "vkontakte"
|
26
|
+
spec.add_dependency "httpclient"
|
27
|
+
spec.add_dependency "multi_json"
|
23
28
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe SocialProfile::People::Facebook do
|
5
|
+
it "should be a Module" do
|
6
|
+
SocialProfile::People.should be_a(Module)
|
7
|
+
end
|
8
|
+
|
9
|
+
context "facebook" do
|
10
|
+
before(:each) do
|
11
|
+
@user = SocialProfile::Person.get(:facebook, "100000730417342", "abc")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be a facebook profile" do
|
15
|
+
@user.should be_a(SocialProfile::People::Facebook)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe SocialProfile::People::Vkontakte do
|
5
|
+
it "should be a Module" do
|
6
|
+
SocialProfile::People.should be_a(Module)
|
7
|
+
end
|
8
|
+
|
9
|
+
context "facebook" do
|
10
|
+
before(:each) do
|
11
|
+
@user = SocialProfile::Person.get(:vkontakte, "123456789", "abc")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be a facebook profile" do
|
15
|
+
@user.should be_a(SocialProfile::People::Vkontakte)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_profile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -43,7 +43,71 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: fb_graph
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: vkontakte
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: httpclient
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: multi_json
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Wrapper for Omniauth profile hash, post photo to album
|
47
111
|
email:
|
48
112
|
- galeta.igor@gmail.com
|
49
113
|
executables: []
|
@@ -57,6 +121,9 @@ files:
|
|
57
121
|
- README.md
|
58
122
|
- Rakefile
|
59
123
|
- lib/social_profile.rb
|
124
|
+
- lib/social_profile/people/facebook.rb
|
125
|
+
- lib/social_profile/people/vkontakte.rb
|
126
|
+
- lib/social_profile/person.rb
|
60
127
|
- lib/social_profile/providers/base.rb
|
61
128
|
- lib/social_profile/providers/facebook.rb
|
62
129
|
- lib/social_profile/providers/vkontakte.rb
|
@@ -64,6 +131,8 @@ files:
|
|
64
131
|
- lib/social_profile/utils.rb
|
65
132
|
- lib/social_profile/version.rb
|
66
133
|
- social_profile.gemspec
|
134
|
+
- spec/people/facebook_spec.rb
|
135
|
+
- spec/people/vkontakte_spec.rb
|
67
136
|
- spec/providers/facebook_spec.rb
|
68
137
|
- spec/providers/vkontakte_spec.rb
|
69
138
|
- spec/spec_helper.rb
|
@@ -93,6 +162,8 @@ signing_key:
|
|
93
162
|
specification_version: 3
|
94
163
|
summary: Wrapper for Omniauth profile hash
|
95
164
|
test_files:
|
165
|
+
- spec/people/facebook_spec.rb
|
166
|
+
- spec/people/vkontakte_spec.rb
|
96
167
|
- spec/providers/facebook_spec.rb
|
97
168
|
- spec/providers/vkontakte_spec.rb
|
98
169
|
- spec/spec_helper.rb
|