qualtrics_api 0.0.10 → 0.0.11

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: 1f836176e18af2d85f18fba39a7af32952e185a2
4
- data.tar.gz: 24a7800f963644225c332126d6df9c85dae67ea0
3
+ metadata.gz: 79a66f0df860f75c6181490b7d6c241b509b0ff8
4
+ data.tar.gz: 34a1db85f28e9ec0bb583b581dba1f6ab1078cad
5
5
  SHA512:
6
- metadata.gz: 01df3b46bf2cbe27349920312e2b54efb0c64a0ecf7d004c57acc35ee3d7ad10f90652c81018f6e8ca210121ae8a7b810815a8f5e0ec38fc40e37e3028eded95
7
- data.tar.gz: 68edbed27d3c5c3f6b66fb2d760e7dc5f6d47dc22136d882ae9e2de47aa16d23d79d61af07167fc923279cda246a18251e3f197c9c1c3b5e09e218ab843f7550
6
+ metadata.gz: f5d214fac45c117c0b06071309d7546bee2075cce098d51b8f1532da7e775a671f7a29ac8a8a544d4387bc73e268218f38cc64353e0039b8463bc23d3b03fd08
7
+ data.tar.gz: 0d3e12210c810d3d6fd3ecb3a2b1784001002da1339a68b5cb0ee22b3c7de28115f9a1e8a4c1e88a393640ccc7046ee3c894b5925eeb04fbf82390243902cf13
data/README.md CHANGED
@@ -35,17 +35,21 @@ end
35
35
 
36
36
  ### Surveys
37
37
 
38
- To paginate all your surveys:
38
+ To enumerate all your surveys:
39
39
 
40
40
  ```ruby
41
- surveys = QualtricsAPI.surveys.fetch
42
- # => #<QualtricsAPI::SurveyCollection:0x007fcb72cce350 ....>
43
-
44
- surveys = surveys.next_page # to fetch next page if not on the last page
45
- # => #<QualtricsAPI::SurveyCollection:0x007fcb72cce350 ....>
41
+ QualtricsAPI.surveys.each do |survey|
42
+ # => #<QualtricsAPI::Survey:0x007fcb72cce350 ....>
43
+ end
44
+ ```
46
45
 
47
- surveys.next_page?
48
- # => true
46
+ To enumerate individual pages:
47
+ ```ruby
48
+ QualtricsAPI.surveys.each_page do |page|
49
+ page.each do |survey|
50
+ # => #<QualtricsAPI::Survey:0x007fcb72cce350 ....>
51
+ end
52
+ end
49
53
  ```
50
54
 
51
55
  You can search for a survey by id:
@@ -137,14 +141,22 @@ export.status
137
141
 
138
142
  ### Panels
139
143
 
140
- To paginate all the panels:
144
+ To enumerate all the panels:
141
145
 
142
146
  ```ruby
143
- panels = QualtricsAPI.panels.fetch
144
- # => #<QualtricsAPI::PanelCollection:0x007f8769aae2c0 ....>
147
+ QualtricsAPI.panels.each do |panel|
148
+ # => #<QualtricsAPI::Panel:0x007f8769aae2c0 ....>
149
+ end
150
+ ```
151
+
152
+ To enumerate individual pages:
145
153
 
146
- panels = panels.next_page # get next page if panels.next_page?
147
- # => #<QualtricsAPI::PanelCollection:0x007f8769aae2c0 ....>
154
+ ```ruby
155
+ QualtricsAPI.panels.each_page do |page|
156
+ page.each do |survey|
157
+ # => #<QualtricsAPI::Panel:0x007f8769aae2c0 ....>
158
+ end
159
+ end
148
160
  ```
149
161
 
150
162
  You can search for a panel by id:
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://co1.qualtrics.com/API/v3/panels
5
+ uri: https://co1.qualtrics.com/API/v3/mailinglists
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -13,7 +13,7 @@ http_interactions:
13
13
  - Faraday v0.9.2
14
14
  response:
15
15
  status:
16
- code: 200
16
+ code: 400
17
17
  message:
18
18
  headers:
19
19
  server:
@@ -2,32 +2,35 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://co1.qualtrics.com/API/v1/panels/ABCD/members?apiToken=6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
5
+ uri: https://co1.qualtrics.com/API/v3/mailinglists/ABCD/contacts
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
9
9
  headers:
10
+ X-API-TOKEN:
11
+ - 6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
10
12
  User-Agent:
11
- - Faraday v0.8.9
13
+ - Faraday v0.9.2
12
14
  response:
13
15
  status:
14
- code: 200
15
- message:
16
+ code: 400
17
+ message:
16
18
  headers:
17
- server:
18
- - Apache-Coyote/1.1
19
19
  content-type:
20
- - application/json
20
+ - application/json; charset=utf-8
21
+ request-time:
22
+ - '178'
21
23
  content-length:
22
- - '223'
24
+ - '2362'
23
25
  date:
24
- - Sun, 28 Jun 2015 21:05:57 GMT
26
+ - Tue, 12 Apr 2016 11:39:15 GMT
25
27
  connection:
26
28
  - close
27
29
  body:
28
30
  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
31
+ string: '{"result":{"elements":[{"id":"ABCE","firstName":"Joe","lastName":"Doe","email":"demo@example.com","externalDataReference":"0001","embeddedData":{"subject_name":"John
32
+ Doe"},"language":null,"unsubscribed":false,"responseHistory":[],"emailHistory":[]}],"nextPage":null},"meta":{"httpStatus":"200
33
+ - OK"}}'
34
+ http_version:
35
+ recorded_at: Tue, 12 Apr 2016 11:39:17 GMT
33
36
  recorded_with: VCR 2.9.3
@@ -6,23 +6,21 @@ module QualtricsAPI
6
6
  include QualtricsAPI::Extensions::SerializableCollection
7
7
  include QualtricsAPI::Connectable
8
8
 
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
9
+ def each
10
+ each_page do |page|
11
+ page.each do |element|
12
+ yield element
13
+ end
14
+ end
20
15
  end
21
16
 
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))
17
+ def each_page
18
+ endpoint = list_endpoint
19
+ loop do
20
+ response = QualtricsAPI.connection(self).get(endpoint)
21
+ endpoint = response.body["result"]["nextPage"]
22
+ yield parse_page(response)
23
+ break unless endpoint
26
24
  end
27
25
  end
28
26
 
@@ -32,19 +30,16 @@ module QualtricsAPI
32
30
  build_result(response.body['result']).propagate_connection(self)
33
31
  end
34
32
 
35
- def next_page?
36
- raise NotYetFetchedError unless fetched
37
- !next_endpoint.nil?
38
- end
39
-
40
33
  protected
41
34
 
42
- def parse_fetch_response(response)
43
- @page = response.body["result"]["elements"].map do |element|
35
+ def page_endpoint(fetched)
36
+ fetched ? @next_endpoint : list_endpoint
37
+ end
38
+
39
+ def parse_page(response)
40
+ response.body["result"]["elements"].map do |element|
44
41
  build_result(element).propagate_connection(self)
45
42
  end
46
- @next_endpoint = response.body["result"]["nextPage"]
47
- @fetched = true
48
43
  end
49
44
  end
50
45
  end
@@ -1,3 +1,3 @@
1
1
  module QualtricsAPI
2
- VERSION = "0.0.10".freeze
2
+ VERSION = "0.0.11".freeze
3
3
  end
@@ -1,10 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe QualtricsAPI::PanelCollection do
4
- it "has no @page when initialized" do
5
- expect(subject.page).to eq []
6
- end
7
-
8
4
  describe "integration" do
9
5
  describe "#find" do
10
6
  let(:result) do
@@ -29,57 +25,31 @@ describe QualtricsAPI::PanelCollection do
29
25
  end
30
26
  end
31
27
  end
32
- describe "#fetch" do
28
+ describe "#each_page" do
33
29
  describe "when success" do
34
- before do
35
- expect(subject.page.size).to eq 0
36
- end
37
-
38
30
  let!(:result) do
39
31
  VCR.use_cassette("panel_collection_fetch_success") do
40
- subject.fetch
32
+ subject.each_page do |page|
33
+ return page
34
+ end
41
35
  end
42
36
  end
43
37
 
44
38
  it "populates the collection" do
45
- expect(subject.page.size).to eq 1
46
- expect(subject.first).to be_a QualtricsAPI::Panel
47
- end
48
-
49
- it "returns itself" do
50
- expect(result).to eq subject
39
+ expect(result.size).to eq 1
40
+ expect(result.first).to be_a QualtricsAPI::Panel
51
41
  end
52
42
  end
53
43
 
54
44
  describe "when failed" do
55
45
  it "raises error and does not reset panels" do
56
- subject.instance_variable_set :@page, [QualtricsAPI::Panel.new({})]
57
46
  expect do
58
47
  VCR.use_cassette("panel_collection_fetch_fail") do
59
- begin
60
- subject.fetch
61
- rescue
62
- nil
63
- end
48
+ subject.each_page
64
49
  end
65
- end.not_to change { subject.page }
50
+ end.to raise_error(QualtricsAPI::BadRequestError)
66
51
  end
67
52
  end
68
53
  end
69
54
  end
70
-
71
- describe 'equality' do
72
- subject { described_class.new(page: [QualtricsAPI::Panel.new("panelId" => "p1"), QualtricsAPI::Panel.new("panelId" => "p2")]) }
73
- context 'when same' do
74
- it 'returns true' do
75
- expect(subject).to eq(described_class.new(page: subject.page))
76
- end
77
- end
78
-
79
- context 'when different' do
80
- it 'returns false' do
81
- expect(subject).not_to eq(described_class.new)
82
- end
83
- end
84
- end
85
55
  end
@@ -1,10 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe QualtricsAPI::PanelMemberCollection do
4
- it "has no @page when initialized" do
5
- expect(subject.page).to eq []
6
- end
7
-
8
4
  describe "integration" do
9
5
  subject { described_class.new(id: 'ABCD') }
10
6
 
@@ -34,34 +30,25 @@ describe QualtricsAPI::PanelMemberCollection do
34
30
 
35
31
  describe "#fetch" do
36
32
  describe "when success" do
37
- before do
38
- expect(subject.page.size).to eq 0
39
- end
40
-
41
33
  let!(:result) do
42
34
  VCR.use_cassette("panel_member_collection_fetch_success") do
43
- subject.fetch
35
+ subject.each_page do |page|
36
+ return page
37
+ end
44
38
  end
45
39
  end
46
40
 
47
41
  it "populates the collection" do
48
- expect(subject.page.size).to eq 1
49
- expect(subject.first).to be_a QualtricsAPI::PanelMember
50
- end
51
-
52
- it "returns itself" do
53
- expect(result).to eq subject
42
+ expect(result.size).to eq 1
43
+ expect(result.first).to be_a QualtricsAPI::PanelMember
54
44
  end
55
45
  end
56
46
 
57
47
  describe "when failed" do
58
- it "raise error and does not change panels" do
59
- subject.instance_variable_set :@page, [QualtricsAPI::PanelMember.new({})]
60
- expect do
61
- VCR.use_cassette("panel_member_collection_fetch_fail") do
62
- expect { subject.fetch }.to raise_error
63
- end
64
- end.not_to change { subject.page }
48
+ it "raise error" do
49
+ VCR.use_cassette("panel_member_collection_fetch_fail") do
50
+ expect { subject.each_page }.to raise_error(QualtricsAPI::BadRequestError)
51
+ end
65
52
  end
66
53
  end
67
54
  end
@@ -95,24 +82,9 @@ describe QualtricsAPI::PanelMemberCollection do
95
82
  let(:panel_members) { [QualtricsAPI::PanelMember.new] }
96
83
 
97
84
  it "returns results" do
98
- expect { result }.to raise_error
85
+ expect { result }.to raise_error(QualtricsAPI::BadRequestError)
99
86
  end
100
87
  end
101
88
  end
102
89
  end
103
-
104
- describe 'equality' do
105
- subject { described_class.new(page: [QualtricsAPI::PanelMember.new("recipientID" => "p1"), QualtricsAPI::PanelMember.new("recipientID" => "p1")]) }
106
- context 'when same' do
107
- it 'returns true' do
108
- expect(subject).to eq(described_class.new(page: subject.page))
109
- end
110
- end
111
-
112
- context 'when different' do
113
- it 'returns false' do
114
- expect(subject).not_to eq(described_class.new)
115
- end
116
- end
117
- end
118
90
  end
@@ -1,10 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe QualtricsAPI::SurveyCollection do
4
- it "has no @page when initialized" do
5
- expect(subject.page).to eq []
6
- end
7
-
8
4
  describe "integration" do
9
5
  subject { described_class.new }
10
6
 
@@ -34,87 +30,48 @@ describe QualtricsAPI::SurveyCollection do
34
30
 
35
31
  describe "#fetch" do
36
32
  describe "when success" do
37
- before do
38
- expect(subject.page.size).to eq 0
39
- end
40
-
41
33
  let!(:result) do
42
34
  VCR.use_cassette("survey_collection_fetch_sucess") do
43
- subject.fetch
35
+ subject.each_page do |page|
36
+ return page
37
+ end
44
38
  end
45
39
  end
46
40
 
47
41
  it "populates the collection" do
48
- expect(subject.page.size).to eq 1
49
- expect(subject.first).to be_a QualtricsAPI::Survey
50
- end
51
-
52
- it "returns itself" do
53
- expect(result).to eq subject
42
+ expect(result.size).to eq 1
43
+ expect(result.first).to be_a QualtricsAPI::Survey
54
44
  end
55
45
  end
56
46
 
57
47
  describe "when failed" do
58
- it "raises error and does not reset surveys" do
59
- subject.instance_variable_set :@page, [QualtricsAPI::Survey.new({})]
60
- expect do
61
- VCR.use_cassette("survey_collection_fetch_fail") do
62
- begin
63
- subject.fetch
64
- rescue
65
- nil
66
- end
67
- end
68
- end.not_to change { subject.page }
48
+ it "raises error" do
49
+ VCR.use_cassette("survey_collection_fetch_fail") do
50
+ expect { subject.each_page }.to raise_error(QualtricsAPI::NotFoundError)
51
+ end
69
52
  end
70
53
  end
71
54
  end
72
55
 
73
56
  describe 'pagination' do
74
57
  it 'fetches pages from list endpoint' do
58
+ page1 = page2 = nil
75
59
  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)
60
+ page_no = 0
61
+ subject.each_page do |page|
62
+ if page_no == 0
63
+ page1 = page
64
+ elsif page_no == 1
65
+ page2 = page
66
+ else
67
+ raise 'should not iterate here'
68
+ end
69
+ page_no += 1
70
+ end
71
+ expect(page1).not_to be_nil
72
+ expect(page2).not_to be_nil
101
73
  end
102
74
  end
103
75
  end
104
76
  end
105
-
106
- describe 'equality' do
107
- subject { described_class.new(page: [QualtricsAPI::Survey.new("id" => "s1"), QualtricsAPI::Survey.new("id" => "s2")]) }
108
- context 'when same' do
109
- it 'returns true' do
110
- expect(subject).to eq(described_class.new(page: subject.page))
111
- end
112
- end
113
-
114
- context 'when different' do
115
- it 'returns false' do
116
- expect(subject).not_to eq(described_class.new)
117
- end
118
- end
119
- end
120
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.10
4
+ version: 0.0.11
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-25 00:00:00.000000000 Z
13
+ date: 2016-04-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday