pinch-api 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.
- checksums.yaml +7 -0
- data/LICENSE +28 -0
- data/README.md +48 -0
- data/lib/pinch.rb +24 -0
- data/lib/pinch/api_exception.rb +21 -0
- data/lib/pinch/api_helper.rb +140 -0
- data/lib/pinch/configuration.rb +23 -0
- data/lib/pinch/controllers/ticket_controller.rb +537 -0
- data/lib/pinch/controllers/webhook_controller.rb +290 -0
- data/lib/pinch/controllers/webhook_type_controller.rb +62 -0
- data/lib/pinch/custom_auth_utility.rb +17 -0
- data/lib/pinch/models/building.rb +107 -0
- data/lib/pinch/models/person.rb +80 -0
- data/lib/pinch/models/ticket.rb +130 -0
- data/lib/pinch/models/unit.rb +89 -0
- data/lib/pinch/models/webhook.rb +62 -0
- data/lib/pinch/models/webhook_type.rb +53 -0
- data/lib/pinch/pinch_client.rb +29 -0
- metadata +89 -0
@@ -0,0 +1,290 @@
|
|
1
|
+
# This file was automatically generated for Pinch by APIMATIC v2.0 ( https://apimatic.io ) on 05/13/2016
|
2
|
+
|
3
|
+
module Pinch
|
4
|
+
class WebhookController
|
5
|
+
@@instance = WebhookController.new
|
6
|
+
# Singleton instance of the controller class
|
7
|
+
def self.instance
|
8
|
+
@@instance
|
9
|
+
end
|
10
|
+
|
11
|
+
# List the webhooks of the current user
|
12
|
+
# @return List of Webhook response from the API call
|
13
|
+
def list
|
14
|
+
# the base uri for api requests
|
15
|
+
_query_builder = Configuration.base_uri.dup
|
16
|
+
|
17
|
+
# prepare query string for API call
|
18
|
+
_query_builder << '/webhooks'
|
19
|
+
|
20
|
+
# validate and preprocess url
|
21
|
+
_query_url = APIHelper.clean_url _query_builder
|
22
|
+
|
23
|
+
# prepare headers
|
24
|
+
_headers = {
|
25
|
+
'user-agent' => 'APIMATIC 2.0',
|
26
|
+
'accept' => 'application/json',
|
27
|
+
'X-API-TOKEN' => Configuration.x_api_token,
|
28
|
+
'X-API-EMAIL' => Configuration.x_api_email
|
29
|
+
}
|
30
|
+
|
31
|
+
# append custom auth authorization
|
32
|
+
CustomAuthUtility.append_custom_auth_params _headers
|
33
|
+
|
34
|
+
# invoke the API call request to fetch the response
|
35
|
+
_response = Unirest.get _query_url, headers: _headers
|
36
|
+
|
37
|
+
# Error handling using HTTP status codes
|
38
|
+
if _response.code == 401
|
39
|
+
raise APIException.new 'Your API key is incorrect', 401, _response.body
|
40
|
+
elsif _response.code == 400
|
41
|
+
raise APIException.new 'There is an error in the parameters you send', 400, _response.body
|
42
|
+
elsif _response.code == 404
|
43
|
+
raise APIException.new 'Cannot find the resource specified', 404, _response.body
|
44
|
+
elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK
|
45
|
+
raise APIException.new 'HTTP Response Not OK', _response.code, _response.body
|
46
|
+
end
|
47
|
+
|
48
|
+
# Try to cast response to list of desired type
|
49
|
+
if _response.body.instance_of? Array
|
50
|
+
value = Array.new
|
51
|
+
_response.body.each do |item|
|
52
|
+
begin
|
53
|
+
value << (Webhook.from_hash(item))
|
54
|
+
rescue Exception
|
55
|
+
raise APIException.new "Invalid JSON returned.", _response.code, _response.body
|
56
|
+
end
|
57
|
+
end
|
58
|
+
value
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# TODO: type endpoint description here
|
63
|
+
# @param [Webhook] webhook Required parameter: TODO: type description here
|
64
|
+
# @return Webhook response from the API call
|
65
|
+
def create(webhook)
|
66
|
+
|
67
|
+
# Validate required parameters
|
68
|
+
if webhook == nil
|
69
|
+
raise ArgumentError.new "Required parameter 'webhook' cannot be nil."
|
70
|
+
end
|
71
|
+
|
72
|
+
# the base uri for api requests
|
73
|
+
_query_builder = Configuration.base_uri.dup
|
74
|
+
|
75
|
+
# prepare query string for API call
|
76
|
+
_query_builder << '/webhooks'
|
77
|
+
|
78
|
+
# validate and preprocess url
|
79
|
+
_query_url = APIHelper.clean_url _query_builder
|
80
|
+
|
81
|
+
# prepare headers
|
82
|
+
_headers = {
|
83
|
+
'user-agent' => 'APIMATIC 2.0',
|
84
|
+
'accept' => 'application/json',
|
85
|
+
'content-type' => 'application/json; charset=utf-8',
|
86
|
+
'X-API-TOKEN' => Configuration.x_api_token,
|
87
|
+
'X-API-EMAIL' => Configuration.x_api_email
|
88
|
+
}
|
89
|
+
|
90
|
+
# append custom auth authorization
|
91
|
+
CustomAuthUtility.append_custom_auth_params _headers
|
92
|
+
|
93
|
+
# invoke the API call request to fetch the response
|
94
|
+
_response = Unirest.post _query_url, headers: _headers, parameters: webhook.to_json
|
95
|
+
|
96
|
+
# Error handling using HTTP status codes
|
97
|
+
if _response.code == 401
|
98
|
+
raise APIException.new 'Your API key is incorrect', 401, _response.body
|
99
|
+
elsif _response.code == 400
|
100
|
+
raise APIException.new 'There is an error in the parameters you send', 400, _response.body
|
101
|
+
elsif _response.code == 404
|
102
|
+
raise APIException.new 'Cannot find the resource specified', 404, _response.body
|
103
|
+
elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK
|
104
|
+
raise APIException.new 'HTTP Response Not OK', _response.code, _response.body
|
105
|
+
end
|
106
|
+
|
107
|
+
# Try to cast response to desired type
|
108
|
+
if _response.body.instance_of? Hash
|
109
|
+
begin
|
110
|
+
Webhook.from_hash(_response.body)
|
111
|
+
rescue Exception
|
112
|
+
raise APIException.new "Invalid JSON returned.", _response.code, _response.body
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# TODO: type endpoint description here
|
118
|
+
# @param [Integer] webhook_id Required parameter: TODO: type description here
|
119
|
+
# @param [Webhook] webhook Optional parameter: TODO: type description here
|
120
|
+
# @return Webhook response from the API call
|
121
|
+
def update(webhook_id,
|
122
|
+
webhook = nil)
|
123
|
+
|
124
|
+
# Validate required parameters
|
125
|
+
if webhook_id == nil
|
126
|
+
raise ArgumentError.new "Required parameter 'webhook_id' cannot be nil."
|
127
|
+
end
|
128
|
+
|
129
|
+
# the base uri for api requests
|
130
|
+
_query_builder = Configuration.base_uri.dup
|
131
|
+
|
132
|
+
# prepare query string for API call
|
133
|
+
_query_builder << '/webhooks/{webhook_id}'
|
134
|
+
|
135
|
+
# process optional query parameters
|
136
|
+
_query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
|
137
|
+
'webhook_id' => webhook_id
|
138
|
+
}
|
139
|
+
|
140
|
+
# validate and preprocess url
|
141
|
+
_query_url = APIHelper.clean_url _query_builder
|
142
|
+
|
143
|
+
# prepare headers
|
144
|
+
_headers = {
|
145
|
+
'user-agent' => 'APIMATIC 2.0',
|
146
|
+
'accept' => 'application/json',
|
147
|
+
'content-type' => 'application/json; charset=utf-8',
|
148
|
+
'X-API-TOKEN' => Configuration.x_api_token,
|
149
|
+
'X-API-EMAIL' => Configuration.x_api_email
|
150
|
+
}
|
151
|
+
|
152
|
+
# append custom auth authorization
|
153
|
+
CustomAuthUtility.append_custom_auth_params _headers
|
154
|
+
|
155
|
+
# invoke the API call request to fetch the response
|
156
|
+
_response = Unirest.put _query_url, headers: _headers, parameters: webhook.to_json
|
157
|
+
|
158
|
+
# Error handling using HTTP status codes
|
159
|
+
if _response.code == 401
|
160
|
+
raise APIException.new 'Your API key is incorrect', 401, _response.body
|
161
|
+
elsif _response.code == 400
|
162
|
+
raise APIException.new 'There is an error in the parameters you send', 400, _response.body
|
163
|
+
elsif _response.code == 404
|
164
|
+
raise APIException.new 'Cannot find the resource specified', 404, _response.body
|
165
|
+
elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK
|
166
|
+
raise APIException.new 'HTTP Response Not OK', _response.code, _response.body
|
167
|
+
end
|
168
|
+
|
169
|
+
# Try to cast response to desired type
|
170
|
+
if _response.body.instance_of? Hash
|
171
|
+
begin
|
172
|
+
Webhook.from_hash(_response.body)
|
173
|
+
rescue Exception
|
174
|
+
raise APIException.new "Invalid JSON returned.", _response.code, _response.body
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# TODO: type endpoint description here
|
180
|
+
# @param [Integer] webhook_id Required parameter: TODO: type description here
|
181
|
+
# @return String response from the API call
|
182
|
+
def destroy(webhook_id)
|
183
|
+
|
184
|
+
# Validate required parameters
|
185
|
+
if webhook_id == nil
|
186
|
+
raise ArgumentError.new "Required parameter 'webhook_id' cannot be nil."
|
187
|
+
end
|
188
|
+
|
189
|
+
# the base uri for api requests
|
190
|
+
_query_builder = Configuration.base_uri.dup
|
191
|
+
|
192
|
+
# prepare query string for API call
|
193
|
+
_query_builder << '/webhooks/{webhook_id}'
|
194
|
+
|
195
|
+
# process optional query parameters
|
196
|
+
_query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
|
197
|
+
'webhook_id' => webhook_id
|
198
|
+
}
|
199
|
+
|
200
|
+
# validate and preprocess url
|
201
|
+
_query_url = APIHelper.clean_url _query_builder
|
202
|
+
|
203
|
+
# prepare headers
|
204
|
+
_headers = {
|
205
|
+
'user-agent' => 'APIMATIC 2.0',
|
206
|
+
'X-API-TOKEN' => Configuration.x_api_token,
|
207
|
+
'X-API-EMAIL' => Configuration.x_api_email
|
208
|
+
}
|
209
|
+
|
210
|
+
# append custom auth authorization
|
211
|
+
CustomAuthUtility.append_custom_auth_params _headers
|
212
|
+
|
213
|
+
# invoke the API call request to fetch the response
|
214
|
+
_response = Unirest.delete _query_url, headers: _headers
|
215
|
+
|
216
|
+
# Error handling using HTTP status codes
|
217
|
+
if _response.code == 401
|
218
|
+
raise APIException.new 'Your API key is incorrect', 401, _response.body
|
219
|
+
elsif _response.code == 400
|
220
|
+
raise APIException.new 'There is an error in the parameters you send', 400, _response.body
|
221
|
+
elsif _response.code == 404
|
222
|
+
raise APIException.new 'Cannot find the resource specified', 404, _response.body
|
223
|
+
elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK
|
224
|
+
raise APIException.new 'HTTP Response Not OK', _response.code, _response.body
|
225
|
+
end
|
226
|
+
|
227
|
+
# Return appropriate type
|
228
|
+
_response.body
|
229
|
+
end
|
230
|
+
|
231
|
+
# Get a specific webhook by its id
|
232
|
+
# @param [String] id Required parameter: TODO: type description here
|
233
|
+
# @return Webhook response from the API call
|
234
|
+
def get(id)
|
235
|
+
|
236
|
+
# Validate required parameters
|
237
|
+
if id == nil
|
238
|
+
raise ArgumentError.new "Required parameter 'id' cannot be nil."
|
239
|
+
end
|
240
|
+
|
241
|
+
# the base uri for api requests
|
242
|
+
_query_builder = Configuration.base_uri.dup
|
243
|
+
|
244
|
+
# prepare query string for API call
|
245
|
+
_query_builder << '/webhooks/{id}'
|
246
|
+
|
247
|
+
# process optional query parameters
|
248
|
+
_query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
|
249
|
+
'id' => id
|
250
|
+
}
|
251
|
+
|
252
|
+
# validate and preprocess url
|
253
|
+
_query_url = APIHelper.clean_url _query_builder
|
254
|
+
|
255
|
+
# prepare headers
|
256
|
+
_headers = {
|
257
|
+
'user-agent' => 'APIMATIC 2.0',
|
258
|
+
'accept' => 'application/json',
|
259
|
+
'X-API-TOKEN' => Configuration.x_api_token,
|
260
|
+
'X-API-EMAIL' => Configuration.x_api_email
|
261
|
+
}
|
262
|
+
|
263
|
+
# append custom auth authorization
|
264
|
+
CustomAuthUtility.append_custom_auth_params _headers
|
265
|
+
|
266
|
+
# invoke the API call request to fetch the response
|
267
|
+
_response = Unirest.get _query_url, headers: _headers
|
268
|
+
|
269
|
+
# Error handling using HTTP status codes
|
270
|
+
if _response.code == 401
|
271
|
+
raise APIException.new 'Your API key is incorrect', 401, _response.body
|
272
|
+
elsif _response.code == 400
|
273
|
+
raise APIException.new 'There is an error in the parameters you send', 400, _response.body
|
274
|
+
elsif _response.code == 404
|
275
|
+
raise APIException.new 'Cannot find the resource specified', 404, _response.body
|
276
|
+
elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK
|
277
|
+
raise APIException.new 'HTTP Response Not OK', _response.code, _response.body
|
278
|
+
end
|
279
|
+
|
280
|
+
# Try to cast response to desired type
|
281
|
+
if _response.body.instance_of? Hash
|
282
|
+
begin
|
283
|
+
Webhook.from_hash(_response.body)
|
284
|
+
rescue Exception
|
285
|
+
raise APIException.new "Invalid JSON returned.", _response.code, _response.body
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# This file was automatically generated for Pinch by APIMATIC v2.0 ( https://apimatic.io ) on 05/13/2016
|
2
|
+
|
3
|
+
module Pinch
|
4
|
+
class WebhookTypeController
|
5
|
+
@@instance = WebhookTypeController.new
|
6
|
+
# Singleton instance of the controller class
|
7
|
+
def self.instance
|
8
|
+
@@instance
|
9
|
+
end
|
10
|
+
|
11
|
+
# List webhook types
|
12
|
+
# @return List of WebhookType response from the API call
|
13
|
+
def list
|
14
|
+
# the base uri for api requests
|
15
|
+
_query_builder = Configuration.base_uri.dup
|
16
|
+
|
17
|
+
# prepare query string for API call
|
18
|
+
_query_builder << '/webhook_types'
|
19
|
+
|
20
|
+
# validate and preprocess url
|
21
|
+
_query_url = APIHelper.clean_url _query_builder
|
22
|
+
|
23
|
+
# prepare headers
|
24
|
+
_headers = {
|
25
|
+
'user-agent' => 'APIMATIC 2.0',
|
26
|
+
'accept' => 'application/json',
|
27
|
+
'X-API-TOKEN' => Configuration.x_api_token,
|
28
|
+
'X-API-EMAIL' => Configuration.x_api_email
|
29
|
+
}
|
30
|
+
|
31
|
+
# append custom auth authorization
|
32
|
+
CustomAuthUtility.append_custom_auth_params _headers
|
33
|
+
|
34
|
+
# invoke the API call request to fetch the response
|
35
|
+
_response = Unirest.get _query_url, headers: _headers
|
36
|
+
|
37
|
+
# Error handling using HTTP status codes
|
38
|
+
if _response.code == 401
|
39
|
+
raise APIException.new 'Your API key is incorrect', 401, _response.body
|
40
|
+
elsif _response.code == 400
|
41
|
+
raise APIException.new 'There is an error in the parameters you send', 400, _response.body
|
42
|
+
elsif _response.code == 404
|
43
|
+
raise APIException.new 'Cannot find the resource specified', 404, _response.body
|
44
|
+
elsif !_response.code.between?(200, 206) # [200,206] = HTTP OK
|
45
|
+
raise APIException.new 'HTTP Response Not OK', _response.code, _response.body
|
46
|
+
end
|
47
|
+
|
48
|
+
# Try to cast response to list of desired type
|
49
|
+
if _response.body.instance_of? Array
|
50
|
+
value = Array.new
|
51
|
+
_response.body.each do |item|
|
52
|
+
begin
|
53
|
+
value << (WebhookType.from_hash(item))
|
54
|
+
rescue Exception
|
55
|
+
raise APIException.new "Invalid JSON returned.", _response.code, _response.body
|
56
|
+
end
|
57
|
+
end
|
58
|
+
value
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was automatically generated for Pinch by APIMATIC v2.0 ( https://apimatic.io ) on 05/13/2016
|
2
|
+
|
3
|
+
module Pinch
|
4
|
+
class CustomAuthUtility
|
5
|
+
# Appends the necessary OAuth credentials for making this authorized call
|
6
|
+
# @param [Hash] The out going request to access the resource
|
7
|
+
def self.append_custom_auth_params(headers)
|
8
|
+
# TODO: Add your custom authentication here
|
9
|
+
# The following properties are available to use
|
10
|
+
# Configuration.x_api_token
|
11
|
+
# Configuration.x_api_email
|
12
|
+
#
|
13
|
+
# i.e., Add a header through:
|
14
|
+
# headers["key"] = "value"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# This file was automatically generated for Pinch by APIMATIC v2.0 ( https://apimatic.io ) on 05/13/2016
|
2
|
+
|
3
|
+
module Pinch
|
4
|
+
class Building
|
5
|
+
|
6
|
+
# TODO: Write general description for this method
|
7
|
+
# @return [String]
|
8
|
+
attr_reader :reference
|
9
|
+
|
10
|
+
# TODO: Write general description for this method
|
11
|
+
# @return [String]
|
12
|
+
attr_reader :name
|
13
|
+
|
14
|
+
# TODO: Write general description for this method
|
15
|
+
# @return [String]
|
16
|
+
attr_reader :address
|
17
|
+
|
18
|
+
# TODO: Write general description for this method
|
19
|
+
# @return [String]
|
20
|
+
attr_reader :zip_code
|
21
|
+
|
22
|
+
# TODO: Write general description for this method
|
23
|
+
# @return [String]
|
24
|
+
attr_reader :city
|
25
|
+
|
26
|
+
# TODO: Write general description for this method
|
27
|
+
# @return [String]
|
28
|
+
attr_reader :country
|
29
|
+
|
30
|
+
# TODO: Write general description for this method
|
31
|
+
# @return [Float]
|
32
|
+
attr_reader :latitude
|
33
|
+
|
34
|
+
# TODO: Write general description for this method
|
35
|
+
# @return [Float]
|
36
|
+
attr_reader :longitude
|
37
|
+
|
38
|
+
def initialize(reference = nil,
|
39
|
+
name = nil,
|
40
|
+
address = nil,
|
41
|
+
zip_code = nil,
|
42
|
+
city = nil,
|
43
|
+
country = nil,
|
44
|
+
latitude = nil,
|
45
|
+
longitude = nil)
|
46
|
+
@reference = reference
|
47
|
+
@name = name
|
48
|
+
@address = address
|
49
|
+
@zip_code = zip_code
|
50
|
+
@city = city
|
51
|
+
@country = country
|
52
|
+
@latitude = latitude
|
53
|
+
@longitude = longitude
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def method_missing(method_name)
|
58
|
+
puts "There is no method called '#{method_name}'."
|
59
|
+
end
|
60
|
+
|
61
|
+
# Creates JSON of the curent object
|
62
|
+
def to_json
|
63
|
+
hash = key_map
|
64
|
+
hash.to_json
|
65
|
+
end
|
66
|
+
|
67
|
+
# Creates an instance of the object from a hash
|
68
|
+
def self.from_hash(hash)
|
69
|
+
if hash == nil
|
70
|
+
nil
|
71
|
+
else
|
72
|
+
# Extract variables from the hash
|
73
|
+
reference = hash["reference"]
|
74
|
+
name = hash["name"]
|
75
|
+
address = hash["address"]
|
76
|
+
zip_code = hash["zip_code"]
|
77
|
+
city = hash["city"]
|
78
|
+
country = hash["country"]
|
79
|
+
latitude = hash["latitude"]
|
80
|
+
longitude = hash["longitude"]
|
81
|
+
# Create object from extracted values
|
82
|
+
Building.new(reference,
|
83
|
+
name,
|
84
|
+
address,
|
85
|
+
zip_code,
|
86
|
+
city,
|
87
|
+
country,
|
88
|
+
latitude,
|
89
|
+
longitude)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Defines the key map for json serialization
|
94
|
+
def key_map
|
95
|
+
hash = {}
|
96
|
+
hash['reference'] = reference
|
97
|
+
hash['name'] = name
|
98
|
+
hash['address'] = address
|
99
|
+
hash['zip_code'] = zip_code
|
100
|
+
hash['city'] = city
|
101
|
+
hash['country'] = country
|
102
|
+
hash['latitude'] = latitude
|
103
|
+
hash['longitude'] = longitude
|
104
|
+
hash
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|