Class: HabiticaClient::Restful
Direct Known Subclasses
Task
Defined Under Namespace
Modules: ClassMethods
Classes: ServerError
Instance Attribute Summary
Attributes inherited from ApiBase
#client
Instance Method Summary
collapse
parse, remap
Methods inherited from ApiBase
#data, #endpoint, endpoint
Constructor Details
#initialize(client, attributes = {}) ⇒ Restful
Returns a new instance of Restful.
31
32
33
34
|
# File 'lib/habitica_client/restful.rb', line 31
def initialize(client, attributes = {})
self.attributes = attributes
super(client)
end
|
Instance Method Details
#attributes=(attributes) ⇒ Object
36
37
38
|
# File 'lib/habitica_client/restful.rb', line 36
def attributes=(attributes)
attributes.each { |k, v| send("#{k}=", v) }
end
|
#delete ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/habitica_client/restful.rb', line 52
def delete
return nil if new?
response = client.class.delete(url)
response.ok?
end
|
#new? ⇒ Boolean
40
41
42
|
# File 'lib/habitica_client/restful.rb', line 40
def new?
id.nil?
end
|
#save ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/habitica_client/restful.rb', line 44
def save
response = put || post
self.attributes = self.class.remap(response)
self
end
|
#to_json ⇒ Object
60
61
62
|
# File 'lib/habitica_client/restful.rb', line 60
def to_json
to_h.to_json
end
|