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.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +72 -40
  3. data/lib/social.rb +65 -30
  4. data/lib/social/balance.rb +1 -14
  5. data/lib/social/config/ok.rb +16 -18
  6. data/lib/social/config/vk.rb +15 -17
  7. data/lib/social/determinant.rb +4 -0
  8. data/lib/social/determinant/request_param.rb +56 -0
  9. data/lib/social/determinant/social_prefix.rb +81 -0
  10. data/lib/social/env.rb +21 -15
  11. data/lib/social/network.rb +9 -1
  12. data/lib/social/network/base.rb +60 -9
  13. data/lib/social/network/graph.rb +1 -40
  14. data/lib/social/network/graph/ok.rb +1 -5
  15. data/lib/social/network/graph/ok/base.rb +50 -56
  16. data/lib/social/network/graph/ok/notification.rb +9 -15
  17. data/lib/social/network/graph/ok/user.rb +61 -67
  18. data/lib/social/network/graph/tail.rb +14 -20
  19. data/lib/social/network/graph/vk.rb +1 -5
  20. data/lib/social/network/graph/vk/base.rb +27 -33
  21. data/lib/social/network/graph/vk/notification.rb +11 -17
  22. data/lib/social/network/graph/vk/user.rb +55 -61
  23. data/lib/social/network/ok.rb +9 -17
  24. data/lib/social/network/stub.rb +2 -7
  25. data/lib/social/network/vk.rb +9 -17
  26. data/lib/social/version.rb +1 -1
  27. data/social.gemspec +1 -0
  28. data/spec/lib/social/ok_api_spec.rb +8 -8
  29. data/spec/lib/social/vk_api_spec.rb +2 -2
  30. data/spec/spec_helper.rb +1 -4
  31. metadata +80 -48
  32. data/lib/social/auth.rb +0 -4
  33. data/lib/social/auth/controller.rb +0 -144
  34. data/lib/social/builder.rb +0 -22
  35. data/lib/social/cache.rb +0 -26
  36. data/lib/social/helper.rb +0 -4
  37. data/lib/social/helper/controller.rb +0 -43
  38. data/lib/social/helper/model.rb +0 -61
  39. data/lib/social/network/params.rb +0 -31
  40. 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
- def root=(root_instance)
7
- @root = root_instance
8
- end
9
-
10
- protected
11
-
12
- def rate
13
- root.rate
14
- end
15
-
16
- def root
17
- @root
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,6 +1,2 @@
1
- module Social
2
- module Network
3
- class Vk
4
- end
5
- end
1
+ module Social::Network::Graph::Vk
6
2
  end
@@ -1,41 +1,35 @@
1
- module Social
2
- module Network
3
- module Graph
4
- module Vk
5
- class Base
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
- def http_query(query)
11
- Net::HTTP.start("api.vkontakte.ru", 80).get(query)
12
- end
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
- def process_secure(params)
23
- process(params.merge('random' => (rand * 10_000).to_i, 'timestamp' => Time.now.to_i))
24
- end
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
- private
27
-
28
- def default_options
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
- def form_signature(params)
33
- str = params.sort.map{|pair| "#{pair[0]}=#{pair[1]}"}.join('') + config['key']
34
- Digest::MD5.hexdigest(str)
35
- end
23
+ private
24
+
25
+ def default_options
26
+ {:v => '3.0', :format => 'JSON', :api_id => config['app_id'] }
27
+ end
36
28
 
37
- end
38
- end
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
- module Network
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
- def send(options = {})
8
- params = { "method" => 'secure.sendNotification', :uids => options[:uids], :message => options[:message] }
9
- result = self.process_secure(params)
10
-
11
- #result = deliver('method' => 'secure.sendNotification', 'text' => options[:message], 'uid' => options[:uids])
12
-
13
- return result unless block_given?
14
- yield(result) if block_given?
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
- module Network
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
- FIELDS = 'uid,first_name,last_name,nickname,domain,sex,birthdate,city,country,timezone,photo,photo_medium,photo_big,has_mobile,rate,contacts,education'
8
-
9
- def get_info(*args)
10
- uids = Array.wrap(args)
11
-
12
- params = { "method" => 'getProfiles', "fields" => FIELDS, :uids => uids.join(",")}
13
-
14
- results = send(:process, params)
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
- results.each_with_index { |result, i|
17
- results[i]['birthday'] = result['bdate'] || result['birthday']
18
- }
19
-
20
- return results unless block_given?
21
- yield(results) if block_given?
22
- end
23
-
24
- def get_friends(uid)
25
- throw 'Not give uid for friends request' unless uid
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
- params = { "method" => 'friends.get', :uid => uid, "fields" => FIELDS}
28
- result = send(:process_secure, params)
24
+ params = { "method" => 'friends.get', :uid => uid, "fields" => FIELDS}
25
+ result = send(:process_secure, params)
29
26
 
30
- return result unless block_given?
31
- yield(result) if block_given?
32
- end
33
-
34
- def balance(uid)
35
- throw 'Not give uid for balance request' unless uid
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
- params = { "method" => 'secure.getBalance', :uid => uid }
38
- result = send(:process_secure, params)
39
- result = ((result / 100).to_f.round(2) * root.rate)
40
-
41
- return result unless block_given?
42
- yield(result) if block_given?
43
- end
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
- def get_friends_profiles(uid)
55
-
56
- friend_uids = get_friends_uids(uid)
57
- friend_profiles = friend_uids.map { |uid| get_info(uid) }.flatten.compact
58
-
59
- return friend_profiles unless block_given?
60
- yield(friend_profiles) if block_given?
61
- end
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
@@ -1,21 +1,13 @@
1
- module Social
2
- module Network
3
- class Ok
4
- include Singleton
5
- include Social::Network::Base
6
- include Social::Config::Ok
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
- def initialize(params = nil)
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
@@ -1,9 +1,4 @@
1
- module Social
2
- module Network
3
- class Stub
4
- include Singleton
5
- include Social::Network::Graph
6
- include Social::Network::Params
7
- end
1
+ class Social::Network
2
+ class Stub < Base
8
3
  end
9
4
  end
@@ -1,21 +1,13 @@
1
- module Social
2
- module Network
3
- class Vk
4
- include Singleton
5
- include Social::Network::Base
6
- include Social::Config::Vk
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
- def initialize(params = nil)
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
@@ -1,3 +1,3 @@
1
1
  module Social
2
- VERSION = "0.0.11"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -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.should_receive(:deliver).with(params).exactly(3).and_return([])
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.should_receive(:deliver).with(params).exactly(3).and_return([])
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.should_receive(:deliver).with(params).exactly(1).and_return([])
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.should_receive(:deliver).with(params).exactly(1).and_return([])
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.should_receive(:deliver).with(params).exactly(1).and_return([])
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.should_receive(:deliver).with(params).exactly(1).and_return([])
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.should_receive(:deliver).with(params).exactly(1).and_return([])
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.stub!(:http_query).and_return([200, data.to_json])
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.should_receive(:process).with(params).exactly(3).and_return([])
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.stub!(:http_query).and_return([200, { :response => data }.to_json])
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