class VkontakteApi::Client
A class representing a connection to VK. It holds the access token.
Constants
- SCOPE
Access rights and their respective number representation.
Attributes
Current user email. @return [String]
Token expiration time @return [Time]
An access token needed by authorized requests. @return [String]
Current user id. @return [Integer]
Public Class Methods
A new API
client. If given an `OAuth2::AccessToken` instance, it extracts and keeps the token string, the user id and the expiration time; otherwise it just stores the given token. @param [String, OAuth2::AccessToken] token An access token.
# File lib/vkontakte_api/client.rb, line 51 def initialize(token = nil) if token.respond_to?(:token) && token.respond_to?(:params) # token is an OAuth2::AccessToken @token = token.token @user_id = token.params['user_id'] @email = token.params['email'] @expires_at = Time.at(token.expires_at) unless token.expires_at.nil? else # token is a String or nil @token = token end end
Public Instance Methods
Called without arguments it returns the `execute` namespace; called with arguments it calls the top-level `execute` API
method.
# File lib/vkontakte_api/client.rb, line 84 def execute(*args) if args.empty? create_namespace(:execute) else call_method([:execute, *args]) end end
Did the token already expire.
# File lib/vkontakte_api/client.rb, line 70 def expired? @expires_at && @expires_at < Time.now end
If the called method is a namespace, it creates and returns a new `VkontakteApi::Namespace` instance. Otherwise it creates a `VkontakteApi::Method` instance and calls it passing the arguments and a block.
# File lib/vkontakte_api/client.rb, line 94 def method_missing(*args, &block) if Namespace.exists?(args.first) create_namespace(args.first) else call_method(args, &block) end end
Access rights of this token. @return [Array] An array of symbols representing the access rights.
# File lib/vkontakte_api/client.rb, line 76 def scope SCOPE.reject do |access_scope, mask| (settings & mask).zero? end.keys end
Private Instance Methods
# File lib/vkontakte_api/client.rb, line 103 def settings @settings ||= self.get_user_settings end