Class: QuestionproRails::ApiRequest

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/questionpro_rails/api_request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(survey_id = nil, response_id = nil, result_mode = 0, start_date = nil, end_date = nil, starting_response_counter = nil, email_group_id = nil, template_id = nil, user_id = nil) ⇒ QuestionproRails::ApiRequest

Initializes a new Api Request.

Parameters:

  • survey_id (Integer) (defaults to: nil)
  • response_id (Integer) (defaults to: nil)
  • result_mode (Integer) (defaults to: 0)
  • start_date (String) (defaults to: nil)
  • end_date (String) (defaults to: nil)
  • starting_response_counter (Integer) (defaults to: nil)
  • email_group_id (Integer) (defaults to: nil)
  • template_id (Integer) (defaults to: nil)
  • user_id (Integer) (defaults to: nil)


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/questionpro_rails/api_request.rb', line 33

def initialize(survey_id = nil, response_id = nil, result_mode = 0, start_date = nil, end_date = nil, starting_response_counter = nil, email_group_id = nil, template_id = nil, user_id = nil)
  @survey_id                 = survey_id
  @response_id               = response_id
  @result_mode               = result_mode
  @start_date                = start_date
  @end_date                  = end_date
  @email_group_id            = email_group_id   
  @template_id               = template_id
  @user_id                   = user_id
  @starting_response_counter = starting_response_counter
end

Instance Attribute Details

#email_group_idObject

Returns the value of attribute email_group_id.



17
18
19
# File 'lib/questionpro_rails/api_request.rb', line 17

def email_group_id
  @email_group_id
end

#end_dateObject

Returns the value of attribute end_date.



17
18
19
# File 'lib/questionpro_rails/api_request.rb', line 17

def end_date
  @end_date
end

#full_responseObject

Returns the value of attribute full_response.



17
18
19
# File 'lib/questionpro_rails/api_request.rb', line 17

def full_response
  @full_response
end

#messageObject

Returns the value of attribute message.



17
18
19
# File 'lib/questionpro_rails/api_request.rb', line 17

def message
  @message
end

#response_idObject

Returns the value of attribute response_id.



17
18
19
# File 'lib/questionpro_rails/api_request.rb', line 17

def response_id
  @response_id
end

#result_modeObject

Returns the value of attribute result_mode.



17
18
19
# File 'lib/questionpro_rails/api_request.rb', line 17

def result_mode
  @result_mode
end

#start_dateObject

Returns the value of attribute start_date.



17
18
19
# File 'lib/questionpro_rails/api_request.rb', line 17

def start_date
  @start_date
end

#starting_response_counterObject

Returns the value of attribute starting_response_counter.



17
18
19
# File 'lib/questionpro_rails/api_request.rb', line 17

def starting_response_counter
  @starting_response_counter
end

#statusObject

Returns the value of attribute status.



17
18
19
# File 'lib/questionpro_rails/api_request.rb', line 17

def status
  @status
end

#successObject

Returns the value of attribute success.



17
18
19
# File 'lib/questionpro_rails/api_request.rb', line 17

def success
  @success
end

#survey_idObject

Returns the value of attribute survey_id.



17
18
19
# File 'lib/questionpro_rails/api_request.rb', line 17

def survey_id
  @survey_id
end

#template_idObject

Returns the value of attribute template_id.



17
18
19
# File 'lib/questionpro_rails/api_request.rb', line 17

def template_id
  @template_id
end

#user_idObject

Returns the value of attribute user_id.



17
18
19
# File 'lib/questionpro_rails/api_request.rb', line 17

def user_id
  @user_id
end

Class Method Details

.base_path(method_url) ⇒ String

Get the base url for api call.

Parameters:

  • method_url (String)

    the api method url.

Returns:

  • (String)

    Url for Api Call.



49
50
51
# File 'lib/questionpro_rails/api_request.rb', line 49

def self.base_path(method_url)
  "/a/api/#{method_url}?apiKey=#{QuestionproRails.api_key}"
end

Instance Method Details

#create_email_list(emails = [], email_group_name = nil) ⇒ Object

Create Email List. Survey ID must be set inside the api request object.

Parameters:

  • emails (Array<String>) (defaults to: [])

    ([]).

  • email_group_name (String) (defaults to: nil)

    (nil).

Returns:

  • sets ApiRequest email_group_id to the created email list id.



412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/questionpro_rails/api_request.rb', line 412

def create_email_list (emails = [], email_group_name = nil)
  url = ApiRequest.base_path("questionpro.survey.createEmailGroup")
  result = self.class.get(url, body: {id: self.survey_id, emails: emails, 
                                      emailGroupName: email_group_name}.compact.to_json)

  self.full_response = result
  self.status = result['status']

  unless result['response']['result']['emailGroupID'].nil?
    self.email_group_id = result['response']['result']['emailGroupID']
  end
end

#delete_email_listObject

Delete Specific Email List. Email Group ID must be set inside the api request object.

Returns:

  • sets ApiRequest success attribute to 1.



222
223
224
225
226
227
228
229
230
231
# File 'lib/questionpro_rails/api_request.rb', line 222

def delete_email_list
  url = ApiRequest.base_path("questionpro.survey.deleteEmailList")
  result = self.class.get(url, body: self.options)

  self.full_response = result
  self.status = result['status']
  self.success = result['response']['success']

  return self
end

#delete_email_templateObject

Delete Specific Template. Template ID must be set inside the api request object.

Returns:

  • sets ApiRequest success attribute to 1.



273
274
275
276
277
278
279
280
281
282
# File 'lib/questionpro_rails/api_request.rb', line 273

def delete_email_template
  url = ApiRequest.base_path("questionpro.survey.deleteEmailTemplate")
  result = self.class.get(url, body: self.options)

  self.full_response = result
  self.status = result['status']
  self.success = result['response']['success']

  return self
end

#delete_responseObject

Delete a specific survey response. Survey ID must be set inside the api request object. Response ID must be set inside the api request object.

Returns:

  • sets ApiRequest success attribute to 1.



171
172
173
174
175
176
177
178
179
180
# File 'lib/questionpro_rails/api_request.rb', line 171

def delete_response
  url = ApiRequest.base_path("questionpro.survey.deleteResponse")
  result = self.class.get(url, body: self.options)
  
  self.full_response = result
  self.status = result['status']
  self.success = result['response']['success']

  return self       
end

#delete_surveyObject

Delete a specific survey. Survey ID must be set inside the api request object.

Returns:

  • sets ApiRequest success attribute to 1.



102
103
104
105
106
107
108
109
110
111
# File 'lib/questionpro_rails/api_request.rb', line 102

def delete_survey
  url = ApiRequest.base_path("questionpro.survey.deleteSurvey")
  result = self.class.get(url, body: self.options)
  
  self.full_response = result
  self.status = result['status']
  self.success = result['response']['success']

  return self
end

#get_accountQuestionproRails::Account

Get Specific Account. User ID must be set inside the api request object.

Returns:



307
308
309
310
311
312
313
314
315
316
317
# File 'lib/questionpro_rails/api_request.rb', line 307

def 
  url = ApiRequest.base_path("questionpro.survey.getAccount")
  result = self.class.get(url, body: self.options)

  self.full_response = result
  self.status = result['status']
  
   = Account.new(result['response']['account'])
  
  return 
end

#get_all_accountsArray<QuestionproRails::Account>

Get all the accounts that belongs to the api key’s owner.

Returns:



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/questionpro_rails/api_request.rb', line 287

def get_all_accounts
  url = ApiRequest.base_path("questionpro.survey.getAllAccounts")
  result = self.class.get(url, body: self.options)

  self.full_response = result
  self.status = result['status']
  
  accounts = []
  result_accounts = result['response']['accounts']
  result_accounts.each do ||
    accounts.push(Account.new())
  end
  
  return accounts
end

#get_email_listQuestionproRails::EmailList

Get Specific Email List. Email Group ID must be set inside the api request object.

Returns:



206
207
208
209
210
211
212
213
214
215
216
# File 'lib/questionpro_rails/api_request.rb', line 206

def get_email_list
  url = ApiRequest.base_path("questionpro.survey.getEmailList")
  result = self.class.get(url, body: self.options)

  self.full_response = result
  self.status = result['status']
  
  email_list = EmailList.new(result['response']['emailList'])
  
  return email_list
end

#get_email_listsArray<QuestionproRails::EmailList>

Get Email Lists related to a specific survey. Survey ID must be set inside the api request object.

Returns:



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/questionpro_rails/api_request.rb', line 186

def get_email_lists
  url = ApiRequest.base_path("questionpro.survey.getEmailLists")
  result = self.class.get(url, body: self.options)

  self.full_response = result
  self.status = result['status']
  
  email_lists = []
  result_email_lists = result['response']['emailLists']
  result_email_lists.each do |email_list|
    email_lists.push(EmailList.new(email_list))
  end
  
  return email_lists
end

#get_email_templateQuestionproRails::Template

Get Specific Template. Template ID must be set inside the api request object.

Returns:



257
258
259
260
261
262
263
264
265
266
267
# File 'lib/questionpro_rails/api_request.rb', line 257

def get_email_template
  url = ApiRequest.base_path("questionpro.survey.getEmailTemplate")
  result = self.class.get(url, body: self.options)

  self.full_response = result
  self.status = result['status']
  
  email_template = EmailTemplate.new(result['response']['emailTemplate'])
  
  return email_template
end

#get_email_templatesArray<QuestionproRails::Template>

Get Templates related to a specific survey. Survey ID must be set inside the api request object.

Returns:



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/questionpro_rails/api_request.rb', line 237

def get_email_templates
  url = ApiRequest.base_path("questionpro.survey.getEmailTemplates")
  result = self.class.get(url, body: self.options)

  self.full_response = result
  self.status = result['status']
  
  email_templates = []
  result_email_templates = result['response']['emailTemplates']
  result_email_templates.each do |email_template|
    email_templates.push(EmailTemplate.new(email_template))
  end
  
  return email_templates
end

#get_send_historyArray<QuestionproRails::EmailBatch>

Get Send History related to a specific survey. Survey ID must be set inside the api request object.

Returns:



375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/questionpro_rails/api_request.rb', line 375

def get_send_history
  url = ApiRequest.base_path("questionpro.survey.emailBatchStatistics")
  result = self.class.get(url, body: self.options)

  self.full_response = result
  self.status = result['status']

  email_batches = []
  result_email_batches = result['response']['emailBatches']
  result_email_batches.each do |email_batch|
    email_batches.push(EmailBatch.new(email_batch))
  end
  
  return email_batches      
end

#get_surveyQuestionproRails::Survey

Get a specific survey. Survey ID must be set inside the api request object.

Returns:



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/questionpro_rails/api_request.rb', line 86

def get_survey
  url = ApiRequest.base_path("questionpro.survey.getSurvey")
  result = self.class.get(url, body: self.options)
  
  self.full_response = result
  self.status = result['status']

  survey = Survey.new(result['response'])

  return survey
end

#get_survey_metaQuestionproRails::SurveyMeta

Survey ID must be set inside the api request object.

Returns:



341
342
343
344
345
346
347
348
349
350
351
# File 'lib/questionpro_rails/api_request.rb', line 341

def get_survey_meta
  url = ApiRequest.base_path("questionpro.survey.sendSurveyMetaData")
  result = self.class.get(url, body: self.options)

  self.full_response = result
  self.status = result['status']
  
  survey_meta = SurveyMeta.new(result['response'])
  
  return survey_meta          
end

#get_survey_reponseQuestionproRails::SurveyResponse

Get a specific survey Response. Survey ID must be set inside the api request object. Response ID must be set inside the api request object.

Returns:



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/questionpro_rails/api_request.rb', line 138

def get_survey_reponse
  url = ApiRequest.base_path("questionpro.survey.surveyResponse")
  result = self.class.get(url, body: self.options)
  
  self.full_response = result
  self.status = result['status']

  response = SurveyResponse.new(result['response']['surveyResponse'])

  return response
end

#get_survey_response_countQuestionproRails::SurveyResponseCount

Get a specific survey Response Statistics. Survey ID must be set inside the api request object.

Returns:



154
155
156
157
158
159
160
161
162
163
164
# File 'lib/questionpro_rails/api_request.rb', line 154

def get_survey_response_count
  url = ApiRequest.base_path("questionpro.survey.responseCount")
  result = self.class.get(url, body: self.options)
  
  self.full_response = result
  self.status = result['status']

  response_count = SurveyResponseCount.new(result['response'])

  return response_count
end

#get_survey_responsesArray<QuestionproRails::SurveyResponse>

Get list of survey Responses. Survey ID must be set inside the api request object.

Returns:



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/questionpro_rails/api_request.rb', line 117

def get_survey_responses
  url = ApiRequest.base_path("questionpro.survey.surveyResponses")
  result = self.class.get(url, body: self.options)

  self.full_response = result
  self.status = result['status']
  
  survey_responses = []
  result_responses = result['response']['responses']
  result_responses.each do |response|
    survey_responses.push(SurveyResponse.new(response))
  end
  
  return survey_responses
end

#get_unsubscribersArray<QuestionproRails::UnsubscribedEmail>

Get Unsubscribed Emails related to the api key.

Returns:



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/questionpro_rails/api_request.rb', line 322

def get_unsubscribers
  url = ApiRequest.base_path("questionpro.survey.getUnsubscribedEmailAddresses")
  result = self.class.get(url, body: self.options)

  self.full_response = result
  self.status = result['status']
  
  unsubscribers = []
  result_unsubscribers = result['response']['response']
  result_unsubscribers.each do |unsubscriber|
    unsubscribers.push(UnsubscribedEmail.new(unsubscriber))
  end
  
  return unsubscribers
end

#list_surveysArray<QuestionproRails::Survey>

Get all the surveys that belongs to the api key’s owner.

Returns:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/questionpro_rails/api_request.rb', line 66

def list_surveys
  url = ApiRequest.base_path("questionpro.survey.getAllSurveys")
  result = self.class.get(url, body: self.options)
  
  self.full_response = result
  self.status = result['status']
  
  surveys = []
  result_surveys = result['response']['surveys']
  result_surveys.each do |survey|
    surveys.push(Survey.new(survey))
  end     

  return surveys
end

#optionsJson

Transform the object to the acceptable json format by questionpro.

Returns:

  • (Json)

    options in the call request.



56
57
58
59
60
61
# File 'lib/questionpro_rails/api_request.rb', line 56

def options
  {id: self.survey_id, surveyID: self.survey_id, responseID: self.response_id, 
   resultMode: self.result_mode, startDate: self.start_date, userID: self.user_id, 
   endDate: self.end_date, startingResponseCounter: self.starting_response_counter, 
   emailGroupID: self.email_group_id, templateID: self.template_id}.compact.to_json
end

#send_remindersObject

Send Reminders. Survey ID must be set inside the api request object. Email Group ID must be set inside the api request object. Template ID must be set inside the api request object.

Returns:

  • sets ApiRequest message attribute to “Message successful.”.



397
398
399
400
401
402
403
404
# File 'lib/questionpro_rails/api_request.rb', line 397

def send_reminders
  url = ApiRequest.base_path("questionpro.survey.sendReminder")
  result = self.class.get(url, body: self.options)

  self.full_response = result
  self.status = result['status']
  self.message = result['response']['result']
end

#send_survey(mode = 1, emails = nil, template_id = nil) ⇒ Object

Send Specific Survey. Survey ID must be set inside the api request object.

Parameters:

  • mode (Integer) (defaults to: 1)

    (1).

  • emails (Array<String>) (defaults to: nil)

    to send to (nil).

  • template_id (Integer) (defaults to: nil)

    of email (nil).

Returns:

  • sets ApiRequest message attribute to “Message successful.”.



360
361
362
363
364
365
366
367
368
369
# File 'lib/questionpro_rails/api_request.rb', line 360

def send_survey(mode = 1, emails = nil, template_id = nil)
  url = ApiRequest.base_path("questionpro.survey.sendSurvey")
  result = self.class.get(url, body: {surveyID: self.survey_id, mode: mode, 
                                      emailGroupID: self.email_group_id, emails: emails, 
                                      templateID: self.template_id, template: template_id}.compact.to_json)

  self.full_response = result
  self.status = result['status']
  self.message = result['response']['result']
end