limeade 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: c32583152633d904c31c68e00648525e8d9f85765f978d82a43fc0eeb2f24b8a
4
- data.tar.gz: 5d3dc02334d0bfa704f64597ccfa81b537b04c6926452593925987422cba1c84
2
+ SHA1:
3
+ metadata.gz: 3ee2d420faf14714fd02821cc10675bde3faf0a9
4
+ data.tar.gz: a4a9ff39e5955422972da6374c790bcc57229d78
5
5
  SHA512:
6
- metadata.gz: dd211d93790439cfbdf9e8c609956769139a56cdcfc76f61fb9c55b0ccf6207cedd4e56a443d12bccfdc8fbfc391e15dae65028ddd7e662a42ebf96dd9d14d2c
7
- data.tar.gz: e4f9efeff8dced2acf1ad56e1d74376a6fb4249acb17aa3c088e9f20cd5847eee711e53711cf75e1fa8ac0007d674998628e1c45b68a1b7404c74cfec3921c3c
6
+ metadata.gz: 495c68105ebcf8dcb3a9e0645cd985906347841958e0f20d9f9c6257ef9fecf983a5c90d7232a9dac2b66acacd0258efbb0c7ebea4f5b4abfd3846ca230133f8
7
+ data.tar.gz: c94203f90122ee29c86224e0912f9353a7339e84d128fc71855b5fcde5b43b37a50b2f5548d4c46e4b0f1430a15c16b8b47c87638f59bae44565071fa967ec7e
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)
@@ -1,10 +1,8 @@
1
1
  require 'limeade/methods'
2
2
 
3
3
  module Limeade
4
-
5
4
  # Client for accessing the LimeSurvey RemoteControl API from Ruby.
6
5
  class Client
7
-
8
6
  #
9
7
  # Instantiate a client and setup a connection to the LimeSurvey RemoteControl API.
10
8
  # Passes configuration for the Faraday::Request::Retry mechanism.
@@ -100,7 +98,7 @@ module Limeade
100
98
  def process_request(method_name, *arguments)
101
99
  raise DisconnectedError unless connected?
102
100
  result = @json_rpc.invoke(method_name, @session_key, *arguments)
103
- if result.is_a? Hash and result['status']
101
+ if result.is_a?(Hash) && result['status']
104
102
  case result['status']
105
103
  when 'OK'
106
104
  true
@@ -108,6 +106,8 @@ module Limeade
108
106
  []
109
107
  when 'No Tokens found'
110
108
  []
109
+ when 'No survey participants table'
110
+ false
111
111
  when /(left to send)|(No candidate tokens)$/
112
112
  result
113
113
  when /Invalid surveyid$/i
@@ -153,5 +153,4 @@ module Limeade
153
153
 
154
154
  # Private exception raised only in the context of #process_request.
155
155
  class NoSessionError < Error; end
156
-
157
156
  end
@@ -1,5 +1,6 @@
1
- module Limeade
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
@@ -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.has_key?('id')
101
- raise(InvalidResponseError, "Response id (#{payload['id']}) does not match request id (#{request_id})") unless (payload['id'] == request_id)
102
- raise(InvalidResponseError, 'Response body must have a result and an error') unless (payload.has_key?('error') && payload.has_key?('result'))
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.has_key?('code')
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.has_key?('message')
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 => parsing_error
117
+ rescue StandardError => e
117
118
  Limeade.logger.info "Failed to parse JSON from:\n#{response.body}"
118
- raise InvalidResponseError, parsing_error.message
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
@@ -1,53 +1,55 @@
1
+ # frozen_string_literal: true
2
+
1
3
  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
4
+ API_METHODS = <<~_API_METHODS
5
+ activate_survey
6
+ activate_tokens
7
+ add_group
8
+ add_language
9
+ add_participants
10
+ add_response
11
+ add_survey
12
+ copy_survey
13
+ cpd_importParticipants
14
+ delete_group
15
+ delete_language
16
+ delete_participants
17
+ delete_question
18
+ delete_survey
19
+ export_responses
20
+ export_responses_by_token
21
+ export_statistics
22
+ export_timeline
23
+ get_group_properties
24
+ get_language_properties
25
+ get_participant_properties
26
+ get_question_properties
27
+ get_response_ids
28
+ get_session_key
29
+ get_site_settings
30
+ get_summary
31
+ get_survey_properties
32
+ get_uploaded_files
33
+ import_group
34
+ import_question
35
+ import_survey
36
+ invite_participants
37
+ list_groups
38
+ list_participants
39
+ list_questions
40
+ list_surveys
41
+ list_users
42
+ mail_registered_participants
43
+ release_session_key
44
+ remind_participants
45
+ set_group_properties
46
+ set_language_properties
47
+ set_participant_properties
48
+ set_question_properties
49
+ set_quota_properties
50
+ set_survey_properties
51
+ update_response
52
+ upload_file
53
+ _API_METHODS
54
+ .split("\n").map(&:to_sym).freeze
55
+ end
@@ -1,3 +1,3 @@
1
1
  module Limeade
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Pellegrini
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-07 00:00:00.000000000 Z
11
+ date: 2019-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -119,7 +119,7 @@ licenses:
119
119
  metadata:
120
120
  allowed_push_host: https://rubygems.org
121
121
  homepage_uri: https://github.com/spokesoftware/limeade
122
- documentation_uri: https://www.rubydoc.info/gems/limeade/0.1.1
122
+ documentation_uri: https://www.rubydoc.info/gems/limeade/0.1.2
123
123
  bug_tracker_uri: https://github.com/spokesoftware/limeade/issues
124
124
  source_code_uri: https://github.com/spokesoftware/limeade
125
125
  changelog_uri: https://github.com/spokesoftware/limeade/releases
@@ -138,7 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  requirements: []
141
- rubygems_version: 3.0.3
141
+ rubyforge_project:
142
+ rubygems_version: 2.5.2
142
143
  signing_key:
143
144
  specification_version: 4
144
145
  summary: A Ruby interface to the LimeSurvey API.