vk-api 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 156589d9bc2889f4c4dc9db6777ad0a36a1fd7d3
4
+ data.tar.gz: 7e6d449593bf659908604484112d35b81557b64b
5
+ SHA512:
6
+ metadata.gz: 702a51aa892f1a266fd62888e3e7a647bbc7a39b8882cfd05fb9753a910f4792641a6ab9a0d55a2def74b4965a0aba0c2d26b76ca2655b63c9fe226463cfa26a
7
+ data.tar.gz: 060c1ce825a02c4927f83506d1551825875eeb56f3ade5e2b0466328a3ba4cc37822693026a4ef0d6ee1489d95e50d63e8f38e61a6468ccbd328533a9ff719f4
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vk-api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 JWo1F
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Vk::Api
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'vk-api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install vk-api
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/vk-api/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/lib/vk-api.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'mechanize'
2
+ require 'oj'
3
+
4
+ require 'vk-api/version'
5
+ require 'vk-api/client'
6
+ require 'vk-api/fake_browser'
7
+ require 'vk-api/error'
8
+ require 'vk-api/base_error'
9
+ require 'vk-api/auth_error'
10
+
11
+ module VkApi
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+ class VkApi::AuthError < VkApi::Error
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class VkApi::BaseError < VkApi::Error
2
+
3
+ end
@@ -0,0 +1,43 @@
1
+ class VkApi::Client
2
+ attr_accessor :access_token
3
+ attr_reader :expires_in
4
+
5
+ def initialize(params)
6
+ @params = {
7
+ redirect_url: 'https://oauth.vk.com/blank.html',
8
+ version: '5.28',
9
+ settings: 'notify,friends,offline',
10
+ display: 'page',
11
+ host: 'https://api.vk.com'
12
+ }
13
+
14
+ @params.merge! params
15
+ end
16
+
17
+ def api(method, params = {})
18
+ params[:version] ||= @params[:version]
19
+ params[:access_token] ||= @access_token
20
+
21
+ url = URI.encode_www_form(params)
22
+ url = "#{@params[:host]}/method/#{method}?#{url}"
23
+
24
+ res = browser.request url
25
+ end
26
+
27
+ def client_auth(login, pass, params)
28
+ @params.merge! params
29
+
30
+ browser.sign_in login, pass
31
+ browser.security_hack login
32
+
33
+ @expires_in = browser.response['expires_in']
34
+ @access_token = browser.response['access_token']
35
+
36
+ return @access_token, @expires_in
37
+ end
38
+
39
+ protected
40
+ def browser
41
+ @browser ||= VkApi::FakeBrowser.new @params
42
+ end
43
+ end
@@ -0,0 +1,13 @@
1
+ class VkApi::Error < Exception
2
+ def initialize(env)
3
+ @env = env
4
+ end
5
+
6
+ def to_s
7
+ "#{@env[:error]}: #{@env[:description]}"
8
+ end
9
+
10
+ def [](key)
11
+ @env[key]
12
+ end
13
+ end
@@ -0,0 +1,87 @@
1
+ class VkApi::FakeBrowser
2
+ def initialize(params)
3
+ @params = params
4
+ end
5
+
6
+ def sign_in(login, pass, type = :client)
7
+ url = authorization_url type: type
8
+
9
+ agent.get(url)
10
+ agent.page.form_with(action: /login.vk.com/){|form| form.email = login; form.pass = pass}.submit
11
+
12
+ url = agent
13
+ .page
14
+ .body
15
+ .gsub("\n",'')
16
+ .gsub(' ','')
17
+ .match(/function allow.+?location.href\s?=\s?['"\s](.+?)['"].+\}/)
18
+ .to_a
19
+ .last
20
+
21
+ agent.get(url)
22
+ rescue => err
23
+ raise VkApi::AuthError.new({error: 'Auth error', description: 'Invalid login or password', more: err})
24
+ end
25
+
26
+ def security_hack(login)
27
+ form = agent.page.form_with(action: /security_check/)
28
+
29
+ if form
30
+ hint = (agent.page / '.field_prefix').last.inner_html[1, 2]
31
+ if login[/#{hint}$/]
32
+ form['code'] = login[-10, 8]
33
+ form.submit
34
+ else
35
+ raise VkApi::AuthError.new({
36
+ error: 'Auth error',
37
+ description: 'error 17'
38
+ })
39
+ end
40
+ end
41
+
42
+ agent
43
+ end
44
+ def response
45
+ puts agent.page.uri
46
+ @response ||= agent.page.uri.fragment.split('&').map{ |s| s.split '=' }.inject({}){ |a, (k,v)| a[k] = v; a }
47
+ end
48
+ def request(url)
49
+ agent.get(url)
50
+ Oj.load agent.page.body
51
+ end
52
+
53
+ protected
54
+ def agent
55
+ @agent ||= Mechanize.new.tap { |m| m.user_agent_alias = 'Mac Safari' }
56
+ end
57
+ def authorization_url(options)
58
+ check! @params, :app_id, :redirect_url, :version
59
+
60
+ case options[:type]
61
+ when :client, :standalone
62
+ 'https://oauth.vk.com/authorize?' << URI.encode_www_form({
63
+ client_id: @params[:app_id],
64
+ scope: @params[:settings],
65
+ redirect_uri: @params[:redirect_url],
66
+ display: @params[:display],
67
+ response_type: :token,
68
+ v: @params[:version]
69
+ })
70
+ when :site, :serverside
71
+ 'https://oauth.vk.com/authorize?' << URI.encode_www_form({
72
+ client_id: @params[:app_id],
73
+ scope: @params[:settings],
74
+ redirect_uri: @params[:redirect_url],
75
+ response_type: :token,
76
+ v: @params[:version]
77
+ })
78
+ else
79
+ raise VkApi::BaseError.new({ error: 'Unknown auth type', description: '' })
80
+ end
81
+ end
82
+ def check!(hash, *params)
83
+ unless hash.keys.any? {|k| params.include? k}
84
+ raise VkApi::BaseError.new({ error: 'Check error', description: 'attributes not found' })
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module VkApi
2
+ VERSION = '0.0.6'
3
+ end
data/vk-api-0.0.5.gem ADDED
Binary file
data/vk-api.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vk-api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'vk-api'
8
+ spec.version = VkApi::VERSION
9
+ spec.authors = ['JWo1F']
10
+ spec.email = ['Savegod1@gmail.com']
11
+ spec.summary = %q{api for vk}
12
+ spec.description = %q{easy api for vk}
13
+ spec.homepage = 'https://github.com/JWo1F/vk-api'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+
24
+ spec.add_dependency 'oj', '~> 2.11'
25
+ spec.add_dependency 'mechanize', '~> 2.7'
26
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vk-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - JWo1F
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: oj
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.11'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mechanize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.7'
69
+ description: easy api for vk
70
+ email:
71
+ - Savegod1@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".idea/.name"
78
+ - ".idea/.rakeTasks"
79
+ - ".idea/dictionaries/jwo1f.xml"
80
+ - ".idea/encodings.xml"
81
+ - ".idea/misc.xml"
82
+ - ".idea/modules.xml"
83
+ - ".idea/scopes/scope_settings.xml"
84
+ - ".idea/vcs.xml"
85
+ - ".idea/vk-api.iml"
86
+ - ".idea/workspace.xml"
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - lib/vk-api.rb
92
+ - lib/vk-api/auth_error.rb
93
+ - lib/vk-api/base_error.rb
94
+ - lib/vk-api/client.rb
95
+ - lib/vk-api/error.rb
96
+ - lib/vk-api/fake_browser.rb
97
+ - lib/vk-api/version.rb
98
+ - vk-api-0.0.5.gem
99
+ - vk-api.gemspec
100
+ homepage: https://github.com/JWo1F/vk-api
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.2.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: api for vk
124
+ test_files: []
125
+ has_rdoc: