class TelphinApi::Client
A class representing a connection to Telphin. It holds the access token.
Attributes
Срок действия маркера доступа (в секундах). @return [Time]
Новый маркер, который можно использовать для обновления маркера с истекшим сроком действия. @return [String]
Значение маркера доступа. Это значение используется при выполнении запросов к API
. @return [String]
Тип маркера. Допустимо только значение Bearer. @return [String]
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/telphin_api/client.rb, line 27 def initialize(token = nil) if token.respond_to?(:token) && token.respond_to?(:params) # token is an OAuth2::AccessToken @token = token.token @token_type = token.params['token_type'] @refresh_token = token.params['refresh_token'] @expires_in = Time.now + token.expires_in unless token.expires_in.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/telphin_api/client.rb, line 52 def execute(*args) if args.empty? create_namespace(:execute) else call_method([:execute, *args]) end end
Did the token already expire.
# File lib/telphin_api/client.rb, line 46 def expired? @expires_in && @expires_in < Time.now end
If the called method is a namespace, it creates and returns a new `TelphinApi::Namespace` instance. Otherwise it creates a `TelphinApi::Method` instance and calls it passing the arguments and a block.
# File lib/telphin_api/client.rb, line 62 def method_missing(*args, &block) if Namespace.exists?(args.first) create_namespace(args.first) else call_method(args, &block) end end
Private Instance Methods
# File lib/telphin_api/client.rb, line 71 def settings @settings ||= self.get_user_settings end