survey.go raw
1 /**
2 * Copyright 2016-2024 IBM Corp.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5 * the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
8 * on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9 * See the License for the specific language governing permissions and limitations under the License.
10 */
11
12 // AUTOMATICALLY GENERATED CODE - DO NOT MODIFY
13
14 package services
15
16 import (
17 "fmt"
18 "strings"
19
20 "github.com/softlayer/softlayer-go/datatypes"
21 "github.com/softlayer/softlayer-go/session"
22 "github.com/softlayer/softlayer-go/sl"
23 )
24
25 // The SoftLayer_Survey data type contains general information relating to a single SoftLayer survey.
26 type Survey struct {
27 Session session.SLSession
28 Options sl.Options
29 }
30
31 // GetSurveyService returns an instance of the Survey SoftLayer service
32 func GetSurveyService(sess session.SLSession) Survey {
33 return Survey{Session: sess}
34 }
35
36 func (r Survey) Id(id int) Survey {
37 r.Options.Id = &id
38 return r
39 }
40
41 func (r Survey) Mask(mask string) Survey {
42 if !strings.HasPrefix(mask, "mask[") && (strings.Contains(mask, "[") || strings.Contains(mask, ",")) {
43 mask = fmt.Sprintf("mask[%s]", mask)
44 }
45
46 r.Options.Mask = mask
47 return r
48 }
49
50 func (r Survey) Filter(filter string) Survey {
51 r.Options.Filter = filter
52 return r
53 }
54
55 func (r Survey) Limit(limit int) Survey {
56 r.Options.Limit = &limit
57 return r
58 }
59
60 func (r Survey) Offset(offset int) Survey {
61 r.Options.Offset = &offset
62 return r
63 }
64
65 // Provides survey details for the given type
66 func (r Survey) GetActiveSurveyByType(typ *string) (resp datatypes.Survey, err error) {
67 params := []interface{}{
68 typ,
69 }
70 err = r.Session.DoRequest("SoftLayer_Survey", "getActiveSurveyByType", params, &r.Options, &resp)
71 return
72 }
73
74 // getObject retrieves the SoftLayer_Survey object whose ID number corresponds to the ID number of the init parameter passed to the SoftLayer_Survey service. You can only retrieve the survey that your portal user has taken.
75 func (r Survey) GetObject() (resp datatypes.Survey, err error) {
76 err = r.Session.DoRequest("SoftLayer_Survey", "getObject", nil, &r.Options, &resp)
77 return
78 }
79
80 // Retrieve The questions for a survey.
81 func (r Survey) GetQuestions() (resp []datatypes.Survey_Question, err error) {
82 err = r.Session.DoRequest("SoftLayer_Survey", "getQuestions", nil, &r.Options, &resp)
83 return
84 }
85
86 // Retrieve The status of the survey
87 func (r Survey) GetStatus() (resp datatypes.Survey_Status, err error) {
88 err = r.Session.DoRequest("SoftLayer_Survey", "getStatus", nil, &r.Options, &resp)
89 return
90 }
91
92 // Retrieve The type of survey
93 func (r Survey) GetType() (resp datatypes.Survey_Type, err error) {
94 err = r.Session.DoRequest("SoftLayer_Survey", "getType", nil, &r.Options, &resp)
95 return
96 }
97
98 // Response to a SoftLayer survey's questions.
99 func (r Survey) TakeSurvey(responses []datatypes.Survey_Response) (resp bool, err error) {
100 params := []interface{}{
101 responses,
102 }
103 err = r.Session.DoRequest("SoftLayer_Survey", "takeSurvey", params, &r.Options, &resp)
104 return
105 }
106