social 0.0.11 → 0.3.0
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.
- checksums.yaml +7 -0
- data/README.md +72 -40
- data/lib/social.rb +65 -30
- data/lib/social/balance.rb +1 -14
- data/lib/social/config/ok.rb +16 -18
- data/lib/social/config/vk.rb +15 -17
- data/lib/social/determinant.rb +4 -0
- data/lib/social/determinant/request_param.rb +56 -0
- data/lib/social/determinant/social_prefix.rb +81 -0
- data/lib/social/env.rb +21 -15
- data/lib/social/network.rb +9 -1
- data/lib/social/network/base.rb +60 -9
- data/lib/social/network/graph.rb +1 -40
- data/lib/social/network/graph/ok.rb +1 -5
- data/lib/social/network/graph/ok/base.rb +50 -56
- data/lib/social/network/graph/ok/notification.rb +9 -15
- data/lib/social/network/graph/ok/user.rb +61 -67
- data/lib/social/network/graph/tail.rb +14 -20
- data/lib/social/network/graph/vk.rb +1 -5
- data/lib/social/network/graph/vk/base.rb +27 -33
- data/lib/social/network/graph/vk/notification.rb +11 -17
- data/lib/social/network/graph/vk/user.rb +55 -61
- data/lib/social/network/ok.rb +9 -17
- data/lib/social/network/stub.rb +2 -7
- data/lib/social/network/vk.rb +9 -17
- data/lib/social/version.rb +1 -1
- data/social.gemspec +1 -0
- data/spec/lib/social/ok_api_spec.rb +8 -8
- data/spec/lib/social/vk_api_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -4
- metadata +80 -48
- data/lib/social/auth.rb +0 -4
- data/lib/social/auth/controller.rb +0 -144
- data/lib/social/builder.rb +0 -22
- data/lib/social/cache.rb +0 -26
- data/lib/social/helper.rb +0 -4
- data/lib/social/helper/controller.rb +0 -43
- data/lib/social/helper/model.rb +0 -61
- data/lib/social/network/params.rb +0 -31
- data/lib/social/provider.rb +0 -42
@@ -1,23 +1,17 @@
|
|
1
|
-
module Social
|
2
|
-
module Network
|
3
|
-
module Graph
|
4
|
-
module Tail
|
1
|
+
module Social::Network::Graph::Tail
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
3
|
+
def root=(root_instance)
|
4
|
+
@root = root_instance
|
5
|
+
end
|
6
|
+
|
7
|
+
protected
|
8
|
+
|
9
|
+
def rate
|
10
|
+
root.rate
|
11
|
+
end
|
12
|
+
|
13
|
+
def root
|
14
|
+
@root
|
22
15
|
end
|
16
|
+
|
23
17
|
end
|
@@ -1,41 +1,35 @@
|
|
1
|
-
module Social
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
include Social::Network::Graph::Tail
|
8
|
-
include Social::Config::Vk
|
1
|
+
module Social::Network::Graph::Vk
|
2
|
+
class Base
|
3
|
+
|
4
|
+
include Social::Network::Graph::Tail
|
5
|
+
include Social::Config::Vk
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def process(params)
|
15
|
-
params = default_options.merge(params).with_indifferent_access
|
16
|
-
params.merge!({'sig' => form_signature(params)})
|
17
|
-
query = "/api.php?#{Rack::Utils.build_query(params)}"
|
18
|
-
status, data = http_query(query)
|
19
|
-
JSON.load(data)['response']
|
20
|
-
end
|
7
|
+
def http_query(query)
|
8
|
+
Net::HTTP.start("api.vkontakte.ru", 80).get(query)
|
9
|
+
end
|
21
10
|
|
22
|
-
|
23
|
-
|
24
|
-
|
11
|
+
def process(params)
|
12
|
+
params = default_options.merge(params).with_indifferent_access
|
13
|
+
params.merge!({'sig' => form_signature(params)})
|
14
|
+
query = "/api.php?#{Rack::Utils.build_query(params)}"
|
15
|
+
status, data = http_query(query)
|
16
|
+
JSON.load(data)['response']
|
17
|
+
end
|
25
18
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
{:v => '3.0', :format => 'JSON', :api_id => config['app_id'] }
|
30
|
-
end
|
19
|
+
def process_secure(params)
|
20
|
+
process(params.merge('random' => (rand * 10_000).to_i, 'timestamp' => Time.now.to_i))
|
21
|
+
end
|
31
22
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
23
|
+
private
|
24
|
+
|
25
|
+
def default_options
|
26
|
+
{:v => '3.0', :format => 'JSON', :api_id => config['app_id'] }
|
27
|
+
end
|
36
28
|
|
37
|
-
|
38
|
-
|
29
|
+
def form_signature(params)
|
30
|
+
str = params.sort.map{|pair| "#{pair[0]}=#{pair[1]}"}.join('') + config['key']
|
31
|
+
Digest::MD5.hexdigest(str)
|
39
32
|
end
|
33
|
+
|
40
34
|
end
|
41
35
|
end
|
@@ -1,21 +1,15 @@
|
|
1
|
-
module Social
|
2
|
-
|
3
|
-
module Graph
|
4
|
-
module Vk
|
5
|
-
class Notification < Social::Network::Graph::Vk::Base
|
1
|
+
module Social::Network::Graph::Vk
|
2
|
+
class Notification < Base
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
4
|
+
def send(options = {})
|
5
|
+
params = { "method" => 'secure.sendNotification', :uids => options[:uids], :message => options[:message] }
|
6
|
+
result = self.process_secure(params)
|
7
|
+
|
8
|
+
#result = deliver('method' => 'secure.sendNotification', 'text' => options[:message], 'uid' => options[:uids])
|
9
|
+
|
10
|
+
return result unless block_given?
|
11
|
+
yield(result) if block_given?
|
19
12
|
end
|
13
|
+
|
20
14
|
end
|
21
15
|
end
|
@@ -1,70 +1,64 @@
|
|
1
|
-
module Social
|
2
|
-
|
3
|
-
module Graph
|
4
|
-
module Vk
|
5
|
-
class User < Social::Network::Graph::Vk::Base
|
1
|
+
module Social::Network::Graph::Vk
|
2
|
+
class User < Base
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
FIELDS = 'uid,first_name,last_name,nickname,domain,sex,birthdate,city,country,timezone,photo,photo_medium,photo_big,has_mobile,rate,contacts,education'
|
5
|
+
|
6
|
+
def get_info(*args)
|
7
|
+
uids = Array.wrap(args)
|
8
|
+
|
9
|
+
params = { "method" => 'getProfiles', "fields" => FIELDS, :uids => uids.join(",")}
|
10
|
+
|
11
|
+
results = send(:process, params)
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
13
|
+
results.each_with_index { |result, i|
|
14
|
+
results[i]['birthday'] = result['bdate'] || result['birthday']
|
15
|
+
}
|
16
|
+
|
17
|
+
return results unless block_given?
|
18
|
+
yield(results) if block_given?
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_friends(uid)
|
22
|
+
throw 'Not give uid for friends request' unless uid
|
26
23
|
|
27
|
-
|
28
|
-
|
24
|
+
params = { "method" => 'friends.get', :uid => uid, "fields" => FIELDS}
|
25
|
+
result = send(:process_secure, params)
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
return result unless block_given?
|
28
|
+
yield(result) if block_given?
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_friends_profiles(uid)
|
32
|
+
|
33
|
+
friend_uids = get_friends_uids(uid)
|
34
|
+
friend_profiles = friend_uids.map { |uid| get_info(uid) }.flatten.compact
|
35
|
+
|
36
|
+
return friend_profiles unless block_given?
|
37
|
+
yield(friend_profiles) if block_given?
|
38
|
+
end
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
def charge_off_balance(uid, balance)
|
46
|
-
amount = (((balance).floor / root.rate.to_f).round(2) * 100).round
|
47
|
-
params = { "method" => 'secure.withdrawVotes', :uid => uid, :votes => amount }
|
48
|
-
result = send(:process_secure, params)
|
49
|
-
|
50
|
-
return result unless block_given?
|
51
|
-
yield(result) if block_given?
|
52
|
-
end
|
40
|
+
def charge_off_balance(uid, balance)
|
41
|
+
amount = (((balance).floor / root.rate.to_f).round(2) * 100).round
|
42
|
+
params = { "method" => 'secure.withdrawVotes', :uid => uid, :votes => amount }
|
43
|
+
result = send(:process_secure, params)
|
44
|
+
|
45
|
+
return result unless block_given?
|
46
|
+
yield(result) if block_given?
|
47
|
+
end
|
53
48
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
alias :get_friends_uids :get_friends
|
64
|
-
alias :get_friends_info :get_friends_profiles
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
49
|
+
def balance(uid)
|
50
|
+
throw 'Not give uid for balance request' unless uid
|
51
|
+
|
52
|
+
params = { "method" => 'secure.getBalance', :uid => uid }
|
53
|
+
result = send(:process_secure, params)
|
54
|
+
result = ((result / 100).to_f.round(2) * root.rate)
|
55
|
+
|
56
|
+
return result unless block_given?
|
57
|
+
yield(result) if block_given?
|
68
58
|
end
|
59
|
+
|
60
|
+
alias :get_friends_uids :get_friends
|
61
|
+
alias :get_friends_info :get_friends_profiles
|
62
|
+
|
69
63
|
end
|
70
64
|
end
|
data/lib/social/network/ok.rb
CHANGED
@@ -1,21 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def rate
|
9
|
-
1
|
10
|
-
end
|
1
|
+
class Social::Network
|
2
|
+
class Ok < Base
|
3
|
+
include Social::Config::Ok
|
4
|
+
|
5
|
+
def rate
|
6
|
+
1
|
7
|
+
end
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
#require File.join(File.dirname(__FILE__), 'graph', 'ok', 'user')
|
15
|
-
#require File.join(File.dirname(__FILE__), 'graph', 'ok', 'notification')
|
16
|
-
|
17
|
-
super('ok', [ :user, :notification ], params)
|
18
|
-
end
|
9
|
+
def initialize(params = nil)
|
10
|
+
super('ok', [ :user, :notification ], params)
|
19
11
|
end
|
20
12
|
end
|
21
13
|
end
|
data/lib/social/network/stub.rb
CHANGED
data/lib/social/network/vk.rb
CHANGED
@@ -1,21 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def rate
|
9
|
-
6
|
10
|
-
end
|
1
|
+
class Social::Network
|
2
|
+
class Vk < Base
|
3
|
+
include Social::Config::Vk
|
4
|
+
|
5
|
+
def rate
|
6
|
+
6
|
7
|
+
end
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
#require File.join(File.dirname(__FILE__), 'graph', 'vk', 'user')
|
15
|
-
#require File.join(File.dirname(__FILE__), 'graph', 'vk', 'notification')
|
16
|
-
|
17
|
-
super('vk', [ :user, :notification ], params)
|
18
|
-
end
|
9
|
+
def initialize(params = nil)
|
10
|
+
super('vk', [ :user, :notification ], params)
|
19
11
|
end
|
20
12
|
end
|
21
13
|
end
|
data/lib/social/version.rb
CHANGED
data/social.gemspec
CHANGED
@@ -28,5 +28,6 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.add_development_dependency "pry", "~> 0.9.8.4"
|
29
29
|
s.add_development_dependency 'activesupport', "~> 3.1.3"
|
30
30
|
s.add_development_dependency 'i18n', '~> 0.6.0'
|
31
|
+
s.add_development_dependency 'rake'
|
31
32
|
#s.add_development_dependency 'multi_json', '= 1.1.0'
|
32
33
|
end
|
@@ -45,7 +45,7 @@ describe 'Спецификация OkApi' do
|
|
45
45
|
:uids => @uids.join(",")
|
46
46
|
}
|
47
47
|
|
48
|
-
@api.user.
|
48
|
+
mock(@api.user).deliver(params).times(3) { [] }
|
49
49
|
@api.user.get_info(*@uids)
|
50
50
|
@api.user.get_info(@uids)
|
51
51
|
@api.user.get_info([@uids])
|
@@ -60,7 +60,7 @@ describe 'Спецификация OkApi' do
|
|
60
60
|
:session_secret_key => @secret
|
61
61
|
}
|
62
62
|
|
63
|
-
@api.user.
|
63
|
+
mock(@api.user).deliver(params).times(3) { [] }
|
64
64
|
@api.user.get_info(@uids, { :secret => @secret })
|
65
65
|
@api.user.get_info([@uids], { :secret => @secret })
|
66
66
|
@api.user.get_info(*@uids, { :secret => @secret })
|
@@ -75,7 +75,7 @@ describe 'Спецификация OkApi' do
|
|
75
75
|
:session_secret_key => @secret
|
76
76
|
}
|
77
77
|
|
78
|
-
@api.user.
|
78
|
+
mock(@api.user).deliver(params) { [] }
|
79
79
|
@api.user.get_info(@uids, { :secret => @secret, :fields => @fields })
|
80
80
|
end
|
81
81
|
|
@@ -90,7 +90,7 @@ describe 'Спецификация OkApi' do
|
|
90
90
|
|
91
91
|
uncorrect_fields = @fields + [ "uncorrect_field 1", "uncorrect_field 2" ]
|
92
92
|
|
93
|
-
@api.user.
|
93
|
+
mock(@api.user).deliver(params) { [] }
|
94
94
|
@api.user.get_info(@uids, { :secret => @secret, :fields => uncorrect_fields })
|
95
95
|
end
|
96
96
|
|
@@ -105,7 +105,7 @@ describe 'Спецификация OkApi' do
|
|
105
105
|
|
106
106
|
uncorrect_fields = [ "uncorrect_field 1", "uncorrect_field 2" ]
|
107
107
|
|
108
|
-
@api.user.
|
108
|
+
mock(@api.user).deliver(params) { [] }
|
109
109
|
@api.user.get_info(@uids, { :secret => @secret, :fields => uncorrect_fields })
|
110
110
|
end
|
111
111
|
|
@@ -116,7 +116,7 @@ describe 'Спецификация OkApi' do
|
|
116
116
|
:uids => @uids.join(",")
|
117
117
|
}
|
118
118
|
|
119
|
-
@api.user.
|
119
|
+
mock(@api.user).deliver(params) { [] }
|
120
120
|
@api.user.get_info(@uids, nil)
|
121
121
|
end
|
122
122
|
|
@@ -127,13 +127,13 @@ describe 'Спецификация OkApi' do
|
|
127
127
|
:uids => @uids.join(",")
|
128
128
|
}
|
129
129
|
|
130
|
-
@api.user.
|
130
|
+
mock(@api.user).deliver(params) { [] }
|
131
131
|
@api.user.get_info(@uids, {})
|
132
132
|
end
|
133
133
|
|
134
134
|
it "данные по пользователю должны возвращаться в известном формате" do
|
135
135
|
data = @make_fake_datas.call(1)
|
136
|
-
@api.user.
|
136
|
+
stub(@api.user).http_query { [200, data.to_json] }
|
137
137
|
results = @api.user.get_info(1234567890)
|
138
138
|
results.should be_a_kind_of Array
|
139
139
|
results.first.should be_a_kind_of Hash
|
@@ -41,7 +41,7 @@ describe 'Спецификация VkApi' do
|
|
41
41
|
:uids => uids.join(',')
|
42
42
|
}
|
43
43
|
|
44
|
-
@api.user.
|
44
|
+
mock(@api.user).process(params).times(3) { [] }
|
45
45
|
@api.user.get_info(*uids)
|
46
46
|
@api.user.get_info(uids)
|
47
47
|
@api.user.get_info([uids])
|
@@ -50,7 +50,7 @@ describe 'Спецификация VkApi' do
|
|
50
50
|
|
51
51
|
it "данные по пользователю должны возвращаться в известном формате" do
|
52
52
|
data = @make_fake_datas.call(1)
|
53
|
-
@api.user.
|
53
|
+
stub(@api.user).http_query { [200, { :response => data }.to_json] }
|
54
54
|
results = @api.user.get_info(1234567890)
|
55
55
|
results.should be_a_kind_of Array
|
56
56
|
results.first.should be_a_kind_of Hash
|