Class: FreshServiceApiv2

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

Direct Known Subclasses

FreshService::Tickets

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ FreshServiceApiv2

Returns a new instance of FreshServiceApiv2.



8
9
10
# File 'lib/freshservice_apiv2.rb', line 8

def initialize(uri)
  @baseurl = uri.chomp('/')
end

Instance Attribute Details

#apikeyObject

Returns the value of attribute apikey.



6
7
8
# File 'lib/freshservice_apiv2.rb', line 6

def apikey
  @apikey
end

#baseurlObject

Returns the value of attribute baseurl.



6
7
8
# File 'lib/freshservice_apiv2.rb', line 6

def baseurl
  @baseurl
end

#headerObject

Returns the value of attribute header.



6
7
8
# File 'lib/freshservice_apiv2.rb', line 6

def header
  @header
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/freshservice_apiv2.rb', line 6

def password
  @password
end

#usernameObject

Returns the value of attribute username.



6
7
8
# File 'lib/freshservice_apiv2.rb', line 6

def username
  @username
end

Instance Method Details

#delete(uri) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/freshservice_apiv2.rb', line 23

def delete(uri)
  begin
    pick_header
    request = RestClient::Resource.new(baseurl+uri)
    response = request.delete(@header)
    return response.code,JSON.parse(response),response
  rescue RestClient::Exception => e
    return e.response.code, JSON.parse(e.response.body)
  end
end

#get(uri) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/freshservice_apiv2.rb', line 12

def get(uri)
  begin
    pick_header
    request = RestClient::Resource.new(baseurl+uri)
    response = request.get(@header)
    return response.code,JSON.parse(response),response
  rescue RestClient::Exception => e
    return e.response.code, JSON.parse(e.response.body)
  end
end

#post(uri, data) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/freshservice_apiv2.rb', line 45

def post(uri,data)
  begin
    pick_header
    request = RestClient::Resource.new(baseurl+uri)
    response = request.post(data,@header)
    return response.code,JSON.parse(response),response
  rescue RestClient::Exception => e
    return e.response.code, JSON.parse(e.response.body)
  end

end

#update(uri, data) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/freshservice_apiv2.rb', line 34

def update(uri,data)
  begin
    pick_header
    request = RestClient::Resource.new(baseurl+uri)
    response = request.put(data,@header)
    return response.code,JSON.parse(response),response
  rescue RestClient::Exception => e
    return e.response.code, JSON.parse(e.response.body)
  end
end