Class: HabiticaClient::ApiBase

Inherits:
Object
  • Object
show all
Defined in:
lib/habitica_client/api_base.rb

Overview

The basis of all HabiticaClient endpoint objects.

All HabiticaClient endpoint objects need a reference to the http client so that we can make the API work using the dot syntax.

Direct Known Subclasses

Restful, Tasks, User

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ApiBase

Returns a new instance of ApiBase.



11
12
13
# File 'lib/habitica_client/api_base.rb', line 11

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/habitica_client/api_base.rb', line 9

def client
  @client
end

Class Method Details

.endpoint(url) ⇒ Object



23
24
25
# File 'lib/habitica_client/api_base.rb', line 23

def self.endpoint(url)
  instance_variable_set(:@endpoint, url)
end

Instance Method Details

#dataObject



15
16
17
# File 'lib/habitica_client/api_base.rb', line 15

def data
  @data ||= client.class.get(endpoint)['data']
end

#endpointObject



19
20
21
# File 'lib/habitica_client/api_base.rb', line 19

def endpoint
  self.class.instance_variable_get(:@endpoint)
end