qualtrics_api 0.0.14 → 0.0.15

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
  SHA256:
3
- metadata.gz: 14a8c584341554937f9191c5092906ecd8132a4e5a35c4bb9b8cfbfb28dda9e1
4
- data.tar.gz: fcba2ec7a04c59497951c88bed64ce65655c3a9f4c799b5d0073b16d38f44c83
3
+ metadata.gz: 614308b0a73ec2d9a904703243f2b7ca0828936113122eb8a104aeff1b34e7be
4
+ data.tar.gz: dd67d5dc10dc3669679f51a368810161f21fe44516e5a0c796da8b56099bfda8
5
5
  SHA512:
6
- metadata.gz: bdc4178b2d5c9b5117deaa74c61ee7c93e250f30953fa3c62370f77cc812707b0c06894251bc13012d6451d6e4048efb835a987ddd2922261252df52bfbac26d
7
- data.tar.gz: f3cc2c6064c1a2ed083910e7cb87237dd2ef7081d7663991f2d71bc0b1229634c3c60799d22cf57ceead3622d2a84e93d91e6043e35f8e4943e0d5827e64557b
6
+ metadata.gz: d900c025250a3ff9104ceedb881ebeeff156b43f58b4b898ea3fee86941752f1c59a3f86ee7439a29b39d1efd604f80de557d8d64cf5765127713c9a01cd2698
7
+ data.tar.gz: 0700d5570105ea93a3ceb7e4c65be6f637a8d239da9d3779929886dbead496ce04a75c872a01c5a5ade6cf1b6d17972c841182e79c448cab65e5aca96bbec848
data/README.md CHANGED
@@ -197,19 +197,20 @@ panel = QualtricsAPI.panels["panelIdHere"]
197
197
 
198
198
  #### Panel Members
199
199
 
200
- To add panel members to a panel:
200
+ To import a batch of panel members:
201
201
 
202
202
  ```ruby
203
203
  panel = QualtricsAPI.panels.find("panelIdHere")
204
204
  members = [QualtricsAPI::PanelMember.new(first_name: 'John', last_name: 'Doe', email: 'test@test.com')]
205
- panel.members.create(members)
205
+ panel.import_members(members)
206
206
  => #<QualtricsAPI::PanelImport:0x007fb7db984668 ...>
207
207
  ```
208
208
 
209
- and update athe status of panel import:
209
+ A `PanelImport` record is returned, you can use it to check the status of panel import:
210
+
210
211
  ```ruby
211
212
  members = [QualtricsAPI::PanelMember.new(first_name: 'John', last_name: 'Doe', email: 'test@test.com')]
212
- panel_import = panel.members.create(members)
213
+ panel_import = panel.members.import_members(members)
213
214
  => #<QualtricsAPI::PanelImport:0x007fb7db984668 ...>
214
215
  panel_import.status
215
216
  => "99.99999%"
@@ -218,6 +219,16 @@ panel_import.status
218
219
  => "100.0%"
219
220
  ```
220
221
 
222
+ To add a single panel member to a panel:
223
+
224
+ ```ruby
225
+ panel = QualtricsAPI.panels.find("panelIdHere")
226
+ member = QualtricsAPI::PanelMember.new(first_name: 'John', last_name: 'Doe', email: 'test@test.com')
227
+ panel.create(member)
228
+ ```
229
+
230
+ A new `PanelMember` record is returned on success; this will give you the ID of the newly created member.
231
+
221
232
  ## Contributing
222
233
 
223
234
  1. Fork it ( https://github.com/pallymore/qualtrics_api/fork )
@@ -0,0 +1,39 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://co1.qualtrics.com/API/v3/mailinglists/ML_ez0Gj1S4SX4TZjv
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-API-TOKEN:
11
+ - xxx
12
+ User-Agent:
13
+ - Faraday v0.13.1
14
+ response:
15
+ status:
16
+ code: 404
17
+ message:
18
+ headers:
19
+ content-type:
20
+ - application/json
21
+ content-length:
22
+ - '129'
23
+ x-edgeconnect-midmile-rtt:
24
+ - '12'
25
+ x-edgeconnect-origin-mex-latency:
26
+ - '195'
27
+ date:
28
+ - Mon, 08 Jan 2018 16:57:07 GMT
29
+ connection:
30
+ - close
31
+ strict-transport-security:
32
+ - max-age=31536000; includeSubDomains; preload
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"meta":{"httpStatus":"404 - Not Found","error":{"errorMessage":"Mailing
36
+ List not found","errorCode":"PACC_6"},"requestId":null}}'
37
+ http_version:
38
+ recorded_at: Mon, 08 Jan 2018 16:57:07 GMT
39
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,82 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://co1.qualtrics.com/API/v3/mailinglists/ML_ez0Gj1S4SX4TZjv
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-API-TOKEN:
11
+ - xxx
12
+ User-Agent:
13
+ - Faraday v0.13.1
14
+ response:
15
+ status:
16
+ code: 200
17
+ message:
18
+ headers:
19
+ request-time:
20
+ - '429'
21
+ content-type:
22
+ - application/json
23
+ content-length:
24
+ - '228'
25
+ x-edgeconnect-midmile-rtt:
26
+ - '14'
27
+ x-edgeconnect-origin-mex-latency:
28
+ - '476'
29
+ date:
30
+ - Mon, 08 Jan 2018 16:45:15 GMT
31
+ connection:
32
+ - close
33
+ strict-transport-security:
34
+ - max-age=31536000; includeSubDomains; preload
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"result":{"id":"ML_ez0Gj1S4SX4TZjv","libraryId":"UR_5dURLpfp5tm43EV","name":"NYC05
38
+ QN-SPS-NYC-STU-EL-6","category":"Unassigned","folder":null},"meta":{"httpStatus":"200
39
+ - OK","requestId":"66f0f343-665b-4616-b525-c367fecfc760"}}'
40
+ http_version:
41
+ recorded_at: Mon, 08 Jan 2018 16:45:29 GMT
42
+ - request:
43
+ method: post
44
+ uri: https://co1.qualtrics.com/API/v3/mailinglists/ML_ez0Gj1S4SX4TZjv/contacts
45
+ body:
46
+ encoding: UTF-8
47
+ string: '{"firstName":"test","lastName":"member","email":"test@test.com"}'
48
+ headers:
49
+ X-API-TOKEN:
50
+ - xxx
51
+ User-Agent:
52
+ - Faraday v0.13.1
53
+ Content-Type:
54
+ - application/json
55
+ response:
56
+ status:
57
+ code: 200
58
+ message:
59
+ headers:
60
+ request-time:
61
+ - '385'
62
+ content-type:
63
+ - application/json
64
+ content-length:
65
+ - '124'
66
+ x-edgeconnect-midmile-rtt:
67
+ - '13'
68
+ x-edgeconnect-origin-mex-latency:
69
+ - '438'
70
+ date:
71
+ - Mon, 08 Jan 2018 16:45:15 GMT
72
+ connection:
73
+ - close
74
+ strict-transport-security:
75
+ - max-age=31536000; includeSubDomains; preload
76
+ body:
77
+ encoding: UTF-8
78
+ string: '{"result":{"id":"MLRP_6lo2XeWwEHBhnk9"},"meta":{"httpStatus":"200 -
79
+ OK","requestId":"b36a2747-33fb-4b73-b559-082d86051939"}}'
80
+ http_version:
81
+ recorded_at: Mon, 08 Jan 2018 16:45:30 GMT
82
+ recorded_with: VCR 3.0.3
@@ -11,6 +11,14 @@ module QualtricsAPI
11
11
  @members ||= QualtricsAPI::PanelMemberCollection.new(options.merge(id: id)).propagate_connection(self)
12
12
  end
13
13
 
14
+ def import_members(mbs)
15
+ members.import_members(mbs)
16
+ end
17
+
18
+ def create(member)
19
+ members.create(member)
20
+ end
21
+
14
22
  private
15
23
 
16
24
  def attributes_mappings
@@ -15,10 +15,14 @@ module QualtricsAPI
15
15
  attributes.to_json
16
16
  end
17
17
 
18
+ def to_create_json
19
+ attributes(attributes_for_create).select{ |k,v| k }.to_json
20
+ end
21
+
18
22
  alias_method :super_attributes, :attributes
19
23
 
20
- def attributes
21
- Hash[super_attributes.map { |k, v| [attributes_for_save[k], v] }].delete_if { |_k, v| v.nil? }
24
+ def attributes(attrs = attributes_for_save)
25
+ Hash[super_attributes.map { |k, v| [attrs[k], v] }].delete_if { |_k, v| v.nil? }
22
26
  end
23
27
 
24
28
  private
@@ -36,6 +40,12 @@ module QualtricsAPI
36
40
  }
37
41
  end
38
42
 
43
+ def attributes_for_create
44
+ attrs = attributes_for_save
45
+ attrs.delete(:id)
46
+ attrs.merge({ :external_reference => "externalDataRef" })
47
+ end
48
+
39
49
  def attributes_mappings
40
50
  {
41
51
  :id => "panelMemberId",
@@ -3,8 +3,16 @@ module QualtricsAPI
3
3
  values do
4
4
  attribute :id, String
5
5
  end
6
+
7
+ def create(panel_member)
8
+ payload = panel_member.to_create_json
9
+ res = QualtricsAPI.connection(self)
10
+ .post("mailinglists/#{id}/contacts", payload)
11
+ .body["result"]
12
+ return QualtricsAPI::PanelMember.new(panel_member.attributes.merge({ id: res['id'] }))
13
+ end
6
14
 
7
- def create(panel_members)
15
+ def import_members(panel_members)
8
16
  payload = {
9
17
  contacts: Faraday::UploadIO.new(StringIO.new(panel_members.to_json), 'application/json', 'contacts.json')
10
18
  }
@@ -1,3 +1,3 @@
1
1
  module QualtricsAPI
2
- VERSION = "0.0.14".freeze
2
+ VERSION = "0.0.15".freeze
3
3
  end
@@ -53,10 +53,10 @@ describe QualtricsAPI::PanelMemberCollection do
53
53
  end
54
54
  end
55
55
 
56
- describe "#create" do
56
+ describe "#import_members" do
57
57
  let(:result) do
58
58
  VCR.use_cassette(cassette, record: :once) do
59
- QualtricsAPI.panels.find('ML_0APx3C4rmHER6w5').members.create(panel_members)
59
+ QualtricsAPI.panels.find('ML_0APx3C4rmHER6w5').members.import_members(panel_members)
60
60
  end
61
61
  end
62
62
 
@@ -86,5 +86,35 @@ describe QualtricsAPI::PanelMemberCollection do
86
86
  end
87
87
  end
88
88
  end
89
+
90
+ describe '#create' do
91
+ let(:result) do
92
+ VCR.use_cassette(cassette, record: :once) do
93
+ QualtricsAPI.panels.find('ML_ez0Gj1S4SX4TZjv').members.create(panel_member)
94
+ end
95
+ end
96
+
97
+ describe 'when success' do
98
+ let(:cassette) { 'panel_member_single_create_success' }
99
+ let(:panel_member) { QualtricsAPI::PanelMember.new(first_name: 'test', last_name: 'member', email: 'test@test.com') }
100
+
101
+ it 'returns PanelMember' do
102
+ expect(result).to be_a QualtricsAPI::PanelMember
103
+ end
104
+
105
+ it 'returns PanelMember with id' do
106
+ expect(result.id).to match(/^MLRP_/)
107
+ end
108
+ end
109
+
110
+ describe 'when failed' do
111
+ let(:cassette) { 'panel_member_single_create_failure' }
112
+ let(:panel_member) { QualtricsAPI::PanelMember.new(first_name: 'test', last_name: 'member', email: 'test@test.com') }
113
+
114
+ it 'raises exception' do
115
+ expect{result}.to raise_error{QualtricsAPI::NotFoundError}
116
+ end
117
+ end
118
+ end
89
119
  end
90
120
  end
@@ -55,4 +55,23 @@ describe QualtricsAPI::Panel do
55
55
  end
56
56
  end
57
57
  end
58
+
59
+ describe '#import_members' do
60
+ it 'is delegated to the panel member collection' do
61
+ collection_double = double()
62
+ allow(subject).to receive(:members) { collection_double }
63
+ collection_double.should_receive(:import_members).with([])
64
+ subject.import_members([])
65
+ end
66
+ end
67
+
68
+ describe '#create' do
69
+ let(:member) { QualtricsAPI::PanelMember.new }
70
+ it 'is delegated to the panel member collection' do
71
+ collection_double = double()
72
+ allow(subject).to receive(:members) { collection_double }
73
+ expect(collection_double).to receive(:create).with(member)
74
+ subject.create(member)
75
+ end
76
+ end
58
77
  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.14
4
+ version: 0.0.15
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: 2017-12-27 00:00:00.000000000 Z
13
+ date: 2018-01-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -145,6 +145,8 @@ files:
145
145
  - fixtures/vcr_cassettes/panel_member_collection_create_success.yml
146
146
  - fixtures/vcr_cassettes/panel_member_collection_fetch_fail.yml
147
147
  - fixtures/vcr_cassettes/panel_member_collection_fetch_success.yml
148
+ - fixtures/vcr_cassettes/panel_member_single_create_failure.yml
149
+ - fixtures/vcr_cassettes/panel_member_single_create_success.yml
148
150
  - fixtures/vcr_cassettes/response_export_start_success.yml
149
151
  - fixtures/vcr_cassettes/response_export_update_success.yml
150
152
  - fixtures/vcr_cassettes/survey_collection_fetch_fail.yml
@@ -208,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
210
  version: '0'
209
211
  requirements: []
210
212
  rubyforge_project:
211
- rubygems_version: 2.7.3
213
+ rubygems_version: 2.7.4
212
214
  signing_key:
213
215
  specification_version: 4
214
216
  summary: A Ruby wrapper for Qualtrics REST API v3.0