Class: Givepulse::Resource

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, path, supported_methods) ⇒ Resource

Returns a new instance of Resource.



7
8
9
10
11
# File 'lib/givepulse/resource.rb', line 7

def initialize(client, path, supported_methods)
    @client ||= client
    @path ||= path
    @supported_methods ||= supported_methods.clone
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/givepulse/resource.rb', line 3

def client
  @client
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#create(data) ⇒ Object



18
19
20
21
# File 'lib/givepulse/resource.rb', line 18

def create(data)
    raise Givepulse::UnsupportedMethod, self.class unless @supported_methods.include?(__method__)
    @client.connection.post(@path, data)
end

#delete(id) ⇒ Object



28
29
30
31
# File 'lib/givepulse/resource.rb', line 28

def delete(id)
    raise Givepulse::UnsupportedMethod, self.class unless @supported_methods.include?(__method__)
    @client.connection.delete("#{@path}/#{id}")
end

#get(options = nil) ⇒ Object



13
14
15
16
# File 'lib/givepulse/resource.rb', line 13

def get(options = nil)
    raise Givepulse::UnsupportedMethod, self.class unless @supported_methods.include?(__method__)
    @client.connection.get(@path, options)
end

#update(id, data) ⇒ Object



23
24
25
26
# File 'lib/givepulse/resource.rb', line 23

def update(id, data)
    raise Givepulse::UnsupportedMethod, self.class unless @supported_methods.include?(__method__)
    @client.connection.put("#{@path}/#{id}", data)
end