qualtrics_api 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f8c86f14151c132a64f4c8aff0873fa87ca6793
4
- data.tar.gz: cc34a47d547633e0bea66b2b3791ad46818fb01d
3
+ metadata.gz: 1f836176e18af2d85f18fba39a7af32952e185a2
4
+ data.tar.gz: 24a7800f963644225c332126d6df9c85dae67ea0
5
5
  SHA512:
6
- metadata.gz: 77d7d06a3bcfc5e8d9806ff0a19c7ca28006bdb8d3311360f3fdd550a1786a0d0dd18092e26016460216661e416515ad07e134f2687d6e8a6bc38f1c40e75ba7
7
- data.tar.gz: 696d86de618b275d3da4e53fdaf65f80c3228b8f590a469f21e1f38d202d10333dd5c01d95a52fd76c9d11125414d2c74bb89874b02e79bf42d7eea2405c9fac
6
+ metadata.gz: 01df3b46bf2cbe27349920312e2b54efb0c64a0ecf7d004c57acc35ee3d7ad10f90652c81018f6e8ca210121ae8a7b810815a8f5e0ec38fc40e37e3028eded95
7
+ data.tar.gz: 68edbed27d3c5c3f6b66fb2d760e7dc5f6d47dc22136d882ae9e2de47aa16d23d79d61af07167fc923279cda246a18251e3f197c9c1c3b5e09e218ab843f7550
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  # QualtricsAPI
6
6
 
7
7
  Ruby wrapper for Qualtrics REST ControlPanel API version 3.0.
8
- [API Documents/Play Ground](https://co1.qualtrics.com/APIDocs/)
8
+ [API Documents/Play Ground](https://api.qualtrics.com/)
9
9
 
10
10
  ## Installation
11
11
 
@@ -35,14 +35,20 @@ end
35
35
 
36
36
  ### Surveys
37
37
 
38
- To get all your surveys:
38
+ To paginate all your surveys:
39
39
 
40
40
  ```ruby
41
- QualtricsAPI.surveys.fetch
41
+ surveys = QualtricsAPI.surveys.fetch
42
42
  # => #<QualtricsAPI::SurveyCollection:0x007fcb72cce350 ....>
43
+
44
+ surveys = surveys.next_page # to fetch next page if not on the last page
45
+ # => #<QualtricsAPI::SurveyCollection:0x007fcb72cce350 ....>
46
+
47
+ surveys.next_page?
48
+ # => true
43
49
  ```
44
50
 
45
- After you have received results, you can search for a survey by id:
51
+ You can search for a survey by id:
46
52
 
47
53
  ```ruby
48
54
  survey = QualtricsAPI.surveys.find("surveyIdHere")
@@ -131,14 +137,17 @@ export.status
131
137
 
132
138
  ### Panels
133
139
 
134
- To get all the panels:
140
+ To paginate all the panels:
135
141
 
136
142
  ```ruby
137
- QualtricsAPI.panels.fetch
143
+ panels = QualtricsAPI.panels.fetch
144
+ # => #<QualtricsAPI::PanelCollection:0x007f8769aae2c0 ....>
145
+
146
+ panels = panels.next_page # get next page if panels.next_page?
138
147
  # => #<QualtricsAPI::PanelCollection:0x007f8769aae2c0 ....>
139
148
  ```
140
149
 
141
- After you have received results, you can search for a panel by id:
150
+ You can search for a panel by id:
142
151
 
143
152
  ```ruby
144
153
  panel = QualtricsAPI.panels.find("panelIdHere")
@@ -157,7 +166,7 @@ panel = QualtricsAPI.panels["panelIdHere"]
157
166
  To add panel members to a panel:
158
167
 
159
168
  ```ruby
160
- panel = QualtricsAPI.panels.fetch["panelIdHere"]
169
+ panel = QualtricsAPI.panels.find("panelIdHere")
161
170
  members = [QualtricsAPI::PanelMember.new(first_name: 'John', last_name: 'Doe', email: 'test@test.com')]
162
171
  panel.members.create(members)
163
172
  => #<QualtricsAPI::PanelImport:0x007fb7db984668 ...>
@@ -32,4 +32,36 @@ http_interactions:
32
32
  - OK"}}'
33
33
  http_version:
34
34
  recorded_at: Mon, 11 Apr 2016 13:26:52 GMT
35
+ - request:
36
+ method: get
37
+ uri: https://co1.qualtrics.com/API/v3/mailinglists
38
+ body:
39
+ encoding: US-ASCII
40
+ string: ''
41
+ headers:
42
+ X-API-TOKEN:
43
+ - 2aYeWieRoRq1cOapLnTKZuHuQc8FMq7zZvSGps0v
44
+ User-Agent:
45
+ - Faraday v0.9.2
46
+ response:
47
+ status:
48
+ code: 200
49
+ message:
50
+ headers:
51
+ content-type:
52
+ - application/json; charset=utf-8
53
+ request-time:
54
+ - '742'
55
+ content-length:
56
+ - '1329'
57
+ date:
58
+ - Mon, 11 Apr 2016 13:26:52 GMT
59
+ connection:
60
+ - close
61
+ body:
62
+ encoding: UTF-8
63
+ string: '{"result":{"elements":[{"panelId":"AB_abcdefghijk","name":"Master Panel","libraryId":"GR_abcdefghijk","category":"Unassigned"}],"nextPage":"https://co1.qualtrics.com/API/v3/mailinglists?offset=20"},"meta":{"httpStatus":"200
64
+ - OK"}}'
65
+ http_version:
66
+ recorded_at: Mon, 11 Apr 2016 13:26:52 GMT
35
67
  recorded_with: VCR 2.9.3
@@ -0,0 +1,65 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://co1.qualtrics.com/API/v3/mailinglists/ML_00c5BS2WNUCWQIt
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-API-TOKEN:
11
+ - 6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
12
+ User-Agent:
13
+ - Faraday v0.9.2
14
+ response:
15
+ status:
16
+ code: 200
17
+ message:
18
+ headers:
19
+ content-type:
20
+ - application/json; charset=utf-8
21
+ request-time:
22
+ - '216'
23
+ content-length:
24
+ - '164'
25
+ date:
26
+ - Wed, 13 Apr 2016 13:15:28 GMT
27
+ connection:
28
+ - close
29
+ body:
30
+ encoding: UTF-8
31
+ string: '{"result":{"id":"ML_00c5BS2WNUCWQIt","libraryId":"UR_5dURLpfp5tm43EV","name":"Panel name","category":"Unassigned"},"meta":{"httpStatus":"200 -
32
+ OK"}}'
33
+ http_version:
34
+ recorded_at: Wed, 13 Apr 2016 13:15:28 GMT
35
+ - request:
36
+ method: get
37
+ uri: https://co1.qualtrics.com/API/v3/mailinglists/ML_00c5BS2WNUCWQI0
38
+ body:
39
+ encoding: US-ASCII
40
+ string: ''
41
+ headers:
42
+ X-API-TOKEN:
43
+ - 6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
44
+ User-Agent:
45
+ - Faraday v0.9.2
46
+ response:
47
+ status:
48
+ code: 400
49
+ message:
50
+ headers:
51
+ content-type:
52
+ - application/json
53
+ content-length:
54
+ - '145'
55
+ date:
56
+ - Wed, 13 Apr 2016 13:15:35 GMT
57
+ connection:
58
+ - close
59
+ body:
60
+ encoding: UTF-8
61
+ string: '{"meta":{"httpStatus":"400 - Bad Request","error":{"errorMessage":"Invalid
62
+ mailingListId parameter. Mailing list not found","errorCode":"GP_0"}}}'
63
+ http_version:
64
+ recorded_at: Wed, 13 Apr 2016 13:15:35 GMT
65
+ recorded_with: VCR 2.9.3
@@ -2,7 +2,39 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://co1.qualtrics.com/API/v3/mailinglists
5
+ uri: https://co1.qualtrics.com/API/v3/mailinglists/ML_0APx3C4rmHER6w5
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-API-TOKEN:
11
+ - 6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
12
+ User-Agent:
13
+ - Faraday v0.9.2
14
+ response:
15
+ status:
16
+ code: 200
17
+ message:
18
+ headers:
19
+ content-type:
20
+ - application/json; charset=utf-8
21
+ request-time:
22
+ - '216'
23
+ content-length:
24
+ - '164'
25
+ date:
26
+ - Wed, 13 Apr 2016 13:15:28 GMT
27
+ connection:
28
+ - close
29
+ body:
30
+ encoding: UTF-8
31
+ string: '{"result":{"id":"ML_0APx3C4rmHER6w5","libraryId":"UR_5dURLpfp5tm43EV","name":"Panel name","category":"Unassigned"},"meta":{"httpStatus":"200 -
32
+ OK"}}'
33
+ http_version:
34
+ recorded_at: Wed, 13 Apr 2016 13:15:28 GMT
35
+ - request:
36
+ method: post
37
+ uri: https://co1.qualtrics.com/API/v3/mailinglists/ML_0APx3C4rmHER6w5/contactimports
6
38
  body:
7
39
  encoding: US-ASCII
8
40
  string: ''
@@ -32,6 +32,38 @@ http_interactions:
32
32
  - OK"}}'
33
33
  http_version:
34
34
  recorded_at: Tue, 12 Apr 2016 21:35:39 GMT
35
+ - request:
36
+ method: get
37
+ uri: https://co1.qualtrics.com/API/v3/mailinglists/ML_0APx3C4rmHER6w5
38
+ body:
39
+ encoding: US-ASCII
40
+ string: ''
41
+ headers:
42
+ X-API-TOKEN:
43
+ - 6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
44
+ User-Agent:
45
+ - Faraday v0.9.2
46
+ response:
47
+ status:
48
+ code: 200
49
+ message:
50
+ headers:
51
+ content-type:
52
+ - application/json; charset=utf-8
53
+ request-time:
54
+ - '216'
55
+ content-length:
56
+ - '164'
57
+ date:
58
+ - Wed, 13 Apr 2016 13:15:28 GMT
59
+ connection:
60
+ - close
61
+ body:
62
+ encoding: UTF-8
63
+ string: '{"result":{"id":"ML_0APx3C4rmHER6w5","libraryId":"UR_5dURLpfp5tm43EV","name":"Panel name","category":"Unassigned"},"meta":{"httpStatus":"200 -
64
+ OK"}}'
65
+ http_version:
66
+ recorded_at: Wed, 13 Apr 2016 13:15:28 GMT
35
67
  - request:
36
68
  method: post
37
69
  uri: https://co1.qualtrics.com/API/v3/mailinglists/ML_0APx3C4rmHER6w5/contactimports
@@ -70,4 +102,36 @@ http_interactions:
70
102
  OK"}}'
71
103
  http_version:
72
104
  recorded_at: Tue, 12 Apr 2016 21:35:40 GMT
105
+ - request:
106
+ method: get
107
+ uri: https://co1.qualtrics.com/API/v3/mailinglists/ML_bC2c5xBz1DxyOYB
108
+ body:
109
+ encoding: US-ASCII
110
+ string: ''
111
+ headers:
112
+ X-API-TOKEN:
113
+ - 6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
114
+ User-Agent:
115
+ - Faraday v0.9.2
116
+ response:
117
+ status:
118
+ code: 200
119
+ message:
120
+ headers:
121
+ content-type:
122
+ - application/json; charset=utf-8
123
+ request-time:
124
+ - '216'
125
+ content-length:
126
+ - '164'
127
+ date:
128
+ - Wed, 13 Apr 2016 13:15:28 GMT
129
+ connection:
130
+ - close
131
+ body:
132
+ encoding: UTF-8
133
+ string: '{"result":{"id":"ML_bC2c5xBz1DxyOYB","libraryId":"UR_5dURLpfp5tm43EV","name":"Panel name","category":"Unassigned"},"meta":{"httpStatus":"200 -
134
+ OK"}}'
135
+ http_version:
136
+ recorded_at: Wed, 13 Apr 2016 13:15:28 GMT
73
137
  recorded_with: VCR 2.9.3
@@ -34,4 +34,36 @@ http_interactions:
34
34
  - OK"}}'
35
35
  http_version:
36
36
  recorded_at: Tue, 12 Apr 2016 10:08:29 GMT
37
+ - request:
38
+ method: get
39
+ uri: https://co1.qualtrics.com/API/v3/surveys/SV_bpCTGQvjOqgd4RD
40
+ body:
41
+ encoding: US-ASCII
42
+ string: ''
43
+ headers:
44
+ X-API-TOKEN:
45
+ - 6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
46
+ User-Agent:
47
+ - Faraday v0.9.2
48
+ response:
49
+ status:
50
+ code: 200
51
+ message:
52
+ headers:
53
+ content-type:
54
+ - application/json; charset=utf-8
55
+ request-time:
56
+ - '642'
57
+ content-length:
58
+ - '1339'
59
+ date:
60
+ - Wed, 13 Apr 2016 13:04:14 GMT
61
+ connection:
62
+ - close
63
+ body:
64
+ encoding: UTF-8
65
+ string: '{"result":{"id":"SV_bpCTGQvjOqgd4RD","name":"test","ownerId":"owner_id","organizationId":"organizationid","isActive":true,"creationDate":"2016-04-01T09:12:05Z","lastModifiedDate":"2016-04-06T15:04:28Z","expiration":{"startDate":null,"endDate":null},"questions":{},"exportColumnMap":{},"blocks":{},"flow":[],"embeddedData":[],"responseCounts":{"auditable":0,"generated":2,"deleted":2}},"meta":{"httpStatus":"200
66
+ - OK"}}'
67
+ http_version:
68
+ recorded_at: Wed, 13 Apr 2016 13:04:14 GMT
37
69
  recorded_with: VCR 2.9.3
@@ -32,4 +32,36 @@ http_interactions:
32
32
  - OK"}}'
33
33
  http_version:
34
34
  recorded_at: Mon, 11 Apr 2016 13:04:55 GMT
35
+ - request:
36
+ method: get
37
+ uri: https://co1.qualtrics.com/API/v3/surveys?offset=10
38
+ body:
39
+ encoding: US-ASCII
40
+ string: ''
41
+ headers:
42
+ X-API-TOKEN:
43
+ - 6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
44
+ User-Agent:
45
+ - Faraday v0.9.2
46
+ response:
47
+ status:
48
+ code: 200
49
+ message:
50
+ headers:
51
+ content-type:
52
+ - application/json; charset=utf-8
53
+ request-time:
54
+ - '573'
55
+ content-length:
56
+ - '1737'
57
+ date:
58
+ - Mon, 11 Apr 2016 13:04:55 GMT
59
+ connection:
60
+ - close
61
+ body:
62
+ encoding: UTF-8
63
+ string: '{"result":{"elements":[],"nextPage":null},"meta":{"httpStatus":"200
64
+ - OK"}}'
65
+ http_version:
66
+ recorded_at: Mon, 11 Apr 2016 13:04:55 GMT
35
67
  recorded_with: VCR 2.9.3
@@ -0,0 +1,65 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://co1.qualtrics.com/API/v3/surveys/SV_0fEV92PdRg8a2e9
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-API-TOKEN:
11
+ - 6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
12
+ User-Agent:
13
+ - Faraday v0.9.2
14
+ response:
15
+ status:
16
+ code: 200
17
+ message:
18
+ headers:
19
+ content-type:
20
+ - application/json; charset=utf-8
21
+ request-time:
22
+ - '642'
23
+ content-length:
24
+ - '1339'
25
+ date:
26
+ - Wed, 13 Apr 2016 13:04:14 GMT
27
+ connection:
28
+ - close
29
+ body:
30
+ encoding: UTF-8
31
+ string: '{"result":{"id":"SV_0fEV92PdRg8a2e9","name":"test","ownerId":"owner_id","organizationId":"organizationid","isActive":true,"creationDate":"2016-04-01T09:12:05Z","lastModifiedDate":"2016-04-06T15:04:28Z","expiration":{"startDate":null,"endDate":null},"questions":{},"exportColumnMap":{},"blocks":{},"flow":[],"embeddedData":[],"responseCounts":{"auditable":0,"generated":2,"deleted":2}},"meta":{"httpStatus":"200
32
+ - OK"}}'
33
+ http_version:
34
+ recorded_at: Wed, 13 Apr 2016 13:04:14 GMT
35
+ - request:
36
+ method: get
37
+ uri: https://co1.qualtrics.com/API/v3/surveys/SV_0fEV92PdRg8a2e0
38
+ body:
39
+ encoding: US-ASCII
40
+ string: ''
41
+ headers:
42
+ X-API-TOKEN:
43
+ - 6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
44
+ User-Agent:
45
+ - Faraday v0.9.2
46
+ response:
47
+ status:
48
+ code: 404
49
+ message:
50
+ headers:
51
+ content-type:
52
+ - application/json
53
+ content-length:
54
+ - '106'
55
+ date:
56
+ - Wed, 13 Apr 2016 13:04:18 GMT
57
+ connection:
58
+ - close
59
+ body:
60
+ encoding: UTF-8
61
+ string: '{"meta":{"httpStatus":"404 - Not Found","error":{"errorMessage":"Survey
62
+ not found.","errorCode":"GSI_2"}}}'
63
+ http_version:
64
+ recorded_at: Wed, 13 Apr 2016 13:04:19 GMT
65
+ recorded_with: VCR 2.9.3
@@ -6,7 +6,45 @@ module QualtricsAPI
6
6
  include QualtricsAPI::Extensions::SerializableCollection
7
7
  include QualtricsAPI::Connectable
8
8
 
9
- def_delegator :all, :each
10
- def_delegator :all, :size
9
+ values do
10
+ attribute :page, Array, :default => []
11
+ attribute :fetched, Boolean, :default => false
12
+ attribute :next_endpoint, String
13
+ end
14
+
15
+ def_delegator :page, :each
16
+
17
+ def fetch
18
+ parse_fetch_response(QualtricsAPI.connection(self).get(list_endpoint))
19
+ self
20
+ end
21
+
22
+ def next_page
23
+ raise NotFoundError unless next_page?
24
+ self.class.new.tap do |r|
25
+ r.parse_fetch_response(QualtricsAPI.connection(self).get(next_endpoint))
26
+ end
27
+ end
28
+
29
+ def find(id)
30
+ response = QualtricsAPI.connection(self).get(endpoint(id))
31
+ return nil unless response.status == 200
32
+ build_result(response.body['result']).propagate_connection(self)
33
+ end
34
+
35
+ def next_page?
36
+ raise NotYetFetchedError unless fetched
37
+ !next_endpoint.nil?
38
+ end
39
+
40
+ protected
41
+
42
+ def parse_fetch_response(response)
43
+ @page = response.body["result"]["elements"].map do |element|
44
+ build_result(element).propagate_connection(self)
45
+ end
46
+ @next_endpoint = response.body["result"]["nextPage"]
47
+ @fetched = true
48
+ end
11
49
  end
12
50
  end
@@ -7,15 +7,15 @@ module QualtricsAPI
7
7
  end
8
8
 
9
9
  def surveys(options = {})
10
- @surveys ||= QualtricsAPI::SurveyCollection.new(options).propagate_connection(self)
10
+ QualtricsAPI::SurveyCollection.new(options).propagate_connection(self)
11
11
  end
12
12
 
13
13
  def response_exports(options = {})
14
- @response_exports ||= QualtricsAPI::ResponseExportCollection.new(options).propagate_connection(self)
14
+ QualtricsAPI::ResponseExportCollection.new(options).propagate_connection(self)
15
15
  end
16
16
 
17
17
  def panels(options = {})
18
- @panels ||= QualtricsAPI::PanelCollection.new(options).propagate_connection(self)
18
+ QualtricsAPI::PanelCollection.new(options).propagate_connection(self)
19
19
  end
20
20
 
21
21
  private
@@ -1,31 +1,21 @@
1
1
  module QualtricsAPI
2
2
  class PanelCollection < BaseCollection
3
- values do
4
- attribute :all, Array, :default => []
5
- end
6
-
7
- def fetch()
8
- @all = []
9
- parse_fetch_response(QualtricsAPI.connection(self).get('mailinglists'))
10
- self
11
- end
12
-
13
3
  def [](panel_id)
14
4
  find(panel_id)
15
5
  end
16
6
 
17
- def find(panel_id)
18
- @all.detect do |panel|
19
- panel.id == panel_id
20
- end || QualtricsAPI::Panel.new("panelId" => panel_id).propagate_connection(self)
7
+ private
8
+
9
+ def build_result(element)
10
+ QualtricsAPI::Panel.new(element)
21
11
  end
22
12
 
23
- private
13
+ def list_endpoint
14
+ 'mailinglists'
15
+ end
24
16
 
25
- def parse_fetch_response(response)
26
- @all = response.body["result"]["elements"].map do |elements|
27
- QualtricsAPI::Panel.new(elements).propagate_connection(self)
28
- end
17
+ def endpoint(id)
18
+ "mailinglists/#{id}"
29
19
  end
30
20
  end
31
21
  end
@@ -2,15 +2,8 @@ module QualtricsAPI
2
2
  class PanelMemberCollection < BaseCollection
3
3
  values do
4
4
  attribute :id, String
5
- attribute :all, Array, :default => []
6
5
  end
7
6
 
8
- def fetch(_options = {})
9
- @all = []
10
- parse_fetch_response(QualtricsAPI.connection(self).get("mailinglists/#{id}/contacts"))
11
- self
12
- end
13
-
14
7
  def create(panel_members)
15
8
  payload = {
16
9
  contacts: Faraday::UploadIO.new(StringIO.new(panel_members.to_json), 'application/json', 'contacts.json')
@@ -22,22 +15,26 @@ module QualtricsAPI
22
15
  QualtricsAPI::PanelImport.new(id: import_id, panel_id: id).propagate_connection(self)
23
16
  end
24
17
 
18
+ def find(id)
19
+ raise QualtricsAPI::NotSupported, 'Find not supported for panel member'
20
+ end
21
+
25
22
  def [](member_id)
26
23
  find(member_id)
27
24
  end
28
-
29
- def find(member_id)
30
- @all.detect do |panel_member|
31
- panel_member.id == member_id
32
- end || QualtricsAPI::PanelMember.new(:id => member_id).propagate_connection(self)
33
- end
34
25
 
35
26
  private
27
+
28
+ def build_result(element)
29
+ QualtricsAPI::PanelMember.new(element)
30
+ end
31
+
32
+ def list_endpoint
33
+ "mailinglists/#{id}/contacts"
34
+ end
36
35
 
37
- def parse_fetch_response(response)
38
- @all = response.body["result"]["elements"].map do |element|
39
- QualtricsAPI::PanelMember.new(element).propagate_connection(self)
40
- end
36
+ def endpoint(member_id)
37
+ "mailinglists/#{id}/contacts/#{member_id}"
41
38
  end
42
39
  end
43
40
  end
@@ -26,8 +26,10 @@ module QualtricsAPI
26
26
  end
27
27
  end
28
28
 
29
+ class NotYetFetchedError < StandardError; end
29
30
  class NotFoundError < StandardError; end
30
31
  class BadRequestError < StandardError; end
31
32
  class UnauthorizedError < StandardError; end
32
33
  class InternalServerError < StandardError; end
34
+ class NotSupported < StandardError; end
33
35
  end
@@ -1,17 +1,14 @@
1
1
  module QualtricsAPI
2
- class ResponseExportCollection < BaseCollection
3
- values do
4
- attribute :all, Array, :default => []
5
- end
2
+ class ResponseExportCollection
3
+ include Virtus.value_object
4
+ include QualtricsAPI::Connectable
6
5
 
7
6
  def [](export_id)
8
7
  find(export_id)
9
8
  end
10
9
 
11
10
  def find(export_id)
12
- @all.detect do |response_export|
13
- response_export.id == export_id
14
- end || QualtricsAPI::ResponseExport.new(:id => export_id).propagate_connection(self)
11
+ QualtricsAPI::ResponseExport.new(:id => export_id).propagate_connection(self)
15
12
  end
16
13
  end
17
14
  end
@@ -1,31 +1,21 @@
1
1
  module QualtricsAPI
2
2
  class SurveyCollection < BaseCollection
3
- values do
4
- attribute :all, Array, :default => []
5
- end
6
-
7
- def fetch
8
- @all = []
9
- parse_fetch_response(QualtricsAPI.connection(self).get('surveys'))
10
- self
11
- end
12
-
13
3
  def [](survey_id)
14
4
  find(survey_id)
15
5
  end
16
6
 
17
- def find(survey_id)
18
- @all.detect do |survey|
19
- survey.id == survey_id
20
- end || QualtricsAPI::Survey.new("id" => survey_id)
7
+ private
8
+
9
+ def build_result(element)
10
+ QualtricsAPI::Survey.new(element)
21
11
  end
22
12
 
23
- private
13
+ def list_endpoint
14
+ 'surveys'
15
+ end
24
16
 
25
- def parse_fetch_response(response)
26
- @all = response.body["result"]['elements'].map do |elements|
27
- QualtricsAPI::Survey.new(elements).propagate_connection(self)
28
- end
17
+ def endpoint(id)
18
+ "surveys/#{id}"
29
19
  end
30
20
  end
31
21
  end
@@ -1,3 +1,3 @@
1
1
  module QualtricsAPI
2
- VERSION = "0.0.9".freeze
2
+ VERSION = "0.0.10".freeze
3
3
  end
@@ -30,6 +30,4 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "rake", "~> 11.1"
31
31
  spec.add_development_dependency "rspec", "~> 3.4"
32
32
  spec.add_development_dependency "vcr", "~> 2.9"
33
- spec.add_development_dependency "guard-rspec", "~> 4.5"
34
- spec.add_development_dependency "pry", "~> 0.10.1"
35
33
  end
@@ -7,20 +7,12 @@ describe QualtricsAPI::Client do
7
7
  it "returns a ResponseExportCollection" do
8
8
  expect(subject.response_exports).to be_a QualtricsAPI::ResponseExportCollection
9
9
  end
10
-
11
- it "caches the collection" do
12
- expect(subject.response_exports.object_id).to eq subject.response_exports.object_id
13
- end
14
10
  end
15
11
 
16
12
  describe "#surveys" do
17
13
  it "returns a SurveyCollection" do
18
14
  expect(subject.surveys).to be_a QualtricsAPI::SurveyCollection
19
15
  end
20
-
21
- it "caches the surveys" do
22
- expect(subject.surveys.object_id).to eq subject.surveys.object_id
23
- end
24
16
  end
25
17
 
26
18
  describe "#initialize" do
@@ -1,32 +1,38 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe QualtricsAPI::PanelCollection do
4
- it "has no @all when initialized" do
5
- expect(subject.all).to eq []
4
+ it "has no @page when initialized" do
5
+ expect(subject.page).to eq []
6
6
  end
7
7
 
8
- describe "#find, #[]" do
9
- let(:panel_1) { QualtricsAPI::Panel.new "panelId" => "p1" }
10
- let(:panel_2) { QualtricsAPI::Panel.new "panelId" => "p2" }
11
-
12
- it "finds the panel by id" do
13
- subject.instance_variable_set :@all, [panel_1, panel_2]
14
- expect(subject.find("p1")).to eq panel_1
15
- expect(subject["p2"]).to eq panel_2
16
- end
8
+ describe "integration" do
9
+ describe "#find" do
10
+ let(:result) do
11
+ VCR.use_cassette("panel_find") do
12
+ subject.find(panel_id)
13
+ end
14
+ end
17
15
 
18
- it "returns a new panel with the id" do
19
- new_panel = subject["p3"]
20
- expect(new_panel).to be_a QualtricsAPI::Panel
21
- expect(new_panel.id).to eq "p3"
16
+ context 'when exists' do
17
+ let(:panel_id) { 'ML_00c5BS2WNUCWQIt' }
18
+
19
+ it 'populates the result' do
20
+ expect(result.attributes).to eq(:id => "ML_00c5BS2WNUCWQIt", :library_id => "UR_5dURLpfp5tm43EV", :name => "Panel name", :category => "Unassigned")
21
+ end
22
+ end
23
+
24
+ context 'when does not exists' do
25
+ let(:panel_id) { 'ML_00c5BS2WNUCWQI0' }
26
+
27
+ it 'raises bad request error' do
28
+ expect { result }.to raise_error(QualtricsAPI::BadRequestError)
29
+ end
30
+ end
22
31
  end
23
- end
24
-
25
- describe "integration" do
26
32
  describe "#fetch" do
27
33
  describe "when success" do
28
34
  before do
29
- expect(subject.size).to eq 0
35
+ expect(subject.page.size).to eq 0
30
36
  end
31
37
 
32
38
  let!(:result) do
@@ -36,7 +42,7 @@ describe QualtricsAPI::PanelCollection do
36
42
  end
37
43
 
38
44
  it "populates the collection" do
39
- expect(subject.size).to eq 1
45
+ expect(subject.page.size).to eq 1
40
46
  expect(subject.first).to be_a QualtricsAPI::Panel
41
47
  end
42
48
 
@@ -46,23 +52,27 @@ describe QualtricsAPI::PanelCollection do
46
52
  end
47
53
 
48
54
  describe "when failed" do
49
- it "resets panels" do
50
- subject.instance_variable_set :@all, [QualtricsAPI::Panel.new({})]
51
- expect {
55
+ it "raises error and does not reset panels" do
56
+ subject.instance_variable_set :@page, [QualtricsAPI::Panel.new({})]
57
+ expect do
52
58
  VCR.use_cassette("panel_collection_fetch_fail") do
53
- subject.fetch rescue nil
59
+ begin
60
+ subject.fetch
61
+ rescue
62
+ nil
63
+ end
54
64
  end
55
- }.to change { subject.all }.to([])
65
+ end.not_to change { subject.page }
56
66
  end
57
67
  end
58
68
  end
59
69
  end
60
70
 
61
71
  describe 'equality' do
62
- subject { described_class.new(all: [QualtricsAPI::Panel.new("panelId" => "p1"), QualtricsAPI::Panel.new("panelId" => "p2")]) }
72
+ subject { described_class.new(page: [QualtricsAPI::Panel.new("panelId" => "p1"), QualtricsAPI::Panel.new("panelId" => "p2")]) }
63
73
  context 'when same' do
64
74
  it 'returns true' do
65
- expect(subject).to eq(described_class.new(all: subject.all))
75
+ expect(subject).to eq(described_class.new(page: subject.page))
66
76
  end
67
77
  end
68
78
 
@@ -1,34 +1,41 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe QualtricsAPI::PanelMemberCollection do
4
- it "has no @all when initialized" do
5
- expect(subject.all).to eq []
4
+ it "has no @page when initialized" do
5
+ expect(subject.page).to eq []
6
6
  end
7
7
 
8
- describe "#find, #[]" do
9
- let(:panel_member_1) { QualtricsAPI::PanelMember.new("panelMemberId" => "p1") }
10
- let(:panel_member_2) { QualtricsAPI::PanelMember.new("panelMemberId" => "p2") }
8
+ describe "integration" do
9
+ subject { described_class.new(id: 'ABCD') }
11
10
 
12
- it "finds the panel member by id" do
13
- subject.instance_variable_set :@all, [panel_member_1, panel_member_2]
14
- expect(subject.find("p1")).to eq panel_member_1
15
- expect(subject["p2"]).to eq panel_member_2
16
- end
11
+ describe "#find" do
12
+ let(:result) do
13
+ VCR.use_cassette("survey_find") do
14
+ subject.find(survey_id)
15
+ end
16
+ end
17
17
 
18
- it "returns a new panel with the id" do
19
- new_panel_member = subject["p3"]
20
- expect(new_panel_member).to be_a QualtricsAPI::PanelMember
21
- expect(new_panel_member.id).to eq "p3"
18
+ context 'when exists' do
19
+ let(:survey_id) { 'SV_0fEV92PdRg8a2e9' }
20
+
21
+ it 'raises error' do
22
+ expect { result }.to raise_error(QualtricsAPI::NotSupported, 'Find not supported for panel member')
23
+ end
24
+ end
25
+
26
+ context 'when does not exists' do
27
+ let(:survey_id) { 'SV_0fEV92PdRg8a2e0' }
28
+
29
+ it 'raises error' do
30
+ expect { result }.to raise_error(QualtricsAPI::NotSupported, 'Find not supported for panel member')
31
+ end
32
+ end
22
33
  end
23
- end
24
-
25
- describe "integration" do
26
- subject { described_class.new(id: 'ABCD') }
27
34
 
28
35
  describe "#fetch" do
29
36
  describe "when success" do
30
37
  before do
31
- expect(subject.size).to eq 0
38
+ expect(subject.page.size).to eq 0
32
39
  end
33
40
 
34
41
  let!(:result) do
@@ -38,7 +45,7 @@ describe QualtricsAPI::PanelMemberCollection do
38
45
  end
39
46
 
40
47
  it "populates the collection" do
41
- expect(subject.size).to eq 1
48
+ expect(subject.page.size).to eq 1
42
49
  expect(subject.first).to be_a QualtricsAPI::PanelMember
43
50
  end
44
51
 
@@ -48,13 +55,13 @@ describe QualtricsAPI::PanelMemberCollection do
48
55
  end
49
56
 
50
57
  describe "when failed" do
51
- it "resets panels" do
52
- subject.instance_variable_set :@all, [QualtricsAPI::PanelMember.new({})]
58
+ it "raise error and does not change panels" do
59
+ subject.instance_variable_set :@page, [QualtricsAPI::PanelMember.new({})]
53
60
  expect do
54
61
  VCR.use_cassette("panel_member_collection_fetch_fail") do
55
62
  expect { subject.fetch }.to raise_error
56
63
  end
57
- end.to change { subject.all }.to([])
64
+ end.not_to change { subject.page }
58
65
  end
59
66
  end
60
67
  end
@@ -62,7 +69,7 @@ describe QualtricsAPI::PanelMemberCollection do
62
69
  describe "#create" do
63
70
  let(:result) do
64
71
  VCR.use_cassette(cassette, record: :once) do
65
- QualtricsAPI.panels.fetch['ML_0APx3C4rmHER6w5'].members.create(panel_members)
72
+ QualtricsAPI.panels.find('ML_0APx3C4rmHER6w5').members.create(panel_members)
66
73
  end
67
74
  end
68
75
 
@@ -95,10 +102,10 @@ describe QualtricsAPI::PanelMemberCollection do
95
102
  end
96
103
 
97
104
  describe 'equality' do
98
- subject { described_class.new(all: [QualtricsAPI::PanelMember.new("recipientID" => "p1"), QualtricsAPI::PanelMember.new("recipientID" => "p1")]) }
105
+ subject { described_class.new(page: [QualtricsAPI::PanelMember.new("recipientID" => "p1"), QualtricsAPI::PanelMember.new("recipientID" => "p1")]) }
99
106
  context 'when same' do
100
107
  it 'returns true' do
101
- expect(subject).to eq(described_class.new(all: subject.all))
108
+ expect(subject).to eq(described_class.new(page: subject.page))
102
109
  end
103
110
  end
104
111
 
@@ -1,16 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe QualtricsAPI::ResponseExportCollection do
4
- it "has no @all when initialized" do
5
- expect(subject.all).to eq []
6
- end
7
-
8
4
  describe "#find, #[]" do
9
5
  let(:export_1) { QualtricsAPI::ResponseExport.new(:id => "export1") }
10
6
  let(:export_2) { QualtricsAPI::ResponseExport.new(:id => "export2") }
11
7
 
12
8
  it "finds the export by id" do
13
- subject.instance_variable_set :@all, [export_1, export_2]
9
+ subject.instance_variable_set :@page, [export_1, export_2]
14
10
  expect(subject.find("export1")).to eq export_1
15
11
  expect(subject["export2"]).to eq export_2
16
12
  end
@@ -21,19 +17,4 @@ describe QualtricsAPI::ResponseExportCollection do
21
17
  expect(sut.id).to eq "eee 3"
22
18
  end
23
19
  end
24
-
25
- describe 'equality' do
26
- subject { described_class.new(all: [QualtricsAPI::ResponseExport.new(:id => "export1"), QualtricsAPI::ResponseExport.new(:id => "export2")]) }
27
- context 'when same' do
28
- it 'returns true' do
29
- expect(subject).to eq(described_class.new(all: subject.all))
30
- end
31
- end
32
-
33
- context 'when different' do
34
- it 'returns false' do
35
- expect(subject).not_to eq(described_class.new)
36
- end
37
- end
38
- end
39
20
  end
@@ -1,34 +1,41 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe QualtricsAPI::SurveyCollection do
4
- it "has no @all when initialized" do
5
- expect(subject.all).to eq []
6
- end
7
-
8
- describe "#find, #[]" do
9
- let(:survey_1) { QualtricsAPI::Survey.new "id" => "s1" }
10
- let(:survey_2) { QualtricsAPI::Survey.new "id" => "s2" }
11
-
12
- it "finds the survey by id" do
13
- subject.instance_variable_set :@all, [survey_1, survey_2]
14
- expect(subject.find("s1")).to eq survey_1
15
- expect(subject["s2"]).to eq survey_2
16
- end
17
-
18
- it "returns a new survey with the id" do
19
- sut = subject["s3"]
20
- expect(sut).to be_a QualtricsAPI::Survey
21
- expect(sut.id).to eq "s3"
22
- end
4
+ it "has no @page when initialized" do
5
+ expect(subject.page).to eq []
23
6
  end
24
7
 
25
8
  describe "integration" do
26
9
  subject { described_class.new }
27
10
 
11
+ describe "#find" do
12
+ let(:result) do
13
+ VCR.use_cassette("survey_find") do
14
+ subject.find(survey_id)
15
+ end
16
+ end
17
+
18
+ context 'when exists' do
19
+ let(:survey_id) { 'SV_0fEV92PdRg8a2e9' }
20
+
21
+ it 'populates the result' do
22
+ expect(result.attributes).to eq(:id => "SV_0fEV92PdRg8a2e9", :name => "test", :owner_id => "owner_id", :last_modified => nil, :is_active => true)
23
+ end
24
+ end
25
+
26
+ context 'when does not exists' do
27
+ let(:survey_id) { 'SV_0fEV92PdRg8a2e0' }
28
+
29
+ it 'populates the result' do
30
+ expect { result }.to raise_error(QualtricsAPI::NotFoundError)
31
+ end
32
+ end
33
+ end
34
+
28
35
  describe "#fetch" do
29
36
  describe "when success" do
30
37
  before do
31
- expect(subject.size).to eq 0
38
+ expect(subject.page.size).to eq 0
32
39
  end
33
40
 
34
41
  let!(:result) do
@@ -38,7 +45,7 @@ describe QualtricsAPI::SurveyCollection do
38
45
  end
39
46
 
40
47
  it "populates the collection" do
41
- expect(subject.size).to eq 1
48
+ expect(subject.page.size).to eq 1
42
49
  expect(subject.first).to be_a QualtricsAPI::Survey
43
50
  end
44
51
 
@@ -48,23 +55,59 @@ describe QualtricsAPI::SurveyCollection do
48
55
  end
49
56
 
50
57
  describe "when failed" do
51
- it "resets surveys" do
52
- subject.instance_variable_set :@all, [QualtricsAPI::Survey.new({})]
53
- expect {
58
+ it "raises error and does not reset surveys" do
59
+ subject.instance_variable_set :@page, [QualtricsAPI::Survey.new({})]
60
+ expect do
54
61
  VCR.use_cassette("survey_collection_fetch_fail") do
55
- subject.fetch rescue nil
62
+ begin
63
+ subject.fetch
64
+ rescue
65
+ nil
66
+ end
56
67
  end
57
- }.to change { subject.all }.to([])
68
+ end.not_to change { subject.page }
69
+ end
70
+ end
71
+ end
72
+
73
+ describe 'pagination' do
74
+ it 'fetches pages from list endpoint' do
75
+ VCR.use_cassette("survey_collection_fetch_sucess") do
76
+ subject.fetch
77
+ expect(subject.fetched).to be_truthy
78
+ expect(subject.page.size).to eq(1)
79
+ expect(subject.next_page?).to be_truthy
80
+ end
81
+ end
82
+
83
+ it 'raises error when next_page without fetch' do
84
+ VCR.use_cassette("survey_collection_fetch_sucess") do
85
+ expect { expect(subject.next_page) }.to raise_error(QualtricsAPI::NotYetFetchedError)
86
+ end
87
+ end
88
+
89
+ it 'fetches pages from next page' do
90
+ VCR.use_cassette("survey_collection_fetch_sucess") do
91
+ result = subject.fetch.next_page
92
+ expect(result.fetched).to be_truthy
93
+ expect(result.page.size).to eq(0)
94
+ expect(result.next_page?).to be_falsey
95
+ end
96
+ end
97
+
98
+ it 'raises error when on last page' do
99
+ VCR.use_cassette("survey_collection_fetch_sucess") do
100
+ expect { subject.fetch.next_page.next_page }.to raise_error(QualtricsAPI::NotFoundError)
58
101
  end
59
102
  end
60
103
  end
61
104
  end
62
105
 
63
106
  describe 'equality' do
64
- subject { described_class.new(all: [QualtricsAPI::Survey.new("id" => "s1"), QualtricsAPI::Survey.new("id" => "s2")]) }
107
+ subject { described_class.new(page: [QualtricsAPI::Survey.new("id" => "s1"), QualtricsAPI::Survey.new("id" => "s2")]) }
65
108
  context 'when same' do
66
109
  it 'returns true' do
67
- expect(subject).to eq(described_class.new(all: subject.all))
110
+ expect(subject).to eq(described_class.new(page: subject.page))
68
111
  end
69
112
  end
70
113
 
@@ -22,7 +22,7 @@ describe QualtricsAPI do
22
22
  context 'chains' do
23
23
  it 'does propagate default connection' do
24
24
  members = VCR.use_cassette('panel_member_collection_create_success') do
25
- QualtricsAPI.panels.fetch['ML_bC2c5xBz1DxyOYB'].members
25
+ QualtricsAPI.panels.find('ML_bC2c5xBz1DxyOYB').members
26
26
  end
27
27
  expect(members.connection).to eq(QualtricsAPI.connection)
28
28
  end
@@ -31,7 +31,7 @@ describe QualtricsAPI do
31
31
  let(:client) { QualtricsAPI::Client.new(TEST_API_TOKEN) }
32
32
  let(:members) do
33
33
  VCR.use_cassette('panel_member_collection_create_success') do
34
- client.panels.fetch['ML_bC2c5xBz1DxyOYB'].members
34
+ client.panels.find('ML_bC2c5xBz1DxyOYB').members
35
35
  end
36
36
  end
37
37
 
@@ -42,12 +42,12 @@ describe QualtricsAPI do
42
42
  it 'has propagated exception to members' do
43
43
  expect(members.connection).to eq(client.connection)
44
44
  end
45
-
45
+
46
46
  context 'with different client' do
47
47
  let(:client_2) { QualtricsAPI::Client.new(TEST_API_TOKEN) }
48
48
  let(:members_2) do
49
49
  VCR.use_cassette('panel_member_collection_create_success') do
50
- client_2.panels.fetch['ML_bC2c5xBz1DxyOYB'].members
50
+ client_2.panels.find('ML_bC2c5xBz1DxyOYB').members
51
51
  end
52
52
  end
53
53
 
@@ -1,5 +1,4 @@
1
1
  require 'qualtrics_api'
2
- require 'pry'
3
2
  require 'vcr'
4
3
 
5
4
  TEST_API_TOKEN = "6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ".freeze
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qualtrics_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yurui Zhang
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-04-21 00:00:00.000000000 Z
13
+ date: 2016-04-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -110,34 +110,6 @@ dependencies:
110
110
  - - "~>"
111
111
  - !ruby/object:Gem::Version
112
112
  version: '2.9'
113
- - !ruby/object:Gem::Dependency
114
- name: guard-rspec
115
- requirement: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - "~>"
118
- - !ruby/object:Gem::Version
119
- version: '4.5'
120
- type: :development
121
- prerelease: false
122
- version_requirements: !ruby/object:Gem::Requirement
123
- requirements:
124
- - - "~>"
125
- - !ruby/object:Gem::Version
126
- version: '4.5'
127
- - !ruby/object:Gem::Dependency
128
- name: pry
129
- requirement: !ruby/object:Gem::Requirement
130
- requirements:
131
- - - "~>"
132
- - !ruby/object:Gem::Version
133
- version: 0.10.1
134
- type: :development
135
- prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- requirements:
138
- - - "~>"
139
- - !ruby/object:Gem::Version
140
- version: 0.10.1
141
113
  description: |-
142
114
  A Ruby wrapper for Qualtrics REST API version 3.0.
143
115
  See https://co1.qualtrics.com/APIDocs/ for API documents.
@@ -159,6 +131,7 @@ files:
159
131
  - Rakefile
160
132
  - fixtures/vcr_cassettes/panel_collection_fetch_fail.yml
161
133
  - fixtures/vcr_cassettes/panel_collection_fetch_success.yml
134
+ - fixtures/vcr_cassettes/panel_find.yml
162
135
  - fixtures/vcr_cassettes/panel_import_update_success.yml
163
136
  - fixtures/vcr_cassettes/panel_member_collection_create_fail.yml
164
137
  - fixtures/vcr_cassettes/panel_member_collection_create_success.yml
@@ -168,6 +141,7 @@ files:
168
141
  - fixtures/vcr_cassettes/response_export_update_success.yml
169
142
  - fixtures/vcr_cassettes/survey_collection_fetch_fail.yml
170
143
  - fixtures/vcr_cassettes/survey_collection_fetch_sucess.yml
144
+ - fixtures/vcr_cassettes/survey_find.yml
171
145
  - lib/qualtrics_api.rb
172
146
  - lib/qualtrics_api/base_collection.rb
173
147
  - lib/qualtrics_api/base_model.rb