Skip to content

Commit

Permalink
Fixed some naming bugs (was born while extracting Vk gem from project)
Browse files Browse the repository at this point in the history
  • Loading branch information
alsemyonov committed May 2, 2011
1 parent a602267 commit 99841fd
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.bundle
Gemfile.lock
pkg/*
doc
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rescue LoadError
end

begin
require 'yard'
require 'yard/rake/yardoc_task'

desc 'Generate documentation'
Expand Down
8 changes: 6 additions & 2 deletions lib/vk.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
module Vk
extend self

autoload :DSL, 'vk/dsl'
autoload :Request, 'vk/request'
autoload :DSL, 'vk/dsl'
autoload :Request, 'vk/request'

class << self
attr_accessor :app_id, :app_secret
end

def request
@request ||= Request.new
Expand Down
2 changes: 1 addition & 1 deletion lib/vk/dsl.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8
require 'vk'

class VK
module Vk
module DSL
# Have user installed app?
# @param [String] uid user’s identifier
Expand Down
9 changes: 4 additions & 5 deletions lib/vk/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,25 @@ class Request
PORT = 80

class << self
attr_accessor :app_id, :app_secret

# Generates auth_key for viewer
# @param [Fixnum, String] viewer_id viewer’s identifier
def auth_key(viewer_id)
Digest::MD5.hexdigest("#{app_id}_#{viewer_id}_#{app_secret}")
Digest::MD5.hexdigest("#{Vk.app_id}_#{viewer_id}_#{Vk.app_secret}")
end

def authenticated?(viewer_id, auth_key)
auth_key == self.auth_key(viewer_id)
end

def dsl!
require 'vk/dsl'
include Vk::DSL
end
end

def request(method_name, data = {})
data.merge!(
api_id: VK.app_id,
api_id: Vk.app_id,
format: :json,
method: method_name,
v: VERSION
Expand All @@ -58,7 +57,7 @@ def method_missing(method_name, options = {})
private

def signature(data)
signature = data.keys.sort.inject('') { |result, key| result << "#{key}=#{data[key]}" } << VK.app_secret
signature = data.keys.sort.inject('') { |result, key| result << "#{key}=#{data[key]}" } << Vk.app_secret
Digest::MD5.hexdigest(signature)
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

Bundler.require(:development)

Vk::Request.app_id = 2311992
Vk::Request.app_secret = 'secret'
Vk.app_id = 2311992
Vk.app_secret = 'secret'

VK_AUTH_KEY = '44b0a08fcf4039bf7919132a777b23ef'
VK_VIEWER_ID = 34160
Expand Down

0 comments on commit 99841fd

Please sign in to comment.