freshservice_apiv2 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/freshservice_apiv2.rb +132 -0
  3. metadata +64 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b6673770e0dc2ab38c591a9a19cd9618ef24d409
4
+ data.tar.gz: 8647ac16511b538befa39d336bfc1c7d6d845ef0
5
+ SHA512:
6
+ metadata.gz: a4cfb4f2647beb3ca6c2573180dc09b568d48ef12fd3602796a00e8b0065a7b5bea8e42e9e7c8659f4f1fce905b15598690fb77668927e8e25bebdcdf624868e
7
+ data.tar.gz: 43d11f12fcfeb5c20d566bf2a06a1cb0bf620587bc01eaaaec00ed1420b004e4b43439657cc8572f4cb3a4cbeb41c8b52fb1b642ccd78762fb9e97dc54b016b7
@@ -0,0 +1,132 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require 'base64'
4
+
5
+ class FreshServiceApiv2
6
+ attr_accessor :header,:username,:password,:apikey,:baseurl
7
+
8
+
9
+
10
+ class AlreadyExistedError < StandardError; end # have to add better error handling #ToDO
11
+ class ConnectionError < StandardError; end
12
+
13
+
14
+ def initialize(uri)
15
+ @baseurl = uri.chomp('/')
16
+ end
17
+
18
+ def get(uri)
19
+ begin
20
+ pick_header
21
+ request = RestClient::Resource.new(baseurl+uri)
22
+ response = request.get(@header)
23
+ return response.code,JSON.parse(response)
24
+ rescue RestClient::Exception => e
25
+ return e.response.code, JSON.parse(e.response.body)
26
+ end
27
+ end
28
+
29
+ def delete(uri)
30
+ begin
31
+ pick_header
32
+ request = RestClient::Resource.new(baseurl+uri)
33
+ response = request.delete(@header)
34
+ return response.code,JSON.parse(response)
35
+ rescue RestClient::Exception => e
36
+ return e.response.code, JSON.parse(e.response.body)
37
+ end
38
+ end
39
+
40
+ def update(uri,data)
41
+ begin
42
+ pick_header
43
+ request = RestClient::Resource.new(baseurl+uri)
44
+ response = request.put(data,@header)
45
+ return response.code,JSON.parse(response)
46
+ rescue RestClient::Exception => e
47
+ return e.response.code, JSON.parse(e.response.body)
48
+ end
49
+ end
50
+
51
+ def post(uri,data)
52
+ begin
53
+ pick_header
54
+ request = RestClient::Resource.new(baseurl+uri)
55
+ response = request.post(data,@header)
56
+ return response.code,JSON.parse(response)
57
+ rescue RestClient::Exception => e
58
+ return e.response.code, JSON.parse(e.response.body)
59
+ end
60
+
61
+ end
62
+
63
+ protected
64
+
65
+ def pick_header
66
+ @header = @header != nil ? @header : { 'Content-Type' => 'application/json' }
67
+ @header['Authorization'] = authenticate
68
+ end
69
+
70
+ def authenticate
71
+ if (@username) && (@password) && (@apikey == nil)
72
+ pass = Base64.encode64("#{@username}:#{@password}").gsub(/\n/,"")
73
+ pass
74
+ elsif @apikey
75
+ encoded = Base64.encode64("#{@apikey}:X")
76
+ "Basic #{encoded}"
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ class Tickets < FreshServiceApiv2
83
+
84
+ TICKET_ENDPOINT = "/api/v2/tickets"
85
+ TICKET_FIELDS = "/api/v2/ticket_fields"
86
+ TICKET_CONVERSATIONS = "/api/v2/conversations"
87
+
88
+ def initialize(uri)
89
+ super(uri)
90
+ end
91
+
92
+ def create_ticket(data)
93
+ response = post(TICKET_ENDPOINT,data.to_json)
94
+ end
95
+
96
+ def view_ticket(id)
97
+ response = get(TICKET_ENDPOINT + "/#{id}")
98
+ end
99
+
100
+ def view_all_ticket_fields
101
+ response = get(TICKET_FIELDS)
102
+ end
103
+
104
+ def delete_ticket(id)
105
+ response = delete(TICKET_ENDPOINT + "/#{id}")
106
+ end
107
+
108
+ def update_ticket(id,data)
109
+ response = update(TICKET_ENDPOINT + "/#{id}", data.to_json)
110
+ end
111
+
112
+ def add_note(id,data)
113
+ response = post(TICKET_ENDPOINT + "/#{id}/notes", data.to_json)
114
+ end
115
+
116
+ def add_reply(id,data)
117
+ response = post(TICKET_ENDPOINT + "/#{id}/reply", data.to_json)
118
+ end
119
+
120
+ def update_conversations(conversation_id,data)
121
+ response = update(TICKET_CONVERSATIONS + "/#{conversation_id}", data.to_json)
122
+ end
123
+
124
+ def delete_conversation(conversation_id)
125
+ response = delete(TICKET_CONVERSATIONS + "/#{conversation_id}")
126
+ end
127
+
128
+ def get_all_conversations(ticket_id)
129
+ response = get(TICKET_ENDPOINT + "/#{ticket_id}/conversations")
130
+ end
131
+
132
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: freshservice_apiv2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rishabh Aditya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.2
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.2
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.2
33
+ description: Wrapper for Freshservice API V2
34
+ email: rishabh.aditya@hotmail.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - lib/freshservice_apiv2.rb
40
+ homepage: https://github.com/rishabh91/freshservice_apiv2
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.4.5.1
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: A simple way to access freshservice API's
64
+ test_files: []