Class: Freshdesk::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/freshdesk/api/v2/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attrs = {}) ⇒ Base
Returns a new instance of Base.
8
9
10
11
12
13
|
# File 'lib/freshdesk/api/v2/base.rb', line 8
def initialize(attrs = {})
@attrs = attrs.dup
@attrs.each do |key,value|
self.instance_variable_set("@#{key}".to_sym, value)
end
end
|
Instance Attribute Details
#apikey ⇒ Object
Returns the value of attribute apikey.
6
7
8
|
# File 'lib/freshdesk/api/v2/base.rb', line 6
def apikey
@apikey
end
|
#domain ⇒ Object
Returns the value of attribute domain.
6
7
8
|
# File 'lib/freshdesk/api/v2/base.rb', line 6
def domain
@domain
end
|
Instance Method Details
#all(options = {}) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/freshdesk/api/v2/base.rb', line 20
def all(options = {})
items = []
link = nil
page = options[:page] || 1
per_page = options[:per_page] || 100
begin
response = client.get("/#{resource_name}",
options.merge(:page => page, :per_page => per_page))
link = response.['link']
response.parsed_response.map { |source| items.push(self.class.new(source)) } if response.success?
page += 1
end until link.nil?
items
end
|
#connected? ⇒ Boolean
15
16
17
18
|
# File 'lib/freshdesk/api/v2/base.rb', line 15
def connected?
response = client.get("tickets")
response.success?
end
|
#create(options = {}, body = {}) ⇒ Object
35
36
37
38
|
# File 'lib/freshdesk/api/v2/base.rb', line 35
def create(options = {},body = {})
response = client.post("/#{resource_name}", options, body)
self.class.new(response) if response.success?
end
|
#delete(id) ⇒ Object
49
50
51
52
|
# File 'lib/freshdesk/api/v2/base.rb', line 49
def delete(id)
response = client.delete("/#{resource_name}/#{id}")
response.success?
end
|
#delete_all ⇒ Object
54
55
56
|
# File 'lib/freshdesk/api/v2/base.rb', line 54
def delete_all
all.each {|s| delete(s.id) }
end
|
#find(id, options = {}) ⇒ Object
40
41
42
43
|
# File 'lib/freshdesk/api/v2/base.rb', line 40
def find(id, options = {})
response = client.get("/#{resource_name}/#{id}", options)
self.class.new(response) if response.success?
end
|
#update(id, options = {}) ⇒ Object
45
46
47
|
# File 'lib/freshdesk/api/v2/base.rb', line 45
def update(id, options = {})
client.class.put("/#{resource_name}/#{id}", {}, options)
end
|