Class: FreshServiceApiv2

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

Direct Known Subclasses

Tickets

Defined Under Namespace

Classes: AlreadyExistedError, ConnectionError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ FreshServiceApiv2

Returns a new instance of FreshServiceApiv2.



14
15
16
# File 'lib/freshservice_apiv2.rb', line 14

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

Instance Attribute Details

#apikey ⇒ Object

Returns the value of attribute apikey.



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

def apikey
  @apikey
end

#baseurl ⇒ Object

Returns the value of attribute baseurl.



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

def baseurl
  @baseurl
end

#header ⇒ Object

Returns the value of attribute header.



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

def header
  @header
end

#password ⇒ Object

Returns the value of attribute password.



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

def password
  @password
end

#username ⇒ Object

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



29
30
31
32
33
34
35
36
37
38
# File 'lib/freshservice_apiv2.rb', line 29

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

#get(uri) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/freshservice_apiv2.rb', line 18

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

#post(uri, data) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/freshservice_apiv2.rb', line 51

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

end

#update(uri, data) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/freshservice_apiv2.rb', line 40

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