Class: App42::Geo::GeoService

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

Overview

Geo Spatial Service on cloud provides the storage, retrieval, querying and updating geo data. One can store the geo data by unique handler on the cloud and can apply search, update and query on it. Geo spatial query includes finding nearby/In circle target point from given point using geo points stored on the cloud.

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(api_key, secret_key, base_url) ⇒ GeoService

this is a constructor that takes

Parameters:

  • apiKey
  • secretKey
  • baseURL


31
32
33
34
35
36
37
38
# File 'lib/geo/GeoService.rb', line 31

def initialize(api_key, secret_key, base_url)
  puts "Geo->initialize"
  @api_key = api_key
  @secret_key = secret_key
  @base_url = base_url
  @resource = "geo"
  @version = "1.0"
end

Instance Method Details

#create_geo_points(geoStorageName, geoPointsList) ⇒ Object

Stores the geo points with unique handler on the cloud. Geo point data contains lat, long and marker of the point.

Parameters:

  • geoStorageName
    • Unique handler for storage name

  • geoPointsList
    • List of Geo Points to be saved

Returns:

  • Geo object containing list of Geo Points that have been saved

Raises:

  • App42Exception



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/geo/GeoService.rb', line 53

def create_geo_points(geoStorageName, geoPointsList)
  puts "Create GeoPoints Called "
  puts "Base url #{@base_url}"
  response = nil;
  geoObj = nil;
  geoObj = Geo.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(geoStorageName, "Geo Storage Name");
  util.throwExceptionIfNullOrBlank(geoPointsList, "Geo Points List");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    geoArray = Array.new
    for geoPoint in geoPointsList do
      geoArray.push(geoPoint)
    end
    body = {'app42' => {"geo"=> { "storage"=> {
      "storageName" => geoStorageName,
      "points" =>{ "point" => geoArray.to_json
      }}}}}.to_json
    puts "Body #{body}"
    params = Hash.new
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("body", body)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/createGeoPoints"
    response = connection.post(signature, resource_url, query_params, body)
    geo = GeoResponseBuilder.new()
    geoObj = geo.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return geoObj
end

#delete_geo_points(geoStorageName, geoPointsList) ⇒ Object

NEW METHOD



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/geo/GeoService.rb', line 424

def delete_geo_points(geoStorageName, geoPointsList)
  puts "deleteGeoPoints Called "
  puts "Base url #{@base_url}"
  response = nil;
  responseObj = App42Response.new();
  util = Util.new
  util.throwExceptionIfNullOrBlank(geoStorageName, "Geo Storage Name");
  util.throwExceptionIfNullOrBlank(geoPointsList, "Geo Points List");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    geoArray = Array.new
    for geoPoint in geoPointsList do
      geoArray.push(geoPoint)
    end
    body = {'app42' => {"geo"=> { "storage"=> {
      "points" =>{ "point" => geoArray.to_json
      }}}}}.to_json
    puts "Body #{body}"
    params = Hash.new
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    params.store("geoPoints", body)
    query_params = params.clone
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/points/#{geoStorageName}"
    response = connection.delete(signature, resource_url, query_params)
    responseObj.strResponse=(response)
    responseObj.isResponseSuccess=(true)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return responseObj
end

#delete_storage(storageName) ⇒ Object

Delete the specifed Geo Storage from Cloud.

Returns:

  • Geo object containing the name of the storage that has been deleted

Raises:

  • App42Exception



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/geo/GeoService.rb', line 312

def delete_storage(storageName)
  puts "Delete Storage Called"
  puts "Base url #{@base_url}"
  response = nil;
  responseObj = App42Response.new();
  util = Util.new
  util.throwExceptionIfNullOrBlank(storageName, "Geo Storage Name");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("storageName", storageName)
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/storage/#{storageName}"
    response = connection.delete(signature, resource_url, query_params)
    responseObj.strResponse=(response)
    responseObj.isResponseSuccess=(true)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return responseObj
end

#get_all_points(storageName) ⇒ Object

Get All Point from storage.

Returns:

  • Geo object containing all the stored Geo Points for the specified storage

Raises:

  • App42Exception



350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/geo/GeoService.rb', line 350

def get_all_points(storageName)
  puts "Get All Points"
  puts "Base url #{@base_url}"
  response = nil;
  geoObjList = nil;
  geoObjList = Array.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(storageName, "Geo Storage Name");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("storageName", storageName)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/points/#{storageName}"
    response = connection.get(signature, resource_url, query_params)
    puts "Response is #{response}"
    geo = GeoResponseBuilder.new()
    geoObjList = geo.buildArrayResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return geoObjList
end

#get_all_points_by_paging(storageName, max, offset) ⇒ Object

NEW METHOD



468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
# File 'lib/geo/GeoService.rb', line 468

def get_all_points_by_paging(storageName, max, offset)
  puts "get_all_points_by_paging Called "
  puts "Base url #{@base_url}"
  response = nil;
  geoList = nil;
  geoList = Array.new();
  util = Util.new
  util.throwExceptionIfNullOrBlank(storageName, "Geo Storage Name");
  util.throwExceptionIfNullOrBlank(max, "Max");
  util.throwExceptionIfNullOrBlank(offset, "Offset");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("storageName", storageName);
    params.store("max", "" + (max.to_i).to_s)
    params.store("offset", "" + (offset.to_i).to_s)
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/paging/points/#{storageName}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
    response = connection.get(signature, resource_url, query_params)
    geo = GeoResponseBuilder.new()
    geoList = geo.buildArrayResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return geoList
end

#get_all_storageObject

Fetch the name of all storage stored on the cloud

Returns:

  • Geo object containing list of all the storage created

Raises:

  • App42Exception



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/geo/GeoService.rb', line 273

def get_all_storage()
  puts "Get All Storage Called "
  puts "Base url #{@base_url}"
  response = nil
  geoObj = nil;
  geoObjList = Array.new
  util = Util.new
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/storage"
    response = connection.get(signature, resource_url, query_params)
    geo = GeoResponseBuilder.new
    geoObjList = geo.buildArrayResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  puts geoObjList[0].createdOn
  return geoObjList
end

#get_all_storage_by_paging(max, offset) ⇒ Object

NEW METHOD



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# File 'lib/geo/GeoService.rb', line 387

def get_all_storage_by_paging(max, offset)
  puts "get_all_storage_by_paging Called "
  puts "Base url #{@base_url}"
  response = nil;
  geoObjList = nil;
  geoObjList = Array.new();
  util = Util.new
  util.throwExceptionIfNullOrBlank(max, "Max");
  util.throwExceptionIfNullOrBlank(offset, "Offset");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("max", "" + (max.to_i).to_s)
    params.store("offset", "" + (offset.to_i).to_s)
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/paging/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
    response = connection.get(signature, resource_url, query_params)
    geo = GeoResponseBuilder.new()
    geoObjList = geo.buildArrayResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return geoObjList
end

#get_near_by_point(storageName, lat, lng, resultLimit) ⇒ Object

Search the near by point from specified source point. Points to be searched should already be stored on cloud using unique storage name handler.

Parameters:

  • storageName
    • Unique handler for storage name

  • lat
    • Lattitude of source point

  • lng
    • Longitude of source point

  • resultLimit
    • Maximum number of results to be retrieved

Returns:

  • Geo object containing the target points in ascending order of distance from source point.

Raises:

  • App42Exception



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/geo/GeoService.rb', line 169

def get_near_by_point(storageName,lat,lng,resultLimit)
  puts "Get Near By Points By Point Called"
  puts "Base url #{@base_url}"
  response = nil;
  geoObj = nil;
  geoObj = Geo.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(storageName, "Geo Storage Name");
  util.throwExceptionIfNullOrBlank(lat, "Latitute");
  util.throwExceptionIfNullOrBlank(lng, "langitude");
  util.throwExceptionIfNullOrBlank(resultLimit, "resultLimit");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("storageName", storageName)
    params.store("lat", lat.to_s + "")
    params.store("lng", lng.to_s + "")
    params.store("resultLimit", resultLimit.to_s+ "")
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/getNearByPoint/storageName/#{storageName}/lat/#{lat}/lng/#{lng}/limit/#{resultLimit}"
    response = connection.get(signature, resource_url, query_params)
    geo = GeoResponseBuilder.new
    geoObj = geo.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return geoObj
end

#get_near_by_points_by_max_distance(storageName, lat, lng, distanceInKM) ⇒ Object

Search the near by point in given range(In KM) from specified source point. Points to be searched should already be stored on cloud using unique storage name handler.

Parameters:

  • storageName
    • Unique handler for storage name

  • lat
    • Latitude of source point

  • lng
    • Longitude of source point

  • distanceInKM
    • Range in KM

Returns:

  • Geo object containing the target points in ascending order of distance from source point.

Raises:

  • App42Exception



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/geo/GeoService.rb', line 114

def get_near_by_points_by_max_distance(storageName,lat,lng,distanceInKM)
  puts "Get Near By Points By Max Distance Called"
  puts "Base url #{@base_url}"
  response = nil;
  geoObj = nil;
  geoObj = Geo.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(storageName, "Geo Storage Name");
  util.throwExceptionIfNullOrBlank(lat, "Latitute");
  util.throwExceptionIfNullOrBlank(lng, "langitude");
  util.throwExceptionIfNullOrBlank(distanceInKM, "Distance In KM");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("storageName", storageName)
    params.store("lat", lat.to_s + "")
    params.store("lng",lng.to_s + "")
    params.store("distanceInKM", distanceInKM.to_s + "")
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/getNearByPoints/storageName/#{storageName}/lat/#{lat}/lng/#{lng}/distanceInKM/#{distanceInKM}"
    response = connection.get(signature, resource_url, query_params)
    geo = GeoResponseBuilder.new
    geoObj = geo.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return geoObj
end

#get_points_with_in_circle(storageName, lat, lng, radiusInKM, resultLimit) ⇒ Object

Search the near by point from specified source point with in specified radius. Points to be searched should already be stored on cloud using unique storage name handler.

Parameters:

  • storageName
    • Unique handler for storage name

  • lat
    • Lattitude of source point

  • lng
    • Longitude of source point

  • radiusInKM
    • Radius in KM

  • resultLimit
    • Maximum number of results to be retrieved

Returns:

  • Geo object containing the target points in ascending order of distance from source point.

Raises:

  • App42Exception



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/geo/GeoService.rb', line 226

def  get_points_with_in_circle(storageName,lat,lng,radiusInKM,resultLimit)
  puts "Get Near By Points By Max Distance Called"
  puts "Base url #{@base_url}"
  response = nil;
  geoObj = nil;
  geoObj = Geo.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(storageName, "Geo Storage Name");
  util.throwExceptionIfNullOrBlank(lat, "Latitute");
  util.throwExceptionIfNullOrBlank(lng, "langitude");
  util.throwExceptionIfNullOrBlank(radiusInKM, "Radius In KM");
  util.throwExceptionIfNullOrBlank(resultLimit, "Result Limit");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("storageName", storageName)
    params.store("lat", lat.to_s + "")
    params.store("lng", lng.to_s + "")
    params.store("resultLimit", resultLimit.to_s + "")
    params.store("radiusInKM", radiusInKM.to_s + "")
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/getPointsWithInCircle/storageName/#{storageName}/lat/#{lat}/lng/#{lng}/radiusInKM/#{radiusInKM}/limit/#{resultLimit}"
    response = connection.get(signature, resource_url, query_params)
    geo = GeoResponseBuilder.new
    geoObj = geo.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return geoObj
end