Class: Calendlyr::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/calendlyr/client.rb

Constant Summary collapse

BASE_URL =
"https://api.calendly.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:) ⇒ Client

Returns a new instance of Client.



7
8
9
# File 'lib/calendlyr/client.rb', line 7

def initialize(token:)
  @token = token
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

Given a client.users, method_missing behaves like this: def users

UsersResource.new(self)

end



24
25
26
27
28
29
30
31
# File 'lib/calendlyr/client.rb', line 24

def method_missing(method_name, *args, &block)
  resource_name = method_name.to_s.split("_").collect(&:capitalize).join + "Resource"
  if Calendlyr.const_defined?(resource_name)
    Calendlyr.const_get(resource_name).new(self)
  else
    super
  end
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



5
6
7
# File 'lib/calendlyr/client.rb', line 5

def token
  @token
end

Instance Method Details

#inspectObject

Avoid returning #<Calendlyr::Client @token=“token” …>



40
41
42
# File 'lib/calendlyr/client.rb', line 40

def inspect
  "#<Calendlyr::Client>"
end

#me(force_reload: false) ⇒ Object



11
12
13
14
# File 'lib/calendlyr/client.rb', line 11

def me(force_reload: false)
  @me = nil if force_reload
  @me ||= users.me
end

#organizationObject



16
17
18
# File 'lib/calendlyr/client.rb', line 16

def organization
  me.organization
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/calendlyr/client.rb', line 33

def respond_to_missing?(method_name, include_private = false)
  resource_name = method_name.to_s.split("_").collect(&:capitalize).join + "Resource"

  Calendlyr.const_defined?(resource_name) || super
end