semantria_sdk 3.0.70

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 04b3da4fca72c6e121e2fbfabc778618c658def2
4
+ data.tar.gz: 2a2817917a43a6a7e3ae23bba763d6f080120f84
5
+ SHA512:
6
+ metadata.gz: 435630637706c28637950627c4fb11a9fbd44a25c194d58832dae51698f97e0881f9f02bcbbbebb100ebdf61862644573453e693ad64537a51c5b8679c10da6e
7
+ data.tar.gz: 04865e65dbc60baf0ed032b3d54737ed0549a26a1a6f08b4d89eefc349eec8cc65f03377544a097297e52fc3f737a6bdc0d5aed9545fe55f4621c333dfc1c79f
data/lib/semantria.rb ADDED
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+ require_relative 'semantria/version'
3
+ require_relative 'semantria/session'
4
+ require_relative 'semantria/authrequest'
5
+ require_relative 'semantria/jsonserializer'
@@ -0,0 +1,165 @@
1
+ # encoding: utf-8
2
+ require 'uri'
3
+ require 'base64'
4
+ require 'cgi'
5
+ require 'digest/md5'
6
+ require 'openssl'
7
+ require 'digest/sha1'
8
+ require 'net/http'
9
+ require 'net/https'
10
+
11
+ OAUTH_VERSION = '1.0'
12
+ OAuthParameterPrefix = "oauth_"
13
+ OAuthConsumerKeyKey = "oauth_consumer_key"
14
+ OAuthVersionKey = "oauth_version"
15
+ OAuthSignatureMethodKey = "oauth_signature_method"
16
+ OAuthSignatureKey = "oauth_signature"
17
+ OAuthTimestampKey = "oauth_timestamp"
18
+ OAuthNonceKey = "oauth_nonce"
19
+
20
+ class AuthRequest
21
+ # Create a new instance
22
+ def initialize(consumer_key, consumer_secret, application_name, use_compression = false)
23
+ @consumer_key = consumer_key
24
+ @consumer_secret = consumer_secret
25
+ @application_name = application_name
26
+ @use_compression = use_compression
27
+ end
28
+
29
+ def authWebRequest(method, url, post_data = nil)
30
+ nonce = generateNonce()
31
+ timestamp = generateTimestamp()
32
+ query = generate_query(method, url, timestamp, nonce)
33
+ auth_header = generate_auth_header(query, timestamp, nonce)
34
+ headers = {'Authorization' => auth_header}
35
+
36
+ headers['Content-type'] = 'application/x-www-form-urlencoded' if method == 'POST'
37
+ headers['x-api-version'] = '3'
38
+ headers['x-app-name'] = @application_name
39
+
40
+ headers['Accept-Encoding'] = 'gzip' if @use_compression
41
+
42
+ uri = URI.parse(query)
43
+ conn = Net::HTTP.new(uri.host, 443)
44
+ conn.use_ssl = true
45
+ conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
46
+
47
+ path = uri.request_uri #'%s?%s' % [qpath, qquery]
48
+ request = get_request(method, path, headers, post_data)
49
+ response = conn.request(request)
50
+
51
+ data = nil
52
+ if response.header['Content-Encoding'].eql? 'gzip'
53
+ sio = StringIO.new( response.body )
54
+ gz = Zlib::GzipReader.new( sio )
55
+ data = gz.read()
56
+ else
57
+ data = response.body
58
+ end
59
+
60
+ {status: response.code.to_i, reason: response.message, data: data}
61
+ end
62
+
63
+ private
64
+ # create the http request object for a given http_method and path
65
+ def get_request(method, path, headers, post_data = nil)
66
+ request = nil
67
+ case method
68
+ when 'POST'
69
+ request = Net::HTTP::Post.new(path, headers)
70
+ when 'PUT'
71
+ request = Net::HTTP::Put.new(path, headers)
72
+ when 'GET'
73
+ request = Net::HTTP::Get.new(path, headers)
74
+ when 'DELETE'
75
+ request = Net::HTTP::Delete.new(path, headers)
76
+ else
77
+ fail ArgumentError, "Don't know how to handle method: :#{method}"
78
+ end
79
+
80
+ unless post_data.nil?
81
+ request.body = post_data
82
+ request['Content-Length'] = request.body.length.to_s
83
+ end
84
+
85
+ request
86
+ end
87
+
88
+ def generate_query(method, url, timestamp, nonce)
89
+ uri = URI.parse(url)
90
+ np = get_normalized_parameters(timestamp, nonce)
91
+
92
+ if uri.query
93
+ uri.query = '%s&%s' % [uri.query, np]
94
+ else
95
+ uri.query = '%s' % np
96
+ end
97
+
98
+ uri.to_s
99
+ end
100
+
101
+ def generate_auth_header(query, timestamp, nonce)
102
+ md5cs = get_md5_hash(@consumer_secret)
103
+ esc_query = escape(query)
104
+ hash = get_sha1(md5cs, esc_query)
105
+ hash = escape(hash)
106
+
107
+ items = Hash.new()
108
+ items['OAuth realm'] = ''
109
+ items[OAuthVersionKey] = "%s" % OAUTH_VERSION
110
+ items[OAuthTimestampKey] = "%s" % timestamp
111
+ items[OAuthNonceKey] = "%s" % nonce
112
+ items[OAuthSignatureMethodKey] = "HMAC-SHA1"
113
+ items[OAuthConsumerKeyKey] = "%s" % @consumer_key
114
+ items[OAuthSignatureKey] = "%s" % hash
115
+
116
+ params = []
117
+ items.keys.sort.each do |key|
118
+ params.push('%s="%s"' % [key, items[key]])
119
+ end
120
+
121
+ params.join(',')
122
+ end
123
+
124
+ def get_normalized_parameters(timestamp, nonce)
125
+ items = Hash.new()
126
+ items[OAuthVersionKey] = OAUTH_VERSION
127
+ items[OAuthTimestampKey] = timestamp
128
+ items[OAuthNonceKey] = nonce
129
+ items[OAuthSignatureMethodKey] = "HMAC-SHA1"
130
+ items[OAuthConsumerKeyKey] = @consumer_key
131
+
132
+ params = []
133
+ for key in items.keys.sort
134
+ params.push('%s=%s' % [key, items[key]])
135
+ end
136
+
137
+ np = params.join('&')
138
+ # Encode signature parameters per Oauth Core 1.0 protocol
139
+ # Spaces must be encoded with "%20" instead of "+"
140
+ return np.gsub('+', '%20').gsub('%7E', '~')
141
+ end
142
+
143
+ def get_md5_hash(str)
144
+ md5hash = Digest::MD5.hexdigest(str)
145
+ end
146
+
147
+ def get_sha1(md5cs, query)
148
+ digest = OpenSSL::Digest::Digest.new('sha1')
149
+ # our composite signing key now has the token secret after the ampersand
150
+ sha1res = OpenSSL::HMAC.digest(digest, md5cs, query)
151
+ Base64.encode64(sha1res).chomp.gsub(/\n/, '')
152
+ end
153
+
154
+ def generateTimestamp()
155
+ Time.now.to_i.to_s
156
+ end
157
+
158
+ def generateNonce(length = 20)
159
+ rand(10 ** length).to_s.rjust(length, '0')
160
+ end
161
+
162
+ def escape(s)
163
+ CGI::escape(s)
164
+ end
165
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ require 'json'
3
+
4
+ class JsonSerializer
5
+ def gettype
6
+ 'json'
7
+ end
8
+
9
+ def serialize(obj, wrapper = nil)
10
+ str = JSON.generate(obj)
11
+
12
+ str.encoding.name != 'UTF-8' ? str.encode('UTF-8') : str
13
+ end
14
+
15
+ def deserialize(str, handler = nil)
16
+ JSON.parse(str)
17
+ end
18
+ end
@@ -0,0 +1,564 @@
1
+ # encoding: utf-8
2
+ #$LOAD_PATH << File.dirname(__FILE__) unless $LOAD_PATH.include?(File.dirname(__FILE__))
3
+ require_relative 'version'
4
+ require_relative 'authrequest'
5
+ require_relative 'jsonserializer'
6
+
7
+ class Session
8
+ attr_accessor :host
9
+
10
+ # Create a new instance
11
+ def initialize(consumer_key, consumer_secret, application_name = nil, use_compression = false, serializer = nil)
12
+ @host = 'https://api30.semantria.com'
13
+ @wrapper_name = "Ruby/#{Semantria::VERSION}"
14
+ @consumer_key = consumer_key
15
+ @consumer_secret = consumer_secret
16
+ @use_compression = use_compression
17
+
18
+ if application_name.nil?
19
+ @application_name = @wrapper_name
20
+ else
21
+ @application_name = '%s/%s' % [application_name, @wrapper_name]
22
+ end
23
+
24
+ if serializer.nil?
25
+ #set default json serializer
26
+ @serializer = JsonSerializer.new()
27
+ @format = @serializer.gettype()
28
+ else
29
+ @serializer = serializer
30
+ @format = @serializer.gettype()
31
+ end
32
+ end
33
+
34
+ def registerSerializer(serializer)
35
+ fail 'Serializer can\'t be null' if serializer.nil?
36
+
37
+ @serializer = serializer
38
+ @format = serializer.gettype()
39
+ end
40
+
41
+ def setCallbackHandler(callback)
42
+ if callback.class < CallbackHandler
43
+ @callback = callback
44
+ else
45
+ fail "Parameter is not subclass of CallbackHandler #{callback}"
46
+ end
47
+ end
48
+
49
+ def getStatus
50
+ url = "#@host/status.#@format"
51
+ runRequest('GET', url, 'get_status')
52
+ end
53
+
54
+ def getSubscription
55
+ url = "#@host/subscription.#@format"
56
+ runRequest('GET', url, 'get_subscription')
57
+ end
58
+
59
+ def getStatistics
60
+ url = "#@host/statistics.#@format"
61
+ runRequest('GET', url, 'get_statistics')
62
+ end
63
+
64
+ def getConfigurations
65
+ url = "#@host/configurations.#@format"
66
+ result = runRequest('GET', url, 'get_configurations')
67
+ result ||= []
68
+ end
69
+
70
+ def addConfigurations(items)
71
+ updateConfigurations(items)
72
+ end
73
+
74
+ def updateConfigurations(items)
75
+ url = "#@host/configurations.#@format"
76
+ wrapper = get_type_wrapper('update_configurations')
77
+ data = @serializer.serialize(items, wrapper)
78
+ runRequest('POST', url, nil, data)
79
+ end
80
+
81
+ def deleteConfigurations(items)
82
+ url = "#@host/configurations.#@format"
83
+
84
+ wrapper = get_type_wrapper('delete_configurations')
85
+ data = @serializer.serialize(items, wrapper)
86
+ runRequest('DELETE', url, nil, data)
87
+ end
88
+
89
+ def getBlacklist(config_id = nil)
90
+ if config_id.nil?
91
+ url = "#@host/blacklist.#@format"
92
+ else
93
+ url = "#@host/blacklist.#@format?config_id=#{config_id}"
94
+ end
95
+
96
+ result = runRequest('GET', url, 'get_blacklist')
97
+ result ||= []
98
+ end
99
+
100
+ def addBlacklist(items, config_id = nil)
101
+ updateBlacklist(items, config_id)
102
+ end
103
+
104
+ def updateBlacklist(items, config_id = nil)
105
+ if config_id.nil?
106
+ url = "#@host/blacklist.#@format"
107
+ else
108
+ url = "#@host/blacklist.#@format?config_id=#{config_id}"
109
+ end
110
+
111
+ wrapper = get_type_wrapper('update_blacklist')
112
+ data = @serializer.serialize(items, wrapper)
113
+ runRequest('POST', url, nil, data)
114
+ end
115
+
116
+ def removeBlacklist(items, config_id = nil)
117
+ if config_id.nil?
118
+ url = "#@host/blacklist.#@format"
119
+ else
120
+ url = "#@host/blacklist.#@format?config_id=#{config_id}"
121
+ end
122
+
123
+ wrapper = get_type_wrapper('remove_blacklist')
124
+ data = @serializer.serialize(items, wrapper)
125
+ runRequest('DELETE', url, nil, data)
126
+ end
127
+
128
+ def getCategories(config_id = nil)
129
+ if config_id.nil?
130
+ url = "#@host/categories.#@format"
131
+ else
132
+ url = "#@host/categories.#@format?config_id=#{config_id}"
133
+ end
134
+
135
+ result = runRequest('GET', url, 'get_categories')
136
+ result ||= []
137
+ end
138
+
139
+ def addCategories(items, config_id = nil)
140
+ updateCategories(items, config_id)
141
+ end
142
+
143
+ def updateCategories(items, config_id = nil)
144
+ if config_id.nil?
145
+ url = "#@host/categories.#@format"
146
+ else
147
+ url = "#@host/categories.#@format?config_id=#{config_id}"
148
+ end
149
+
150
+ wrapper = get_type_wrapper('update_categories')
151
+ data = @serializer.serialize(items, wrapper)
152
+ runRequest('POST', url, nil, data)
153
+ end
154
+
155
+ def removeCategories(items, config_id = nil)
156
+ if config_id.nil?
157
+ url = "#@host/categories.#@format"
158
+ else
159
+ url = "#@host/categories.#@format?config_id=#{config_id}"
160
+ end
161
+
162
+ wrapper = get_type_wrapper('remove_categories')
163
+ data = @serializer.serialize(items, wrapper)
164
+ runRequest('DELETE', url, nil, data)
165
+ end
166
+
167
+ def getQueries(config_id = nil)
168
+ if config_id.nil?
169
+ url = "#@host/queries.#@format"
170
+ else
171
+ url = "#@host/queries.#@format?config_id=#{config_id}"
172
+ end
173
+
174
+ result = runRequest('GET', url, 'get_queries')
175
+ result ||= []
176
+ end
177
+
178
+ def addQueries(items, config_id = nil)
179
+ updateQueries(items, config_id)
180
+ end
181
+
182
+ def updateQueries(items, config_id = nil)
183
+ if config_id.nil?
184
+ url = "#@host/queries.#@format"
185
+ else
186
+ url = "#@host/queries.#@format?config_id=#{config_id}"
187
+ end
188
+
189
+ wrapper = get_type_wrapper('update_queries')
190
+ data = @serializer.serialize(items, wrapper)
191
+ runRequest('POST', url, nil, data)
192
+ end
193
+
194
+ def removeQueries(items, config_id = nil)
195
+ if config_id.nil?
196
+ url = "#@host/queries.#@format"
197
+ else
198
+ url = "#@host/queries.#@format?config_id=#{config_id}"
199
+ end
200
+
201
+ wrapper = get_type_wrapper('remove_queries')
202
+ data = @serializer.serialize(items, wrapper)
203
+ runRequest('DELETE', url, nil, data)
204
+ end
205
+
206
+ def getPhrases(config_id = nil)
207
+ if config_id.nil?
208
+ url = "#@host/phrases.#@format"
209
+ else
210
+ url = "#@host/phrases.#@format?config_id=#{config_id}"
211
+ end
212
+
213
+ result = runRequest('GET', url, 'get_sentiment_phrases')
214
+ result ||= []
215
+ end
216
+
217
+ def addPhrases(items, config_id = nil)
218
+ updatePhrases(items, config_id)
219
+ end
220
+
221
+ def updatePhrases(items, config_id = nil)
222
+ if config_id.nil?
223
+ url = "#@host/phrases.#@format"
224
+ else
225
+ url = "#@host/phrases.#@format?config_id=#{config_id}"
226
+ end
227
+
228
+ wrapper = get_type_wrapper('update_sentiment_phrases')
229
+ data = @serializer.serialize(items, wrapper)
230
+ runRequest('POST', url, nil, data)
231
+ end
232
+
233
+ def removePhrases(items, config_id = nil)
234
+ if config_id.nil?
235
+ url = "#@host/phrases.#@format"
236
+ else
237
+ url = "#@host/phrases.#@format?config_id=#{config_id}"
238
+ end
239
+
240
+ wrapper = get_type_wrapper('remove_phrases')
241
+ data = @serializer.serialize(items, wrapper)
242
+ runRequest('DELETE', url, nil, data)
243
+ end
244
+
245
+ def getEntities(config_id = nil)
246
+ if config_id.nil?
247
+ url = "#@host/entities.#@format"
248
+ else
249
+ url = "#@host/entities.#@format?config_id=#{config_id}"
250
+ end
251
+
252
+ result = runRequest('GET', url, 'get_entities')
253
+ result ||= []
254
+ end
255
+
256
+ def addEntities(items, config_id = nil)
257
+ updateEntities(items, config_id)
258
+ end
259
+
260
+ def updateEntities(items, config_id = nil)
261
+ if config_id.nil?
262
+ url = "#@host/entities.#@format"
263
+ else
264
+ url = "#@host/entities.#@format?config_id=#{config_id}"
265
+ end
266
+
267
+ wrapper = get_type_wrapper('update_entities')
268
+ data = @serializer.serialize(items, wrapper)
269
+ runRequest('POST', url, nil, data)
270
+ end
271
+
272
+ def removeEntities(items, config_id = nil)
273
+ if config_id.nil?
274
+ url = "#@host/entities.#@format"
275
+ else
276
+ url = "#@host/entities.#@format?config_id=#{config_id}"
277
+ end
278
+
279
+ wrapper = get_type_wrapper('remove_entities')
280
+ data = @serializer.serialize(items, wrapper)
281
+ runRequest('DELETE', url, nil, data)
282
+ end
283
+
284
+ def queueDocument(task, config_id = nil)
285
+ if config_id.nil?
286
+ url = "#@host/document.#@format"
287
+ else
288
+ url = "#@host/document.#@format?config_id=#{config_id}"
289
+ end
290
+
291
+ wrapper = get_type_wrapper('queue_document')
292
+ data = @serializer.serialize(task, wrapper)
293
+ result = runRequest('POST', url, 'get_processed_documents', data)
294
+ if result != nil && result.is_a?(Array)
295
+ onDocsAutoResponse(result)
296
+ 200
297
+ else
298
+ result
299
+ end
300
+ end
301
+
302
+ def queueBatch(batch, config_id = nil)
303
+ if config_id.nil?
304
+ url = "#@host/document/batch.#@format"
305
+ else
306
+ url = "#@host/document/batch.#@format?config_id=#{config_id}"
307
+ end
308
+
309
+ wrapper = get_type_wrapper('queue_batch_documents')
310
+ data = @serializer.serialize(batch, wrapper)
311
+ result = runRequest('POST', url, 'get_processed_documents', data)
312
+ if result != nil && result.is_a?(Array)
313
+ onDocsAutoResponse(result)
314
+ 200
315
+ else
316
+ result
317
+ end
318
+ end
319
+
320
+ def getDocument(doc_id, config_id = nil)
321
+ fail 'Document ID is nil or empty' if doc_id.nil?
322
+
323
+ if config_id.nil?
324
+ url = "#@host/document/#{doc_id}.#@format"
325
+ else
326
+ url = "#@host/document/#{doc_id}.#@format?config_id=#{config_id}"
327
+ end
328
+
329
+ runRequest('GET', url, 'get_document')
330
+ end
331
+
332
+ def cancelDocument(doc_id, config_id = nil)
333
+ fail 'Document ID is nil or empty' if doc_id.nil?
334
+
335
+ if config_id.nil?
336
+ url = "#@host/document/#{doc_id}.#@format"
337
+ else
338
+ url = "#@host/document/#{doc_id}.#@format?config_id=#{config_id}"
339
+ end
340
+
341
+ runRequest('DELETE', url)
342
+ end
343
+
344
+ def getProcessedDocuments(config_id = nil)
345
+ if config_id.nil?
346
+ url = "#@host/document/processed.#@format"
347
+ else
348
+ url = "#@host/document/processed.#@format?config_id=#{config_id}"
349
+ end
350
+
351
+ result = runRequest('GET', url, 'get_processed_documents')
352
+ result ||= []
353
+ end
354
+
355
+ def queueCollection(task, config_id = nil)
356
+ if config_id.nil?
357
+ url = "#@host/collection.#@format"
358
+ else
359
+ url = "#@host/collection.#@format?config_id=#{config_id}"
360
+ end
361
+
362
+ wrapper = get_type_wrapper('queue_collection')
363
+ data = @serializer.serialize(task, wrapper)
364
+ result = runRequest('POST', url, 'get_processed_collections', data)
365
+ if result != nil && result.is_a?(Array)
366
+ onCollsAutoResponse(result)
367
+ 200
368
+ else
369
+ result
370
+ end
371
+ end
372
+
373
+ def getCollection(id, config_id = nil)
374
+ fail 'Collection ID is nil or empty' if id.nil?
375
+
376
+ if config_id.nil?
377
+ url = "#@host/collection/#{id}.#@format"
378
+ else
379
+ url = "#@host/collection/#{id}.#@format?config_id=#{config_id}"
380
+ end
381
+
382
+ runRequest('GET', url, 'get_collection')
383
+ end
384
+
385
+ def cancelCollection(id, config_id = nil)
386
+ fail 'Collection ID is nil or empty' if id.nil?
387
+
388
+ if config_id.nil?
389
+ url = "#@host/collection/#{id}.#@format"
390
+ else
391
+ url = "#@host/collection/#{id}.#@format?config_id=#{config_id}"
392
+ end
393
+
394
+ runRequest('DELETE', url)
395
+ end
396
+
397
+ def getProcessedCollections(config_id = nil)
398
+ if config_id.nil?
399
+ url = "#@host/collection/processed.#@format"
400
+ else
401
+ url = "#@host/collection/processed.#@format?config_id=#{config_id}"
402
+ end
403
+
404
+ result = runRequest('GET', url, 'get_processed_collections')
405
+ result ||= []
406
+ end
407
+
408
+ private
409
+ def runRequest(method, url, type = nil, post_data = nil)
410
+ request = AuthRequest.new(@consumer_key, @consumer_secret, @application_name, @use_compression)
411
+ onRequest({'method' => method, 'url' => url, 'message' => post_data})
412
+ response = request.authWebRequest(method, url, post_data)
413
+ onResponse({'status' => response[:status], 'reason' => response[:reason], 'message' => response[:data]})
414
+
415
+ status = response[:status]
416
+ message = response[:reason]
417
+
418
+ message = response[:data] unless response[:data].to_s.empty?
419
+
420
+ if method == 'DELETE'
421
+ if status == 200 || status == 202
422
+ return status
423
+ else
424
+ resolve_error(status, message)
425
+ return status
426
+ end
427
+ else
428
+ if status == 200
429
+ handler = get_type_handler(type)
430
+ message = @serializer.deserialize(response[:data], handler)
431
+ return message
432
+ elsif status == 202
433
+ if method == 'POST'
434
+ return status
435
+ else
436
+ return nil
437
+ end
438
+ else
439
+ resolve_error(status, message)
440
+ end
441
+ end
442
+ end
443
+
444
+ def get_type_handler(type)
445
+ if @serializer.gettype() == 'json'
446
+ return nil
447
+ end
448
+
449
+ #only for xml serializer
450
+ case
451
+ when type == 'get_status' then return GetStatusHandler.new()
452
+ when type == 'get_subscription' then return GetSubscriptionHandler.new()
453
+ when type == 'get_configurations' then return GetConfigurationsHandler.new()
454
+ when type == 'get_blacklist' then return GetBlacklistHandler.new()
455
+ when type == 'get_categories' then return GetCategoriesHandler.new()
456
+ when type == 'get_queries' then return GetQueriesHandler.new()
457
+ when type == 'get_sentiment_phrases' then return GetSentimentPhrasesHandler.new()
458
+ when type == 'get_entities' then return GetEntitiesHandler.new()
459
+ when type == 'get_document' then return GetDocumentHandler.new()
460
+ when type == 'get_processed_documents' then return GetProcessedDocumentsHandler.new()
461
+ when type == 'get_collection' then return GetCollectionHandler.new()
462
+ when type == 'get_processed_collections' then return GetProcessedCollectionsHandler.new()
463
+ else return nil
464
+ end
465
+ end
466
+
467
+ def get_type_wrapper(type)
468
+ if @serializer.gettype() == 'json'
469
+ nil
470
+ end
471
+
472
+ #only for xml serializer
473
+ #if type == "update_configurations"
474
+ # return {"root" => "configurations", "added" => "configuration", "removed" => "configuration"}
475
+ #elsif type == "update_blacklist"
476
+ # return {"root" => "blacklist", "added" => "item", "removed" => "item"}
477
+ #elsif type == "update_categories"
478
+ # return {"root" => "categories", "added" => "category", "removed" => "category", "samples" => "sample"}
479
+ #elsif type == "update_queries"
480
+ # return {"root" => "queries", "added" => "query", "removed" => "query"}
481
+ #elsif type == "update_sentiment_phrases"
482
+ # return {"root" => "phrases", "added" => "phrase", "removed" => "phrase"}
483
+ #elsif type == "update_entities"
484
+ # return {"root" => "entities", "added" => "entity", "removed" => "entity"}
485
+ #elsif type == "queue_document"
486
+ # return {"root" => "document"}
487
+ #elsif type == "queue_batch_documents"
488
+ # return {"root" => "documents", "item" => "document"}
489
+ #elsif type == "queue_collection"
490
+ # return {"root" => "collection", "documents" => "document"}
491
+ #else
492
+ # return nil
493
+ #end
494
+ end
495
+
496
+ def resolve_error(status, message = nil)
497
+ if status == 400 || status == 401 || status == 402 || status == 403 || status == 406 || status == 500
498
+ onError({'status' => status, 'message' => message})
499
+ else
500
+ fail "HTTP error was found with status: #{status} and message: #{message}"
501
+ end
502
+ end
503
+
504
+ def onRequest(request)
505
+ unless @callback.nil?
506
+ @callback.onRequest(self, request)
507
+ end
508
+ end
509
+
510
+ def onResponse(response)
511
+ unless @callback.nil?
512
+ @callback.onResponse(self, response)
513
+ end
514
+ end
515
+
516
+ def onError(response)
517
+ unless @callback.nil?
518
+ @callback.onError(self, response)
519
+ end
520
+ end
521
+
522
+ def onDocsAutoResponse(response)
523
+ unless @callback.nil?
524
+ @callback.onDocsAutoResponse(self, response)
525
+ end
526
+ end
527
+
528
+ def onCollsAutoResponse(response)
529
+ unless @callback.nil?
530
+ @callback.onCollsAutoResponse(self, response)
531
+ end
532
+ end
533
+ end
534
+
535
+ class CallbackHandler
536
+ def initialize
537
+ fail 'Don\'t instantiate me!' if abstract_class?
538
+ end
539
+
540
+ private
541
+ def abstract_class?
542
+ self.class == CallbackHandler
543
+ end
544
+
545
+ def onRequest(sender, args)
546
+ fail 'Abstract method onRequest'
547
+ end
548
+
549
+ def onResponse(sender, args)
550
+ fail 'Abstract method onResponse'
551
+ end
552
+
553
+ def onError(sender, args)
554
+ fail 'Abstract method onError'
555
+ end
556
+
557
+ def onDocsAutoResponse(sender, args)
558
+ fail 'Abstract method onDocsAutoResponse'
559
+ end
560
+
561
+ def onCollsAutoResponse(sender, args)
562
+ fail 'Abstract method onCollsAutoResponse'
563
+ end
564
+ end
@@ -0,0 +1,3 @@
1
+ module Semantria
2
+ VERSION = '3.0.70'
3
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: semantria_sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.70
5
+ platform: ruby
6
+ authors:
7
+ - Semantria, LLC
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |2-
14
+
15
+ Semantria is a text analytics and sentiment analysis API. It allows you to gain valuable
16
+ insights from your unstructured text content. It is based on Lexalytics’ Salience – a text
17
+ analytics and sentiment analysis engine. It is the same engine as the one being used by
18
+ Oracle, Cisco, Thomson Reuters, Saleforce.com - Radian6, Visible, Lithium, and 50+ other
19
+ leaders in the space.
20
+
21
+ Semantria offers Ruby SDK, that is the most convenient way to get started with the Semantria API on Ruby.
22
+ SDK implements all the available Semantria features and demonstrate best practices of API usage.
23
+ email: support@semantria.com
24
+ executables: []
25
+ extensions: []
26
+ extra_rdoc_files: []
27
+ files:
28
+ - lib/semantria.rb
29
+ - lib/semantria/session.rb
30
+ - lib/semantria/version.rb
31
+ - lib/semantria/authrequest.rb
32
+ - lib/semantria/jsonserializer.rb
33
+ homepage: https://semantria.com
34
+ licenses:
35
+ - GPL v3
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 2.0.0
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Semantria Ruby SDK
57
+ test_files: []