Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 7648dd572e2311ee91049ab09ce7f7fea67337c7 0 parents
Andrew ZInenko authored
5 .document
@@ -0,0 +1,5 @@
+lib/**/*.rb
+bin/*
+-
+features/**/*.feature
+LICENSE.txt
43 .gitignore
@@ -0,0 +1,43 @@
+# rcov generated
+coverage
+
+# rdoc generated
+rdoc
+
+# yard generated
+doc
+.yardoc
+
+# bundler
+.bundle
+
+# jeweler generated
+pkg
+.redcar
+
+# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
+#
+# * Create a file at ~/.gitignore
+# * Include files you want ignored
+# * Run: git config --global core.excludesfile ~/.gitignore
+#
+# After doing this, these files will be ignored in all your git projects,
+# saving you from having to 'pollute' every project you touch with them
+#
+# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
+#
+# For MacOS:
+#
+#.DS_Store
+#
+# For TextMate
+#*.tmproj
+#tmtags
+#
+# For emacs:
+#*~
+#\#*
+#.\#*
+#
+# For vim:
+#*.swp
8 Gemfile
@@ -0,0 +1,8 @@
+source "http://rubygems.org"
+
+group :development do
+ gem "shoulda", ">= 0"
+ gem "bundler", "~> 1.0.0"
+ gem "jeweler", "~> 1.6.0"
+ gem "rcov", ">= 0"
+end
20 Gemfile.lock
@@ -0,0 +1,20 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ git (1.2.5)
+ jeweler (1.6.0)
+ bundler (~> 1.0.0)
+ git (>= 1.2.5)
+ rake
+ rake (0.9.2)
+ rcov (0.9.9)
+ shoulda (2.11.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bundler (~> 1.0.0)
+ jeweler (~> 1.6.0)
+ rcov
+ shoulda
20 LICENSE.txt
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Andrew Zinenko
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 README.rdoc
@@ -0,0 +1,23 @@
+= vk-ruby
+
+Ruby wrapper for vk.com API
+
+== Install
+
+ gem install vk-ruby
+
+== Contributing to vk-ruby
+
+* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
+* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
+* Fork the project
+* Start a feature/bugfix branch
+* Commit and push until you are happy with your contribution
+* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
+* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
+
+== Copyright
+
+Copyright (c) 2011 Andi Zinenko. See LICENSE.txt for
+further details.
+
25 Rakefile
@@ -0,0 +1,25 @@
+# encoding: utf-8
+
+require 'rubygems'
+require 'bundler'
+begin
+ Bundler.setup(:default, :development)
+rescue Bundler::BundlerError => e
+ $stderr.puts e.message
+ $stderr.puts "Run `bundle install` to install missing gems"
+ exit e.status_code
+end
+require 'rake'
+
+require 'jeweler'
+Jeweler::Tasks.new do |gem|
+ gem.name = "vk-ruby"
+ gem.homepage = "http://github.com/zinenko/vk-ruby"
+ gem.license = "MIT"
+ gem.summary = %Q{ Ruby wrapper for vk.com API }
+ gem.description = %Q{ Ruby wrapper for vk.com API }
+ gem.email = "zinenkoan@gmail.com"
+ gem.authors = ["Andrew Zinenko"]
+ gem.files.include 'lib/**/*'
+ gem.add_runtime_dependency 'transformer'
+end
1  VERSION
@@ -0,0 +1 @@
+0.6.0
9 lib/vk-ruby.rb
@@ -0,0 +1,9 @@
+require 'rubygems'
+require 'net/https'
+require 'transformer'
+require 'json'
+require 'yaml'
+
+%w(core secure serverside standalone).each do |lib|
+ require "vk-ruby/#{lib}"
+end
109 lib/vk-ruby/api/base.yml
@@ -0,0 +1,109 @@
+- isAppUser
+- getProfiles
+- getUserBalance
+- getUserSettings
+- getGroups
+- getGroupsFull
+- getVariable
+- getVariables
+- putVariable
+- getHighScores
+- setUserScore
+- getMessages
+- sendMessage
+- getServerTime
+- getAds
+- setNameInMenu
+- execute
+-
+ friends:
+ - get
+ - getAppUsers
+ - getOnline
+ - getMutual
+ photos:
+ - getAlbums
+ - get
+ - getById
+ - createAlbum
+ - editAlbum
+ - edit
+ - move
+ - makeCover
+ - reorderAlbums
+ - reorderPhotos
+ - getUploadServer
+ - save
+ - getProfileUploadServer
+ - saveProfilePhoto
+ - getWallUploadServer
+ - saveWallPhoto
+ wall:
+ - get
+ - getById
+ - savePost
+ - getPhotoUploadServer
+ audio:
+ - get
+ - audio
+ - getById
+ - getLyrics
+ - getUploadServer
+ - save
+ - search
+ - add
+ - delete
+ - edit
+ - restore
+ - reorder
+ video:
+ - get
+ - edit
+ - add
+ - delete
+ - search
+ - getUserVideos
+ - getComments
+ - createComment
+ - editComment
+ - deleteComment
+ - getTags
+ - putTag
+ - removeTag
+ - save
+ notes:
+ - get
+ - getById
+ - getFriendsNotes
+ - add
+ - edit
+ - delete
+ - getComments
+ - createComment
+ - editComment
+ - deleteComment
+ - restoreComment
+ pages:
+ - get
+ - save
+ - saveAccess
+ - getVersion
+ - getHistory
+ - getTitles
+ places:
+ - add
+ - getById
+ - search
+ - checkin
+ - getCheckins
+ - getTypes
+ - getCountries
+ - getCities
+ - getCountryById
+ - getCityById
+ storage:
+ - set
+ - get
+ sms:
+ - setSMSPrefix
+ - getSMSPrefix
63 lib/vk-ruby/api/ext.yml
@@ -0,0 +1,63 @@
+messages:
+ - get
+ - getDialogs
+ - search
+ - send
+ - delete
+ - restore
+ - markAsNew
+ - markAsRead
+ - getHistory
+ - getLongPollServer
+docs:
+ - get
+ - getById
+ - getUploadServer
+ - getWallUploadServer
+ - save
+wall:
+ - post
+ - delete
+ - restore
+ - getComments
+ - addComment
+ - deleteComment
+ - restoreComment
+ - addLike
+ - deleteLike
+photos:
+ - getComments
+ - getAllComments
+ - createComment
+ - editComment
+ - deleteComment
+ - restoreComment
+ - getAll
+ - getUserPhotos
+ - getTags
+ - putTag
+ - removeTag
+newsfeed:
+ - get
+ - getBanned
+ - addBan
+ - deleteBan
+status:
+ - get
+ - set
+likes:
+ - add
+ - delete
+ - getList
+ - isLiked
+friends:
+ - getLists
+polls:
+ - getById
+ - addVote
+ - deleteVote
+subscriptions:
+ - get
+ - getFollowers
+ - follow
+ - unfollow
16 lib/vk-ruby/api/secure.yml
@@ -0,0 +1,16 @@
+- sendNotification
+- getAppBalance
+- getBalance
+- withdrawVotes
+- getTransactionsHistory
+- addRating
+- setCounter
+- getSMSHistory
+- sendSMSNotification
+- getSMS
+- setLanguageValue
+- deleteLanguageValue
+- saveAppStatus
+- getAppStatus
+- setSMSPrefix
+- getSMSPrefix
63 lib/vk-ruby/core.rb
@@ -0,0 +1,63 @@
+module VK
+ module Core
+ attr_accessor :debug, :logger
+ attr_reader :app_id
+
+ def authorize(code = nil)
+ prms = {:client_id => @app_id, :client_secret => @app_secret}
+ unless code # secure server
+ prms[:grant_type] = 'client_credentials'
+ else # serverside app
+ prms[:code] = code
+ end
+
+ query = {:debug => @debug, :path => "/oauth/access_token", :params => prms }
+ result = JSON.parse(request(query).body)
+
+ raise result['error'] if result['error']
+ @expires_in = result["expires_in"] if result['expires_in']
+ @user_id = result["user_id"] if result['user_id']
+ @access_token = result["access_token"] if result['access_token']
+
+ result
+ end
+
+ private
+
+ def vk_call(method_name,p)
+ p[0].delete(:format) == :xml ? format = '.xml' : foramt = ''
+ path = "/method/#{method_name}#{format}"
+ prms = p[0].merge :access_token => @access_token
+ query = {:debug => @debug, :path => path, :params => prms }
+ request(query).body
+ end
+
+ def request(p={})
+ host = p[:host] ||='api.vk.com'
+ port = p[:port] ||=443
+ http = Net::HTTP.new(host,port)
+
+ http.set_debug_output(@logger) if @logger
+
+ unless p[:ssl] == false
+ http.use_ssl = true
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ end
+
+ prms = "?" + (p[:params].map{|k,v| "#{k}=#{v}" }).join('&')
+ http.request(Net::HTTP::Get.new(p[:path] + prms))
+ end
+
+ def base_api
+ @@base_api ||= YAML.load_file( File.expand_path( File.dirname(__FILE__) + "/api/base.yml" ))
+ end
+
+ def ext_api
+ @@ext_api ||= YAML.load_file( File.expand_path( File.dirname(__FILE__) + "/api/ext.yml" ))
+ end
+
+ def secure_api
+ @@secure_api ||= YAML.load_file( File.expand_path( File.dirname(__FILE__) + "/api/secure.yml" ))
+ end
+ end
+end
14 lib/vk-ruby/secure.rb
@@ -0,0 +1,14 @@
+module VK
+ class Secure
+ include Core
+ include Transformer
+
+ attr_reader :app_secret
+
+ def initialize(p={})
+ raise 'undefined application id' unless @app_id = p[:app_id]
+ raise 'undefined application secret' unless @secret = p[:app_secret]
+ transform secure_api, self.method(:vk_call)
+ end
+ end
+end
17 lib/vk-ruby/serverside.rb
@@ -0,0 +1,17 @@
+module VK
+ class Serverside
+ include Core
+ include Transformer
+
+ attr_reader :app_secret, :settings, :debug
+
+ def initialize(p={})
+ raise 'undefined application id' unless @app_id = p[:app_id]
+ raise 'undefined application secret' unless @app_secret = p[:app_secret]
+
+ @logger = p[:logger] if p[:logger]
+ @settings = p[:settings] ||= 'notify,friends,offline'
+ transform base_api, self.method(:vk_call)
+ end
+ end
+end
16 lib/vk-ruby/standalone.rb
@@ -0,0 +1,16 @@
+module VK
+ class Standalone
+ include Core
+ include Transformer
+
+ def initialize(p={})
+ raise 'undefined application id' unless @app_id = p[:app_id]
+ raise 'undefined access token' unless @access_token = p[:access_token]
+
+ @scope = p[:scope] ||= 'notify,friends'
+ transform base_api, self.method(:vk_call)
+ transform ext_api, self.method(:vk_call)
+ end
+
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.