Browse files

+ irb mode

  • Loading branch information...
1 parent 6e73183 commit d853fdc47608ddc6b007fb36fee0602465eb36bd Andrew Zinenko committed Sep 15, 2012
View
2 LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright (c) 2011 Andrew Zinenko
+Copyright (c) 2011-2012 Andrew Zinenko
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
1 VERSION
@@ -1 +0,0 @@
-0.7.5
View
88 bin/vk.rb
@@ -0,0 +1,88 @@
+#!/usr/bin/env ruby
+# encoding: utf-8
+
+require 'optparse'
+require 'logger'
+
+$:.unshift File.expand_path('../../lib', __FILE__)
+
+require 'vk-ruby'
+
+__options__ = {}
+
+optparser = OptionParser.new do |opts|
+ opts.banner = 'Usage: %s [options]' % $0
+
+ opts.on_tail '-h', '--help', 'Display this help and exit' do
+ puts opts
+ exit
+ end
+
+ opts.on_tail '-v', '--version', 'Output version infomation and exit' do
+ puts 'VK-RUBY v%s' % VK::VERSION
+ puts 'Copyright (c) 2011-2012 Andrew Zinenko'
+ exit
+ end
+
+ opts.on_tail '-e', '--eval [code]', 'Evaluate the given code and exit' do |e|
+ __options__[:eval] = e
+ end
+
+ opts.on_tail '-a', '--access_token [token]', 'Your access token' do |a|
+ __options__[:access_token] = a
+ end
+
+ opts.on_tail '-t', '--type [type]',[:serverside, :standalone, :secure], 'Application type' do |t|
+ __options__[:type] = t
+ end
+
+ opts.on_tail '-i', '--id [id]', 'Application ID' do |i|
+ __options__[:id] = i
+ end
+
+ opts.on_tail '-s', '--secret [secret]', 'Application secret' do |s|
+ __options__[:secret] = s
+ end
+
+ opts.on_tail '-l', '--logfile', 'Logfile' do |l|
+ __options__[:logfile] = l
+ end
+
+ opts.on_tail '-T', '--types', 'List application types' do |t|
+ puts %w[serverside standalone secure]
+ exit
+ end
+
+end
+
+optparser.tap{ |opts| opts.parse! }
+
+# puts __options__
+
+def vk
+ @vk
+end
+
+_app_params = {}
+
+_app_params[:app_id] = __options__[:id] || ''
+_app_params[:logger] = Logger.new(__options__[:logfile] || nil)
+_app_params[:app_secret] = __options__[:secret] || ''
+
+case (__options__[:type].downcase.to_sym rescue nil)
+when :standalone
+ @vk = VK::Standalone.new _app_params
+when :secure
+ @vk = VK::Secure.new _app_params
+else
+ @vk = VK::Serverside.new _app_params
+end
+
+if __options__[:eval]
+ eval(__options__[:eval], binding, __FILE__, __LINE__)
+ exit
+else
+ require 'vk-ruby/core_ext/irb'
+ IRB.start_session(binding)
+ exit
+end
View
4 lib/vk-ruby.rb
@@ -12,4 +12,6 @@
MultiJson.load(body)
end
-%w(middleware/validate_utf middleware/normalize_utf middleware/vk_logger configurable core secure serverside standalone vk_exception).each{|lib| require "vk-ruby/#{lib}"}
+%w(validate_utf normalize_utf vk_logger).each{|lib| require "vk-ruby/middleware/response/#{lib}"}
+
+%w(configurable core secure serverside standalone vk_exception version).each{|lib| require "vk-ruby/#{lib}"}
View
27 lib/vk-ruby/core_ext/irb.rb
@@ -0,0 +1,27 @@
+# encoding: utf-8
+
+require 'irb'
+
+# @private
+module IRB
+ def self.start_session(binding)
+ unless @__initialized
+ args = ARGV
+ ARGV.replace(ARGV.dup)
+ IRB.setup(nil)
+ ARGV.replace(args)
+ @__initialized = true
+ end
+
+ workspace = WorkSpace.new(binding)
+
+ irb = Irb.new(workspace)
+
+ @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
+ @CONF[:MAIN_CONTEXT] = irb.context
+
+ catch(:IRB_EXIT) do
+ irb.eval_input
+ end
+ end
+end
View
0 lib/vk-ruby/middleware/normalize_utf.rb → ...ruby/middleware/response/normalize_utf.rb
File renamed without changes.
View
0 lib/vk-ruby/middleware/validate_utf.rb → ...-ruby/middleware/response/validate_utf.rb
File renamed without changes.
View
0 lib/vk-ruby/middleware/vk_logger.rb → lib/vk-ruby/middleware/response/vk_logger.rb
File renamed without changes.
View
2 lib/vk-ruby/serverside.rb
@@ -14,7 +14,7 @@ class VK::Serverside
def initialize(params = {})
params.each{|k,v| instance_variable_set(:"@#{k}", v) }
- raise 'undefined application id' unless self.app_id
+ raise 'undefined application id' unless self.app_id
raise 'undefined application secret' unless self.app_secret
transform base_api, self.method(:vk_call)

0 comments on commit d853fdc

Please sign in to comment.