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,79 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'App42_Ruby_API/App42Response'
|
6
|
+
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# This Catalogue object is the value object which contains the properties of
|
10
|
+
# Catalogue.
|
11
|
+
#
|
12
|
+
#
|
13
|
+
|
14
|
+
module App42
|
15
|
+
module Shopping
|
16
|
+
class Catalogue < App42Response
|
17
|
+
attr_accessor :name, :description, :categoryList
|
18
|
+
|
19
|
+
@name
|
20
|
+
@description
|
21
|
+
@categoryList = Array.new
|
22
|
+
end
|
23
|
+
|
24
|
+
class Category
|
25
|
+
attr_accessor :name, :description, :itemList
|
26
|
+
|
27
|
+
@name
|
28
|
+
@description
|
29
|
+
@itemList = Array.new
|
30
|
+
|
31
|
+
#
|
32
|
+
# This is a constructor that takes no parameter
|
33
|
+
#
|
34
|
+
#
|
35
|
+
def initialize(catalogue)
|
36
|
+
catalogue.categoryList.push(self)
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# Returns the Cart Response in JSON format.
|
41
|
+
#
|
42
|
+
# @return the response in JSON format.
|
43
|
+
#
|
44
|
+
|
45
|
+
def to_s
|
46
|
+
return "name : #{@name}" + "description : #{@description}";
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Item
|
51
|
+
attr_accessor :itemId, :name, :description, :url, :price, :tinyUrl
|
52
|
+
|
53
|
+
@itemId
|
54
|
+
@name
|
55
|
+
@description
|
56
|
+
@url
|
57
|
+
@price
|
58
|
+
@tinyUrl
|
59
|
+
|
60
|
+
#
|
61
|
+
# This is a constructor that takes no parameter
|
62
|
+
#
|
63
|
+
def initialize(category)
|
64
|
+
category.itemList.push(self)
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Returns the Cart Response in JSON format.
|
69
|
+
#
|
70
|
+
# @return the response in JSON format.
|
71
|
+
#
|
72
|
+
#
|
73
|
+
|
74
|
+
def toString
|
75
|
+
return "itemId : #{@itemId}" + "name : #{@name}" + "description : #{@description}" + "url : #{@url}" + "price : #{@price}";
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,170 @@
|
|
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 'shopping/Catalogue'
|
8
|
+
|
9
|
+
module App42
|
10
|
+
module Shopping
|
11
|
+
|
12
|
+
#
|
13
|
+
#
|
14
|
+
# CatalogueResponseBuilder class converts the JSON response retrieved from the
|
15
|
+
# server to the value object i.e Catalogue
|
16
|
+
#
|
17
|
+
#
|
18
|
+
class CatalogueResponseBuilder < App42ResponseBuilder
|
19
|
+
|
20
|
+
#
|
21
|
+
# Converts the response in JSON format to the value object i.e Catalogue
|
22
|
+
#
|
23
|
+
# @param json
|
24
|
+
# - response in JSON format
|
25
|
+
#
|
26
|
+
# @return Catalogue object filled with json data
|
27
|
+
#
|
28
|
+
#
|
29
|
+
def buildResponse(json)
|
30
|
+
puts "testing #{json}"
|
31
|
+
cataloguesJSONObject = getServiceJSONObject("catalogues", json);
|
32
|
+
|
33
|
+
catalogueJSONObject = cataloguesJSONObject.fetch("catalogue")
|
34
|
+
catalogue = buildCatalogueObject(catalogueJSONObject);
|
35
|
+
|
36
|
+
catalogue.strResponse=json
|
37
|
+
catalogue.isResponseSuccess = isResponseSuccess(json)
|
38
|
+
|
39
|
+
return catalogue
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Converts the response in JSON format to the list of value objects i.e
|
44
|
+
# Catalogue
|
45
|
+
#
|
46
|
+
# @param response
|
47
|
+
# - response in JSON format
|
48
|
+
#
|
49
|
+
# @return List of Catalogue object filled with json data
|
50
|
+
#
|
51
|
+
#
|
52
|
+
|
53
|
+
def buildArrayResponse(json)
|
54
|
+
cataloguesJSONObject = getServiceJSONObject("catalogues", json);
|
55
|
+
catalogueList = Array.new
|
56
|
+
|
57
|
+
if cataloguesJSONObject["catalogue"].instance_of?(Array)
|
58
|
+
catalogueJSONArray = cataloguesJSONObject.fetch("catalogue");
|
59
|
+
catalogueJSONArray.length.times do |i|
|
60
|
+
catalogueJSONObj = catalogueJSONArray[i]
|
61
|
+
# catalogue = Catalogue.new
|
62
|
+
catalogue = buildCatalogueObject(catalogueJSONObj);
|
63
|
+
catalogue.strResponse=json
|
64
|
+
catalogue.isResponseSuccess = isResponseSuccess(json)
|
65
|
+
catalogueList.push(catalogue)
|
66
|
+
end
|
67
|
+
else
|
68
|
+
catalogueJSONObj = cataloguesJSONObject["catalogue"]
|
69
|
+
catalogue = buildCatalogueObject(catalogueJSONObj);
|
70
|
+
catalogue.strResponse=json
|
71
|
+
catalogue.isResponseSuccess = isResponseSuccess(json)
|
72
|
+
catalogueList.push(catalogue)
|
73
|
+
end
|
74
|
+
return catalogueList
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# Converts the User JSON object to the value object i.e Catalogue
|
79
|
+
#
|
80
|
+
# @param catalogueJSONObj
|
81
|
+
# - Catalogue data as JSONObject
|
82
|
+
#
|
83
|
+
# @return Catalogue object filled with json data
|
84
|
+
#
|
85
|
+
|
86
|
+
def buildCatalogueObject(catalogueJSONObj)
|
87
|
+
catalogue = Catalogue.new();
|
88
|
+
categoryList = Array.new
|
89
|
+
catalogue.categoryList = categoryList
|
90
|
+
buildObjectFromJSONTree(catalogue, catalogueJSONObj);
|
91
|
+
|
92
|
+
if catalogueJSONObj.key?("categories") && catalogueJSONObj.fetch("categories").key?("category")
|
93
|
+
#Fetch Category
|
94
|
+
|
95
|
+
if catalogueJSONObj.fetch("categories").fetch("category").instance_of?(Hash)
|
96
|
+
#Single Category
|
97
|
+
|
98
|
+
categoryJSONObj = catalogueJSONObj.fetch("categories").fetch("category");
|
99
|
+
catalogueCategory = App42::Shopping::Category.new(catalogue)
|
100
|
+
itemList = Array.new
|
101
|
+
catalogueCategory.itemList=(itemList)
|
102
|
+
buildObjectFromJSONTree(catalogueCategory, categoryJSONObj);
|
103
|
+
|
104
|
+
#Check for Items Now
|
105
|
+
if(categoryJSONObj.key?("items") && categoryJSONObj.fetch("items").key?("item"))
|
106
|
+
|
107
|
+
if categoryJSONObj.fetch("items").fetch("item").instance_of?(Hash)
|
108
|
+
|
109
|
+
#Single Item
|
110
|
+
itemJSONObj = categoryJSONObj.fetch("items").fetch("item");
|
111
|
+
item = App42::Shopping::Item.new(catalogueCategory)
|
112
|
+
buildObjectFromJSONTree(item, itemJSONObj);
|
113
|
+
|
114
|
+
else
|
115
|
+
|
116
|
+
# Multiple Items
|
117
|
+
categoryJSONArray = categoryJSONObj.fetch("items").fetch("item");
|
118
|
+
|
119
|
+
categoryJSONArray.length.times do |j|
|
120
|
+
itemJSONObj = categoryJSONArray[j]
|
121
|
+
item = App42::Shopping::Item.new(catalogueCategory)
|
122
|
+
buildObjectFromJSONTree(item, itemJSONObj);
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
else
|
128
|
+
#Multiple Categories
|
129
|
+
|
130
|
+
itemJSONArray = catalogueJSONObj.fetch("categories").fetch("category");
|
131
|
+
|
132
|
+
itemJSONArray.length.times do |j|
|
133
|
+
categoryJSONObj = itemJSONArray(j)
|
134
|
+
catalogueCategory = App42::Shopping::Category.new(catalogue)
|
135
|
+
buildObjectFromJSONTree(catalogueCategory, categoryJSONObj);
|
136
|
+
|
137
|
+
# Check for Items Now
|
138
|
+
if categoryJSONObj.key?("items") && categoryJSONObj.fetch("items").key?("item")
|
139
|
+
|
140
|
+
if categoryJSONObj.fetch("items").fetch("item").instance_of?(Hash)
|
141
|
+
|
142
|
+
#Single Item
|
143
|
+
itemJSONObj = categoryJSONObj.fetch("items").fetch("item");
|
144
|
+
item = App42::Shopping::Item.new(catalogueCategory)
|
145
|
+
itemList = Array.new
|
146
|
+
catalogueCategory.itemList=(itemList)
|
147
|
+
buildObjectFromJSONTree(item, itemJSONObj);
|
148
|
+
|
149
|
+
else
|
150
|
+
|
151
|
+
#Multiple Items
|
152
|
+
categoryJSONArray = categoryJSONObj.fetch("items").fetch("item");
|
153
|
+
categoryJSONArray.length.times do |j|
|
154
|
+
itemJSONObj = categoryJSONArray(j)
|
155
|
+
item = App42::Shopping::Item.new(catalogueCategory)
|
156
|
+
buildObjectFromJSONTree(item, itemJSONObj);
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
return catalogue;
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,649 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'connection/RESTConnection'
|
7
|
+
require 'util/util'
|
8
|
+
require 'json/pure'
|
9
|
+
require 'App42_Ruby_API/App42Response'
|
10
|
+
require 'shopping/CatalogueResponseBuilder'
|
11
|
+
require 'App42_Ruby_API/App42Exception'
|
12
|
+
require 'shopping/Catalogue'
|
13
|
+
require 'shopping/ItemData'
|
14
|
+
|
15
|
+
module App42
|
16
|
+
module Shopping
|
17
|
+
#
|
18
|
+
# This Service provides a complete cloud based catalogue management. An app can keep
|
19
|
+
# all its items based on category on the Cloud. This service provides several utility
|
20
|
+
# methods to manage catalogue on the cloud.
|
21
|
+
#
|
22
|
+
# One can add items with its related information in a particular category. And there can
|
23
|
+
# be several categories in a catalogue. The App developer can create several catalogues if needed.
|
24
|
+
#
|
25
|
+
# The Cart service can be used along with Catalogue service to create an end to end Shopping feature for
|
26
|
+
# a Mobile and Web App.
|
27
|
+
#
|
28
|
+
# @see Cart, ItemData
|
29
|
+
#
|
30
|
+
class CatalogueService
|
31
|
+
#
|
32
|
+
# this is a constructor that takes
|
33
|
+
#
|
34
|
+
# @param apiKey
|
35
|
+
# @param secretKey
|
36
|
+
# @param baseURL
|
37
|
+
#
|
38
|
+
def initialize(api_key, secret_key, base_url)
|
39
|
+
puts "Shopping ->initialize"
|
40
|
+
@api_key = api_key
|
41
|
+
@secret_key = secret_key
|
42
|
+
@base_url = base_url
|
43
|
+
@resource = "catalogue"
|
44
|
+
@version = "1.0"
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Creates a Catalogue for a particular App. Categories can be added to the Catalogue
|
49
|
+
#
|
50
|
+
# @param catalogueName
|
51
|
+
# - Name of the Catalogue to be created
|
52
|
+
# @param catalogueDescription
|
53
|
+
# - Description of the catalogue to be createds
|
54
|
+
#
|
55
|
+
# @return Catalogue object
|
56
|
+
#
|
57
|
+
# @raise App42Exception
|
58
|
+
#
|
59
|
+
|
60
|
+
def create_catalogue(catalogueName, catalogueDescription)
|
61
|
+
puts "Create Catalogue Called "
|
62
|
+
puts "Base url #{catalogueDescription}"
|
63
|
+
response = nil;
|
64
|
+
catalogueObj = nil;
|
65
|
+
catalogueObj = Catalogue.new
|
66
|
+
util = Util.new
|
67
|
+
util.throwExceptionIfNullOrBlank(catalogueName, "catalogueName");
|
68
|
+
util.throwExceptionIfNullOrBlank(catalogueDescription, "catalogueDescription");
|
69
|
+
begin
|
70
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
71
|
+
body = {'app42' => {"catalogue"=> {
|
72
|
+
"name" => catalogueName,
|
73
|
+
"description" => catalogueDescription
|
74
|
+
}}}.to_json
|
75
|
+
puts "Body #{body}"
|
76
|
+
query_params = Hash.new
|
77
|
+
params = {
|
78
|
+
'apiKey'=> @api_key,
|
79
|
+
'version' => @version,
|
80
|
+
'timeStamp' => util.get_timestamp_utc,
|
81
|
+
}
|
82
|
+
query_params = params.clone
|
83
|
+
params.store("body", body)
|
84
|
+
signature = util.sign(@secret_key, params)
|
85
|
+
resource_url = "#{@version}/#{@resource}"
|
86
|
+
response = connection.post(signature, resource_url, query_params, body)
|
87
|
+
catalogue = CatalogueResponseBuilder.new()
|
88
|
+
catalogueObj = catalogue.buildResponse(response)
|
89
|
+
rescue App42Exception =>e
|
90
|
+
raise e
|
91
|
+
rescue Exception => e
|
92
|
+
raise App42Exception.new(e)
|
93
|
+
end
|
94
|
+
return catalogueObj
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# Creates a Category for a particular Catalogue e.g. Books, Music etc.
|
99
|
+
#
|
100
|
+
# @param catalogueName
|
101
|
+
# - Name of the Catalogue for which Category has to be created
|
102
|
+
# @param categoryName
|
103
|
+
# - Name of the Category that has to be created
|
104
|
+
# @param categoryDescription
|
105
|
+
# - Description of the category to be created
|
106
|
+
#
|
107
|
+
# @return Catalogue object containing created category information
|
108
|
+
#
|
109
|
+
# @raise App42Exception
|
110
|
+
#
|
111
|
+
|
112
|
+
def create_category(catalogueName, categoryName, categoryDescription)
|
113
|
+
puts "Create Category Called "
|
114
|
+
puts "Base url #{@base_url}"
|
115
|
+
response = nil;
|
116
|
+
catalogueObj = nil;
|
117
|
+
catalogueObj = Catalogue.new
|
118
|
+
util = Util.new
|
119
|
+
util.throwExceptionIfNullOrBlank(catalogueName, "catalogueName");
|
120
|
+
util.throwExceptionIfNullOrBlank(categoryName, "categoryName");
|
121
|
+
util.throwExceptionIfNullOrBlank(categoryDescription, "categoryDescription");
|
122
|
+
begin
|
123
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
124
|
+
body = {'app42' => {"catalogue"=> {"categories"=> {"category" =>
|
125
|
+
{ "name" => categoryName,
|
126
|
+
"description" => categoryDescription,
|
127
|
+
}}}}}.to_json
|
128
|
+
puts "Body #{body}"
|
129
|
+
query_params = Hash.new
|
130
|
+
params = {
|
131
|
+
'apiKey'=> @api_key,
|
132
|
+
'version' => @version,
|
133
|
+
'timeStamp' => util.get_timestamp_utc,
|
134
|
+
}
|
135
|
+
query_params = params.clone
|
136
|
+
params.store("body", body)
|
137
|
+
params.store("catalogueName", catalogueName)
|
138
|
+
signature = util.sign(@secret_key, params)
|
139
|
+
resource_url = "#{@version}/#{@resource}/#{catalogueName}/category"
|
140
|
+
response = connection.post(signature, resource_url, query_params, body)
|
141
|
+
catalogue = CatalogueResponseBuilder.new()
|
142
|
+
catalogueObj = catalogue.buildResponse(response)
|
143
|
+
rescue App42Exception =>e
|
144
|
+
raise e
|
145
|
+
rescue Exception => e
|
146
|
+
raise App42Exception.new(e)
|
147
|
+
end
|
148
|
+
return catalogueObj
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# Creates a Item in a Category for a particular Catelogue
|
153
|
+
#
|
154
|
+
# @param catalogueName
|
155
|
+
# - Name of the Catalogue to which item has to be added
|
156
|
+
# @param categoryName
|
157
|
+
# - Name of the Category to which item has to be added
|
158
|
+
# @param itemData
|
159
|
+
# - Item Information that has to be added
|
160
|
+
#
|
161
|
+
# @return Catalogue object containing added item.
|
162
|
+
#
|
163
|
+
# @raise App42Exception
|
164
|
+
#
|
165
|
+
# @see ItemData
|
166
|
+
#
|
167
|
+
|
168
|
+
def add_item(catalogueName, categoryName, itemData)
|
169
|
+
puts "Add Item Called "
|
170
|
+
puts "Base url #{@base_url}"
|
171
|
+
response = nil;
|
172
|
+
catalogueObj = nil;
|
173
|
+
catalogueObj = Catalogue.new
|
174
|
+
util = Util.new
|
175
|
+
util.throwExceptionIfNullOrBlank(catalogueName, "CatalogueName");
|
176
|
+
util.throwExceptionIfNullOrBlank(categoryName, "CategoryName");
|
177
|
+
util.throwExceptionIfNullOrBlank(itemData, "ItemData");
|
178
|
+
file = File.new(itemData.image())
|
179
|
+
if (FileTest.exists?(file) == false)
|
180
|
+
raise App42Exception.new("The file with the name #{file} not found")
|
181
|
+
end
|
182
|
+
begin
|
183
|
+
puts "file is #{file} and #{itemData.itemId}"
|
184
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
185
|
+
query_params = Hash.new
|
186
|
+
post_params=Hash.new
|
187
|
+
query_params = {
|
188
|
+
'apiKey'=> @api_key,
|
189
|
+
'version' => @version,
|
190
|
+
'timeStamp' => util.get_timestamp_utc,
|
191
|
+
'catalogueName' => catalogueName,
|
192
|
+
'categoryName' => categoryName
|
193
|
+
}
|
194
|
+
params = query_params.clone
|
195
|
+
post_params.store("itemId",itemData.itemId)
|
196
|
+
post_params.store("name",itemData.name)
|
197
|
+
post_params.store("description",itemData.description)
|
198
|
+
post_params.store("price",(itemData.price.to_i).to_s)
|
199
|
+
params = params.merge(post_params)
|
200
|
+
signature = util.sign(@secret_key, params)
|
201
|
+
resource_url = "#{@version}/#{@resource}/#{catalogueName}/#{categoryName}/item"
|
202
|
+
response = connection.shopMultipart(signature, resource_url, query_params, params, file)
|
203
|
+
catalogue = CatalogueResponseBuilder.new()
|
204
|
+
catalogueObj = catalogue.buildResponse(response)
|
205
|
+
rescue App42Exception =>e
|
206
|
+
raise e
|
207
|
+
rescue Exception => e
|
208
|
+
raise App42Exception.new(e)
|
209
|
+
end
|
210
|
+
return catalogueObj
|
211
|
+
end
|
212
|
+
|
213
|
+
#
|
214
|
+
# Fetches all items for a Catalogue
|
215
|
+
#
|
216
|
+
# @param catalogueName
|
217
|
+
# - Name of the Catalogue from which item has to be fetched
|
218
|
+
#
|
219
|
+
# @return Catalogue object containing all Items
|
220
|
+
#
|
221
|
+
# @raise App42Exception
|
222
|
+
#
|
223
|
+
|
224
|
+
def get_items(catalogueName)
|
225
|
+
puts "Get Items Called "
|
226
|
+
puts "Base url #{@base_url}"
|
227
|
+
response = nil;
|
228
|
+
catalogueObj = nil;
|
229
|
+
catalogueObj = Catalogue.new
|
230
|
+
util = Util.new
|
231
|
+
util.throwExceptionIfNullOrBlank(catalogueName, "catalogueName");
|
232
|
+
begin
|
233
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
234
|
+
query_params = Hash.new
|
235
|
+
params = {
|
236
|
+
'apiKey'=> @api_key,
|
237
|
+
'version' => @version,
|
238
|
+
'timeStamp' => util.get_timestamp_utc,
|
239
|
+
}
|
240
|
+
query_params = params.clone
|
241
|
+
puts params
|
242
|
+
params.store("catalogueName", catalogueName)
|
243
|
+
puts query_params
|
244
|
+
signature = util.sign(@secret_key, params)
|
245
|
+
resource_url = "#{@version}/#{@resource}/#{catalogueName}"
|
246
|
+
response = connection.get(signature, resource_url, query_params)
|
247
|
+
catalogue = CatalogueResponseBuilder.new
|
248
|
+
catalogueObj = catalogue.buildResponse(response)
|
249
|
+
rescue App42Exception =>e
|
250
|
+
raise e
|
251
|
+
rescue Exception => e
|
252
|
+
raise App42Exception.new(e)
|
253
|
+
end
|
254
|
+
return catalogueObj
|
255
|
+
end
|
256
|
+
|
257
|
+
#
|
258
|
+
# Fetches all items for a Catalogue and Category
|
259
|
+
#
|
260
|
+
# @param catalogueName
|
261
|
+
# - Name of the Catalogue from which item has to be fetched
|
262
|
+
# @param categoryName
|
263
|
+
# - Name of the Category from which item has to be fetched
|
264
|
+
#
|
265
|
+
# @return Catalogue object
|
266
|
+
#
|
267
|
+
# @raise App42Exception
|
268
|
+
#
|
269
|
+
|
270
|
+
def get_items_by_category(catalogueName, categoryName)
|
271
|
+
puts "Get Items By Category Called "
|
272
|
+
puts "Base url #{@base_url}"
|
273
|
+
response = nil;
|
274
|
+
catalogueObj = nil;
|
275
|
+
catalogueObj = Catalogue.new
|
276
|
+
util = Util.new
|
277
|
+
util.throwExceptionIfNullOrBlank(catalogueName, "catalogueName");
|
278
|
+
util.throwExceptionIfNullOrBlank(categoryName, "categoryName");
|
279
|
+
begin
|
280
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
281
|
+
query_params = Hash.new
|
282
|
+
params = {
|
283
|
+
'apiKey'=> @api_key,
|
284
|
+
'version' => @version,
|
285
|
+
'timeStamp' => util.get_timestamp_utc,
|
286
|
+
}
|
287
|
+
query_params = params.clone
|
288
|
+
params.store("catalogueName", catalogueName)
|
289
|
+
params.store("categoryName", categoryName)
|
290
|
+
puts query_params
|
291
|
+
signature = util.sign(@secret_key, params)
|
292
|
+
resource_url = "#{@version}/#{@resource}/#{catalogueName}/#{categoryName}"
|
293
|
+
response = connection.get(signature, resource_url, query_params)
|
294
|
+
catalogue = CatalogueResponseBuilder.new
|
295
|
+
catalogueObj = catalogue.buildResponse(response)
|
296
|
+
rescue App42Exception =>e
|
297
|
+
raise e
|
298
|
+
rescue Exception => e
|
299
|
+
raise App42Exception.new(e)
|
300
|
+
end
|
301
|
+
return catalogueObj
|
302
|
+
end
|
303
|
+
|
304
|
+
#
|
305
|
+
# Fetches Item by id for a Catalogue and Category
|
306
|
+
#
|
307
|
+
# @param catalogueName
|
308
|
+
# - Name of the Catalogue from which item has to be fetched
|
309
|
+
# @param categoryName
|
310
|
+
# - Name of the Category from which item has to be fetched
|
311
|
+
# @param itemId
|
312
|
+
# - Item id for which information has to be fetched.
|
313
|
+
#
|
314
|
+
# @return Catalogue object
|
315
|
+
#
|
316
|
+
# @raise App42Exception
|
317
|
+
#
|
318
|
+
|
319
|
+
def get_item_by_id(catalogueName, categoryName, itemId)
|
320
|
+
puts "Get Items By ID Called "
|
321
|
+
puts "Base url #{@base_url}"
|
322
|
+
response = nil;
|
323
|
+
catalogueObj = nil;
|
324
|
+
catalogueObj = Catalogue.new
|
325
|
+
util = Util.new
|
326
|
+
util.throwExceptionIfNullOrBlank(catalogueName, "catalogueName");
|
327
|
+
util.throwExceptionIfNullOrBlank(categoryName, "categoryName");
|
328
|
+
util.throwExceptionIfNullOrBlank(itemId, "itemId");
|
329
|
+
begin
|
330
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
331
|
+
query_params = Hash.new
|
332
|
+
params = {
|
333
|
+
'apiKey'=> @api_key,
|
334
|
+
'version' => @version,
|
335
|
+
'timeStamp' => util.get_timestamp_utc,
|
336
|
+
}
|
337
|
+
query_params = params.clone
|
338
|
+
puts params
|
339
|
+
params.store("catalogueName", catalogueName)
|
340
|
+
params.store("categoryName", categoryName)
|
341
|
+
params.store("itemId", itemId)
|
342
|
+
puts query_params
|
343
|
+
signature = util.sign(@secret_key, params)
|
344
|
+
resource_url = "#{@version}/#{@resource}/#{catalogueName}/#{categoryName}/#{itemId}"
|
345
|
+
response = connection.get(signature, resource_url, query_params)
|
346
|
+
catalogue = CatalogueResponseBuilder.new
|
347
|
+
catalogueObj = catalogue.buildResponse(response)
|
348
|
+
rescue App42Exception =>e
|
349
|
+
raise e
|
350
|
+
rescue Exception => e
|
351
|
+
raise App42Exception.new(e)
|
352
|
+
end
|
353
|
+
return catalogueObj
|
354
|
+
end
|
355
|
+
|
356
|
+
#
|
357
|
+
# Removes all Items in a Catalogue
|
358
|
+
#
|
359
|
+
# @param catalogueName
|
360
|
+
# - Name of the Catalogue from which item has to be removed
|
361
|
+
#
|
362
|
+
# @return Catalogue object containing removed items
|
363
|
+
#
|
364
|
+
# @raise App42Exception
|
365
|
+
#
|
366
|
+
|
367
|
+
def remove_all_items(catalogueName)
|
368
|
+
puts "Remove All Items Called "
|
369
|
+
puts "Base url #{@base_url}"
|
370
|
+
response = nil;
|
371
|
+
responseObj = App42Response.new();
|
372
|
+
util = Util.new
|
373
|
+
util.throwExceptionIfNullOrBlank(catalogueName, "catalogueName");
|
374
|
+
begin
|
375
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
376
|
+
query_params = Hash.new
|
377
|
+
params = {
|
378
|
+
'apiKey'=> @api_key,
|
379
|
+
'version' => @version,
|
380
|
+
'timeStamp' => util.get_timestamp_utc,
|
381
|
+
}
|
382
|
+
query_params = params.clone
|
383
|
+
puts params
|
384
|
+
params.store("catalogueName", catalogueName)
|
385
|
+
puts query_params
|
386
|
+
signature = util.sign(@secret_key, params)
|
387
|
+
resource_url = "#{@version}/#{@resource}/#{catalogueName}"
|
388
|
+
response = connection.delete(signature, resource_url, query_params)
|
389
|
+
responseObj.strResponse=(response)
|
390
|
+
responseObj.isResponseSuccess=(true)
|
391
|
+
rescue App42Exception =>e
|
392
|
+
raise e
|
393
|
+
rescue Exception => e
|
394
|
+
raise App42Exception.new(e)
|
395
|
+
end
|
396
|
+
return responseObj
|
397
|
+
end
|
398
|
+
|
399
|
+
#
|
400
|
+
# Removes all Items from a Catalogue and Category
|
401
|
+
#
|
402
|
+
# @param catalogueName
|
403
|
+
# - Name of the Catalogue from which item has to be removed
|
404
|
+
# @param categoryName
|
405
|
+
# - Name of the Category from which item has to be removed
|
406
|
+
#
|
407
|
+
# @return Catalogue object containing removed item
|
408
|
+
#
|
409
|
+
# @raise App42Exception
|
410
|
+
#
|
411
|
+
|
412
|
+
def remove_items_by_category(catalogueName, categoryName)
|
413
|
+
puts "Remove Items By Category Called "
|
414
|
+
puts "Base url #{@base_url}"
|
415
|
+
response = nil;
|
416
|
+
responseObj = App42Response.new();
|
417
|
+
util = Util.new
|
418
|
+
util.throwExceptionIfNullOrBlank(catalogueName, "catalogueName");
|
419
|
+
util.throwExceptionIfNullOrBlank(categoryName, "categoryName");
|
420
|
+
begin
|
421
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
422
|
+
query_params = Hash.new
|
423
|
+
params = {
|
424
|
+
'apiKey'=> @api_key,
|
425
|
+
'version' => @version,
|
426
|
+
'timeStamp' => util.get_timestamp_utc,
|
427
|
+
}
|
428
|
+
query_params = params.clone
|
429
|
+
puts params
|
430
|
+
params.store("catalogueName", catalogueName)
|
431
|
+
params.store("categoryName", categoryName)
|
432
|
+
puts query_params
|
433
|
+
signature = util.sign(@secret_key, params)
|
434
|
+
resource_url = "#{@version}/#{@resource}/#{catalogueName}/#{categoryName}"
|
435
|
+
response = connection.delete(signature, resource_url, query_params)
|
436
|
+
responseObj.strResponse=(response)
|
437
|
+
responseObj.isResponseSuccess=(true)
|
438
|
+
rescue App42Exception =>e
|
439
|
+
raise e
|
440
|
+
rescue Exception => e
|
441
|
+
raise App42Exception.new(e)
|
442
|
+
end
|
443
|
+
return responseObj
|
444
|
+
end
|
445
|
+
|
446
|
+
#
|
447
|
+
# Removes Item by Id
|
448
|
+
#
|
449
|
+
# @param catalogueName
|
450
|
+
# - Name of the Catalogue from which item has to be removed
|
451
|
+
# @param categoryName
|
452
|
+
# - Name of the Category from which item has to be removed
|
453
|
+
# @param itemId
|
454
|
+
# - Item id which has to be removed
|
455
|
+
#
|
456
|
+
# @return Catalogue object containing removed item
|
457
|
+
#
|
458
|
+
# @raise App42Exception
|
459
|
+
#
|
460
|
+
|
461
|
+
def remove_item_by_id(catalogueName, categoryName, itemId)
|
462
|
+
puts "Remove Items By ID Called "
|
463
|
+
puts "Base url #{@base_url}"
|
464
|
+
response = nil;
|
465
|
+
responseObj = App42Response.new();
|
466
|
+
util = Util.new
|
467
|
+
util.throwExceptionIfNullOrBlank(catalogueName, "catalogueName");
|
468
|
+
util.throwExceptionIfNullOrBlank(categoryName, "categoryName");
|
469
|
+
util.throwExceptionIfNullOrBlank(itemId, "itemId");
|
470
|
+
begin
|
471
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
472
|
+
query_params = Hash.new
|
473
|
+
params = {
|
474
|
+
'apiKey'=> @api_key,
|
475
|
+
'version' => @version,
|
476
|
+
'timeStamp' => util.get_timestamp_utc,
|
477
|
+
}
|
478
|
+
query_params = params.clone
|
479
|
+
puts params
|
480
|
+
params.store("catalogueName", catalogueName)
|
481
|
+
params.store("categoryName", categoryName)
|
482
|
+
params.store("itemId", itemId)
|
483
|
+
puts query_params
|
484
|
+
signature = util.sign(@secret_key, params)
|
485
|
+
resource_url = "#{@version}/#{@resource}/#{catalogueName}/#{categoryName}/#{itemId}"
|
486
|
+
response = connection.delete(signature, resource_url, query_params)
|
487
|
+
responseObj.strResponse=(response)
|
488
|
+
responseObj.isResponseSuccess=(true)
|
489
|
+
rescue App42Exception =>e
|
490
|
+
raise e
|
491
|
+
rescue Exception => e
|
492
|
+
raise App42Exception.new(e)
|
493
|
+
end
|
494
|
+
return responseObj
|
495
|
+
end
|
496
|
+
|
497
|
+
#
|
498
|
+
# Fetches all items for a Catalogue and Category by paging.
|
499
|
+
#
|
500
|
+
# @param catalogueName
|
501
|
+
# - Name of the Catalogue from which item has to be fetched
|
502
|
+
# @param categoryName
|
503
|
+
# - Name of the Category from which item has to be fetched
|
504
|
+
# @param max
|
505
|
+
# - Maximum number of records to be fetched
|
506
|
+
# @param offset
|
507
|
+
# - From where the records are to be fetched
|
508
|
+
#
|
509
|
+
# @return Catalogue object
|
510
|
+
#
|
511
|
+
# @raise App42Exception
|
512
|
+
#
|
513
|
+
|
514
|
+
def get_items_by_category_by_paging(catalogueName, categoryName, max, offset)
|
515
|
+
puts "Get Items By Category Called "
|
516
|
+
puts "Base url #{@base_url}"
|
517
|
+
response = nil;
|
518
|
+
catalogueObj = nil;
|
519
|
+
catalogueObj = Catalogue.new
|
520
|
+
util = Util.new
|
521
|
+
util.validateMax(max);
|
522
|
+
util.throwExceptionIfNullOrBlank(catalogueName, "catalogueName");
|
523
|
+
util.throwExceptionIfNullOrBlank(categoryName, "categoryName");
|
524
|
+
util.throwExceptionIfNullOrBlank(max, "Max");
|
525
|
+
util.throwExceptionIfNullOrBlank(offset, "Offset");
|
526
|
+
begin
|
527
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
528
|
+
query_params = Hash.new
|
529
|
+
params = {
|
530
|
+
'apiKey'=> @api_key,
|
531
|
+
'version' => @version,
|
532
|
+
'timeStamp' => util.get_timestamp_utc,
|
533
|
+
}
|
534
|
+
query_params = params.clone
|
535
|
+
params.store("catalogueName", catalogueName)
|
536
|
+
params.store("categoryName", categoryName)
|
537
|
+
params.store("max", "" + (max.to_i).to_s);
|
538
|
+
params.store("offset", "" + (offset.to_i).to_s);
|
539
|
+
puts query_params
|
540
|
+
signature = util.sign(@secret_key, params)
|
541
|
+
resource_url = "#{@version}/#{@resource}/paging/#{catalogueName}/#{categoryName}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
|
542
|
+
response = connection.get(signature, resource_url, query_params)
|
543
|
+
catalogue = CatalogueResponseBuilder.new
|
544
|
+
catalogueObj = catalogue.buildResponse(response)
|
545
|
+
rescue App42Exception =>e
|
546
|
+
raise e
|
547
|
+
rescue Exception => e
|
548
|
+
raise App42Exception.new(e)
|
549
|
+
end
|
550
|
+
return catalogueObj
|
551
|
+
end
|
552
|
+
|
553
|
+
#
|
554
|
+
# Fetches count of all items for a Catalogue and Category
|
555
|
+
#
|
556
|
+
# @param catalogueName
|
557
|
+
# - Name of the Catalogue from which count of item has to be fetched
|
558
|
+
# @param categoryName
|
559
|
+
# - Name of the Category from which count of item has to be fetched
|
560
|
+
#
|
561
|
+
# @return App42Response object
|
562
|
+
#
|
563
|
+
# @raise App42Exception
|
564
|
+
#
|
565
|
+
|
566
|
+
def get_items_count_by_category(catalogueName, categoryName)
|
567
|
+
puts "get_items_count_by_category Called "
|
568
|
+
puts "Base url #{@base_url}"
|
569
|
+
response = nil;
|
570
|
+
responseObj = App42Response.new
|
571
|
+
util = Util.new
|
572
|
+
util.throwExceptionIfNullOrBlank(catalogueName, "CatalogueName");
|
573
|
+
util.throwExceptionIfNullOrBlank(categoryName, "CategoryName");
|
574
|
+
begin
|
575
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
576
|
+
query_params = Hash.new
|
577
|
+
params = {
|
578
|
+
'apiKey'=> @api_key,
|
579
|
+
'version' => @version,
|
580
|
+
'timeStamp' => util.get_timestamp_utc,
|
581
|
+
}
|
582
|
+
query_params = params.clone
|
583
|
+
params.store("catalogueName", catalogueName);
|
584
|
+
params.store("categoryName", categoryName);
|
585
|
+
puts query_params
|
586
|
+
signature = util.sign(@secret_key, params)
|
587
|
+
resource_url = "#{@version}/#{@resource}/#{catalogueName}/#{categoryName}/count"
|
588
|
+
response = connection.get(signature, resource_url, query_params)
|
589
|
+
responseObj.strResponse = response
|
590
|
+
responseObj.isResponseSuccess = true
|
591
|
+
responseObj = CatalogueResponseBuilder.new()
|
592
|
+
responseObj.getTotalRecords(response);
|
593
|
+
rescue App42Exception =>e
|
594
|
+
raise e
|
595
|
+
rescue Exception => e
|
596
|
+
raise App42Exception.new(e)
|
597
|
+
end
|
598
|
+
return responseObj
|
599
|
+
end
|
600
|
+
|
601
|
+
#
|
602
|
+
# Deletes category
|
603
|
+
#
|
604
|
+
# @param catalogueName
|
605
|
+
# - Name of the Catalogue from which count of item has to be fetched
|
606
|
+
# @param categoryName
|
607
|
+
# - Name of the Category from which count of item has to be fetched
|
608
|
+
#
|
609
|
+
# @return App42Response object
|
610
|
+
#
|
611
|
+
# @raise App42Exception
|
612
|
+
#
|
613
|
+
|
614
|
+
def delete_category(catalogueName, categoryName)
|
615
|
+
puts "deleteCategory Called "
|
616
|
+
puts "Base url #{@base_url}"
|
617
|
+
response = nil;
|
618
|
+
responseObj = App42Response.new
|
619
|
+
util = Util.new
|
620
|
+
util.throwExceptionIfNullOrBlank(catalogueName, "CatalogueName");
|
621
|
+
util.throwExceptionIfNullOrBlank(categoryName, "CategoryName");
|
622
|
+
begin
|
623
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
624
|
+
query_params = Hash.new
|
625
|
+
params = {
|
626
|
+
'apiKey'=> @api_key,
|
627
|
+
'version' => @version,
|
628
|
+
'timeStamp' => util.get_timestamp_utc,
|
629
|
+
}
|
630
|
+
query_params = params.clone
|
631
|
+
params.store("catalogueName", catalogueName);
|
632
|
+
params.store("categoryName", categoryName);
|
633
|
+
puts query_params
|
634
|
+
signature = util.sign(@secret_key, params)
|
635
|
+
resource_url = "#{@version}/#{@resource}/#{catalogueName}/category/#{categoryName}"
|
636
|
+
response = connection.delete(signature, resource_url, query_params)
|
637
|
+
responseObj.strResponse = response
|
638
|
+
responseObj.isResponseSuccess = true
|
639
|
+
rescue App42Exception => e
|
640
|
+
raise e
|
641
|
+
rescue Exception => e
|
642
|
+
raise App42Exception.new(e)
|
643
|
+
end
|
644
|
+
return responseObj
|
645
|
+
end
|
646
|
+
|
647
|
+
end
|
648
|
+
end
|
649
|
+
end
|