limeade 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/limeade/client.rb +65 -20
- data/lib/limeade/errors.rb +2 -2
- data/lib/limeade/json_rpc.rb +12 -12
- data/lib/limeade/version.rb +1 -1
- data/limeade.gemspec +1 -1
- metadata +13 -8
- data/lib/limeade/methods.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb14f9082aa25256534bdfe452342afa8e85c91f6865af7018ba29ba1bec0da6
|
4
|
+
data.tar.gz: 1eb9ce140d18269679297942b43eebc05999262f04b1e8458fc434b48370fa1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '06690414adef52692099da672515d777a452f7e6cf2b1cd4e5bd6f81c4e92e09b9dc0725a5408c6474427be1c26c5726ccce931667ac0f8ccc81a24e111c6ff8'
|
7
|
+
data.tar.gz: e1e0b2bce2473578c58d1e72c0f461d2b044fbc673ac08c435c2a36b739784d9e098e27bc77e53f1007146494e3c2b9cab44372dce07880d3ad2600f204a4c9e
|
data/README.md
CHANGED
@@ -42,7 +42,10 @@ require 'limeade'
|
|
42
42
|
```
|
43
43
|
|
44
44
|
Instantiate a client and start invoking API methods on it. The API methods are documented
|
45
|
-
[here](https://api.limesurvey.org/classes/remotecontrol_handle.html).
|
45
|
+
[here](https://api.limesurvey.org/classes/remotecontrol_handle.html). Do not specify the
|
46
|
+
`$sSessionKey`, as it is added as the first argument automatically. (Recall that the session is
|
47
|
+
managed for you transparently.)
|
48
|
+
|
46
49
|
|
47
50
|
```ruby
|
48
51
|
client = Limeade::Client.new(api_uri, username, password)
|
data/lib/limeade/client.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
require 'limeade/methods'
|
2
|
-
|
3
1
|
module Limeade
|
4
|
-
|
5
2
|
# Client for accessing the LimeSurvey RemoteControl API from Ruby.
|
6
3
|
class Client
|
7
|
-
|
8
4
|
#
|
9
5
|
# Instantiate a client and setup a connection to the LimeSurvey RemoteControl API.
|
10
6
|
# Passes configuration for the Faraday::Request::Retry mechanism.
|
@@ -67,25 +63,73 @@ module Limeade
|
|
67
63
|
end
|
68
64
|
end
|
69
65
|
|
70
|
-
#
|
71
|
-
# @param method [Symbol] the method invoked
|
72
|
-
# @param arguments [Array] the arguments to the method
|
66
|
+
# Define a LimeSurvey RemoteControl API method call.
|
73
67
|
#
|
74
|
-
# @
|
75
|
-
# @
|
68
|
+
# @param ruby_method [Symbol] the name of the ruby method to define
|
69
|
+
# @param rpc_method [Symbol, String] the name of the JSON RPC method to call
|
70
|
+
# @!macro [attach] define_api_method
|
71
|
+
# @method $1
|
72
|
+
# Invoke the +${-1}+ JSON RPC method on the given endpoint.
|
76
73
|
#
|
77
|
-
#
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
74
|
+
# @see https://api.limesurvey.org/classes/remotecontrol_handle.html#method_${-1}
|
75
|
+
# @param [variable] *arguments see LimeSurvey documentation
|
76
|
+
# @raise [ServerError] The API endpoint server is having issues. An error code and message are included.
|
77
|
+
# @raise [InvalidResponseError] The API endpoint is returning malformed JSON RPC responses. A descriptive message
|
78
|
+
# @return [Object] the result of invoking the method on the endpoint
|
79
|
+
def self.define_api_method(ruby_method, rpc_method = ruby_method)
|
80
|
+
define_method(ruby_method) do |*arguments|
|
81
|
+
process_request(rpc_method, *arguments)
|
83
82
|
end
|
84
83
|
end
|
85
84
|
|
86
|
-
|
87
|
-
|
88
|
-
|
85
|
+
define_api_method :activate_survey
|
86
|
+
define_api_method :activate_tokens
|
87
|
+
define_api_method :add_group
|
88
|
+
define_api_method :add_language
|
89
|
+
define_api_method :add_participants
|
90
|
+
define_api_method :add_response
|
91
|
+
define_api_method :add_survey
|
92
|
+
define_api_method :copy_survey
|
93
|
+
define_api_method :cpd_importParticipants
|
94
|
+
define_api_method :delete_group
|
95
|
+
define_api_method :delete_language
|
96
|
+
define_api_method :delete_participants
|
97
|
+
define_api_method :delete_question
|
98
|
+
define_api_method :delete_survey
|
99
|
+
define_api_method :export_responses
|
100
|
+
define_api_method :export_responses_by_token
|
101
|
+
define_api_method :export_statistics
|
102
|
+
define_api_method :export_timeline
|
103
|
+
define_api_method :get_group_properties
|
104
|
+
define_api_method :get_language_properties
|
105
|
+
define_api_method :get_participant_properties
|
106
|
+
define_api_method :get_question_properties
|
107
|
+
define_api_method :get_response_ids
|
108
|
+
define_api_method :get_session_key
|
109
|
+
define_api_method :get_site_settings
|
110
|
+
define_api_method :get_summary
|
111
|
+
define_api_method :get_survey_properties
|
112
|
+
define_api_method :get_uploaded_files
|
113
|
+
define_api_method :import_group
|
114
|
+
define_api_method :import_question
|
115
|
+
define_api_method :import_survey
|
116
|
+
define_api_method :invite_participants
|
117
|
+
define_api_method :list_groups
|
118
|
+
define_api_method :list_participants
|
119
|
+
define_api_method :list_questions
|
120
|
+
define_api_method :list_surveys
|
121
|
+
define_api_method :list_users
|
122
|
+
define_api_method :mail_registered_participants
|
123
|
+
define_api_method :release_session_key
|
124
|
+
define_api_method :remind_participants
|
125
|
+
define_api_method :set_group_properties
|
126
|
+
define_api_method :set_language_properties
|
127
|
+
define_api_method :set_participant_properties
|
128
|
+
define_api_method :set_question_properties
|
129
|
+
define_api_method :set_quota_properties
|
130
|
+
define_api_method :set_survey_properties
|
131
|
+
define_api_method :update_response
|
132
|
+
define_api_method :upload_file
|
89
133
|
|
90
134
|
private
|
91
135
|
|
@@ -100,7 +144,7 @@ module Limeade
|
|
100
144
|
def process_request(method_name, *arguments)
|
101
145
|
raise DisconnectedError unless connected?
|
102
146
|
result = @json_rpc.invoke(method_name, @session_key, *arguments)
|
103
|
-
if result.is_a?
|
147
|
+
if result.is_a?(Hash) && result['status']
|
104
148
|
case result['status']
|
105
149
|
when 'OK'
|
106
150
|
true
|
@@ -108,6 +152,8 @@ module Limeade
|
|
108
152
|
[]
|
109
153
|
when 'No Tokens found'
|
110
154
|
[]
|
155
|
+
when 'No survey participants table'
|
156
|
+
false
|
111
157
|
when /(left to send)|(No candidate tokens)$/
|
112
158
|
result
|
113
159
|
when /Invalid surveyid$/i
|
@@ -153,5 +199,4 @@ module Limeade
|
|
153
199
|
|
154
200
|
# Private exception raised only in the context of #process_request.
|
155
201
|
class NoSessionError < Error; end
|
156
|
-
|
157
202
|
end
|
data/lib/limeade/errors.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module Limeade
|
3
4
|
class Error < StandardError; end
|
4
5
|
|
5
6
|
class InvalidResponseError < Error; end
|
@@ -27,5 +28,4 @@ module Limeade
|
|
27
28
|
super("LimeSurvey API '#{method}' returned a failure status: #{status}")
|
28
29
|
end
|
29
30
|
end
|
30
|
-
|
31
31
|
end
|
data/lib/limeade/json_rpc.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faraday'
|
2
4
|
require 'multi_json'
|
3
5
|
|
4
6
|
module Limeade
|
5
|
-
|
6
7
|
# An implementation of JSON RPC version 1. This is inspired by jsonrpc-client, which implements
|
7
8
|
# version 2 of the spec. This implementation adds retry capability via Faraday::Request::Retry.
|
8
9
|
|
9
10
|
class JSON_RPC
|
10
|
-
|
11
|
-
JSON_RPC_VERSION = '1.0'.freeze
|
11
|
+
JSON_RPC_VERSION = '1.0'
|
12
12
|
|
13
13
|
#
|
14
14
|
# Instantiate a client and setup a connection to the endpoint.
|
@@ -69,7 +69,7 @@ module Limeade
|
|
69
69
|
|
70
70
|
private
|
71
71
|
|
72
|
-
STANDARD_HEADERS = {content_type: 'application/json'}.freeze
|
72
|
+
STANDARD_HEADERS = { content_type: 'application/json' }.freeze
|
73
73
|
|
74
74
|
def connection
|
75
75
|
@connection ||= ::Faraday.new do |connection|
|
@@ -84,6 +84,7 @@ module Limeade
|
|
84
84
|
payload = payload_from(response)
|
85
85
|
verify_payload(payload, request_id)
|
86
86
|
raise ServerError.new(payload['error']['code'], payload['error']['message']) if payload['error']
|
87
|
+
|
87
88
|
payload['result']
|
88
89
|
end
|
89
90
|
|
@@ -97,30 +98,29 @@ module Limeade
|
|
97
98
|
def verify_payload(payload, request_id)
|
98
99
|
Limeade.logger.debug "verify_payload: #{payload.inspect}"
|
99
100
|
raise(InvalidResponseError, 'Response body is not a Hash') unless payload.is_a?(::Hash)
|
100
|
-
raise(InvalidResponseError, 'Response body is missing the id') unless payload.
|
101
|
-
raise(InvalidResponseError, "Response id (#{payload['id']}) does not match request id (#{request_id})") unless
|
102
|
-
raise(InvalidResponseError, 'Response body must have a result and an error') unless
|
101
|
+
raise(InvalidResponseError, 'Response body is missing the id') unless payload.key?('id')
|
102
|
+
raise(InvalidResponseError, "Response id (#{payload['id']}) does not match request id (#{request_id})") unless payload['id'] == request_id
|
103
|
+
raise(InvalidResponseError, 'Response body must have a result and an error') unless payload.key?('error') && payload.key?('result')
|
103
104
|
|
104
105
|
if payload['error']
|
105
106
|
error = payload['error']
|
106
107
|
raise(InvalidResponseError, 'Response error is not a Hash') unless error.is_a?(::Hash)
|
107
|
-
raise(InvalidResponseError, 'Response error is missing the code') unless error.
|
108
|
+
raise(InvalidResponseError, 'Response error is missing the code') unless error.key?('code')
|
108
109
|
raise(InvalidResponseError, 'Response error code is not a number') unless error['code'].is_a?(::Integer)
|
109
|
-
raise(InvalidResponseError, 'Response error is missing the message') unless error.
|
110
|
+
raise(InvalidResponseError, 'Response error is missing the message') unless error.key?('message')
|
110
111
|
raise(InvalidResponseError, 'Response error message is not a string') unless error['message'].is_a?(::String)
|
111
112
|
end
|
112
113
|
end
|
113
114
|
|
114
115
|
def payload_from(response)
|
115
116
|
::MultiJson.decode(response.body)
|
116
|
-
rescue =>
|
117
|
+
rescue StandardError => e
|
117
118
|
Limeade.logger.info "Failed to parse JSON from:\n#{response.body}"
|
118
|
-
raise InvalidResponseError,
|
119
|
+
raise InvalidResponseError, e.message
|
119
120
|
end
|
120
121
|
|
121
122
|
def make_id
|
122
123
|
rand(10**12)
|
123
124
|
end
|
124
|
-
|
125
125
|
end
|
126
126
|
end
|
data/lib/limeade/version.rb
CHANGED
data/limeade.gemspec
CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
37
|
spec.require_paths = ['lib']
|
38
38
|
|
39
|
-
spec.add_runtime_dependency 'faraday', '>= 0.12.0'
|
39
|
+
spec.add_runtime_dependency 'faraday', '>= 0.12.0', '< 2.0'
|
40
40
|
spec.add_runtime_dependency 'multi_json', '~> 1.13'
|
41
41
|
|
42
42
|
spec.add_development_dependency 'bundler', '>= 1.17', '< 3.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: limeade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Pellegrini
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.12.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 0.12.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: multi_json
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,7 +116,6 @@ files:
|
|
110
116
|
- lib/limeade/client.rb
|
111
117
|
- lib/limeade/errors.rb
|
112
118
|
- lib/limeade/json_rpc.rb
|
113
|
-
- lib/limeade/methods.rb
|
114
119
|
- lib/limeade/version.rb
|
115
120
|
- limeade.gemspec
|
116
121
|
homepage: https://github.com/spokesoftware/limeade
|
@@ -119,11 +124,11 @@ licenses:
|
|
119
124
|
metadata:
|
120
125
|
allowed_push_host: https://rubygems.org
|
121
126
|
homepage_uri: https://github.com/spokesoftware/limeade
|
122
|
-
documentation_uri: https://www.rubydoc.info/gems/limeade/0.1.
|
127
|
+
documentation_uri: https://www.rubydoc.info/gems/limeade/0.1.3
|
123
128
|
bug_tracker_uri: https://github.com/spokesoftware/limeade/issues
|
124
129
|
source_code_uri: https://github.com/spokesoftware/limeade
|
125
130
|
changelog_uri: https://github.com/spokesoftware/limeade/releases
|
126
|
-
post_install_message:
|
131
|
+
post_install_message:
|
127
132
|
rdoc_options: []
|
128
133
|
require_paths:
|
129
134
|
- lib
|
@@ -138,8 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
143
|
- !ruby/object:Gem::Version
|
139
144
|
version: '0'
|
140
145
|
requirements: []
|
141
|
-
rubygems_version: 3.
|
142
|
-
signing_key:
|
146
|
+
rubygems_version: 3.1.6
|
147
|
+
signing_key:
|
143
148
|
specification_version: 4
|
144
149
|
summary: A Ruby interface to the LimeSurvey API.
|
145
150
|
test_files: []
|
data/lib/limeade/methods.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module Limeade
|
2
|
-
API_METHODS = (<<_API_METHODS
|
3
|
-
activate_survey
|
4
|
-
activate_tokens
|
5
|
-
add_group
|
6
|
-
add_language
|
7
|
-
add_participants
|
8
|
-
add_response
|
9
|
-
add_survey
|
10
|
-
copy_survey
|
11
|
-
cpd_importParticipants
|
12
|
-
delete_group
|
13
|
-
delete_language
|
14
|
-
delete_participants
|
15
|
-
delete_question
|
16
|
-
delete_survey
|
17
|
-
export_responses
|
18
|
-
export_responses_by_token
|
19
|
-
export_statistics
|
20
|
-
export_timeline
|
21
|
-
get_group_properties
|
22
|
-
get_language_properties
|
23
|
-
get_participant_properties
|
24
|
-
get_question_properties
|
25
|
-
get_response_ids
|
26
|
-
get_session_key
|
27
|
-
get_site_settings
|
28
|
-
get_summary
|
29
|
-
get_survey_properties
|
30
|
-
get_uploaded_files
|
31
|
-
import_group
|
32
|
-
import_question
|
33
|
-
import_survey
|
34
|
-
invite_participants
|
35
|
-
list_groups
|
36
|
-
list_participants
|
37
|
-
list_questions
|
38
|
-
list_surveys
|
39
|
-
list_users
|
40
|
-
mail_registered_participants
|
41
|
-
release_session_key
|
42
|
-
remind_participants
|
43
|
-
set_group_properties
|
44
|
-
set_language_properties
|
45
|
-
set_participant_properties
|
46
|
-
set_question_properties
|
47
|
-
set_quota_properties
|
48
|
-
set_survey_properties
|
49
|
-
update_response
|
50
|
-
upload_file
|
51
|
-
_API_METHODS
|
52
|
-
).split("\n").map(&:to_sym).freeze
|
53
|
-
end
|