Class: GetResponse::Api

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

Instance Method Summary collapse

Constructor Details

#initializeApi

Returns a new instance of Api.



4
5
6
# File 'lib/get_response/api.rb', line 4

def initialize
  @path_parts = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



8
9
10
11
12
13
# File 'lib/get_response/api.rb', line 8

def method_missing(method, *args)
  @path_parts << method.to_s.gsub("_", "-").downcase
  @path_parts << args if args.length > 0
  @path_parts.flatten!
  self
end

Instance Method Details

#create(params = {}) ⇒ Object



15
16
17
18
19
20
# File 'lib/get_response/api.rb', line 15

def create(params = {})
  resp = GetResponse::Request.post(path, params)
  Response.new(resp)
ensure
  reset
end

#deleteObject



36
37
38
39
40
41
# File 'lib/get_response/api.rb', line 36

def delete
  resp = GetResponse::Request.delete(path, params)
  Response.new(resp)
ensure
  reset
end

#retrieve(params = {}) ⇒ Object



29
30
31
32
33
34
# File 'lib/get_response/api.rb', line 29

def retrieve(params = {})
  resp = GetResponse::Request.get(path, params)
  Response.new(resp)
ensure
  reset
end

#update(params) ⇒ Object



22
23
24
25
26
27
# File 'lib/get_response/api.rb', line 22

def update(params)
  resp = GetResponse::Request.post(path, params)
  Response.new(resp)
ensure
  reset
end