Class: App42::AppTab::BillResponseBuilder

Inherits:
App42ResponseBuilder show all
Defined in:
lib/appTab/BillResponseBuilder.rb

Overview

BillResponseBuilder class converts the JSON response retrieved from the server to the value object i.e Bill

Instance Method Summary collapse

Methods inherited from App42ResponseBuilder

#buildObjectFromJSONTree, #getNames, #getServiceJSONObject, #getTotalRecords, #isResponseSuccess

Instance Method Details

#buildArrayResponse(json) ⇒ Object

Converts the response in JSON format to the list of value objects i.e Bill

Parameters:

  • json
    • response in JSON format

Returns:

  • List of Bill object filled with json data



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/appTab/BillResponseBuilder.rb', line 223

def buildArrayResponse(json)
  billsJSONObj = getServiceJSONObject("bill", json);
  billJSONArray = billsJSONObj["bill"]
  billList = Array.new()

  billJSONArray.length.times do |i|
    billJSONObject = billJSONArray[i]
    bill = buildBillObject(billJSONObject);
    bill.strResponse=json
    bill.isResponseSuccess = isResponseSuccess(json)
    billList.push(bill)
  end

  return billList
end

#buildBillObject(billJSONObj) ⇒ Object

Converts the Bill JSON object to the value object i.e Bill

Parameters:

  • billJSONObj
    • Bill data as JSONObject

Returns:

  • Bill object filled with json data



43
44
45
46
47
48
49
50
51
52
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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
205
206
207
208
209
210
# File 'lib/appTab/BillResponseBuilder.rb', line 43

def buildBillObject(billJSONObj)
  bill = Bill.new
  buildObjectFromJSONTree(bill, billJSONObj)

  if billJSONObj.key?("storageTransaction")
    storageTransJson = billJSONObj["storageTransaction"]
    storageTrans = StorageTransaction.new()
    transactionList = Array.new
    storageTrans.transactionList=(transactionList)
    buildObjectFromJSONTree(storageTrans, storageTransJson)

    if storageTransJson.key?("transactions") && storageTransJson["transactions"].key?("transaction")

      if storageTransJson["transactions"].fetch("transaction").instance_of?(Hash)
        transactionJsonObj = storageTransJson.fetch("transactions").fetch("transaction");
        transaction =  App42::AppTab::TransactionStor.new(storageTrans)
        buildObjectFromJSONTree(transaction, transactionJsonObj)

      else

        transactionJsonArray = storageTransJson.fetch("transactions").fetch("transaction");

        transactionJsonArray.length.times do |i|
          transactionJsonObj = userJSONArray[i]
          transaction =  App42::AppTab::TransactionStor.new(storageTrans)
          buildObjectFromJSONTree(transaction, transactionJsonObj);
        end
      end
    end
  end

  if billJSONObj.key?("timeTransaction")
    storageTransJson  = billJSONObj.fetch("timeTransaction");
    timeTrans = TimeTransaction.new()
    transactionList = Array.new
    timeTrans.transactionList=(transactionList)
    buildObjectFromJSONTree(timeTrans,storageTransJson);

    if storageTransJson.key?("transactions") && storageTransJson.fetch("transactions").key?("transaction")

      if storageTransJson.fetch("transactions").fetch("transaction").instance_of?(Hash)
        transactionJsonObj = storageTransJson.fetch("transactions").fetch("transaction");
        transaction = App42::AppTab::TransactionTim.new(timeTrans)
        buildObjectFromJSONTree(transaction, transactionJsonObj);

      else

        transactionJsonArray = storageTransJson.fetch("transactions").fetch("transaction");

        transactionJsonArray.length.times do |i|
          transactionJsonObj = transactionJsonArray.fetch(i);
          transaction = App42::AppTab::TransactionTim.new(timeTrans)
          buildObjectFromJSONTree(transaction, transactionJsonObj);
        end
      end
    end
  end

  if billJSONObj.key?("bandWidthTransaction")
    storageTransJson = billJSONObj.fetch("bandWidthTransaction");
    bwTrans = BandwidthTransaction.new()
    transactionList = Array.new
    bwTrans.transactionList=(transactionList)
    buildObjectFromJSONTree(bwTrans,storageTransJson);

    if storageTransJson.key?("transactions") && storageTransJson.fetch("transactions").key?("transaction")

      if storageTransJson.fetch("transactions").fetch("transaction").instance_of?(Hash)

        transactionJsonObj = storageTransJson.fetch("transactions").fetch("transaction");
        transaction =  App42::AppTab::TransactionBand.new(bwTrans)
        buildObjectFromJSONTree(transaction, transactionJsonObj);

      else

        transactionJsonArray = storageTransJson.fetch("transactions").fetch("transaction");

        transactionJsonArray.length.times do |i|
          transactionJsonObj = transactionJsonArray.fetch(i);
          transaction =  App42::AppTab::TransactionBand.new(bwTrans)
          buildObjectFromJSONTree(transaction, transactionJsonObj);
        end
      end
    end
  end

  if billJSONObj.key?("levelTransaction")
    storageTransJson  = billJSONObj.fetch("levelTransaction");
    levelTrans = LevelTransaction.new()
    transactionList = Array.new
    levelTrans.transactionList=(transactionList)
    buildObjectFromJSONTree(levelTrans, storageTransJson);

    if storageTransJson.key?("transactions") && storageTransJson.fetch("transactions").key?("transaction")

      if storageTransJson.fetch("transactions").fetch("transaction").instance_of?(Hash)
        transactionJsonObj = storageTransJson.fetch("transactions").fetch("transaction");
        transaction =  App42::AppTab::TransactionLev.new(levelTrans)
        buildObjectFromJSONTree(transaction, transactionJsonObj);
      else

        transactionJsonArray = storageTransJson.fetch("transactions").fetch("transaction");
        transactionJsonArray.length.times do |i|
          transactionJsonObj = transactionJsonArray.fetch(i);
          transaction =  App42::AppTab::TransactionLev.new(levelTrans)
          buildObjectFromJSONTree(transaction, transactionJsonObj);
        end
      end
    end
  end

  if billJSONObj.key?("featureTransaction")
    storageTransJson  = billJSONObj.fetch("featureTransaction");
    featureTrans = FeatureTransaction.new()
    transactionList = Array.new
    featureTrans.transactionList=(transactionList)
    buildObjectFromJSONTree(featureTrans,storageTransJson);

    if storageTransJson.key?("transactions") && storageTransJson.fetch("transactions").key?("transaction")

      if storageTransJson.fetch("transactions").fetch("transaction").instance_of?(Hash)
        transactionJsonObj = storageTransJson.fetch("transactions").fetch("transaction");
        transaction = App42::AppTab::TransactionFeat.new(featureTrans)
        buildObjectFromJSONTree(transaction, transactionJsonObj);

      else

        transactionJsonArray = storageTransJson.fetch("transactions").fetch("transaction");

        transactionJsonArray.length.times do |i|
          transactionJsonObj = transactionJsonArray.fetch(i);
          transaction = App42::AppTab::TransactionFeat.new(featureTrans)
          buildObjectFromJSONTree(transaction, transactionJsonObj);
        end
      end
    end
  end

  if billJSONObj.key?("licenseTransaction")
    storageTransJson  = billJSONObj.fetch("licenseTransaction");
    licenseTrans = LicenseTransaction.new()
    transactionList = Array.new
    licenseTrans.transactionList=(transactionList)
    buildObjectFromJSONTree(licenseTrans, storageTransJson);

    if storageTransJson.key?("transactions") && storageTransJson.fetch("transactions").key?("transaction")

      if storageTransJson.fetch("transactions").fetch("transaction").instance_of?(Hash)

        transactionJsonObj = storageTransJson.fetch("transactions").fetch("transaction");
        transaction = App42::AppTab::TransactionLic.new(licenseTrans)
        buildObjectFromJSONTree(transaction, transactionJsonObj);

      else

        transactionJsonArray = storageTransJson.fetch("transactions").fetch("transaction");

        transactionJsonArray.length.times do |i|
          transactionJsonObj = transactionJsonArray.fetch(i);
          transaction = App42::AppTab::TransactionLic.new(licenseTrans)
          buildObjectFromJSONTree(transaction, transactionJsonObj);
        end
      end
    end
  end

  return bill;
end

#buildResponse(json) ⇒ Object

Converts the response in JSON format to the value object i.e Bill

Parameters:

  • json
    • response in JSON format

Returns:

  • Bill object filled with json data



25
26
27
28
29
30
31
32
# File 'lib/appTab/BillResponseBuilder.rb', line 25

def buildResponse(json)
  billsJsonObj = getServiceJSONObject("bills", json);
  billJsonObj = billsJsonObj.fetch("bill");
  bill = buildBillObject(billJsonObj);
  bill.strResponse = json
  bill.isResponseSuccess = isResponseSuccess(json)
  return bill
end