Skip to content
This repository
Browse code

update transformer

  • Loading branch information...
commit 07c6ea02bdf208fa1fb5e0b67d7ead79f3ba3b91 1 parent a26e968
Andrew Zinenko authored
6  Gemfile.lock
@@ -6,10 +6,10 @@ GEM
6 6
       bundler (~> 1.0)
7 7
       git (>= 1.2.5)
8 8
       rake
9  
-    rake (0.9.2)
10  
-    rcov (0.9.10)
  9
+    rake (0.9.2.2)
  10
+    rcov (0.9.11)
11 11
     shoulda (2.11.3)
12  
-    transformer (0.1.0)
  12
+    transformer (0.2.0)
13 13
 
14 14
 PLATFORMS
15 15
   ruby
9  lib/vk-ruby/core.rb
@@ -11,14 +11,8 @@ def authorize(code = nil, auto_save = true)
11 11
       end
12 12
 
13 13
       result = to_json(request({:path => "/oauth/access_token", :params => prms }).body)
14  
-
15 14
       raise VK::VkAuthorizeException.new(result) if result['error']
16  
-
17  
-      if auto_save
18  
-        @expires_in = result["expires_in"]      if result['expires_in']
19  
-           @user_id = result["user_id"]         if result['user_id']
20  
-        @access_token = result["access_token"]  if result['access_token']
21  
-      end
  15
+      result.each{|k,v| instance_variable_set(:"@#{k}", v) } if auto_save
22 16
 
23 17
       result
24 18
     end
@@ -30,7 +24,6 @@ def vk_call(method_name,p)
30 24
       params[:access_token] ||= @access_token
31 25
 
32 26
       result = to_json(request(:path => "/method/#{method_name}", :params => params).body)
33  
-
34 27
       raise VK::VkException.new(method_name,result) if result['error']
35 28
 
36 29
       result['response']
5  lib/vk-ruby/secure.rb
@@ -6,8 +6,9 @@ class Secure
6 6
     attr_reader :app_secret
7 7
 
8 8
     def initialize(p={})
9  
-      raise 'undefined application id' unless @app_id = p[:app_id]  
10  
-      raise 'undefined application secret' unless @secret = p[:app_secret]
  9
+      p.each{|k,v| instance_variable_set(:"@#{k}", v) }
  10
+      raise 'undefined application id' unless @app_id
  11
+      raise 'undefined application secret' unless @secret
11 12
       transform secure_api, self.method(:vk_call)
12 13
     end
13 14
   end
9  lib/vk-ruby/serverside.rb
@@ -6,11 +6,12 @@ class Serverside
6 6
     attr_accessor :app_secret, :settings
7 7
 
8 8
     def initialize(p={})
9  
-      raise 'undefined application id' unless @app_id = p[:app_id] 
10  
-      raise 'undefined application secret' unless @app_secret = p[:app_secret] 
  9
+      p.each{|k,v| instance_variable_set(:"@#{k}", v) }
  10
+      raise 'undefined application id' unless @app_id
  11
+      raise 'undefined application secret' unless @app_secret
11 12
       
12  
-      @logger = p[:logger] if p[:logger]
13  
-      @settings = p[:settings] ||= 'notify,friends,offline' 
  13
+      @settings ||= 'notify,friends,offline' 
  14
+
14 15
       transform base_api, self.method(:vk_call)
15 16
     end
16 17
   end
8  lib/vk-ruby/standalone.rb
@@ -3,12 +3,14 @@ class Standalone
3 3
     include Core
4 4
     include Transformer
5 5
 
6  
-     attr_accessor :settings
  6
+    attr_accessor :settings
7 7
 
8 8
     def initialize(p={})
9  
-      raise 'undefined application id' unless @app_id = p[:app_id]
  9
+      p.each{|k,v| instance_variable_set(:"@#{k}", v) }
  10
+      raise 'undefined application id' unless @app_id
  11
+
  12
+      @settings ||= 'notify,friends'
10 13
 
11  
-      @scope = p[:scope] ||= 'notify,friends'
12 14
       transform base_api, self.method(:vk_call)
13 15
       transform ext_api, self.method(:vk_call)
14 16
     end

0 notes on commit 07c6ea0

Please sign in to comment.
Something went wrong with that request. Please try again.