qualtrics_api 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1bc31e5bdb1d4226c3a1f0511a03dd30e90a733
4
- data.tar.gz: 75c496a12eddd15a9cafc638eaf3ef1d1c176692
3
+ metadata.gz: abd7228ac110efc90a89dce24f0a7de7e7335704
4
+ data.tar.gz: bc6f5225fd701ad819038027d0d3baadec2ecdf8
5
5
  SHA512:
6
- metadata.gz: 062dd62b815df05915fa106c95018d3347093db0b18a8c16639f0aca2cb0dd88f8f6047e5fa5d4a7b4cfe47195eba83fc933a763c2bf0632965bd64c16b42eb4
7
- data.tar.gz: e18f3a82dcc31b40ae17c9d97c51e245ee5893726d72ff3e17cfbe2b49d30e27a6ef01325ae47c6f9ce278bef1f6e55950da708d76b70ddd6c2d633e45e7e533
6
+ metadata.gz: 813bbed6a8992818faec40c1dc93707bc5c2c5769cc2f422de93578a19c941516ee3b1912963fac4c8e9be7aeeda22bbcd378db449dba7a3e3ab5b365acc7287
7
+ data.tar.gz: 147e595c36036bd0664d5fb3d90ec387a74f46fb35120f1ab7c7d56551433b7505303e15dc5471aa94907e9da007b5b59874265f2b7d4c794b7b4590db5ae96f
data/README.md CHANGED
@@ -136,6 +136,52 @@ export.status
136
136
  => "99.99999%"
137
137
  ```
138
138
 
139
+ ### Panels
140
+
141
+ To get all the panels:
142
+
143
+ ```ruby
144
+ client.panels.fetch
145
+ # => #<QualtricsAPI::PanelCollection:0x007f8769aae2c0 ....>
146
+ ```
147
+
148
+ After you have received results, you can search for a panel by id:
149
+
150
+ ```ruby
151
+ panel = client.panels.find("panelIdHere")
152
+ # => #<QualtricsAPI::Panel:0x007f876906f278 @id="panelIdHere" ...>
153
+ ```
154
+
155
+ or just:
156
+
157
+ ```ruby
158
+ panel = client.panels["panelIdHere"]
159
+ # => #<QualtricsAPI::Panel:0x007f876906f278 @id="panelIdHere" ...>
160
+ ```
161
+
162
+ #### Panel Members
163
+
164
+ To add panel members to a panel:
165
+
166
+ ```ruby
167
+ panel = client.panels.fetch["panelIdHere"]
168
+ members = [QualtricsAPI::PanelMember.new(first_name: 'John', last_name: 'Doe', email: 'test@test.com')]
169
+ panel.members.create(members)
170
+ => #<QualtricsAPI::PanelImport:0x007fb7db984668 ...>
171
+ ```
172
+
173
+ and update athe status of panel import:
174
+ ```ruby
175
+ members = [QualtricsAPI::PanelMember.new(first_name: 'John', last_name: 'Doe', email: 'test@test.com')]
176
+ panel_import = panel.members.create(members)
177
+ => #<QualtricsAPI::PanelImport:0x007fb7db984668 ...>
178
+ panel_import.status
179
+ => "99.99999%"
180
+ panel_import.update_status
181
+ panel_import.status
182
+ => "100.0%"
183
+ ```
184
+
139
185
  ## Contributing
140
186
 
141
187
  1. Fork it ( https://github.com/pallymore/qualtrics_api/fork )
@@ -0,0 +1,33 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://co1.qualtrics.com/API/v1/panels?apiToken=6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.9
12
+ response:
13
+ status:
14
+ code: 200
15
+ message:
16
+ headers:
17
+ server:
18
+ - Apache-Coyote/1.1
19
+ content-type:
20
+ - application/json
21
+ content-length:
22
+ - '223'
23
+ date:
24
+ - Sun, 28 Jun 2015 21:05:57 GMT
25
+ connection:
26
+ - close
27
+ body:
28
+ encoding: UTF-8
29
+ string: '{"meta":{"status":"Error","errorMessage":"You do not have permission
30
+ to access this resource.","internalErrorCode":"GS_5","errorId":"3d6a9018-3b87-4265-b662-572ad96bbe6c"},"result":null}'
31
+ http_version:
32
+ recorded_at: Sun, 28 Jun 2015 21:05:57 GMT
33
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,32 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://co1.qualtrics.com/API/v1/panels?apiToken=6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.9
12
+ response:
13
+ status:
14
+ code: 200
15
+ message:
16
+ headers:
17
+ server:
18
+ - Apache-Coyote/1.1
19
+ content-type:
20
+ - application/json
21
+ content-length:
22
+ - '223'
23
+ date:
24
+ - Sun, 28 Jun 2015 21:05:57 GMT
25
+ connection:
26
+ - close
27
+ body:
28
+ encoding: UTF-8
29
+ string: '{"result":[{"panelId":"AB_abcdefghijk","name":"Master Panel","libraryId":"GR_abcdefghijk","category":"Unassigned"}],"meta":{"status":"Success","qualtricsErrorCode":null,"errorMessage":null}}'
30
+ http_version:
31
+ recorded_at: Sun, 28 Jun 2015 21:05:57 GMT
32
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,32 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://co1.qualtrics.com/API/v1/panels/ML_bC2c5xBz1DxyOYB/members/panelImports/PGRS_bEJLYLkqMBs8Bwx?apiToken=6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.9
12
+ response:
13
+ status:
14
+ code: 200
15
+ message:
16
+ headers:
17
+ server:
18
+ - Apache-Coyote/1.1
19
+ content-type:
20
+ - application/json
21
+ date:
22
+ - Tue, 30 Jun 2015 18:36:33 GMT
23
+ content-length:
24
+ - '85'
25
+ connection:
26
+ - close
27
+ body:
28
+ encoding: UTF-8
29
+ string: '{"result":{"status":"COMPLETED","percentComplete":100.0},"meta":{"status":"Success"}}'
30
+ http_version:
31
+ recorded_at: Tue, 30 Jun 2015 18:36:34 GMT
32
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,31 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://co1.qualtrics.com/API/v1/panels/ABCD/members?apiToken=6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.9
12
+ response:
13
+ status:
14
+ code: 400
15
+ message:
16
+ headers:
17
+ server:
18
+ - Apache-Coyote/1.1
19
+ content-type:
20
+ - application/json
21
+ date:
22
+ - Tue, 30 Jun 2015 11:02:46 GMT
23
+ connection:
24
+ - close
25
+ body:
26
+ encoding: UTF-8
27
+ string: '{"meta":{"status":"Error","errorMessage":"Missing or invalid parameter
28
+ panelId.","internalErrorCode":"GPR_1","errorId":"f399b7aa-7ce4-4d1d-9903-61435a929a9d"},"result":null}'
29
+ http_version:
30
+ recorded_at: Tue, 30 Jun 2015 11:02:46 GMT
31
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,66 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://co1.qualtrics.com/API/v1/panels?apiToken=6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.9
12
+ response:
13
+ status:
14
+ code: 200
15
+ message:
16
+ headers:
17
+ server:
18
+ - Apache-Coyote/1.1
19
+ content-type:
20
+ - application/json
21
+ date:
22
+ - Tue, 30 Jun 2015 11:05:46 GMT
23
+ content-length:
24
+ - '1104'
25
+ connection:
26
+ - close
27
+ body:
28
+ encoding: UTF-8
29
+ string: '{"result":[{"libraryId":"UR_a3IUfBgXyuCHefP","panelId":"ML_bC2c5xBz1DxyOYB","name":"Test
30
+ Panel","category":"Unassigned"},{"libraryId":"GR_2aaKA1aGidXQtOA","panelId":"ML_3DWuh7BTCbBDMrz","name":"1032
31
+ test","category":"Unassigned"},{"libraryId":"GR_2aaKA1aGidXQtOA","panelId":"ML_801qFFVH8bOdbdH","name":"Master2015","category":"Unassigned"},{"libraryId":"GR_2aaKA1aGidXQtOA","panelId":"ML_8CTTM1NuWINZUO1","name":"29.X-2","category":"Unassigned"},{"libraryId":"GR_2aaKA1aGidXQtOA","panelId":"ML_8FZn6SlO02EfpwV","name":"29.X","category":"Unassigned"},{"libraryId":"GR_2aaKA1aGidXQtOA","panelId":"ML_aYrBXdYJZ5SnYqx","name":"ML_b3GT2LOMImo2Rnf","category":"Unassigned"},{"libraryId":"GR_2aaKA1aGidXQtOA","panelId":"ML_bJj6bKQErauewzH","name":"GRPSteacherSpring2013fixed_seperate","category":"Unassigned"},{"libraryId":"GR_2aaKA1aGidXQtOA","panelId":"ML_bseUhQDwAJolD1j","name":"Master
32
+ Panel","category":"Unassigned"},{"libraryId":"GR_2aaKA1aGidXQtOA","panelId":"ML_eRKRb6a6Waiukap","name":"OhioSpring2015","category":"Unassigned"}],"meta":{"status":"Success","qualtricsErrorCode":null,"errorMessage":null}}'
33
+ http_version:
34
+ recorded_at: Tue, 30 Jun 2015 11:05:47 GMT
35
+ - request:
36
+ method: post
37
+ uri: https://co1.qualtrics.com/API/v1/panels/ML_bC2c5xBz1DxyOYB/members?apiToken=6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
38
+ body:
39
+ encoding: US-ASCII
40
+ string: apiToken=6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ&panelMembers=%5B%7B%22FirstName%22%3A%22Marcin%22%2C%22LastName%22%3A%22Naglik%22%2C%22Email%22%3A%22test%40test.com%22%7D%5D
41
+ headers:
42
+ User-Agent:
43
+ - Faraday v0.8.9
44
+ Content-Type:
45
+ - application/x-www-form-urlencoded
46
+ response:
47
+ status:
48
+ code: 200
49
+ message:
50
+ headers:
51
+ server:
52
+ - Apache-Coyote/1.1
53
+ content-type:
54
+ - application/json
55
+ date:
56
+ - Tue, 30 Jun 2015 11:05:47 GMT
57
+ content-length:
58
+ - '203'
59
+ connection:
60
+ - close
61
+ body:
62
+ encoding: UTF-8
63
+ string: '{"result":{"importStatus":"http://co1.qualtrics.com/API/v1/panels/ML_bC2c5xBz1DxyOYB/members/panelImports/PGRS_bEJLYLkqMBs8Bwx"},"meta":{"status":"Success","qualtricsErrorCode":null,"errorMessage":null}}'
64
+ http_version:
65
+ recorded_at: Tue, 30 Jun 2015 11:05:47 GMT
66
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,33 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://co1.qualtrics.com/API/v1/panels/ABCD/members?apiToken=6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.9
12
+ response:
13
+ status:
14
+ code: 200
15
+ message:
16
+ headers:
17
+ server:
18
+ - Apache-Coyote/1.1
19
+ content-type:
20
+ - application/json
21
+ content-length:
22
+ - '223'
23
+ date:
24
+ - Sun, 28 Jun 2015 21:05:57 GMT
25
+ connection:
26
+ - close
27
+ body:
28
+ encoding: UTF-8
29
+ string: '{"meta":{"status":"Error","errorMessage":"You do not have permission
30
+ to access this resource.","internalErrorCode":"GS_5","errorId":"3d6a9018-3b87-4265-b662-572ad96bbe6c"},"result":null}'
31
+ http_version:
32
+ recorded_at: Sun, 28 Jun 2015 21:05:57 GMT
33
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,33 @@
1
+
2
+ ---
3
+ http_interactions:
4
+ - request:
5
+ method: get
6
+ uri: https://co1.qualtrics.com/API/v1/panels/ABCD/members?apiToken=6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
7
+ body:
8
+ encoding: US-ASCII
9
+ string: ''
10
+ headers:
11
+ User-Agent:
12
+ - Faraday v0.8.9
13
+ response:
14
+ status:
15
+ code: 200
16
+ message:
17
+ headers:
18
+ server:
19
+ - Apache-Coyote/1.1
20
+ content-type:
21
+ - application/json
22
+ content-length:
23
+ - '223'
24
+ date:
25
+ - Sun, 28 Jun 2015 21:05:57 GMT
26
+ connection:
27
+ - close
28
+ body:
29
+ encoding: UTF-8
30
+ string: '{ "result": [ { "rowId": "33369396", "panelMemberId": "MLRP_abcd", "firstName": "Thom", "lastName": "Yorke", "email": "thom@yorke.com", "externalDataReference": null, "embeddedData": { } } ], "meta": { "status": "Success", "qualtricsErrorCode": null, "errorMessage": null }}'
31
+ http_version:
32
+ recorded_at: Sun, 28 Jun 2015 21:05:57 GMT
33
+ recorded_with: VCR 2.9.3
@@ -1,3 +1,4 @@
1
+ require 'json'
1
2
  require 'virtus'
2
3
  require "faraday"
3
4
  require "faraday_middleware"
@@ -12,13 +13,16 @@ require "qualtrics_api/survey"
12
13
  require "qualtrics_api/survey_collection"
13
14
  require "qualtrics_api/response_export"
14
15
  require "qualtrics_api/response_export_collection"
16
+ require "qualtrics_api/panel"
17
+ require "qualtrics_api/panel_collection"
18
+ require "qualtrics_api/panel_member"
19
+ require "qualtrics_api/panel_member_collection"
20
+ require "qualtrics_api/panel_import"
15
21
 
16
22
  require "qualtrics_api/services/response_export_service"
17
23
 
18
24
  module QualtricsAPI
19
-
20
25
  def self.new(token)
21
26
  Client.new(api_token: token)
22
27
  end
23
-
24
28
  end
@@ -5,17 +5,21 @@ module QualtricsAPI
5
5
  attribute :api_token, String
6
6
 
7
7
  def surveys(options = {})
8
- @surveys ||= QualtricsAPI::SurveyCollection.new options.merge(connection: connection)
8
+ @surveys ||= QualtricsAPI::SurveyCollection.new(options.merge(connection: connection))
9
9
  end
10
10
 
11
11
  def response_exports(options = {})
12
- @response_exports ||= QualtricsAPI::ResponseExportCollection.new options.merge(connection: connection)
12
+ @response_exports ||= QualtricsAPI::ResponseExportCollection.new(options.merge(connection: connection))
13
+ end
14
+
15
+ def panels(options = {})
16
+ @panels ||= QualtricsAPI::PanelCollection.new(options.merge(connection: connection))
13
17
  end
14
18
 
15
19
  def connection
16
20
  @conn ||= Faraday.new(url: QualtricsAPI::URL,
17
21
  params: { apiToken: api_token }) do |faraday|
18
- faraday.request :json
22
+ faraday.request :url_encoded
19
23
  faraday.response :json, :content_type => /\bjson$/
20
24
 
21
25
  faraday.use FaradayMiddleware::FollowRedirects
@@ -0,0 +1,32 @@
1
+ module QualtricsAPI
2
+ class Panel
3
+ include Virtus.value_object
4
+
5
+ attribute :connection
6
+ attribute :id, String
7
+ attribute :library_id, String
8
+ attribute :name, String
9
+ attribute :category, String
10
+
11
+ def initialize(options = {})
12
+ attributes_mappings.each do |key, qualtrics_key|
13
+ instance_variable_set "@#{key}", options[qualtrics_key]
14
+ end
15
+ super
16
+ end
17
+
18
+ def members(options = {})
19
+ @members ||= QualtricsAPI::PanelMemberCollection.new(options.merge(id: id, connection: connection))
20
+ end
21
+
22
+ private
23
+
24
+ def attributes_mappings
25
+ {
26
+ :id => "panelId",
27
+ :library_id => "libraryId",
28
+ :name => "name"
29
+ }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ module QualtricsAPI
2
+ class PanelCollection
3
+ extend Forwardable
4
+ include Enumerable
5
+ include Virtus.value_object
6
+
7
+ attribute :connection
8
+ attribute :all, Array, :default => []
9
+
10
+ def_delegator :all, :each
11
+ def_delegator :all, :size
12
+
13
+ def fetch(_options = {})
14
+ @all = []
15
+ parse_fetch_response(connection.get('panels'))
16
+ self
17
+ end
18
+
19
+ def [](panel_id)
20
+ find(panel_id)
21
+ end
22
+
23
+ def find(panel_id)
24
+ @all.detect do |panel|
25
+ panel.id == panel_id
26
+ end || QualtricsAPI::Panel.new("panelId" => panel_id, connection: connection)
27
+ end
28
+
29
+ private
30
+
31
+ def parse_fetch_response(response)
32
+ @all = response.body["result"].map do |result|
33
+ QualtricsAPI::Panel.new result.merge(connection: connection)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,30 @@
1
+ module QualtricsAPI
2
+ class PanelImport
3
+ include Virtus.value_object
4
+
5
+ attribute :connection
6
+ attribute :id, String
7
+ attribute :panel_id, String
8
+
9
+ def update_status
10
+ res = connection.get("panels/#{panel_id}/members/panelImports/#{id}").body["result"]
11
+ @import_progress = res["percentComplete"]
12
+ @completed = true if @import_progress == 100.0
13
+ self
14
+ end
15
+
16
+ def status
17
+ update_status unless completed?
18
+ "#{@import_progress}%"
19
+ end
20
+
21
+ def percent_completed
22
+ update_status unless completed?
23
+ @import_progress
24
+ end
25
+
26
+ def completed?
27
+ @completed == true
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,50 @@
1
+ module QualtricsAPI
2
+ class PanelMember
3
+ include Virtus.value_object
4
+
5
+ attribute :connection
6
+ attribute :id, String
7
+ attribute :first_name, String
8
+ attribute :last_name, String
9
+ attribute :email, String
10
+ attribute :language, String
11
+ attribute :unsubscribed, Integer
12
+ attribute :external_data_reference, String
13
+ attribute :embeded_data, Hash
14
+
15
+ def initialize(options = {})
16
+ attributes_mappings.each do |key, qualtrics_key|
17
+ instance_variable_set "@#{key}", options[qualtrics_key]
18
+ end
19
+ super
20
+ end
21
+
22
+ def to_json(_options = {})
23
+ serialized_attributes.to_json
24
+ end
25
+
26
+ private
27
+
28
+ def serialized_attributes
29
+ Hash[attributes.map { |k, v| [mapped_and_uppercased_attribute(k), v] }].tap do |h|
30
+ h.delete("Connection")
31
+ end.delete_if { |_k, v| v.nil? }
32
+ end
33
+
34
+ def mapped_and_uppercased_attribute(attribute)
35
+ (attributes_mappings[attribute] || attribute).to_s.tap do |a|
36
+ a[0] = a[0].upcase
37
+ end
38
+ end
39
+
40
+ def attributes_mappings
41
+ {
42
+ :id => "panelMemberId",
43
+ :first_name => "firstName",
44
+ :last_name => "lastName",
45
+ :external_data_reference => "externalDataReference",
46
+ :embeded_data => "embeddedData"
47
+ }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,46 @@
1
+ module QualtricsAPI
2
+ class PanelMemberCollection
3
+ extend Forwardable
4
+ include Enumerable
5
+ include Virtus.value_object
6
+
7
+ attribute :connection
8
+ attribute :id, String
9
+ attribute :all, Array, :default => []
10
+
11
+ def_delegator :all, :each
12
+ def_delegator :all, :size
13
+
14
+ def fetch(_options = {})
15
+ @all = []
16
+ parse_fetch_response(connection.get("panels/#{id}/members"))
17
+ self
18
+ end
19
+
20
+ def create(panel_members)
21
+ res = connection
22
+ .post("panels/#{id}/members", connection.params.merge(panelMembers: panel_members.to_json))
23
+ .body["result"]
24
+ import_id = res['importStatus'].split('/').last
25
+ QualtricsAPI::PanelImport.new(id: import_id, panel_id: id, connection: connection)
26
+ end
27
+
28
+ def [](member_id)
29
+ find(member_id)
30
+ end
31
+
32
+ def find(member_id)
33
+ @all.detect do |panel_member|
34
+ panel_member.id == member_id
35
+ end || QualtricsAPI::PanelMember.new(:id => member_id, connection: connection)
36
+ end
37
+
38
+ private
39
+
40
+ def parse_fetch_response(response)
41
+ @all = response.body["result"].map do |result|
42
+ QualtricsAPI::PanelMember.new(result.merge(connection: connection))
43
+ end
44
+ end
45
+ end
46
+ end
@@ -15,9 +15,9 @@ module QualtricsAPI
15
15
  end
16
16
 
17
17
  def find(export_id)
18
- @all.select do |response_export|
18
+ @all.detect do |response_export|
19
19
  response_export.id == export_id
20
- end.first || QualtricsAPI::ResponseExport.new(:id => export_id, connection: connection)
20
+ end || QualtricsAPI::ResponseExport.new(:id => export_id, connection: connection)
21
21
  end
22
22
  end
23
23
  end
@@ -10,8 +10,6 @@ module QualtricsAPI
10
10
  attribute :created_at, String
11
11
  attribute :status, String
12
12
 
13
- attr_accessor :id, :name, :owner_id, :last_modified, :status, :created_at
14
-
15
13
  def initialize(options = {})
16
14
  attributes_mappings.each do |key, qualtrics_key|
17
15
  instance_variable_set "@#{key}", options[qualtrics_key]
@@ -35,9 +35,9 @@ module QualtricsAPI
35
35
  end
36
36
 
37
37
  def find(survey_id)
38
- @all.select do |survey|
38
+ @all.detect do |survey|
39
39
  survey.id == survey_id
40
- end.first || QualtricsAPI::Survey.new("id" => survey_id, connection: connection)
40
+ end || QualtricsAPI::Survey.new("id" => survey_id, connection: connection)
41
41
  end
42
42
 
43
43
  private
@@ -1,3 +1,3 @@
1
1
  module QualtricsAPI
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe QualtricsAPI::PanelCollection do
4
+ let(:connection) { double('connection') }
5
+
6
+ subject { described_class.new connection: connection }
7
+
8
+ it "has no @all when initialized" do
9
+ expect(subject.all).to eq []
10
+ end
11
+
12
+ it "takes a connection" do
13
+ expect(subject.connection).to eq connection
14
+ end
15
+
16
+ describe "#find, #[]" do
17
+ let(:panel_1) { QualtricsAPI::Panel.new "panelId" => "p1" }
18
+ let(:panel_2) { QualtricsAPI::Panel.new "panelId" => "p2" }
19
+
20
+ it "finds the panel by id" do
21
+ subject.instance_variable_set :@all, [panel_1, panel_2]
22
+ expect(subject.find("p1")).to eq panel_1
23
+ expect(subject["p2"]).to eq panel_2
24
+ end
25
+
26
+ it "returns a new panel with the id" do
27
+ new_panel = subject["p3"]
28
+ expect(new_panel).to be_a QualtricsAPI::Panel
29
+ expect(new_panel.id).to eq "p3"
30
+ expect(new_panel.connection).to eq connection
31
+ end
32
+ end
33
+
34
+ describe "integration" do
35
+ let(:client) { QualtricsAPI.new TEST_API_TOKEN }
36
+
37
+ subject { described_class.new connection: client.connection }
38
+
39
+ describe "#fetch" do
40
+ describe "when success" do
41
+ before do
42
+ expect(subject.size).to eq 0
43
+ end
44
+
45
+ let!(:result) do
46
+ VCR.use_cassette("panel_collection_fetch_success") do
47
+ subject.fetch
48
+ end
49
+ end
50
+
51
+ it "populates the collection" do
52
+ expect(subject.size).to eq 1
53
+ expect(subject.first).to be_a QualtricsAPI::Panel
54
+ end
55
+
56
+ it "passes down the connection" do
57
+ expect(subject.all.first.connection).to eq client.connection
58
+ end
59
+
60
+ it "returns itself" do
61
+ expect(result).to eq subject
62
+ end
63
+ end
64
+
65
+ describe "when failed" do
66
+ it "resets panels" do
67
+ subject.instance_variable_set :@all, [QualtricsAPI::Panel.new({})]
68
+ expect {
69
+ VCR.use_cassette("panel_collection_fetch_fail") do
70
+ subject.fetch rescue nil
71
+ end
72
+ }.to change { subject.all }.to([])
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe QualtricsAPI::PanelImport do
4
+ describe "integration" do
5
+ let(:connection) { QualtricsAPI.new(TEST_API_TOKEN).connection }
6
+ subject { described_class.new(id: 'PGRS_bEJLYLkqMBs8Bwx', panel_id: 'ML_bC2c5xBz1DxyOYB', connection: connection) }
7
+
8
+ describe "#update_status" do
9
+ let(:result) do
10
+ VCR.use_cassette('panel_import_update_success') do
11
+ subject.update_status
12
+ end
13
+ end
14
+
15
+ it "updates status" do
16
+ expect(result.status).to eq('100.0%')
17
+ end
18
+
19
+ it "updates percent completed" do
20
+ expect(result.percent_completed).to eq(100.0)
21
+ end
22
+
23
+ it "updates completed" do
24
+ expect(result.completed?).to be_truthy
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,115 @@
1
+ require 'spec_helper'
2
+
3
+ describe QualtricsAPI::PanelMemberCollection do
4
+ let(:connection) { double('connection') }
5
+
6
+ subject { described_class.new connection: connection }
7
+
8
+ it "has no @all when initialized" do
9
+ expect(subject.all).to eq []
10
+ end
11
+
12
+ it "takes a connection" do
13
+ expect(subject.connection).to eq connection
14
+ end
15
+
16
+ describe "#find, #[]" do
17
+ let(:panel_member_1) { QualtricsAPI::PanelMember.new("panelMemberId" => "p1") }
18
+ let(:panel_member_2) { QualtricsAPI::PanelMember.new("panelMemberId" => "p2") }
19
+
20
+ it "finds the panel member by id" do
21
+ subject.instance_variable_set :@all, [panel_member_1, panel_member_2]
22
+ expect(subject.find("p1")).to eq panel_member_1
23
+ expect(subject["p2"]).to eq panel_member_2
24
+ end
25
+
26
+ it "returns a new panel with the id" do
27
+ new_panel_member = subject["p3"]
28
+ expect(new_panel_member).to be_a QualtricsAPI::PanelMember
29
+ expect(new_panel_member.id).to eq "p3"
30
+ expect(new_panel_member.connection).to eq connection
31
+ end
32
+ end
33
+
34
+ describe "integration" do
35
+ let(:client) { QualtricsAPI.new TEST_API_TOKEN }
36
+
37
+ subject { described_class.new(connection: client.connection, id: 'ABCD') }
38
+
39
+ describe "#fetch" do
40
+ describe "when success" do
41
+ before do
42
+ expect(subject.size).to eq 0
43
+ end
44
+
45
+ let!(:result) do
46
+ VCR.use_cassette("panel_member_collection_fetch_success") do
47
+ subject.fetch
48
+ end
49
+ end
50
+
51
+ it "populates the collection" do
52
+ expect(subject.size).to eq 1
53
+ expect(subject.first).to be_a QualtricsAPI::PanelMember
54
+ end
55
+
56
+ it "passes down the connection" do
57
+ expect(subject.all.first.connection).to eq client.connection
58
+ end
59
+
60
+ it "returns itself" do
61
+ expect(result).to eq subject
62
+ end
63
+ end
64
+
65
+ describe "when failed" do
66
+ it "resets panels" do
67
+ subject.instance_variable_set :@all, [QualtricsAPI::PanelMember.new({})]
68
+ expect do
69
+ VCR.use_cassette("panel_member_collection_fetch_fail") do
70
+ expect { subject.fetch }.to raise_error
71
+ end
72
+ end.to change { subject.all }.to([])
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "#create" do
78
+ let(:result) do
79
+ VCR.use_cassette(cassette) do
80
+ QualtricsAPI.new(TEST_API_TOKEN).panels.fetch['ML_bC2c5xBz1DxyOYB'].members.create(panel_members)
81
+ end
82
+ end
83
+
84
+ describe "when success" do
85
+ let(:cassette) { "panel_member_collection_create_success" }
86
+ let(:panel_members) { [QualtricsAPI::PanelMember.new(first_name: 'Marcin', last_name: 'Naglik', email: 'test@test.com')] }
87
+
88
+ it "returns PanelImport" do
89
+ expect(result).to be_a QualtricsAPI::PanelImport
90
+ end
91
+
92
+ it "returns PanelImport with id" do
93
+ expect(result.id).to eq('PGRS_bEJLYLkqMBs8Bwx')
94
+ end
95
+
96
+ it "returns PanelImport with panel id" do
97
+ expect(result.panel_id).to eq('ML_bC2c5xBz1DxyOYB')
98
+ end
99
+
100
+ it "returns PanelImport with connection" do
101
+ expect(result.connection).not_to be_nil
102
+ end
103
+ end
104
+
105
+ describe "when failed" do
106
+ let(:cassette) { "panel_member_collection_create_fail" }
107
+ let(:panel_members) { [QualtricsAPI::PanelMember.new] }
108
+
109
+ it "returns results" do
110
+ expect { result }.to raise_error
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe QualtricsAPI::PanelMember do
4
+ let(:panel_member) do
5
+ {
6
+ "panelMemberId" => "ML_abcdefg",
7
+ "firstName" => "Thom",
8
+ "lastName" => "Yorke",
9
+ "email" => "thom@radiohead.com",
10
+ "language" => "EN",
11
+ "unsubscribed" => 1,
12
+ "externalDataReference" => "1234",
13
+ "embeddedData" => { "a" => "b", "b" => "c" }
14
+ }
15
+ end
16
+
17
+ let(:connection) { double('connection', get: {}) }
18
+ subject { described_class.new panel_member.merge(connection: connection) }
19
+
20
+ it "has a panel member id" do
21
+ expect(subject.id).to eq(panel_member["panelMemberId"])
22
+ end
23
+
24
+ it "has a first name" do
25
+ expect(subject.first_name).to eq(panel_member["firstName"])
26
+ end
27
+
28
+ it "has a last name" do
29
+ expect(subject.last_name).to eq(panel_member["lastName"])
30
+ end
31
+
32
+ it "has an email" do
33
+ expect(subject.email).to eq(panel_member["email"])
34
+ end
35
+
36
+ it "has language" do
37
+ expect(subject.language).to eq(panel_member["language"])
38
+ end
39
+
40
+ it "has unsubscribed flag" do
41
+ expect(subject.unsubscribed).to eq(panel_member["unsubscribed"])
42
+ end
43
+
44
+ it "has external data reference" do
45
+ expect(subject.external_data_reference).to eq(panel_member["externalDataReference"])
46
+ end
47
+
48
+ it "has embedded data" do
49
+ expect(subject.embeded_data).to eq(panel_member["embeddedData"])
50
+ end
51
+
52
+ context "#to_json" do
53
+ let(:members) { [subject].to_json }
54
+ it "serialize array of panel members" do
55
+ expect(JSON.parse(members)).to eq(
56
+ [{ "PanelMemberId" => "ML_abcdefg",
57
+ "FirstName" => "Thom",
58
+ "LastName" => "Yorke",
59
+ "Email" => "thom@radiohead.com",
60
+ "Language" => "EN",
61
+ "Unsubscribed" => 1,
62
+ "ExternalDataReference" => "1234",
63
+ "EmbeddedData" => { "a" => "b", "b" => "c" } }])
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe QualtricsAPI::Panel do
4
+ let(:qualtrics_response) do
5
+ {
6
+ "panelid" => "ML_bseUhQDwAJolD1j",
7
+ "name" => "Master Panel",
8
+ "libraryId" => "GR_2aaKA1aGidXQtOA",
9
+ "category" => "Unassigned"
10
+ }
11
+ end
12
+
13
+ let(:connection) { double('connection', get: {}) }
14
+
15
+ subject { described_class.new qualtrics_response.merge(connection: connection) }
16
+
17
+ it "has an panelId" do
18
+ expect(subject.id).to eq qualtrics_response["panelId"]
19
+ end
20
+
21
+ it "has a name" do
22
+ expect(subject.name).to eq qualtrics_response["name"]
23
+ end
24
+
25
+ it "has an libraryId" do
26
+ expect(subject.library_id).to eq qualtrics_response["libraryId"]
27
+ end
28
+
29
+ it "has a category" do
30
+ expect(subject.category).to eq qualtrics_response["category"]
31
+ end
32
+
33
+ it "has a connection" do
34
+ expect(subject.connection).to eq(connection)
35
+ end
36
+
37
+ describe "#members" do
38
+ it "returns a PanelMemberCollection" do
39
+ expect(subject.members).to be_a QualtricsAPI::PanelMemberCollection
40
+ end
41
+
42
+ it "sets connection" do
43
+ expect(subject.members.connection).to eq subject.connection
44
+ end
45
+
46
+ it "assigns panel id" do
47
+ expect(subject.members.id).to eq subject.id
48
+ end
49
+
50
+ it "caches the members" do
51
+ expect(subject.members.object_id).to eq subject.members.object_id
52
+ end
53
+ end
54
+ end
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.2
4
+ version: 0.0.3
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: 2015-06-26 00:00:00.000000000 Z
13
+ date: 2015-06-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -143,6 +143,13 @@ files:
143
143
  - LICENSE.txt
144
144
  - README.md
145
145
  - Rakefile
146
+ - fixtures/vcr_cassettes/panel_collection_fetch_fail.yml
147
+ - fixtures/vcr_cassettes/panel_collection_fetch_success.yml
148
+ - fixtures/vcr_cassettes/panel_import_update_success.yml
149
+ - fixtures/vcr_cassettes/panel_member_collection_create_fail.yml
150
+ - fixtures/vcr_cassettes/panel_member_collection_create_success.yml
151
+ - fixtures/vcr_cassettes/panel_member_collection_fetch_fail.yml
152
+ - fixtures/vcr_cassettes/panel_member_collection_fetch_success.yml
146
153
  - fixtures/vcr_cassettes/response_export_start_success.yml
147
154
  - fixtures/vcr_cassettes/response_export_update_success.yml
148
155
  - fixtures/vcr_cassettes/survey_collection_fetch_fail.yml
@@ -150,6 +157,11 @@ files:
150
157
  - fixtures/vcr_cassettes/survey_collection_fetch_with_scopeId_success.yml
151
158
  - lib/qualtrics_api.rb
152
159
  - lib/qualtrics_api/client.rb
160
+ - lib/qualtrics_api/panel.rb
161
+ - lib/qualtrics_api/panel_collection.rb
162
+ - lib/qualtrics_api/panel_import.rb
163
+ - lib/qualtrics_api/panel_member.rb
164
+ - lib/qualtrics_api/panel_member_collection.rb
153
165
  - lib/qualtrics_api/request_error_handler.rb
154
166
  - lib/qualtrics_api/response_export.rb
155
167
  - lib/qualtrics_api/response_export_collection.rb
@@ -160,6 +172,11 @@ files:
160
172
  - lib/qualtrics_api/version.rb
161
173
  - qualtrics_api.gemspec
162
174
  - spec/lib/client_spec.rb
175
+ - spec/lib/panel_collection_spec.rb
176
+ - spec/lib/panel_import_spec.rb
177
+ - spec/lib/panel_member_collection_spec.rb
178
+ - spec/lib/panel_member_spec.rb
179
+ - spec/lib/panel_spec.rb
163
180
  - spec/lib/response_export_collection_spec.rb
164
181
  - spec/lib/response_export_spec.rb
165
182
  - spec/lib/services/response_export_service_spec.rb
@@ -193,6 +210,11 @@ specification_version: 4
193
210
  summary: A Ruby wrapper for Qualtrics REST API v3.0
194
211
  test_files:
195
212
  - spec/lib/client_spec.rb
213
+ - spec/lib/panel_collection_spec.rb
214
+ - spec/lib/panel_import_spec.rb
215
+ - spec/lib/panel_member_collection_spec.rb
216
+ - spec/lib/panel_member_spec.rb
217
+ - spec/lib/panel_spec.rb
196
218
  - spec/lib/response_export_collection_spec.rb
197
219
  - spec/lib/response_export_spec.rb
198
220
  - spec/lib/services/response_export_service_spec.rb