App42_Ruby_API 0.8.4
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/.gitignore +21 -0
- data/App42_Ruby_API.gemspec +33 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/TODO.rb +3 -0
- data/lib/App42_Ruby_API.rb +232 -0
- data/lib/App42_Ruby_API/App42BadParameterException.rb +31 -0
- data/lib/App42_Ruby_API/App42Exception.rb +39 -0
- data/lib/App42_Ruby_API/App42LimitException.rb +15 -0
- data/lib/App42_Ruby_API/App42NotFoundException.rb +15 -0
- data/lib/App42_Ruby_API/App42Response.rb +13 -0
- data/lib/App42_Ruby_API/App42ResponseBuilder.rb +67 -0
- data/lib/App42_Ruby_API/App42SecurityException.rb +15 -0
- data/lib/App42_Ruby_API/version.rb +3 -0
- data/lib/connection/RESTConnection.rb +713 -0
- data/lib/email/Email.rb +51 -0
- data/lib/email/EmailMIME.rb +51 -0
- data/lib/email/EmailResponseBuilder.rb +76 -0
- data/lib/email/EmailService.rb +244 -0
- data/lib/gallery/Album.rb +56 -0
- data/lib/gallery/AlbumResponseBuilder.rb +168 -0
- data/lib/gallery/AlbumService.rb +337 -0
- data/lib/gallery/PhotoService.rb +591 -0
- data/lib/game/Game.rb +39 -0
- data/lib/game/GameResponseBuilder.rb +106 -0
- data/lib/game/GameService.rb +268 -0
- data/lib/game/Reward.rb +24 -0
- data/lib/game/RewardResponseBuilder.rb +85 -0
- data/lib/game/RewardService.rb +440 -0
- data/lib/game/ScoreBoardService.rb +433 -0
- data/lib/game/ScoreService.rb +157 -0
- data/lib/geo/Geo.rb +51 -0
- data/lib/geo/GeoPoint.rb +43 -0
- data/lib/geo/GeoResponseBuilder.rb +145 -0
- data/lib/geo/GeoService.rb +505 -0
- data/lib/imageProcessor/Image.rb +42 -0
- data/lib/imageProcessor/ImageProcessorResponseBuilder.rb +40 -0
- data/lib/imageProcessor/ImageProcessorService.rb +1054 -0
- data/lib/log/Log.rb +49 -0
- data/lib/log/LogResponseBuilder.rb +61 -0
- data/lib/log/LogService.rb +920 -0
- data/lib/message/Queue.rb +50 -0
- data/lib/message/QueueResponseBuilder.rb +64 -0
- data/lib/message/QueueService.rb +469 -0
- data/lib/push/DeviceType.rb +56 -0
- data/lib/push/PushNotification.rb +38 -0
- data/lib/push/PushNotificationResposneBuilder.rb +74 -0
- data/lib/push/PushNotificationService.rb +458 -0
- data/lib/recommend/PreferenceData.rb +25 -0
- data/lib/recommend/Recommender.rb +48 -0
- data/lib/recommend/RecommenderResponseBuilder.rb +70 -0
- data/lib/recommend/RecommenderService.rb +1092 -0
- data/lib/recommend/RecommenderSimilarity.rb +52 -0
- data/lib/review/Review.rb +38 -0
- data/lib/review/ReviewResponseBuilder.rb +76 -0
- data/lib/review/ReviewService.rb +590 -0
- data/lib/session/Session.rb +43 -0
- data/lib/session/SessionResponseBuilder.rb +70 -0
- data/lib/session/SessionService.rb +427 -0
- data/lib/shopping/Cart.rb +77 -0
- data/lib/shopping/CartResponseBuilder.rb +118 -0
- data/lib/shopping/CartService.rb +902 -0
- data/lib/shopping/Catalogue.rb +79 -0
- data/lib/shopping/CatalogueResponseBuilder.rb +170 -0
- data/lib/shopping/CatalogueService.rb +649 -0
- data/lib/shopping/ItemData.rb +29 -0
- data/lib/shopping/PaymentStatus.rb +60 -0
- data/lib/social/Social.rb +35 -0
- data/lib/social/SocialResponseBuilder.rb +38 -0
- data/lib/social/SocialService.rb +585 -0
- data/lib/storage/OrderByType.rb +29 -0
- data/lib/storage/Query.rb +39 -0
- data/lib/storage/QueryBuilder.rb +118 -0
- data/lib/storage/Storage.rb +45 -0
- data/lib/storage/StorageResponseBuilder.rb +86 -0
- data/lib/storage/StorageService.rb +775 -0
- data/lib/upload/Upload.rb +40 -0
- data/lib/upload/UploadFileType.rb +83 -0
- data/lib/upload/UploadResponseBuilder.rb +58 -0
- data/lib/upload/UploadService.rb +960 -0
- data/lib/user/User.rb +102 -0
- data/lib/user/UserResponseBuilder.rb +105 -0
- data/lib/user/UserService.rb +1209 -0
- data/lib/util/util.rb +244 -0
- data/question.rb +79 -0
- metadata +204 -0
@@ -0,0 +1,157 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'connection/RESTConnection'
|
6
|
+
require 'util/util'
|
7
|
+
require 'json/pure'
|
8
|
+
|
9
|
+
module App42
|
10
|
+
module Game
|
11
|
+
#
|
12
|
+
# Allows ingame scoring. It has to be used for scoring for a parituclar Game
|
13
|
+
# Session. If scores have to be stored across Game sessions then the service
|
14
|
+
# ScoreBoard has to be used. It is especially useful for Multiplayer online or
|
15
|
+
# mobile games. The Game service allows Game, User, Score and ScoreBoard
|
16
|
+
# Management on the Cloud. The service allows Game Developer to create a Game
|
17
|
+
# and then do in Game Scoring using the Score service. It also allows to
|
18
|
+
# maintain a Scoreboard across game sessions using the ScoreBoard service. One
|
19
|
+
# can query for average or highest score for user for a Game and highest and
|
20
|
+
# average score across users for a Game. It also gives ranking of the user
|
21
|
+
# against other users for a particular game. The Reward and RewardPoints allows
|
22
|
+
# the Game Developer to assign rewards to a user and redeem the rewards. E.g.
|
23
|
+
# One can give Swords or Energy etc. The services Game, Score, ScoreBoard,
|
24
|
+
# Reward, RewardPoints can be used in Conjunction for complete Game Scoring and
|
25
|
+
# Reward Management.
|
26
|
+
#
|
27
|
+
# @see Game, RewardPoint, RewardPoint, ScoreBoard
|
28
|
+
#
|
29
|
+
class ScoreService
|
30
|
+
#
|
31
|
+
# this is a constructor that takes
|
32
|
+
#
|
33
|
+
# @param apiKey
|
34
|
+
# @param secretKey
|
35
|
+
# @param baseURL
|
36
|
+
#
|
37
|
+
def initialize(api_key, secret_key, base_url)
|
38
|
+
puts "Game->initialize"
|
39
|
+
@api_key = api_key
|
40
|
+
@secret_key = secret_key
|
41
|
+
@base_url = base_url
|
42
|
+
@resource = "game/score"
|
43
|
+
@version = "1.0"
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Adds game score for the specified user.
|
48
|
+
#
|
49
|
+
# @param gameName
|
50
|
+
# - Name of the game for which scores have to be added
|
51
|
+
# @param gameUserName
|
52
|
+
# - The user for whom scores have to be added
|
53
|
+
# @param gameScore
|
54
|
+
# - nThe scores that have to be added
|
55
|
+
#
|
56
|
+
# @return Game object containing the scores that has been added
|
57
|
+
#
|
58
|
+
# @raise App42Exception
|
59
|
+
#
|
60
|
+
|
61
|
+
def addScore(gameName, gameUserName, gameScore)
|
62
|
+
puts "Add score Called "
|
63
|
+
puts "Base url #{@base_url}"
|
64
|
+
response = nil;
|
65
|
+
scoreObj = nil;
|
66
|
+
scoreObj = Game.new
|
67
|
+
util = Util.new
|
68
|
+
util.throwExceptionIfNullOrBlank(gameName, "Game Name");
|
69
|
+
util.throwExceptionIfNullOrBlank(gameUserName, "User Name");
|
70
|
+
begin
|
71
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
72
|
+
body = {'app42' => {"game"=> {
|
73
|
+
"name" => gameName,"scores" => { "score" => {
|
74
|
+
"value" => gameScore,
|
75
|
+
"userName" => gameUserName
|
76
|
+
}}}}}.to_json
|
77
|
+
puts "Body #{body}"
|
78
|
+
query_params = Hash.new
|
79
|
+
params = {
|
80
|
+
'apiKey'=> @api_key,
|
81
|
+
'version' => @version,
|
82
|
+
'timeStamp' => util.get_timestamp_utc,
|
83
|
+
}
|
84
|
+
query_params = params.clone
|
85
|
+
params.store("body", body)
|
86
|
+
puts query_params
|
87
|
+
signature = util.sign(@secret_key, params)
|
88
|
+
resource_url = "#{@version}/#{@resource}/add"
|
89
|
+
response = connection.post(signature, resource_url, query_params, body)
|
90
|
+
puts "Response is #{response}"
|
91
|
+
game = GameResponseBuilder.new()
|
92
|
+
scoreObj = game.buildResponse(response)
|
93
|
+
rescue App42Exception =>e
|
94
|
+
raise e
|
95
|
+
rescue Exception => e
|
96
|
+
raise App42Exception.new(e)
|
97
|
+
end
|
98
|
+
return scoreObj
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Deducts the score from users account for a particular Game
|
103
|
+
#
|
104
|
+
# @param gameName
|
105
|
+
# - Name of the game for which scores have to be deducted
|
106
|
+
# @param gameUserName
|
107
|
+
# - The user for whom scores have to be deducted
|
108
|
+
# @param gameScore
|
109
|
+
# - The scores that have to be deducted
|
110
|
+
#
|
111
|
+
# @return Game object containing the scores that has been deducted
|
112
|
+
#
|
113
|
+
# @raise App42Exception
|
114
|
+
#
|
115
|
+
|
116
|
+
def deductScore(gameName, gameUserName, gameScore)
|
117
|
+
puts "Deduct Score Called "
|
118
|
+
puts "Base url #{@base_url}"
|
119
|
+
response = nil;
|
120
|
+
scoreObj = nil;
|
121
|
+
scoreObj = Game.new
|
122
|
+
util = Util.new
|
123
|
+
util.throwExceptionIfNullOrBlank(gameName, "Game Name");
|
124
|
+
util.throwExceptionIfNullOrBlank(gameUserName, "User Name");
|
125
|
+
begin
|
126
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
127
|
+
body = {'app42' => {"game"=> {
|
128
|
+
"name" => gameName,"scores" => { "score" => {
|
129
|
+
"value" => gameScore,
|
130
|
+
"userName" => gameUserName
|
131
|
+
}}}}}.to_json
|
132
|
+
puts "Body #{body}"
|
133
|
+
query_params = Hash.new
|
134
|
+
params = {
|
135
|
+
'apiKey'=> @api_key,
|
136
|
+
'version' => @version,
|
137
|
+
'timeStamp' => util.get_timestamp_utc,
|
138
|
+
}
|
139
|
+
query_params = params.clone
|
140
|
+
query_params = params.clone
|
141
|
+
params.store("body", body)
|
142
|
+
signature = util.sign(@secret_key, params)
|
143
|
+
resource_url = "#{@version}/#{@resource}/deduct"
|
144
|
+
response = connection.post(signature, resource_url, query_params,body)
|
145
|
+
puts "Response is #{response}"
|
146
|
+
game = GameResponseBuilder.new()
|
147
|
+
scoreObj = game.buildResponse(response)
|
148
|
+
rescue App42Exception =>e
|
149
|
+
raise e
|
150
|
+
rescue Exception => e
|
151
|
+
raise App42Exception.new(e)
|
152
|
+
end
|
153
|
+
return scoreObj
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
data/lib/geo/Geo.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'App42_Ruby_API/App42Response'
|
6
|
+
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# This Geo object is the value object which contains the properties of Geo.
|
10
|
+
#
|
11
|
+
#
|
12
|
+
|
13
|
+
module App42
|
14
|
+
module Geo
|
15
|
+
class Geo < App42Response
|
16
|
+
attr_accessor :pointList,:storageName,:sourceLat,:sourceLng,:distanceInKM,:createdOn
|
17
|
+
@pointList = Array.new
|
18
|
+
@storageName
|
19
|
+
@sourceLat
|
20
|
+
@sourceLng
|
21
|
+
@distanceInKM
|
22
|
+
@createdOn
|
23
|
+
end
|
24
|
+
|
25
|
+
class Point
|
26
|
+
attr_accessor :lat,:lng,:marker
|
27
|
+
#
|
28
|
+
# This is a constructor that takes no parameter
|
29
|
+
#
|
30
|
+
#
|
31
|
+
def initialize(geo)
|
32
|
+
geo.pointList.push(self);
|
33
|
+
end
|
34
|
+
@lat
|
35
|
+
@lng
|
36
|
+
@marker
|
37
|
+
|
38
|
+
#
|
39
|
+
# Returns the Geo Response in JSON format.
|
40
|
+
#
|
41
|
+
# @return the response in JSON format.
|
42
|
+
#
|
43
|
+
#
|
44
|
+
|
45
|
+
def to_s
|
46
|
+
return "Lat : #{@lat}" + "Long : #{@lng}" + "Marker : #{@marker}";
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/geo/GeoPoint.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'App42_Ruby_API/App42Response'
|
6
|
+
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# This Geo Point object is the value object which contains the properties of
|
10
|
+
# Geo Point.
|
11
|
+
#
|
12
|
+
#
|
13
|
+
|
14
|
+
module App42
|
15
|
+
module Geo
|
16
|
+
class GeoPoint < App42Response
|
17
|
+
attr_accessor :lat,:lng,:marker
|
18
|
+
@lat
|
19
|
+
@lng
|
20
|
+
@marker
|
21
|
+
def GeoPoint(lat, lng, marker)
|
22
|
+
@lat = lat
|
23
|
+
@lng = lng
|
24
|
+
@marker = marker
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# Values coming from response are converted into JSON format.
|
29
|
+
#
|
30
|
+
# @return JSON Response
|
31
|
+
# @throws JSONException
|
32
|
+
#
|
33
|
+
|
34
|
+
def getJSONObject()
|
35
|
+
obj = Hash.new
|
36
|
+
obj.store("lat", lat);
|
37
|
+
obj.store("lng", lng);
|
38
|
+
obj.store("marker", marker);
|
39
|
+
return obj
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'json/pure'
|
6
|
+
require 'App42_Ruby_API/App42ResponseBuilder'
|
7
|
+
require 'geo/Geo'
|
8
|
+
require 'geo/GeoPoint'
|
9
|
+
|
10
|
+
module App42
|
11
|
+
module Geo
|
12
|
+
#
|
13
|
+
#
|
14
|
+
# GeoResponseBuilder class converts the JSON response retrieved from the server
|
15
|
+
# to the value object i.e Geo
|
16
|
+
#
|
17
|
+
#
|
18
|
+
class GeoResponseBuilder < App42ResponseBuilder
|
19
|
+
#
|
20
|
+
# Converts the response in JSON format to the value object i.e Geo
|
21
|
+
#
|
22
|
+
# @param json
|
23
|
+
# - response in JSON format
|
24
|
+
#
|
25
|
+
# @return Geo object filled with json data
|
26
|
+
#
|
27
|
+
#
|
28
|
+
def buildResponse(json)
|
29
|
+
puts "testing #{json}"
|
30
|
+
geoObj = Geo.new()
|
31
|
+
pointList = Array.new
|
32
|
+
geoObj.pointList=(pointList)
|
33
|
+
|
34
|
+
geoObj.strResponse=json
|
35
|
+
jsonObj = JSON.parse(json)
|
36
|
+
jsonObjApp42 = jsonObj.fetch("app42")
|
37
|
+
jsonObjResponse = jsonObjApp42.fetch("response")
|
38
|
+
geoObj.isResponseSuccess = jsonObjResponse.fetch("success")
|
39
|
+
jsonObjGeoStorage = jsonObjResponse.fetch("geo").fetch("storage")
|
40
|
+
|
41
|
+
buildObjectFromJSONTree(geoObj, jsonObjGeoStorage);
|
42
|
+
|
43
|
+
if jsonObjGeoStorage.key?("points") == false
|
44
|
+
return geoObj
|
45
|
+
end
|
46
|
+
|
47
|
+
buildInternalObj(geoObj, jsonObjGeoStorage);
|
48
|
+
return geoObj;
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# Converts the response in JSON format to the list of value objects i.e Geo
|
53
|
+
#
|
54
|
+
# @param json
|
55
|
+
# - response in JSON format
|
56
|
+
#
|
57
|
+
# @return List of Geo Points object filled with json data
|
58
|
+
#
|
59
|
+
#
|
60
|
+
|
61
|
+
def buildArrayResponse(json)
|
62
|
+
geoObjList = Array.new
|
63
|
+
|
64
|
+
jsonObj = JSON.parse(json)
|
65
|
+
jsonObjApp42 = jsonObj.fetch("app42")
|
66
|
+
jsonObjResponse = jsonObjApp42.fetch("response")
|
67
|
+
jsonObjGeoStorage = jsonObjResponse.fetch("geo")
|
68
|
+
|
69
|
+
if jsonObjGeoStorage.fetch("storage").instance_of?(Hash)
|
70
|
+
#Single Item
|
71
|
+
jsonObjGeoStorage = jsonObjGeoStorage.fetch("storage");
|
72
|
+
geoObj = App42::Geo::Geo.new()
|
73
|
+
pointList = Array.new
|
74
|
+
geoObj.pointList=pointList
|
75
|
+
geoObj.strResponse=json
|
76
|
+
geoObj.isResponseSuccess = jsonObjResponse.fetch("success")
|
77
|
+
|
78
|
+
buildObjectFromJSONTree(geoObj, jsonObjGeoStorage);
|
79
|
+
geoObjList.push(geoObj)
|
80
|
+
|
81
|
+
if jsonObjGeoStorage.key?("points")
|
82
|
+
buildInternalObj(geoObj,jsonObjGeoStorage);
|
83
|
+
end
|
84
|
+
|
85
|
+
else
|
86
|
+
jsonStorageArray = jsonObjGeoStorage.fetch("storage");
|
87
|
+
|
88
|
+
jsonStorageArray.length.times do |i|
|
89
|
+
jsonObjStorage = jsonStorageArray[i]
|
90
|
+
geoObj = App42::Geo::Geo.new()
|
91
|
+
pointList = Array.new
|
92
|
+
geoObj.pointList=pointList
|
93
|
+
geoObj.strResponse=json
|
94
|
+
geoObj.isResponseSuccess = jsonObjResponse.fetch("success")
|
95
|
+
buildObjectFromJSONTree(geoObj, jsonObjStorage);
|
96
|
+
geoObjList.push(geoObj)
|
97
|
+
|
98
|
+
if jsonObjStorage.key?("points")
|
99
|
+
buildInternalObj(geoObj,jsonObjStorage);
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
return geoObjList
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
# Converts the Geo JSON object to the value object i.e Geo
|
109
|
+
#
|
110
|
+
# @param jsonObjGeoStorage
|
111
|
+
# - geo data as JSONObject
|
112
|
+
# @param geoObj
|
113
|
+
# - new geo object
|
114
|
+
#
|
115
|
+
# @return Geo object filled with json data
|
116
|
+
#
|
117
|
+
#
|
118
|
+
|
119
|
+
def buildInternalObj(geoObj, jsonObjGeoStorage)
|
120
|
+
jsonGeoPoints = jsonObjGeoStorage.fetch("points");
|
121
|
+
|
122
|
+
if jsonGeoPoints.key?("point") == false
|
123
|
+
return geoObj
|
124
|
+
end
|
125
|
+
|
126
|
+
if jsonGeoPoints.fetch("point").instance_of?(Hash)
|
127
|
+
#Only One attribute is there
|
128
|
+
jsonObjPoint = jsonGeoPoints.fetch("point")
|
129
|
+
pointsItem = App42::Geo::Point.new(geoObj)
|
130
|
+
buildObjectFromJSONTree(pointsItem, jsonObjPoint);
|
131
|
+
else
|
132
|
+
#There is an Array of attribute
|
133
|
+
jsonObjPointsArray = jsonGeoPoints.fetch("point");
|
134
|
+
jsonObjPointsArray.length.times do |i|
|
135
|
+
jsonObjPoint = jsonObjPointsArray[i]
|
136
|
+
pointsItem = App42::Geo::Point.new(geoObj)
|
137
|
+
buildObjectFromJSONTree(pointsItem, jsonObjPoint);
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
141
|
+
return geoObj;
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,505 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'connection/RESTConnection'
|
6
|
+
require 'util/util'
|
7
|
+
require 'json/pure'
|
8
|
+
require 'App42_Ruby_API/App42Response'
|
9
|
+
require 'geo/GeoResponseBuilder'
|
10
|
+
require 'geo/Geo'
|
11
|
+
require 'geo/GeoPoint'
|
12
|
+
require 'bigdecimal'
|
13
|
+
|
14
|
+
module App42
|
15
|
+
module Geo
|
16
|
+
#
|
17
|
+
# Geo Spatial Service on cloud provides the storage, retrieval, querying and updating geo data.
|
18
|
+
# One can store the geo data by unique handler on the cloud and can apply search, update and query on it.
|
19
|
+
# Geo spatial query includes finding nearby/In circle target point from given point using geo points stored on the cloud.
|
20
|
+
#
|
21
|
+
# @see Geo
|
22
|
+
#
|
23
|
+
class GeoService
|
24
|
+
#
|
25
|
+
# this is a constructor that takes
|
26
|
+
#
|
27
|
+
# @param apiKey
|
28
|
+
# @param secretKey
|
29
|
+
# @param baseURL
|
30
|
+
#
|
31
|
+
def initialize(api_key, secret_key, base_url)
|
32
|
+
puts "Geo->initialize"
|
33
|
+
@api_key = api_key
|
34
|
+
@secret_key = secret_key
|
35
|
+
@base_url = base_url
|
36
|
+
@resource = "geo"
|
37
|
+
@version = "1.0"
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Stores the geo points with unique handler on the cloud. Geo point data contains lat, long and marker of the point.
|
42
|
+
#
|
43
|
+
# @param geoStorageName
|
44
|
+
# - Unique handler for storage name
|
45
|
+
# @param geoPointsList
|
46
|
+
# - List of Geo Points to be saved
|
47
|
+
#
|
48
|
+
# @return Geo object containing list of Geo Points that have been saved
|
49
|
+
#
|
50
|
+
# @raise App42Exception
|
51
|
+
#
|
52
|
+
|
53
|
+
def create_geo_points(geoStorageName, geoPointsList)
|
54
|
+
puts "Create GeoPoints Called "
|
55
|
+
puts "Base url #{@base_url}"
|
56
|
+
response = nil;
|
57
|
+
geoObj = nil;
|
58
|
+
geoObj = Geo.new
|
59
|
+
util = Util.new
|
60
|
+
util.throwExceptionIfNullOrBlank(geoStorageName, "Geo Storage Name");
|
61
|
+
util.throwExceptionIfNullOrBlank(geoPointsList, "Geo Points List");
|
62
|
+
begin
|
63
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
64
|
+
geoArray = Array.new
|
65
|
+
for geoPoint in geoPointsList do
|
66
|
+
geoArray.push(geoPoint)
|
67
|
+
end
|
68
|
+
body = {'app42' => {"geo"=> { "storage"=> {
|
69
|
+
"storageName" => geoStorageName,
|
70
|
+
"points" =>{ "point" => geoArray.to_json
|
71
|
+
}}}}}.to_json
|
72
|
+
puts "Body #{body}"
|
73
|
+
params = Hash.new
|
74
|
+
query_params = Hash.new
|
75
|
+
params = {
|
76
|
+
'apiKey'=> @api_key,
|
77
|
+
'version' => @version,
|
78
|
+
'timeStamp' => util.get_timestamp_utc,
|
79
|
+
}
|
80
|
+
query_params = params.clone
|
81
|
+
params.store("body", body)
|
82
|
+
puts query_params
|
83
|
+
signature = util.sign(@secret_key, params)
|
84
|
+
resource_url = "#{@version}/#{@resource}/createGeoPoints"
|
85
|
+
response = connection.post(signature, resource_url, query_params, body)
|
86
|
+
geo = GeoResponseBuilder.new()
|
87
|
+
geoObj = geo.buildResponse(response)
|
88
|
+
rescue App42Exception =>e
|
89
|
+
raise e
|
90
|
+
rescue Exception => e
|
91
|
+
raise App42Exception.new(e)
|
92
|
+
end
|
93
|
+
return geoObj
|
94
|
+
end
|
95
|
+
|
96
|
+
#
|
97
|
+
# Search the near by point in given range(In KM) from specified source point.
|
98
|
+
# Points to be searched should already be stored on cloud using unique storage name handler.
|
99
|
+
#
|
100
|
+
# @param storageName
|
101
|
+
# - Unique handler for storage name
|
102
|
+
# @param lat
|
103
|
+
# - Latitude of source point
|
104
|
+
# @param lng
|
105
|
+
# - Longitude of source point
|
106
|
+
# @param distanceInKM
|
107
|
+
# - Range in KM
|
108
|
+
#
|
109
|
+
# @return Geo object containing the target points in ascending order of distance from source point.
|
110
|
+
#
|
111
|
+
# @raise App42Exception
|
112
|
+
#
|
113
|
+
|
114
|
+
def get_near_by_points_by_max_distance(storageName,lat,lng,distanceInKM)
|
115
|
+
puts "Get Near By Points By Max Distance Called"
|
116
|
+
puts "Base url #{@base_url}"
|
117
|
+
response = nil;
|
118
|
+
geoObj = nil;
|
119
|
+
geoObj = Geo.new
|
120
|
+
util = Util.new
|
121
|
+
util.throwExceptionIfNullOrBlank(storageName, "Geo Storage Name");
|
122
|
+
util.throwExceptionIfNullOrBlank(lat, "Latitute");
|
123
|
+
util.throwExceptionIfNullOrBlank(lng, "langitude");
|
124
|
+
util.throwExceptionIfNullOrBlank(distanceInKM, "Distance In KM");
|
125
|
+
begin
|
126
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
127
|
+
query_params = Hash.new
|
128
|
+
params = {
|
129
|
+
'apiKey'=> @api_key,
|
130
|
+
'version' => @version,
|
131
|
+
'timeStamp' => util.get_timestamp_utc,
|
132
|
+
}
|
133
|
+
query_params = params.clone
|
134
|
+
params.store("storageName", storageName)
|
135
|
+
params.store("lat", lat.to_s + "")
|
136
|
+
params.store("lng",lng.to_s + "")
|
137
|
+
params.store("distanceInKM", distanceInKM.to_s + "")
|
138
|
+
signature = util.sign(@secret_key, params)
|
139
|
+
resource_url = "#{@version}/#{@resource}/getNearByPoints/storageName/#{storageName}/lat/#{lat}/lng/#{lng}/distanceInKM/#{distanceInKM}"
|
140
|
+
response = connection.get(signature, resource_url, query_params)
|
141
|
+
geo = GeoResponseBuilder.new
|
142
|
+
geoObj = geo.buildResponse(response)
|
143
|
+
rescue App42Exception =>e
|
144
|
+
raise e
|
145
|
+
rescue Exception => e
|
146
|
+
raise App42Exception.new(e)
|
147
|
+
end
|
148
|
+
return geoObj
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# Search the near by point from specified source point.
|
153
|
+
# Points to be searched should already be stored on cloud using unique storage name handler.
|
154
|
+
#
|
155
|
+
# @param storageName
|
156
|
+
# - Unique handler for storage name
|
157
|
+
# @param lat
|
158
|
+
# - Lattitude of source point
|
159
|
+
# @param lng
|
160
|
+
# - Longitude of source point
|
161
|
+
# @param resultLimit
|
162
|
+
# - Maximum number of results to be retrieved
|
163
|
+
#
|
164
|
+
# @return Geo object containing the target points in ascending order of distance from source point.
|
165
|
+
#
|
166
|
+
# @raise App42Exception
|
167
|
+
#
|
168
|
+
|
169
|
+
def get_near_by_point(storageName,lat,lng,resultLimit)
|
170
|
+
puts "Get Near By Points By Point Called"
|
171
|
+
puts "Base url #{@base_url}"
|
172
|
+
response = nil;
|
173
|
+
geoObj = nil;
|
174
|
+
geoObj = Geo.new
|
175
|
+
util = Util.new
|
176
|
+
util.throwExceptionIfNullOrBlank(storageName, "Geo Storage Name");
|
177
|
+
util.throwExceptionIfNullOrBlank(lat, "Latitute");
|
178
|
+
util.throwExceptionIfNullOrBlank(lng, "langitude");
|
179
|
+
util.throwExceptionIfNullOrBlank(resultLimit, "resultLimit");
|
180
|
+
begin
|
181
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
182
|
+
query_params = Hash.new
|
183
|
+
params = {
|
184
|
+
'apiKey'=> @api_key,
|
185
|
+
'version' => @version,
|
186
|
+
'timeStamp' => util.get_timestamp_utc,
|
187
|
+
}
|
188
|
+
query_params = params.clone
|
189
|
+
params.store("storageName", storageName)
|
190
|
+
params.store("lat", lat.to_s + "")
|
191
|
+
params.store("lng", lng.to_s + "")
|
192
|
+
params.store("resultLimit", resultLimit.to_s+ "")
|
193
|
+
signature = util.sign(@secret_key, params)
|
194
|
+
resource_url = "#{@version}/#{@resource}/getNearByPoint/storageName/#{storageName}/lat/#{lat}/lng/#{lng}/limit/#{resultLimit}"
|
195
|
+
response = connection.get(signature, resource_url, query_params)
|
196
|
+
geo = GeoResponseBuilder.new
|
197
|
+
geoObj = geo.buildResponse(response)
|
198
|
+
rescue App42Exception =>e
|
199
|
+
raise e
|
200
|
+
rescue Exception => e
|
201
|
+
raise App42Exception.new(e)
|
202
|
+
end
|
203
|
+
return geoObj
|
204
|
+
end
|
205
|
+
|
206
|
+
#
|
207
|
+
# Search the near by point from specified source point with in specified radius.
|
208
|
+
# Points to be searched should already be stored on cloud using unique storage name handler.
|
209
|
+
#
|
210
|
+
# @param storageName
|
211
|
+
# - Unique handler for storage name
|
212
|
+
# @param lat
|
213
|
+
# - Lattitude of source point
|
214
|
+
# @param lng
|
215
|
+
# - Longitude of source point
|
216
|
+
# @param radiusInKM
|
217
|
+
# - Radius in KM
|
218
|
+
# @param resultLimit
|
219
|
+
# - Maximum number of results to be retrieved
|
220
|
+
#
|
221
|
+
# @return Geo object containing the target points in ascending order of distance from source point.
|
222
|
+
#
|
223
|
+
# @raise App42Exception
|
224
|
+
#
|
225
|
+
|
226
|
+
def get_points_with_in_circle(storageName,lat,lng,radiusInKM,resultLimit)
|
227
|
+
puts "Get Near By Points By Max Distance Called"
|
228
|
+
puts "Base url #{@base_url}"
|
229
|
+
response = nil;
|
230
|
+
geoObj = nil;
|
231
|
+
geoObj = Geo.new
|
232
|
+
util = Util.new
|
233
|
+
util.throwExceptionIfNullOrBlank(storageName, "Geo Storage Name");
|
234
|
+
util.throwExceptionIfNullOrBlank(lat, "Latitute");
|
235
|
+
util.throwExceptionIfNullOrBlank(lng, "langitude");
|
236
|
+
util.throwExceptionIfNullOrBlank(radiusInKM, "Radius In KM");
|
237
|
+
util.throwExceptionIfNullOrBlank(resultLimit, "Result Limit");
|
238
|
+
begin
|
239
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
240
|
+
query_params = Hash.new
|
241
|
+
params = {
|
242
|
+
'apiKey'=> @api_key,
|
243
|
+
'version' => @version,
|
244
|
+
'timeStamp' => util.get_timestamp_utc,
|
245
|
+
}
|
246
|
+
query_params = params.clone
|
247
|
+
params.store("storageName", storageName)
|
248
|
+
params.store("lat", lat.to_s + "")
|
249
|
+
params.store("lng", lng.to_s + "")
|
250
|
+
params.store("resultLimit", resultLimit.to_s + "")
|
251
|
+
params.store("radiusInKM", radiusInKM.to_s + "")
|
252
|
+
signature = util.sign(@secret_key, params)
|
253
|
+
resource_url = "#{@version}/#{@resource}/getPointsWithInCircle/storageName/#{storageName}/lat/#{lat}/lng/#{lng}/radiusInKM/#{radiusInKM}/limit/#{resultLimit}"
|
254
|
+
response = connection.get(signature, resource_url, query_params)
|
255
|
+
geo = GeoResponseBuilder.new
|
256
|
+
geoObj = geo.buildResponse(response)
|
257
|
+
rescue App42Exception =>e
|
258
|
+
raise e
|
259
|
+
rescue Exception => e
|
260
|
+
raise App42Exception.new(e)
|
261
|
+
end
|
262
|
+
return geoObj
|
263
|
+
end
|
264
|
+
|
265
|
+
#
|
266
|
+
# Fetch the name of all storage stored on the cloud
|
267
|
+
#
|
268
|
+
# @return Geo object containing list of all the storage created
|
269
|
+
#
|
270
|
+
# @raise App42Exception
|
271
|
+
#
|
272
|
+
|
273
|
+
def get_all_storage()
|
274
|
+
puts "Get All Storage Called "
|
275
|
+
puts "Base url #{@base_url}"
|
276
|
+
response = nil
|
277
|
+
geoObj = nil;
|
278
|
+
geoObjList = Array.new
|
279
|
+
util = Util.new
|
280
|
+
begin
|
281
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
282
|
+
query_params = Hash.new
|
283
|
+
params = {
|
284
|
+
'apiKey'=> @api_key,
|
285
|
+
'version' => @version,
|
286
|
+
'timeStamp' => util.get_timestamp_utc,
|
287
|
+
}
|
288
|
+
query_params = params.clone
|
289
|
+
puts query_params
|
290
|
+
signature = util.sign(@secret_key, params)
|
291
|
+
resource_url = "#{@version}/#{@resource}/storage"
|
292
|
+
response = connection.get(signature, resource_url, query_params)
|
293
|
+
geo = GeoResponseBuilder.new
|
294
|
+
geoObjList = geo.buildArrayResponse(response)
|
295
|
+
rescue App42Exception =>e
|
296
|
+
raise e
|
297
|
+
rescue Exception => e
|
298
|
+
raise App42Exception.new(e)
|
299
|
+
end
|
300
|
+
puts geoObjList[0].createdOn
|
301
|
+
return geoObjList
|
302
|
+
end
|
303
|
+
|
304
|
+
#
|
305
|
+
# Delete the specifed Geo Storage from Cloud.
|
306
|
+
#
|
307
|
+
# @return Geo object containing the name of the storage that has been deleted
|
308
|
+
#
|
309
|
+
# @raise App42Exception
|
310
|
+
#
|
311
|
+
|
312
|
+
def delete_storage(storageName)
|
313
|
+
puts "Delete Storage Called"
|
314
|
+
puts "Base url #{@base_url}"
|
315
|
+
response = nil;
|
316
|
+
responseObj = App42Response.new();
|
317
|
+
util = Util.new
|
318
|
+
util.throwExceptionIfNullOrBlank(storageName, "Geo Storage Name");
|
319
|
+
begin
|
320
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
321
|
+
query_params = Hash.new
|
322
|
+
params = {
|
323
|
+
'apiKey'=> @api_key,
|
324
|
+
'version' => @version,
|
325
|
+
'timeStamp' => util.get_timestamp_utc,
|
326
|
+
}
|
327
|
+
query_params = params.clone
|
328
|
+
params.store("storageName", storageName)
|
329
|
+
signature = util.sign(@secret_key, params)
|
330
|
+
resource_url = "#{@version}/#{@resource}/storage/#{storageName}"
|
331
|
+
response = connection.delete(signature, resource_url, query_params)
|
332
|
+
responseObj.strResponse=(response)
|
333
|
+
responseObj.isResponseSuccess=(true)
|
334
|
+
rescue App42Exception =>e
|
335
|
+
raise e
|
336
|
+
rescue Exception => e
|
337
|
+
raise App42Exception.new(e)
|
338
|
+
end
|
339
|
+
return responseObj
|
340
|
+
end
|
341
|
+
|
342
|
+
#
|
343
|
+
# Get All Point from storage.
|
344
|
+
#
|
345
|
+
# @return Geo object containing all the stored Geo Points for the specified storage
|
346
|
+
#
|
347
|
+
# @raise App42Exception
|
348
|
+
#
|
349
|
+
|
350
|
+
def get_all_points(storageName)
|
351
|
+
puts "Get All Points"
|
352
|
+
puts "Base url #{@base_url}"
|
353
|
+
response = nil;
|
354
|
+
geoObjList = nil;
|
355
|
+
geoObjList = Array.new
|
356
|
+
util = Util.new
|
357
|
+
util.throwExceptionIfNullOrBlank(storageName, "Geo Storage Name");
|
358
|
+
begin
|
359
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
360
|
+
query_params = Hash.new
|
361
|
+
params = {
|
362
|
+
'apiKey'=> @api_key,
|
363
|
+
'version' => @version,
|
364
|
+
'timeStamp' => util.get_timestamp_utc,
|
365
|
+
}
|
366
|
+
query_params = params.clone
|
367
|
+
params.store("storageName", storageName)
|
368
|
+
puts query_params
|
369
|
+
signature = util.sign(@secret_key, params)
|
370
|
+
resource_url = "#{@version}/#{@resource}/points/#{storageName}"
|
371
|
+
response = connection.get(signature, resource_url, query_params)
|
372
|
+
puts "Response is #{response}"
|
373
|
+
geo = GeoResponseBuilder.new()
|
374
|
+
geoObjList = geo.buildArrayResponse(response)
|
375
|
+
rescue App42Exception =>e
|
376
|
+
raise e
|
377
|
+
rescue Exception => e
|
378
|
+
raise App42Exception.new(e)
|
379
|
+
end
|
380
|
+
return geoObjList
|
381
|
+
end
|
382
|
+
|
383
|
+
#
|
384
|
+
# NEW METHOD
|
385
|
+
#
|
386
|
+
|
387
|
+
def get_all_storage_by_paging(max, offset)
|
388
|
+
puts "get_all_storage_by_paging Called "
|
389
|
+
puts "Base url #{@base_url}"
|
390
|
+
response = nil;
|
391
|
+
geoObjList = nil;
|
392
|
+
geoObjList = Array.new();
|
393
|
+
util = Util.new
|
394
|
+
util.throwExceptionIfNullOrBlank(max, "Max");
|
395
|
+
util.throwExceptionIfNullOrBlank(offset, "Offset");
|
396
|
+
begin
|
397
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
398
|
+
query_params = Hash.new
|
399
|
+
params = {
|
400
|
+
'apiKey'=> @api_key,
|
401
|
+
'version' => @version,
|
402
|
+
'timeStamp' => util.get_timestamp_utc,
|
403
|
+
}
|
404
|
+
query_params = params.clone
|
405
|
+
params.store("max", "" + (max.to_i).to_s)
|
406
|
+
params.store("offset", "" + (offset.to_i).to_s)
|
407
|
+
signature = util.sign(@secret_key, params)
|
408
|
+
resource_url = "#{@version}/#{@resource}/paging/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
|
409
|
+
response = connection.get(signature, resource_url, query_params)
|
410
|
+
geo = GeoResponseBuilder.new()
|
411
|
+
geoObjList = geo.buildArrayResponse(response)
|
412
|
+
rescue App42Exception =>e
|
413
|
+
raise e
|
414
|
+
rescue Exception => e
|
415
|
+
raise App42Exception.new(e)
|
416
|
+
end
|
417
|
+
return geoObjList
|
418
|
+
end
|
419
|
+
|
420
|
+
#
|
421
|
+
# NEW METHOD
|
422
|
+
#
|
423
|
+
|
424
|
+
def delete_geo_points(geoStorageName, geoPointsList)
|
425
|
+
puts "deleteGeoPoints Called "
|
426
|
+
puts "Base url #{@base_url}"
|
427
|
+
response = nil;
|
428
|
+
responseObj = App42Response.new();
|
429
|
+
util = Util.new
|
430
|
+
util.throwExceptionIfNullOrBlank(geoStorageName, "Geo Storage Name");
|
431
|
+
util.throwExceptionIfNullOrBlank(geoPointsList, "Geo Points List");
|
432
|
+
begin
|
433
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
434
|
+
geoArray = Array.new
|
435
|
+
for geoPoint in geoPointsList do
|
436
|
+
geoArray.push(geoPoint)
|
437
|
+
end
|
438
|
+
body = {'app42' => {"geo"=> { "storage"=> {
|
439
|
+
"points" =>{ "point" => geoArray.to_json
|
440
|
+
}}}}}.to_json
|
441
|
+
puts "Body #{body}"
|
442
|
+
params = Hash.new
|
443
|
+
query_params = Hash.new
|
444
|
+
params = {
|
445
|
+
'apiKey'=> @api_key,
|
446
|
+
'version' => @version,
|
447
|
+
'timeStamp' => util.get_timestamp_utc,
|
448
|
+
}
|
449
|
+
params.store("geoPoints", body)
|
450
|
+
query_params = params.clone
|
451
|
+
signature = util.sign(@secret_key, params)
|
452
|
+
resource_url = "#{@version}/#{@resource}/points/#{geoStorageName}"
|
453
|
+
response = connection.delete(signature, resource_url, query_params)
|
454
|
+
responseObj.strResponse=(response)
|
455
|
+
responseObj.isResponseSuccess=(true)
|
456
|
+
rescue App42Exception =>e
|
457
|
+
raise e
|
458
|
+
rescue Exception => e
|
459
|
+
raise App42Exception.new(e)
|
460
|
+
end
|
461
|
+
return responseObj
|
462
|
+
end
|
463
|
+
|
464
|
+
#
|
465
|
+
# NEW METHOD
|
466
|
+
#
|
467
|
+
|
468
|
+
def get_all_points_by_paging(storageName, max, offset)
|
469
|
+
puts "get_all_points_by_paging Called "
|
470
|
+
puts "Base url #{@base_url}"
|
471
|
+
response = nil;
|
472
|
+
geoList = nil;
|
473
|
+
geoList = Array.new();
|
474
|
+
util = Util.new
|
475
|
+
util.throwExceptionIfNullOrBlank(storageName, "Geo Storage Name");
|
476
|
+
util.throwExceptionIfNullOrBlank(max, "Max");
|
477
|
+
util.throwExceptionIfNullOrBlank(offset, "Offset");
|
478
|
+
begin
|
479
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
480
|
+
query_params = Hash.new
|
481
|
+
params = {
|
482
|
+
'apiKey'=> @api_key,
|
483
|
+
'version' => @version,
|
484
|
+
'timeStamp' => util.get_timestamp_utc,
|
485
|
+
}
|
486
|
+
query_params = params.clone
|
487
|
+
params.store("storageName", storageName);
|
488
|
+
params.store("max", "" + (max.to_i).to_s)
|
489
|
+
params.store("offset", "" + (offset.to_i).to_s)
|
490
|
+
signature = util.sign(@secret_key, params)
|
491
|
+
resource_url = "#{@version}/#{@resource}/paging/points/#{storageName}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
|
492
|
+
response = connection.get(signature, resource_url, query_params)
|
493
|
+
geo = GeoResponseBuilder.new()
|
494
|
+
geoList = geo.buildArrayResponse(response)
|
495
|
+
rescue App42Exception =>e
|
496
|
+
raise e
|
497
|
+
rescue Exception => e
|
498
|
+
raise App42Exception.new(e)
|
499
|
+
end
|
500
|
+
return geoList
|
501
|
+
end
|
502
|
+
|
503
|
+
end
|
504
|
+
end
|
505
|
+
end
|