Class: App42ResponseBuilder
- Inherits:
-
Object
- Object
- App42ResponseBuilder
- Defined in:
- lib/App42ResponseBuilder.rb
Direct Known Subclasses
App42::AppTab::BillResponseBuilder, App42::AppTab::DiscountResponseBuilder, App42::AppTab::LicenseResponseBuilder, App42::AppTab::PackageResponseBuilder, App42::AppTab::SchemeResponseBuilder, App42::AppTab::UsageResponseBuilder, App42::Email::EmailResponseBuilder, App42::Gallery::AlbumResponseBuilder, App42::Game::GameResponseBuilder, App42::Game::RewardResponseBuilder, App42::Geo::GeoResponseBuilder, App42::ImageProcessor::ImageProcessorResponseBuilder, App42::Log::LogResponseBuilder, App42::Message::QueueResponseBuilder, App42::Push::PushNotificationResponseBuilder, App42::Recommend::RecommenderResponseBuilder, App42::Review::ReviewResponseBuilder, App42::Session::SessionResponseBuilder, App42::Shopping::CartResponseBuilder, App42::Shopping::CatalogueResponseBuilder, App42::Social::SocialResponseBuilder, App42::Storage::StorageResponseBuilder, App42::Upload::UploadResponseBuilder, App42::User::UserResponseBuilder
Instance Method Summary collapse
-
#buildObjectFromJSONTree(obj, jsonObj) ⇒ Object
@param obj @param jsonObj @raise Exception.
- #getNames(obj) ⇒ Object
-
#getServiceJSONObject(serviceName, json) ⇒ Object
@param serviceName @param json @return @raise Exception.
- #getTotalRecords(json) ⇒ Object
-
#isResponseSuccess(json) ⇒ Object
@param json @return @raise Exception.
Instance Method Details
#buildObjectFromJSONTree(obj, jsonObj) ⇒ Object
@param obj
@param jsonObj
@raise Exception
11 12 13 14 15 16 17 18 |
# File 'lib/App42ResponseBuilder.rb', line 11 def buildObjectFromJSONTree(obj,jsonObj) names = getNames(jsonObj) for name in names value = jsonObj[name] fieldName = "@"+name obj.instance_variable_set(:"#{fieldName}", value) end end |
#getNames(obj) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/App42ResponseBuilder.rb', line 44 def getNames(obj) names = [] obj.each do |key, value| # puts"key is #{key}" # key holds the key, value holds the value names.push(key) end return names end |
#getServiceJSONObject(serviceName, json) ⇒ Object
@param serviceName
@param json
@return
@raise Exception
25 26 27 28 29 30 31 |
# File 'lib/App42ResponseBuilder.rb', line 25 def getServiceJSONObject(serviceName,json) jsonObj = JSON.parse(json) rescue nil jsonObjApp42 = jsonObj["app42"] jsonObjResponse = jsonObjApp42["response"] jsonObjService = jsonObjResponse["#{serviceName}"] return jsonObjService; end |
#getTotalRecords(json) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/App42ResponseBuilder.rb', line 53 def getTotalRecords(json) totalRecords = -1; jsonObj = JSON.parse(json) rescue nil jsonObjApp42 = jsonObj["app42"] jsonObjResponse = jsonObjApp42["response"] if jsonObjResponse != nil && jsonObjResponse.key?("totalRecords") totalRecords = jsonObjResponse.fetch("totalRecords"); end return totalRecords end |
#isResponseSuccess(json) ⇒ Object
@param json
@return
@raise Exception
37 38 39 40 41 42 |
# File 'lib/App42ResponseBuilder.rb', line 37 def isResponseSuccess(json) jsonObj = JSON.parse(json) rescue nil jsonObjApp42 = jsonObj["app42"] jsonObjResponse = jsonObjApp42["response"] return jsonObjResponse["success"] end |