semantria_sdk 3.0.70 → 3.8.79

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