class Zaikio::Hub::Client
Public Class Methods
from_credentials(client_id, client_secret)
click to toggle source
# File lib/zaikio/hub/client.rb, line 36 def self.from_credentials(client_id, client_secret) new(client_id: client_id, client_secret: client_secret) end
from_token(token)
click to toggle source
# File lib/zaikio/hub/client.rb, line 32 def self.from_token(token) new(token: token) end
new(token: nil, client_id: nil, client_secret: nil)
click to toggle source
# File lib/zaikio/hub/client.rb, line 40 def initialize(token: nil, client_id: nil, client_secret: nil) @token = token @client_id = client_id @client_secret = client_secret end
Public Instance Methods
connections()
click to toggle source
# File lib/zaikio/hub/client.rb, line 96 def connections raise "Only available with credentials" unless credentials? RequestWrapper.new(Zaikio::Hub::Connection.all, self) end
credentials?()
click to toggle source
# File lib/zaikio/hub/client.rb, line 64 def credentials? @token.nil? end
jwt()
click to toggle source
# File lib/zaikio/hub/client.rb, line 46 def jwt return if @token.nil? @jwt ||= begin payload = JWT.decode(@token, nil, false).first Zaikio::Hub.create_token_data(payload) end end
method_missing(method_name, *args, &block)
click to toggle source
# File lib/zaikio/hub/client.rb, line 120 def method_missing(method_name, *args, &block) result = with_auth { subject_class.new.public_send(method_name, *args, &block) } RequestWrapper.new(result, self) end
organization()
click to toggle source
# File lib/zaikio/hub/client.rb, line 84 def organization raise "Current organization is not available for person" unless organization? with_auth { Zaikio::Hub::CurrentOrganization.find } end
organization?()
click to toggle source
# File lib/zaikio/hub/client.rb, line 56 def organization? jwt&.subject_type == "Organization" end
person()
click to toggle source
# File lib/zaikio/hub/client.rb, line 90 def person raise "Current person is not available for organization" unless person? with_auth { Zaikio::Hub::CurrentPerson.find } end
person?()
click to toggle source
# File lib/zaikio/hub/client.rb, line 60 def person? jwt&.subject_type == "Person" end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/zaikio/hub/client.rb, line 114 def respond_to_missing?(method_name, include_private = false) return super if credentials? subject_class.new.respond_to?(method_name, include_private) || super end
subject_class()
click to toggle source
# File lib/zaikio/hub/client.rb, line 68 def subject_class if organization? Zaikio::Hub::CurrentOrganization elsif person? Zaikio::Hub::CurrentPerson end end
subscriptions()
click to toggle source
# File lib/zaikio/hub/client.rb, line 102 def subscriptions raise "Only available with credentials" unless credentials? RequestWrapper.new(Zaikio::Hub::Subscription.all, self) end
test_accounts()
click to toggle source
# File lib/zaikio/hub/client.rb, line 108 def test_accounts raise "Only available with credentials" unless credentials? RequestWrapper.new(Zaikio::Hub::TestAccount.all, self) end
with_auth(&block)
click to toggle source
# File lib/zaikio/hub/client.rb, line 76 def with_auth(&block) if @token.nil? Zaikio::Hub.with_basic_auth(@client_id, @client_secret, &block) else Zaikio::Hub.with_token(@token, &block) end end