Class: Spark::Base

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

Direct Known Subclasses

Membership, Message, Person, Room, Team, TeamMembership, Webhook

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Base

Returns a new instance of Base.



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

def initialize(data)
    self.refresh(data)
end

Instance Method Details

#[](key) ⇒ Object



25
26
27
28
# File 'lib/base.rb', line 25

def [](key)
    return nil unless respond_to?(key)
    public_send(key)
end

#deleteObject



22
23
24
# File 'lib/base.rb', line 22

def delete()
    res = Spark::rest('DELETE',"/#{@api_endpoint}/#{@id}")
end

#refresh(data) ⇒ Object



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

def refresh(data)
    data.each {|k,v| public_send("#{k}=",v)}
end

#update(data = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/base.rb', line 8

def update(data={})
    data.each {|k,v| public_send("#{k}=",v)}
    payload = {}
    @update_fields.each { |k| payload[k] = self[k] }
    res = Spark::rest('PUT',"/#{@api_endpoint}/#{@id}", {:payload => payload})
    if res.ok
        self.refresh(JSON.parse(res.body))
        return true
    end
    return false
end