lime_survey 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 431db8ddd4dc8272c123ed1fe3c08dd669c522d61d8fac2bb826f369dcaa6084
4
+ data.tar.gz: c406f56c9345080233afd8da85119ec2b5c5d461a883ecddfd51e64aa648f78d
5
+ SHA512:
6
+ metadata.gz: 6388f481393a6056fac428649863b8e1a2a3951c3e6cd008ff59b76c5bc69c1a1896780e406a18ba0e5c95ef336ae71ef3cdedf2831b58d9988e5f356acaeefd
7
+ data.tar.gz: f03148d9ddf6e9dd87e44e2b2d44afe519606258a542e400c0aa0b99f150a4839906620efc52035827b44e63ea6d644ee18b41d9e343df77f04b4cb0a4c7bde9
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.env.sample ADDED
@@ -0,0 +1,4 @@
1
+ LIMESURVEY_API_URL: "https://YOUR_URL/survey/index.php?r=admin/remotecontrol"
2
+ LIMESURVEY_USERNAME: "my-username"
3
+ LIMESURVEY_PASSWORD: "my-password"
4
+ LIMESURVEY_BASE_URL: "https://YOUR_URL/survey/index.php"
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.sublime-project
16
+ *.sublime-workspace
17
+
18
+ .DS_Store
19
+ .env
20
+ .ruby-version
21
+ .ruby-gemset
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.2
7
+ before_install: gem install bundler -v 1.16.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at beneggett@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in lime_survey.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Ben Eggett
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,353 @@
1
+ [![Gem Version](https://badge.fury.io/rb/lime_survey.svg)](https://badge.fury.io/rb/lime_survey)
2
+ [![Build Status](https://travis-ci.com/beneggett/lime_survey.svg?branch=master)](https://travis-ci.com/beneggett/lime_survey)
3
+ [![Coverage Status](https://coveralls.io/repos/github/beneggett/lime_survey/badge.svg?branch=master)](https://coveralls.io/github/beneggett/lime_survey?branch=master)
4
+ # LimeSurvey
5
+
6
+ Fully Implements the LimeSurvey API in Ruby
7
+
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+ ```ruby
13
+ gem 'lime_survey'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install lime_survey
23
+
24
+ Be sure to define your LimeSurvey credentials by setting up environment variables in your application appropriately. Refer to the .env.sample file for details.
25
+ ```
26
+ LIMESURVEY_API_URL = "https://YOUR_URL/survey/index.php?r=admin/remotecontrol"
27
+ LIMESURVEY_USERNAME = "my-user"
28
+ LIMESURVEY_PASSWORD = "my-password"
29
+ ```
30
+
31
+ If you simply would like to play with the API, you can use the public demo credentials which are:
32
+
33
+ ```
34
+ LIMESURVEY_API_URL: "https://demo.limesurvey.org/index.php?r=admin/remotecontrol"
35
+ LIMESURVEY_USERNAME: "demo"
36
+ LIMESURVEY_PASSWORD: "demo"
37
+
38
+ ```
39
+ Public credentials last updated 4/25/2019
40
+
41
+ ## Usage
42
+
43
+ There are 48 primary APIs that are wrapped. Below you will see basic examples of how to use them. For more information about what optional query parameters are available, please consult the [LimeSurvey API Docs](https://api.limesurvey.org/classes/remotecontrol_handle.html#method_list_surveys)
44
+
45
+ Authenticated calls require a token, this library already handles the request & reload of tokens as needed via the `check_authentication` & `get_session_key methods` defined in LimeSurvey::Api
46
+
47
+ #### Activate Survey
48
+
49
+ ```
50
+ LimeSurvey::Api.new.activate_survey survey_id: 1
51
+ ```
52
+
53
+ #### Activate Tokens
54
+
55
+ ```
56
+ LimeSurvey::Api.new.activate_tokens survey_id: 1, attribute_fields: [3,5,7]
57
+ ```
58
+
59
+ #### Add Group
60
+
61
+ ```
62
+ LimeSurvey::Api.new.add_group
63
+ ```
64
+
65
+ #### Add Language
66
+
67
+ ```
68
+ LimeSurvey::Api.new.add_language
69
+ ```
70
+
71
+ #### Add Participants
72
+
73
+ ```
74
+ LimeSurvey::Api.new.add_participants
75
+ ```
76
+
77
+ #### Add Response
78
+
79
+ ```
80
+ LimeSurvey::Api.new.add_response
81
+ ```
82
+
83
+ #### Add Survey
84
+
85
+ ```
86
+ LimeSurvey::Api.new.add_survey
87
+ ```
88
+
89
+ #### Copy Survey
90
+
91
+ ```
92
+ LimeSurvey::Api.new.copy_survey
93
+ ```
94
+
95
+ #### Cpd Import Participants
96
+
97
+ ```
98
+ LimeSurvey::Api.new.cpd_import_participants
99
+ ```
100
+
101
+ #### Delete Group
102
+
103
+ ```
104
+ LimeSurvey::Api.new.delete_group
105
+ ```
106
+
107
+ #### Delete Language
108
+
109
+ ```
110
+ LimeSurvey::Api.new.delete_language
111
+ ```
112
+
113
+ #### Delete Participants
114
+
115
+ ```
116
+ LimeSurvey::Api.new.delete_participants
117
+ ```
118
+
119
+ #### Delete Question
120
+
121
+ ```
122
+ LimeSurvey::Api.new.delete_question
123
+ ```
124
+
125
+ #### Delete Survey
126
+
127
+ ```
128
+ LimeSurvey::Api.new.delete_survey
129
+ ```
130
+
131
+ #### Export Responses
132
+
133
+ ```
134
+ LimeSurvey::Api.new.export_responses
135
+ ```
136
+
137
+ #### Export Responses By Token
138
+
139
+ ```
140
+ LimeSurvey::Api.new.export_responses_by_token
141
+ ```
142
+
143
+ #### Export Statistics
144
+
145
+ ```
146
+ LimeSurvey::Api.new.export_statistics
147
+ ```
148
+
149
+ #### Export Timeline
150
+
151
+ ```
152
+ LimeSurvey::Api.new.export_timeline
153
+ ```
154
+
155
+ #### Get Group Properties
156
+
157
+ ```
158
+ LimeSurvey::Api.new.get_group_properties
159
+ ```
160
+
161
+ #### Get Language Properties
162
+
163
+ ```
164
+ LimeSurvey::Api.new.get_language_properties
165
+ ```
166
+
167
+ #### Get Participant Properties
168
+
169
+ ```
170
+ LimeSurvey::Api.new.get_participant_properties
171
+ ```
172
+
173
+ #### Get Question Properties
174
+
175
+ ```
176
+ LimeSurvey::Api.new.get_question_properties
177
+ ```
178
+
179
+ #### Get Response Ids
180
+
181
+ ```
182
+ LimeSurvey::Api.new.get_response_ids
183
+ ```
184
+
185
+ #### Get Session Key
186
+
187
+ ```
188
+ LimeSurvey::Api.new.get_session_key
189
+ ```
190
+
191
+ #### Get Site Settings
192
+
193
+ ```
194
+ LimeSurvey::Api.new.get_site_settings
195
+ ```
196
+
197
+ #### Get Summary
198
+
199
+ ```
200
+ LimeSurvey::Api.new.get_summary
201
+ ```
202
+
203
+ #### Get Survey Properties
204
+
205
+ ```
206
+ LimeSurvey::Api.new.get_survey_properties
207
+ ```
208
+
209
+ #### Get Uploaded Files
210
+
211
+ ```
212
+ LimeSurvey::Api.new.get_uploaded_files
213
+ ```
214
+
215
+ #### Import Group
216
+
217
+ ```
218
+ LimeSurvey::Api.new.import_group
219
+ ```
220
+
221
+ #### Import Question
222
+
223
+ ```
224
+ LimeSurvey::Api.new.import_question
225
+ ```
226
+
227
+ #### Import Survey
228
+
229
+ ```
230
+ LimeSurvey::Api.new.import_survey
231
+ ```
232
+
233
+ #### Invite Participants
234
+
235
+ ```
236
+ LimeSurvey::Api.new.invite_participants
237
+ ```
238
+
239
+ #### List Groups
240
+
241
+ ```
242
+ LimeSurvey::Api.new.list_groups
243
+ ```
244
+
245
+ #### List Participants
246
+
247
+ ```
248
+ LimeSurvey::Api.new.list_participants
249
+ ```
250
+
251
+ #### List Questions
252
+
253
+ ```
254
+ LimeSurvey::Api.new.list_questions
255
+ ```
256
+
257
+ #### List Surveys
258
+
259
+ ```
260
+ LimeSurvey::Api.new.list_surveys
261
+ ```
262
+
263
+ #### List Users
264
+
265
+ ```
266
+ LimeSurvey::Api.new.list_users
267
+ ```
268
+
269
+ #### Mail Registered Participants
270
+
271
+ ```
272
+ LimeSurvey::Api.new.mail_registered_participants
273
+ ```
274
+
275
+ #### Release Session Key
276
+
277
+ ```
278
+ LimeSurvey::Api.new.release_session_key
279
+ ```
280
+
281
+ #### Remind Participants
282
+
283
+ ```
284
+ LimeSurvey::Api.new.remind_participants
285
+ ```
286
+
287
+ #### Set Group Properties
288
+
289
+ ```
290
+ LimeSurvey::Api.new.set_group_properties
291
+ ```
292
+
293
+ #### Set Language Properties
294
+
295
+ ```
296
+ LimeSurvey::Api.new.set_language_properties
297
+ ```
298
+
299
+ #### Set Participant Properties
300
+
301
+ ```
302
+ LimeSurvey::Api.new.set_participant_properties
303
+ ```
304
+
305
+ #### Set Question Properties
306
+
307
+ ```
308
+ LimeSurvey::Api.new.set_question_properties
309
+ ```
310
+
311
+ #### Set Quota Properties
312
+
313
+ ```
314
+ LimeSurvey::Api.new.set_quota_properties
315
+ ```
316
+
317
+ #### Set Survey Properties
318
+
319
+ ```
320
+ LimeSurvey::Api.new.set_survey_properties
321
+ ```
322
+
323
+ #### Update Response
324
+
325
+ ```
326
+ LimeSurvey::Api.new.update_response
327
+ ```
328
+
329
+ #### Upload File
330
+
331
+ ```
332
+ LimeSurvey::Api.new.upload_file
333
+ ```
334
+
335
+ ## Development
336
+
337
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
338
+
339
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
340
+
341
+ ## Contributing
342
+
343
+ Bug reports and pull requests are welcome on GitHub at https://github.com/beneggett/lime_survey. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
344
+
345
+ ## License
346
+
347
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
348
+
349
+ ## Code of Conduct
350
+
351
+ Everyone interacting in the LimeSurvey project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/beneggett/lime_survey/blob/master/CODE_OF_CONDUCT.md).
352
+
353
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require "dotenv"
3
+ Dotenv.load
4
+ require "bundler/setup"
5
+ require "lime_survey"
6
+
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ require "pry"
13
+ Pry.start
14
+
15
+ # require "irb"
16
+ # IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,290 @@
1
+ module LimeSurvey
2
+ class Api
3
+ URL_ENDPOINT = ENV.fetch("LIMESURVEY_API_URL", "not-implemented")
4
+
5
+ include HTTParty
6
+
7
+ attr_accessor :username, :password, :token
8
+
9
+ def initialize(options = {})
10
+ @username = options.fetch(:username, default_username)
11
+ @password = options.fetch(:password, default_password)
12
+ @token = options.dig(:token)
13
+ end
14
+
15
+ # LimeSurvey::Api.new.activate_survey survey_id: 1
16
+ def activate_survey(survey_id:)
17
+ authenticated_post "activate_survey", [survey_id].compact
18
+ end
19
+
20
+ # LimeSurvey::Api.new.activate_tokens survey_id: 1, attribute_fields: [3,5,7]
21
+ def activate_tokens(survey_id:, attribute_fields: [])
22
+ authenticated_post "activate_tokens", [survey_id, attribute_fields]
23
+ end
24
+
25
+ # LimeSurvey::Api.new.add_group
26
+ def add_group(survey_id:, group_title: , group_description: '' )
27
+ authenticated_post "add_group", [survey_id, group_title, group_description]
28
+ end
29
+
30
+ def add_language(survey_id: , language: )
31
+ authenticated_post "add_language", [survey_id, language]
32
+ end
33
+
34
+ def add_participants(survey_id: , participant_data: [], create_token: true)
35
+ authenticated_post "add_participants", [survey_id, participant_data, create_token]
36
+ end
37
+
38
+ def add_response(survey_id: , response_data: [])
39
+ authenticated_post "add_response", [survey_id, response_data]
40
+ end
41
+
42
+ # Format can be A|G|S
43
+ # LimeSurvey::Api.new.add_survey survey_id: 1234, survey_title: "Survey 1234", survey_language: "en", format: "A"
44
+ def add_survey(survey_id: , survey_title: , survey_language: , format: 'G' )
45
+ authenticated_post "add_survey", [survey_id, survey_title, survey_language, format]
46
+ end
47
+
48
+ def copy_survey(survey_id: , survey_name: )
49
+ authenticated_post "copy_survey", [survey_id, survey_name]
50
+ end
51
+
52
+ def cpd_import_participants(participants: [])
53
+ authenticated_post "cpd_importParticipants", [participants]
54
+ end
55
+
56
+ def delete_group(survey_id: , group_id: )
57
+ authenticated_post "delete_group", [survey_id, group_id]
58
+ end
59
+
60
+ def delete_language(survey_id: , language: )
61
+ authenticated_post "delete_language", [survey_id, language]
62
+ end
63
+
64
+ def delete_participants(survey_id: , participants: [])
65
+ authenticated_post "delete_participants", [survey_id, participants]
66
+ end
67
+
68
+ def delete_question(question_id: )
69
+ authenticated_post "delete_question", [question_id]
70
+ end
71
+
72
+ def delete_survey(survey_id: )
73
+ authenticated_post "delete_survey", [survey_id]
74
+ end
75
+
76
+ # document types: pdf, csv, xls, doc, json-rpc
77
+ def export_responses(survey_id: , document_type: 'json', language_code: 'en', completion_status: 'complete', heading_type: nil, response_type: nil, from_response_id: 0, to_response_id: 1_000_000, fields: nil)
78
+ authenticated_post "export_responses", [survey_id, document_type, language_code, completion_status, heading_type, response_type, from_response_id, to_response_id, fields]
79
+ end
80
+
81
+ def export_responses_by_token(survey_id: , document_type: 'json', token: , language_code: 'en', completion_status: 'all', heading_type: 'code', response_type: 'long', fields: nil)
82
+ authenticated_post "export_responses_by_token", [survey_id, document_type, token, language_code, completion_status, heading_type, response_type, fields]
83
+ end
84
+
85
+ def export_statistics(survey_id: , document_type: , token: , language_code: , graph: 'no', group_ids: nil)
86
+ authenticated_post "export_statistics", [survey_id, document_type, token, language_code, graph, group_ids]
87
+ end
88
+
89
+ def export_timeline(survey_id: , survey_type: 'day', start_time: , end_time: )
90
+ authenticated_post "export_timeline", [survey_id, survey_type, start_time, end_time]
91
+ end
92
+
93
+ def get_group_properties(group_id: , group_settings: [])
94
+ authenticated_post "get_group_properties", [group_id, group_settings]
95
+ end
96
+
97
+ def get_language_properties(survey_id: , survey_locale_settings: nil, language: nil)
98
+ authenticated_post "get_language_properties", [survey_id, survey_locale_settings, language]
99
+ end
100
+
101
+ def get_participant_properties(survey_id: , token_query_properties: nil, token_properties: nil)
102
+ authenticated_post "get_participant_properties", [survey_id, token_query_properties, token_properties]
103
+ end
104
+
105
+ def get_question_properties(question_id: , question_settings: [], language: nil)
106
+ authenticated_post "get_question_properties", [question_id, question_settings, language]
107
+ end
108
+
109
+ def get_response_ids(survey_id: , token: )
110
+ authenticated_post "get_response_ids", [survey_id, token]
111
+ end
112
+
113
+ def get_session_key
114
+ response = post "get_session_key", [username, password]
115
+ end
116
+
117
+ def get_site_settings(setting_name: )
118
+ authenticated_post "get_site_settings", [setting_name]
119
+ end
120
+
121
+ def get_summary(survey_id: , stat_name: nil)
122
+ authenticated_post "get_summary", [survey_id, stat_name].compact
123
+ end
124
+
125
+ def get_survey_properties(survey_id: , survey_settings: nil)
126
+ authenticated_post "get_survey_properties", [survey_id, survey_settings].compact
127
+ end
128
+
129
+ def get_uploaded_files(survey_id: , token: )
130
+ authenticated_post "get_uploaded_files", [survey_id, token]
131
+ end
132
+
133
+ def import_group(survey_id: , import_data: , import_data_type: , new_group_name: nil, new_group_description: nil)
134
+ authenticated_post "import_group", [survey_id, import_data, import_data_type, new_group_name, new_group_description]
135
+ end
136
+
137
+ def import_question(survey_id: , group_id: , import_data: , import_data_type: , mandatory: 'no', new_question_title: nil, new_q_question: nil, new_question_help: nil)
138
+ authenticated_post "import_question", [survey_id, group_id, import_data, import_data_type, mandatory, new_question_title, new_q_question, new_question_help]
139
+ end
140
+
141
+ def import_survey(import_data: , import_data_type: , new_survey_name: nil, destination_survey_id: nil)
142
+ authenticated_post "import_survey", [import_data, import_data_type, new_survey_name, destination_survey_id]
143
+ end
144
+ # email: TRUE / FALSE
145
+ def invite_participants(survey_id: , token_ids: [], email: )
146
+ authenticated_post "invite_participants", [survey_id, token_ids, email]
147
+ end
148
+
149
+ def list_groups(survey_id: )
150
+ authenticated_post "list_groups", [survey_id]
151
+ end
152
+
153
+ def list_participants(survey_id: , start: 0, limit: 10_000, unused: false, attributes: [], conditions: [])
154
+ authenticated_post "list_participants", [survey_id, start, limit, unused, attributes, conditions]
155
+ end
156
+
157
+ def list_questions(survey_id: , group_id: nil, language: nil)
158
+ authenticated_post "list_questions", [survey_id, group_id, language]
159
+ end
160
+
161
+ # LimeSurvey::Api.new.list_surveys
162
+ def list_surveys(username: nil)
163
+ authenticated_post "list_surveys", [username].compact
164
+ end
165
+
166
+ def list_users(user_id: nil)
167
+ authenticated_post "list_users", [user_id].compact
168
+ end
169
+
170
+ def mail_registered_participants(survey_id: , override_all_conditions: [])
171
+ authenticated_post "mail_registered_participants", [survey_id, override_all_conditions]
172
+ end
173
+
174
+ def release_session_key
175
+ authenticated_post "release_session_key"
176
+ @token = nil
177
+ end
178
+
179
+ def remind_participants(survey_id: , min_days_between: nil, max_reminders: nil, token_ids: nil)
180
+ authenticated_post "remind_participants", [survey_id, min_days_between, max_reminders, token_ids]
181
+ end
182
+
183
+ def set_group_properties(group_id: , group_data: [])
184
+ authenticated_post "set_group_properties", [group_id, group_data]
185
+ end
186
+
187
+ def set_language_properties(survey_id: , survey_locale_data: [], language: nil)
188
+ authenticated_post "set_language_properties", [survey_id, survey_locale_data, language]
189
+ end
190
+
191
+ def set_participant_properties(survey_id: , token_query_properties: , token_data: )
192
+ authenticated_post "set_participant_properties", [survey_id, token_query_properties, token_data]
193
+ end
194
+
195
+ def set_question_properties(question_id: , question_data: , language: )
196
+ authenticated_post "set_question_properties", [question_id, question_data, language]
197
+ end
198
+
199
+ def set_quota_properties(quota_id: , quota_data: )
200
+ authenticated_post "set_quota_properties", [quota_id, quota_data]
201
+ end
202
+
203
+ def set_survey_properties(survey_id: , survey_data: )
204
+ authenticated_post "set_survey_properties", [survey_id, suvey_data]
205
+ end
206
+
207
+ def update_response(survey_id: , response_data: )
208
+ authenticated_post "update_response", [survey_id, response_data]
209
+ end
210
+
211
+ #file_data is BASE64
212
+ def upload_file(survey_id: , field_name: , file_name: , file_data: )
213
+ authenticated_post "upload_file", params
214
+ end
215
+
216
+
217
+ def authenticated_post(method_name, params = [])
218
+ check_authentication
219
+ post method_name, params
220
+ end
221
+
222
+ def post(method_name, params = [])
223
+ response = self.class.post(URL_ENDPOINT, body: modify_body(method_name, params), timeout: 60, headers: headers)
224
+ OpenStruct.new body: JSON::parse(response.body), request: response.request, code: response.code
225
+ end
226
+
227
+ def check_authentication
228
+ if token
229
+ return self
230
+ else
231
+ authenticate!
232
+ end
233
+ end
234
+
235
+ private
236
+
237
+
238
+ def authenticate!
239
+ response = get_session_key
240
+ raise AuthenticationError.new(response.body.dig("result", "status")) if response.body.dig("result").is_a?(Hash) && response.body.dig("result", "status") == "Invalid user name or password"
241
+ @token = response.body.dig("result")
242
+ response
243
+ end
244
+
245
+ def argument_cleaner(required_params: , optional_params: , options: )
246
+ missing_required = required_params - options.map {|k,v| k.to_sym }
247
+ raise ArgumentError.new("Missing Required Arguments: #{missing_required.join(', ')}") if missing_required.any?
248
+ all_params = (required_params + optional_params).flatten
249
+ return options.select {|k,v| all_params.include?(k.to_sym)}
250
+ end
251
+
252
+ def modify_body(method_name, params = [])
253
+
254
+ default_params = {
255
+ method: method_name,
256
+ params: params,
257
+ id: 'json-rpc'
258
+ }
259
+
260
+ default_params[:params] = [token] + params if token
261
+ default_params.to_json
262
+ end
263
+
264
+
265
+ def headers
266
+ @headers = {
267
+ "Accept" => "application/json",
268
+ "Content-Type" => "application/json",
269
+ "Connection" => "Keep-Alive",
270
+ }
271
+ end
272
+
273
+ def default_username
274
+ ENV["LIMESURVEY_USERNAME"]
275
+ end
276
+
277
+ def default_password
278
+ ENV["LIMESURVEY_PASSWORD"]
279
+ end
280
+
281
+ def default_base_url
282
+ ENV["LIMESURVEY_BASE_URL"]
283
+ end
284
+
285
+ end
286
+ end
287
+
288
+ # api_method = 'get_session_key'
289
+
290
+
@@ -0,0 +1,3 @@
1
+ module LimeSurvey
2
+ VERSION = "0.10.0"
3
+ end
@@ -0,0 +1,16 @@
1
+ # require "active_support/all"
2
+ require "httparty"
3
+ require "ostruct"
4
+
5
+ require "lime_survey/api"
6
+ require "lime_survey/version"
7
+
8
+
9
+ module LimeSurvey
10
+ class Api::AuthenticationError < StandardError
11
+ def initialize(msg="Could not Authenticate")
12
+ super
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,50 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "lime_survey/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lime_survey"
8
+ spec.version = LimeSurvey::VERSION
9
+ spec.authors = ["Ben Eggett"]
10
+ spec.email = ["beneggett@gmail.com"]
11
+
12
+ spec.summary = %q{LimeSurvey API wrapper}
13
+ spec.description = %q{Fully implements LimeSurvey API}
14
+ spec.homepage = "https://github.com/beneggett/lime_survey"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.16"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "minitest", "~> 5.0"
39
+ spec.add_development_dependency "vcr"
40
+ spec.add_development_dependency "webmock"
41
+ spec.add_development_dependency "pry"
42
+ # spec.add_development_dependency "guard"
43
+ # spec.add_development_dependency "guard-minitest"
44
+ spec.add_development_dependency "coveralls"
45
+ spec.add_development_dependency "simplecov"
46
+ spec.add_development_dependency "dotenv"
47
+ spec.add_dependency "httparty", ">= 0.14.0"
48
+ # spec.add_dependency "activesupport"
49
+ spec.add_dependency "builder"
50
+ end
metadata ADDED
@@ -0,0 +1,213 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lime_survey
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Eggett
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: dotenv
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: httparty
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 0.14.0
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 0.14.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: builder
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Fully implements LimeSurvey API
168
+ email:
169
+ - beneggett@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".coveralls.yml"
175
+ - ".env.sample"
176
+ - ".gitignore"
177
+ - ".travis.yml"
178
+ - CODE_OF_CONDUCT.md
179
+ - Gemfile
180
+ - LICENSE.txt
181
+ - README.md
182
+ - Rakefile
183
+ - bin/console
184
+ - bin/setup
185
+ - lib/lime_survey.rb
186
+ - lib/lime_survey/api.rb
187
+ - lib/lime_survey/version.rb
188
+ - lime_survey.gemspec
189
+ homepage: https://github.com/beneggett/lime_survey
190
+ licenses:
191
+ - MIT
192
+ metadata:
193
+ allowed_push_host: https://rubygems.org
194
+ post_install_message:
195
+ rdoc_options: []
196
+ require_paths:
197
+ - lib
198
+ required_ruby_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ required_rubygems_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ requirements: []
209
+ rubygems_version: 3.0.3
210
+ signing_key:
211
+ specification_version: 4
212
+ summary: LimeSurvey API wrapper
213
+ test_files: []