Permalink
Browse files

~

  • Loading branch information...
1 parent 7ec7df8 commit 9bf659924c08871cba5715ee75c8af6e3000b227 Andrew Zinenko committed Sep 25, 2012
Showing with 44 additions and 61 deletions.
  1. +0 −2 -config.yml
  2. +1 −14 README.md
  3. +1 −3 Rakefile
  4. +0 −42 lib/vk-ruby/application.rb
  5. +42 −0 lib/vk-ruby/core.rb
View
@@ -1,2 +0,0 @@
-app_id: 3138594
-access_token: 'f2373150a7000d6ff7e3d5524ef770d88bff758f75f3ca8e196ee3adc58662b'
View
@@ -23,23 +23,10 @@ app.friends.getOnline uid: 1 # => Online friends
# similar call
-app.vk_call 'friends.getOnline', {uid: 1}
-
-app = VK::Serverside.new access_token: TOKEN, underscore_methods: true
-
app.friends.get_online uid: 1
-```
-
-### Underscore methods
-
-
-```.ruby
app.vk_call 'friends.getOnline', {uid: 1}
-app = VK::Serverside.new access_token: TOKEN, underscore_methods: true
-
-app.friends.get_online uid: 1
```
### Upload files
@@ -48,7 +35,7 @@ app.friends.get_online uid: 1
url = 'http://cs2222.vkontakte.ru/upload.php?act=do_add'
-VK.upload(url: url, photo: ['/path/to/example.jpg', 'image/jpeg'])
+app.upload(url: url, photo: ['/path/to/example.jpg', 'image/jpeg'])
```
### Authorization
View
@@ -14,11 +14,9 @@ end
require 'rake'
require 'rake/testtask'
-# task default: :test
+task default: :test
Rake::TestTask.new do |test|
- # include Rake::DSL
-
test.pattern = 'tests/*_test.rb'
test.verbose = true
end
View
@@ -13,46 +13,4 @@ def initialize(params = {})
init_namespaces(NAMESPACES)
end
- # Authorization (getting the access token by code)
- # {http://vk.com/developers.php?oid=-1&p=%D0%90%D0%B2%D1%82%D0%BE%D1%80%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F_%D1%81%D0%B0%D0%B9%D1%82%D0%BE%D0%B2 Read more}
- #
- # @param [String] param - is param required from getting access token.
- # @param [Hash] params configurable options request. if you do not pass the option that will be used by the same name attribute.
- # @option params [Boolean] :save indicator that you want to save the returns parameters. Default `true`.
- # @option params [Symbol] :type authorization type `:serverside` or `:secure`.
- # @option params [Symbol] :code code param required for serverside authorization. Default `serverside`.
- #
- # @raise [VK::AuthorizeException] if vk.com return json with key error.
-
- def authorize(params = {})
- raise 'undefined application id' unless self.app_id
- raise 'undefined application secret' unless self.app_secret
-
- params[:save].nil? ? (params[:save] = true) : (params[:save] = false)
- params[:type] ||= :serverside
-
- options = case params[:type]
- when :serverside
- {host: 'https://oauth.vk.com',
- client_id: self.app_id,
- client_secret: self.app_secret,
- code: params[:code],
- verb: :get}
- when :secure
- {host: 'https://oauth.vk.com',
- client_id: self.app_id,
- client_secret: self.app_secret,
- grant_type: :client_credentials,
- verb: :get}
- end
-
- response = request("/access_token", options)
-
- raise VK::AuthorizeException.new(response) if response.body['error']
-
- response.body.each{|k,v| instance_variable_set(:"@#{k}", v) } if params[:save]
-
- response.body
- end
-
end
View
@@ -203,6 +203,48 @@ def upload(params = {})
Faraday.new(&faraday_middleware).post(url, files)
end
+ # Authorization (getting the access token by code)
+ # {http://vk.com/developers.php?oid=-1&p=%D0%90%D0%B2%D1%82%D0%BE%D1%80%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F_%D1%81%D0%B0%D0%B9%D1%82%D0%BE%D0%B2 Read more}
+ #
+ # @param [String] param - is param required from getting access token.
+ # @param [Hash] params configurable options request. if you do not pass the option that will be used by the same name attribute.
+ # @option params [Boolean] :save indicator that you want to save the returns parameters. Default `true`.
+ # @option params [Symbol] :type authorization type `:serverside` or `:secure`.
+ # @option params [Symbol] :code code param required for serverside authorization. Default `serverside`.
+ #
+ # @raise [VK::AuthorizeException] if vk.com return json with key error.
+
+ def authorize(params = {})
+ raise 'undefined application id' unless self.app_id
+ raise 'undefined application secret' unless self.app_secret
+
+ params[:save].nil? ? (params[:save] = true) : (params[:save] = false)
+ params[:type] ||= :serverside
+
+ options = case params[:type]
+ when :serverside
+ {host: 'https://oauth.vk.com',
+ client_id: self.app_id,
+ client_secret: self.app_secret,
+ code: params[:code],
+ verb: :get}
+ when :secure
+ {host: 'https://oauth.vk.com',
+ client_id: self.app_id,
+ client_secret: self.app_secret,
+ grant_type: :client_credentials,
+ verb: :get}
+ end
+
+ response = request("/access_token", options)
+
+ raise VK::AuthorizeException.new(response) if response.body['error']
+
+ response.body.each{|k,v| instance_variable_set(:"@#{k}", v) } if params[:save]
+
+ response.body
+ end
+
private
# @private

0 comments on commit 9bf6599

Please sign in to comment.