micro_vkontakte 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1 @@
1
+ v0.0.1 first release
data/LICENSE ADDED
File without changes
data/Manifest ADDED
@@ -0,0 +1,10 @@
1
+ CHANGELOG
2
+ LICENSE
3
+ Manifest
4
+ README
5
+ Rakefile
6
+ init.rb
7
+ lib/micro_vkontakte.rb
8
+ lib/micro_vkontakte/base.rb
9
+ lib/micro_vkontakte/session.rb
10
+ micro_vkontakte.gemspec
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('micro_vkontakte', '0.0.1') do |p|
6
+ p.description = "Vkontakte api tools."
7
+ p.url = "http://github.com/gvalmon/micro_vkontakte"
8
+ p.author = "Iskander Haziev"
9
+ p.email = "gvalmon@gmail.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.runtime_dependencies = ['json']
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'micro_vkontakte'
@@ -0,0 +1,6 @@
1
+ # Author: Iskander Haziev
2
+ # License: MIT License
3
+ # http://www.opensource.org/licenses/mit-license.php
4
+
5
+ require 'micro_vkontakte/base'
6
+ require 'micro_vkontakte/session'
@@ -0,0 +1,24 @@
1
+ module MicroVkontakte
2
+ class Base
3
+ attr_accessor :session
4
+
5
+ def initialize(app_id, api_secret, prefix = nil)
6
+ self.session = MicroVkontakte::Session.new(app_id, api_secret, prefix)
7
+ end
8
+
9
+ def method_missing(name, *args)
10
+ self.session.send(name, *args)
11
+ end
12
+ end
13
+
14
+ class Error < ::StandardError
15
+ end
16
+
17
+ class ServerError < Error
18
+ attr_accessor :method, :params, :error
19
+ def initialize(method, params, error)
20
+ super 'Server error'
21
+ @method, @params, @error = method, params, error
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,58 @@
1
+ require 'uri'
2
+ require 'digest/md5'
3
+ require 'net/http'
4
+ require 'json'
5
+ require 'ostruct'
6
+
7
+ module MicroVkontakte
8
+ class Session
9
+ VK_API_URL = 'http://api.vk.com/api.php'
10
+ VK_METHODS = %w{
11
+ wall fiends photos messages newsfeed status audio video places
12
+ secure language notes pages offers questions polls subscriptions
13
+ }
14
+ attr_accessor :app_id, :api_secret
15
+
16
+ def initialize(app_id, api_secret, prefix)
17
+ @app_id, @api_secret, @prefix = app_id, api_secret, prefix
18
+ end
19
+
20
+ def call(method, params = {})
21
+ params[:method] = @prefix ? "#{@prefix}.#{method}" : method
22
+ params[:api_id] = app_id
23
+ params[:format] = 'json'
24
+ params[:sig] = sig(params.stringify_keys)
25
+ response = JSON.parse(Net::HTTP.post_form(URI.parse(VK_API_URL), params).body)
26
+ if response['error']
27
+ raise ServerError.new(method, params, response['error'])
28
+ response['response']
29
+ end
30
+ end
31
+
32
+ def sig(params)
33
+ Digest::MD5::hexdigest(
34
+ params.keys.sort.map{|key| "#{key}=#{params[key]}"}.join + api_secret
35
+ )
36
+ end
37
+
38
+ VK_METHODS.each do |method|
39
+ add_method(method)
40
+ end
41
+
42
+ class << self
43
+ def add_method(method)
44
+ self.class_eval do
45
+ define_method(method) do
46
+ variable = instance_variable_get("@#{method}")
47
+ unless variable
48
+ variable = self.new(app_id, api_secret, method)
49
+ instance_variable_set("@#{method}", variable)
50
+ end
51
+ variable
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{micro_vkontakte}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Iskander Haziev"]
9
+ s.date = %q{2011-03-05}
10
+ s.description = %q{Vkontakte api tools.}
11
+ s.email = %q{gvalmon@gmail.com}
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/micro_vkontakte.rb", "lib/micro_vkontakte/base.rb", "lib/micro_vkontakte/session.rb"]
13
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "init.rb", "lib/micro_vkontakte.rb", "lib/micro_vkontakte/base.rb", "lib/micro_vkontakte/session.rb", "micro_vkontakte.gemspec"]
14
+ s.homepage = %q{http://github.com/gvalmon/micro_vkontakte}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Micro_vkontakte", "--main", "README"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{micro_vkontakte}
18
+ s.rubygems_version = %q{1.5.2}
19
+ s.summary = %q{Vkontakte api tools.}
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ s.add_runtime_dependency(%q<json>, [">= 0"])
26
+ else
27
+ s.add_dependency(%q<json>, [">= 0"])
28
+ end
29
+ else
30
+ s.add_dependency(%q<json>, [">= 0"])
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: micro_vkontakte
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Iskander Haziev
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-05 00:00:00 +03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: json
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Vkontakte api tools.
36
+ email: gvalmon@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - CHANGELOG
43
+ - LICENSE
44
+ - README
45
+ - lib/micro_vkontakte.rb
46
+ - lib/micro_vkontakte/base.rb
47
+ - lib/micro_vkontakte/session.rb
48
+ files:
49
+ - CHANGELOG
50
+ - LICENSE
51
+ - Manifest
52
+ - README
53
+ - Rakefile
54
+ - init.rb
55
+ - lib/micro_vkontakte.rb
56
+ - lib/micro_vkontakte/base.rb
57
+ - lib/micro_vkontakte/session.rb
58
+ - micro_vkontakte.gemspec
59
+ has_rdoc: true
60
+ homepage: http://github.com/gvalmon/micro_vkontakte
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --line-numbers
66
+ - --inline-source
67
+ - --title
68
+ - Micro_vkontakte
69
+ - --main
70
+ - README
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 11
88
+ segments:
89
+ - 1
90
+ - 2
91
+ version: "1.2"
92
+ requirements: []
93
+
94
+ rubyforge_project: micro_vkontakte
95
+ rubygems_version: 1.5.2
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Vkontakte api tools.
99
+ test_files: []
100
+