Class: QuestionproRails::ApiRequest
- Inherits:
-
Object
- Object
- QuestionproRails::ApiRequest
- Includes:
- HTTParty
- Defined in:
- lib/questionpro_rails/api_request.rb
Instance Attribute Summary collapse
-
#email_group_id ⇒ Object
Returns the value of attribute email_group_id.
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#full_response ⇒ Object
Returns the value of attribute full_response.
-
#message ⇒ Object
Returns the value of attribute message.
-
#response_id ⇒ Object
Returns the value of attribute response_id.
-
#result_mode ⇒ Object
Returns the value of attribute result_mode.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#starting_response_counter ⇒ Object
Returns the value of attribute starting_response_counter.
-
#status ⇒ Object
Returns the value of attribute status.
-
#success ⇒ Object
Returns the value of attribute success.
-
#survey_id ⇒ Object
Returns the value of attribute survey_id.
-
#template_id ⇒ Object
Returns the value of attribute template_id.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Class Method Summary collapse
-
.base_path(method_url) ⇒ String
Get the base url for api call.
Instance Method Summary collapse
-
#create_email_list(emails = [], email_group_name = nil) ⇒ Object
Create Email List.
-
#delete_email_list ⇒ Object
Delete Specific Email List.
-
#delete_email_template ⇒ Object
Delete Specific Template.
-
#delete_response ⇒ Object
Delete a specific survey response.
-
#delete_survey ⇒ Object
Delete a specific survey.
-
#get_account ⇒ QuestionproRails::Account
Get Specific Account.
-
#get_all_accounts ⇒ Array<QuestionproRails::Account>
Get all the accounts that belongs to the api key’s owner.
-
#get_email_list ⇒ QuestionproRails::EmailList
Get Specific Email List.
-
#get_email_lists ⇒ Array<QuestionproRails::EmailList>
Get Email Lists related to a specific survey.
-
#get_email_template ⇒ QuestionproRails::Template
Get Specific Template.
-
#get_email_templates ⇒ Array<QuestionproRails::Template>
Get Templates related to a specific survey.
-
#get_send_history ⇒ Array<QuestionproRails::EmailBatch>
Get Send History related to a specific survey.
-
#get_survey ⇒ QuestionproRails::Survey
Get a specific survey.
-
#get_survey_meta ⇒ QuestionproRails::SurveyMeta
Survey ID must be set inside the api request object.
-
#get_survey_reponse ⇒ QuestionproRails::SurveyResponse
Get a specific survey Response.
-
#get_survey_response_count ⇒ QuestionproRails::SurveyResponseCount
Get a specific survey Response Statistics.
-
#get_survey_responses ⇒ Array<QuestionproRails::SurveyResponse>
Get list of survey Responses.
-
#get_unsubscribers ⇒ Array<QuestionproRails::UnsubscribedEmail>
Get Unsubscribed Emails related to the api key.
-
#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
constructor
Initializes a new Api Request.
-
#list_surveys ⇒ Array<QuestionproRails::Survey>
Get all the surveys that belongs to the api key’s owner.
-
#options ⇒ Json
Transform the object to the acceptable json format by questionpro.
-
#send_reminders ⇒ Object
Send Reminders.
-
#send_survey(mode = 1, emails = nil, template_id = nil) ⇒ Object
Send Specific Survey.
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.
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_id ⇒ Object
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_date ⇒ Object
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_response ⇒ Object
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 |
#message ⇒ Object
Returns the value of attribute message.
17 18 19 |
# File 'lib/questionpro_rails/api_request.rb', line 17 def @message end |
#response_id ⇒ Object
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_mode ⇒ Object
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_date ⇒ Object
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_counter ⇒ Object
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 |
#status ⇒ Object
Returns the value of attribute status.
17 18 19 |
# File 'lib/questionpro_rails/api_request.rb', line 17 def status @status end |
#success ⇒ Object
Returns the value of attribute success.
17 18 19 |
# File 'lib/questionpro_rails/api_request.rb', line 17 def success @success end |
#survey_id ⇒ Object
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_id ⇒ Object
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_id ⇒ Object
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.
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.
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_list ⇒ Object
Delete Specific Email List. Email Group ID must be set inside the api request object.
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.) self.full_response = result self.status = result['status'] self.success = result['response']['success'] return self end |
#delete_email_template ⇒ Object
Delete Specific Template. Template ID must be set inside the api request object.
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.) self.full_response = result self.status = result['status'] self.success = result['response']['success'] return self end |
#delete_response ⇒ Object
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.
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.) self.full_response = result self.status = result['status'] self.success = result['response']['success'] return self end |
#delete_survey ⇒ Object
Delete a specific survey. Survey ID must be set inside the api request object.
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.) self.full_response = result self.status = result['status'] self.success = result['response']['success'] return self end |
#get_account ⇒ QuestionproRails::Account
Get Specific Account. User ID must be set inside the api request object.
307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/questionpro_rails/api_request.rb', line 307 def get_account url = ApiRequest.base_path("questionpro.survey.getAccount") result = self.class.get(url, body: self.) self.full_response = result self.status = result['status'] account = Account.new(result['response']['account']) return account end |
#get_all_accounts ⇒ Array<QuestionproRails::Account>
Get all the accounts that belongs to the api key’s owner.
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.) self.full_response = result self.status = result['status'] accounts = [] result_accounts = result['response']['accounts'] result_accounts.each do |account| accounts.push(Account.new(account)) end return accounts end |
#get_email_list ⇒ QuestionproRails::EmailList
Get Specific Email List. Email Group ID must be set inside the api request object.
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.) self.full_response = result self.status = result['status'] email_list = EmailList.new(result['response']['emailList']) return email_list end |
#get_email_lists ⇒ Array<QuestionproRails::EmailList>
Get Email Lists related to a specific survey. Survey ID must be set inside the api request object.
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.) 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_template ⇒ QuestionproRails::Template
Get Specific Template. Template ID must be set inside the api request object.
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.) self.full_response = result self.status = result['status'] email_template = EmailTemplate.new(result['response']['emailTemplate']) return email_template end |
#get_email_templates ⇒ Array<QuestionproRails::Template>
Get Templates related to a specific survey. Survey ID must be set inside the api request object.
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.) 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_history ⇒ Array<QuestionproRails::EmailBatch>
Get Send History related to a specific survey. Survey ID must be set inside the api request object.
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.) 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_survey ⇒ QuestionproRails::Survey
Get a specific survey. Survey ID must be set inside the api request object.
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.) self.full_response = result self.status = result['status'] survey = Survey.new(result['response']) return survey end |
#get_survey_meta ⇒ QuestionproRails::SurveyMeta
Survey ID must be set inside the api request object.
341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/questionpro_rails/api_request.rb', line 341 def url = ApiRequest.base_path("questionpro.survey.sendSurveyMetaData") result = self.class.get(url, body: self.) self.full_response = result self.status = result['status'] = SurveyMeta.new(result['response']) return end |
#get_survey_reponse ⇒ QuestionproRails::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.
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.) self.full_response = result self.status = result['status'] response = SurveyResponse.new(result['response']['surveyResponse']) return response end |
#get_survey_response_count ⇒ QuestionproRails::SurveyResponseCount
Get a specific survey Response Statistics. Survey ID must be set inside the api request object.
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.) self.full_response = result self.status = result['status'] response_count = SurveyResponseCount.new(result['response']) return response_count end |
#get_survey_responses ⇒ Array<QuestionproRails::SurveyResponse>
Get list of survey Responses. Survey ID must be set inside the api request object.
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.) 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_unsubscribers ⇒ Array<QuestionproRails::UnsubscribedEmail>
Get Unsubscribed Emails related to the api key.
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.) 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_surveys ⇒ Array<QuestionproRails::Survey>
Get all the surveys that belongs to the api key’s owner.
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.) 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 |
#options ⇒ Json
Transform the object to the acceptable json format by questionpro.
56 57 58 59 60 61 |
# File 'lib/questionpro_rails/api_request.rb', line 56 def {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_reminders ⇒ Object
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.
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.) self.full_response = result self.status = result['status'] self. = 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.
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. = result['response']['result'] end |