social 0.0.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.
Files changed (42) hide show
  1. data/.gitignore +4 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +22 -0
  5. data/README.md +78 -0
  6. data/Rakefile +3 -0
  7. data/lib/social.rb +124 -0
  8. data/lib/social/auth.rb +4 -0
  9. data/lib/social/auth/controller.rb +144 -0
  10. data/lib/social/balance.rb +40 -0
  11. data/lib/social/builder.rb +22 -0
  12. data/lib/social/cache.rb +26 -0
  13. data/lib/social/config.rb +52 -0
  14. data/lib/social/config/ok.rb +12 -0
  15. data/lib/social/config/vk.rb +13 -0
  16. data/lib/social/env.rb +34 -0
  17. data/lib/social/helper.rb +4 -0
  18. data/lib/social/helper/controller.rb +43 -0
  19. data/lib/social/helper/model.rb +61 -0
  20. data/lib/social/network.rb +4 -0
  21. data/lib/social/network/base.rb +14 -0
  22. data/lib/social/network/graph.rb +41 -0
  23. data/lib/social/network/graph/ok.rb +6 -0
  24. data/lib/social/network/graph/ok/base.rb +57 -0
  25. data/lib/social/network/graph/ok/notification.rb +18 -0
  26. data/lib/social/network/graph/ok/user.rb +49 -0
  27. data/lib/social/network/graph/tail.rb +23 -0
  28. data/lib/social/network/graph/vk.rb +6 -0
  29. data/lib/social/network/graph/vk/base.rb +37 -0
  30. data/lib/social/network/graph/vk/notification.rb +21 -0
  31. data/lib/social/network/graph/vk/user.rb +62 -0
  32. data/lib/social/network/ok.rb +21 -0
  33. data/lib/social/network/params.rb +31 -0
  34. data/lib/social/network/stub.rb +9 -0
  35. data/lib/social/network/vk.rb +21 -0
  36. data/lib/social/networks.rb +29 -0
  37. data/lib/social/provider.rb +42 -0
  38. data/lib/social/version.rb +3 -0
  39. data/social.gemspec +30 -0
  40. data/spec/lib/social_spec.rb +12 -0
  41. data/spec/spec_helper.rb +17 -0
  42. metadata +157 -0
@@ -0,0 +1,23 @@
1
+ module Social
2
+ module Network
3
+ module Graph
4
+ module Tail
5
+
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
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ module Social
2
+ module Network
3
+ class Vk
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,37 @@
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
9
+
10
+ def process(params)
11
+ params = default_options.merge(params).with_indifferent_access
12
+ params.merge!({'sig' => form_signature(params)})
13
+ query = "/api.php?#{Rack::Utils.build_query(params)}"
14
+ status, data = Net::HTTP.start("api.vkontakte.ru", 80).get(query)
15
+ ActiveSupport::JSON.decode(data)['response']
16
+ end
17
+
18
+ def process_secure(params)
19
+ process(params.merge('random' => (rand * 10_000).to_i, 'timestamp' => Time.now.to_i))
20
+ end
21
+
22
+ private
23
+
24
+ def default_options
25
+ {:v => '3.0', :format => 'JSON', :api_id => config['app_id'] }
26
+ end
27
+
28
+ def form_signature(params)
29
+ str = params.sort.map{|pair| "#{pair[0]}=#{pair[1]}"}.join('') + config['key']
30
+ Digest::MD5.hexdigest(str)
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ module Social
2
+ module Network
3
+ module Graph
4
+ module Vk
5
+ class Notification < Social::Network::Graph::Vk::Base
6
+
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
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,62 @@
1
+ module Social
2
+ module Network
3
+ module Graph
4
+ module Vk
5
+ class User < Social::Network::Graph::Vk::Base
6
+
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(uids)
10
+
11
+ params = { "method" => 'getProfiles', "fields" => FIELDS, :uids => Array.wrap(uids).join(",")}
12
+ result = send(:process, params)
13
+
14
+ result['birthday'] = result['bdate']
15
+
16
+ return result unless block_given?
17
+ yield(result) if block_given?
18
+ end
19
+
20
+ def get_friends(uid)
21
+ params = { "method" => 'friends.get', :uid => uid, "fields" => FIELDS}
22
+ result = send(:process_secure, params)
23
+
24
+ return result unless block_given?
25
+ yield(result) if block_given?
26
+ end
27
+
28
+ def balance(uid)
29
+ params = { "method" => 'secure.getBalance', :uid => uid }
30
+ result = send(:process_secure, params)
31
+ result = ((result / 100).to_f.round(2) * root.rate)
32
+
33
+ return result unless block_given?
34
+ yield(result) if block_given?
35
+ end
36
+
37
+ def charge_off_balance(uid, balance)
38
+ amount = (((balance).floor / root.rate).to_f.round(2) * 100).round
39
+ params = { "method" => 'secure.withdrawVotes', :uid => uid, :votes => amount }
40
+ result = send(:process_secure, params)
41
+
42
+ return result unless block_given?
43
+ yield(result) if block_given?
44
+ end
45
+
46
+ def get_friends_profiles(uid)
47
+
48
+ friend_uids = get_friends_uids(uid)
49
+ friend_profiles = friend_uids.map { |uid| get_info(uid) }.flatten.compact
50
+
51
+ return friend_profiles unless block_given?
52
+ yield(friend_profiles) if block_given?
53
+ end
54
+
55
+ alias :get_friends_uids :get_friends
56
+ alias :get_friends_info :get_friends_profiles
57
+
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,21 @@
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
11
+
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
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ module Social
2
+ module Network
3
+ module Params
4
+
5
+ def params()
6
+ @params
7
+ end
8
+
9
+ def params!(params)
10
+ @params = params
11
+ self
12
+ end
13
+
14
+ def param(key)
15
+ @params[key]
16
+ end
17
+
18
+ def param!(key, value)
19
+ @params[key] = value
20
+ self
21
+ end
22
+
23
+ protected
24
+
25
+ def init_params(params)
26
+ @params = params.is_a?(Hash) ? params : {}
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ module Social
2
+ module Network
3
+ class Stub
4
+ include Singleton
5
+ include Social::Network::Graph
6
+ include Social::Network::Params
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
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
11
+
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
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ module Social
2
+ class Networks
3
+ include Singleton
4
+
5
+ def initialize()
6
+ @domains = {}
7
+ end
8
+
9
+ def site(network, params)
10
+ @domains[network.to_sym] ||= deploy(network)
11
+ @domains[network.to_sym].params!(params)
12
+ end
13
+
14
+ def sites
15
+ @domains
16
+ end
17
+
18
+ protected
19
+
20
+ def deploy(network)
21
+ network_name = network.to_s.classify
22
+ if Social::Network.const_defined?(network_name)
23
+ @network = Social::Network.const_get(network_name).instance
24
+ else
25
+ @network = Social::Network::Stub.instance
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ module Social
2
+ class Provider
3
+ def self.build(prefix)
4
+
5
+ klass = Class.new do
6
+
7
+ class << self
8
+ attr_accessor :prefix
9
+ end
10
+
11
+ def initialize(app)
12
+ @app = app
13
+ end
14
+
15
+ def call(env)
16
+ request = Rack::Request.new(env)
17
+
18
+ prefix = self.class.prefix
19
+ type = Social.type_by_prefix(prefix)
20
+ id = Social.id_by_type(type)
21
+
22
+ request['social_env'] = {
23
+ 'prefix' => prefix,
24
+ 'type' => type,
25
+ 'id' => id
26
+ }
27
+
28
+ # Устарели
29
+ request['soc_prefix'] = prefix
30
+ request['soc_type'] = type
31
+ request['soc_id'] = id
32
+
33
+ @app.call(request.env)
34
+ end
35
+
36
+ end
37
+
38
+ klass.prefix = prefix
39
+ klass
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module Social
2
+ VERSION = "0.0.1"
3
+ end
data/social.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "social/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "social"
7
+ s.version = Social::VERSION
8
+ s.authors = ["Kazantsev Nickolay"]
9
+ s.email = ["kazantsev.nickolay@gmail.com"]
10
+ s.homepage = 'http://github.com/realb0t/social'
11
+ s.summary = 'Social API wrapper and Tools'
12
+ s.description = 'This is social networks api wrapper and authorization tools for social applications.
13
+ Now it is a compilation of code from various projects in production. Without tests. =( NOT RECOMMENDED USE IN PRODUCTION.'
14
+
15
+ s.rubyforge_project = "social"
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
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ s.add_development_dependency "rspec-core", "~> 2.0"
25
+ s.add_development_dependency "rspec-expectations", "~> 2.0"
26
+ s.add_development_dependency 'rack', '~> 1.4.1'
27
+ s.add_development_dependency 'rack-test', '~> 0.6.1'
28
+ s.add_development_dependency "rr", "~> 1.0"
29
+ s.add_development_dependency 'activesupport', "~> 3.1.3"
30
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Social do
4
+
5
+ it "support ok" do
6
+ Social::Network(:ok).user.should_not be_nil
7
+ end
8
+
9
+ it "support vk" do
10
+ Social::Network(:vk).user.should_not be_nil
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'social'
9
+
10
+ #require File.join(File.dirname(__FILE__), '..', 'lib', 'social')
11
+
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+ config.mock_with :rr
17
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: social
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kazantsev Nickolay
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-10 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec-core
16
+ requirement: &70326545755480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70326545755480
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec-expectations
27
+ requirement: &70326545754940 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70326545754940
36
+ - !ruby/object:Gem::Dependency
37
+ name: rack
38
+ requirement: &70326545754440 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.4.1
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70326545754440
47
+ - !ruby/object:Gem::Dependency
48
+ name: rack-test
49
+ requirement: &70326545753960 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.6.1
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70326545753960
58
+ - !ruby/object:Gem::Dependency
59
+ name: rr
60
+ requirement: &70326545753420 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '1.0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70326545753420
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: &70326545752900 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 3.1.3
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70326545752900
80
+ description: ! "This is social networks api wrapper and authorization tools for social
81
+ applications. \n Now it is a compilation of code from various projects in production.
82
+ Without tests. =( NOT RECOMMENDED USE IN PRODUCTION."
83
+ email:
84
+ - kazantsev.nickolay@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - .gitignore
90
+ - .rspec
91
+ - Gemfile
92
+ - LICENSE
93
+ - README.md
94
+ - Rakefile
95
+ - lib/social.rb
96
+ - lib/social/auth.rb
97
+ - lib/social/auth/controller.rb
98
+ - lib/social/balance.rb
99
+ - lib/social/builder.rb
100
+ - lib/social/cache.rb
101
+ - lib/social/config.rb
102
+ - lib/social/config/ok.rb
103
+ - lib/social/config/vk.rb
104
+ - lib/social/env.rb
105
+ - lib/social/helper.rb
106
+ - lib/social/helper/controller.rb
107
+ - lib/social/helper/model.rb
108
+ - lib/social/network.rb
109
+ - lib/social/network/base.rb
110
+ - lib/social/network/graph.rb
111
+ - lib/social/network/graph/ok.rb
112
+ - lib/social/network/graph/ok/base.rb
113
+ - lib/social/network/graph/ok/notification.rb
114
+ - lib/social/network/graph/ok/user.rb
115
+ - lib/social/network/graph/tail.rb
116
+ - lib/social/network/graph/vk.rb
117
+ - lib/social/network/graph/vk/base.rb
118
+ - lib/social/network/graph/vk/notification.rb
119
+ - lib/social/network/graph/vk/user.rb
120
+ - lib/social/network/ok.rb
121
+ - lib/social/network/params.rb
122
+ - lib/social/network/stub.rb
123
+ - lib/social/network/vk.rb
124
+ - lib/social/networks.rb
125
+ - lib/social/provider.rb
126
+ - lib/social/version.rb
127
+ - social.gemspec
128
+ - spec/lib/social_spec.rb
129
+ - spec/spec_helper.rb
130
+ homepage: http://github.com/realb0t/social
131
+ licenses: []
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project: social
150
+ rubygems_version: 1.8.6
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: Social API wrapper and Tools
154
+ test_files:
155
+ - spec/lib/social_spec.rb
156
+ - spec/spec_helper.rb
157
+ has_rdoc: