electionbuddy-ruby 0.3.0 → 0.4.0

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: 05e63dbc220f5455343b5a43e4a2fa3754c377f7cb56aceb133acddf3a09fe84
4
- data.tar.gz: 57afed7e7acaaf77e7ba70a7afae1d1efd56e058d403bf5eed9904d7e546d1d2
3
+ metadata.gz: 64c0f48e8da4cd5811d86506d945b853e4e284afd8a8041878d680bf46117d4d
4
+ data.tar.gz: b635df1e9e3f7f013c769818e2722f6224de5cea279bd5ad36364a80c6d9d15b
5
5
  SHA512:
6
- metadata.gz: 39d9ac1b3891a72787f0c2a80603d2e824e769109c04f977f9a7ef810bd78a34c0dd4403356d7658b67db80462297e59f8040df8f9ee10e4f96658c6f65f8b7c
7
- data.tar.gz: b6f5c57a45c8075f25c515efeddf23825db14d8c694bf4fa9b6f70b919501d66bd4dffa9639cc940a0a809a8d0739febdd83f06b378e0247591fc9e844ab95fc
6
+ metadata.gz: b0dc2ca445cb784a1d72b27c6bcd4a5f0221ea50ca87e577dd301e0603189a11623eb85f9d794005350486efd82ce62bdb40d1492afe5ef536cde58a39fdb060
7
+ data.tar.gz: 4438b38fefa9ebaf8d22d7b57bc71272042bf89eda5dfe459fe29d647fd1c7d0d6141e31c5befe25e7267c5010cf5fad67b7f8ab729ef067b155b68ceed07fea
data/CHANGELOG.md CHANGED
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.0] - 2024-11-20
11
+
12
+ ### Added
13
+
14
+ - Ability to import voters to a vote
15
+ - Automated gem release using GitHub Actions
16
+
10
17
  ## [0.3.0] - 2024-11-18
11
18
 
12
19
  ### Added
@@ -47,7 +54,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
47
54
 
48
55
  - Initial release
49
56
 
50
- [unreleased]: https://github.com/electionbuddy/electionbuddy-ruby/compare/v0.3.0...HEAD
57
+ [unreleased]: https://github.com/electionbuddy/electionbuddy-ruby/compare/v0.4.0...HEAD
58
+ [0.4.0]: https://github.com/electionbuddy/electionbuddy-ruby/compare/v0.3.0...v0.4.0
51
59
  [0.3.0]: https://github.com/electionbuddy/electionbuddy-ruby/compare/v0.2.0...v0.3.0
52
60
  [0.2.0]: https://github.com/electionbuddy/electionbuddy-ruby/compare/v0.1.0...v0.2.0
53
61
  [0.1.0]: https://github.com/electionbuddy/electionbuddy-ruby/releases/tag/v0.1.0
data/README.md CHANGED
@@ -49,6 +49,27 @@ Alternatively, you can still pass the API key directly during initialization. If
49
49
  client = ElectionBuddy::Client.new(api_key: 'your-api-key')
50
50
  ```
51
51
 
52
+ ### Voter List Importation
53
+
54
+ To import a voter list for an election, use the `voter_list.import(vote_id, voters, append_mode: false)` method:
55
+
56
+ ```ruby
57
+ voters = [
58
+ { email: 'voter1@example.com', label: 'Voter One' },
59
+ { email: 'voter2@example.com', label: 'Voter Two' }
60
+ ]
61
+
62
+ import = client.voter_list.import(1, voters, append_mode: false)
63
+
64
+ if import.done?
65
+ puts "Import completed successfully! Identifier: #{import.identifier}"
66
+ else
67
+ puts "Import failed: #{import.error}"
68
+ end
69
+ ```
70
+
71
+ The `append_mode` parameter determines whether the voters should be appended to the existing list (`true`) or replace the existing list (`false`). The default value is `false`.
72
+
52
73
  ### Voter List Validation
53
74
 
54
75
  To validate a voter list, use the `voter_list.validate(vote_id)` method:
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ElectionBuddy
4
+ # Represents an importation operation for voter lists
5
+ #
6
+ # @example
7
+ # importation = Importation.new(response)
8
+ # if importation.done?
9
+ # puts "Import successful: #{importation.identifier}"
10
+ # else
11
+ # puts "Import failed: #{importation.error}"
12
+ # end
13
+ #
14
+ class Importation
15
+ # @param response [Hash] The API response containing importation details
16
+ def initialize(response)
17
+ @response = response
18
+ end
19
+
20
+ # Returns the identifier for this importation
21
+ #
22
+ # @return [String] The importation identifier or "Not Available"
23
+ def identifier
24
+ @response["importation_identifier"] || "Not Available"
25
+ end
26
+
27
+ # Checks if the importation completed successfully
28
+ #
29
+ # @return [Boolean] true if importation was successful, false otherwise
30
+ def done?
31
+ @response["error"].nil?
32
+ end
33
+
34
+ # Returns the error message if importation failed
35
+ #
36
+ # @return [String, nil] The formatted error message or nil if importation was successful
37
+ def error
38
+ return nil if done?
39
+
40
+ ErrorFormatter.format(@response["error"])
41
+ end
42
+ end
43
+ end
@@ -9,6 +9,18 @@ module ElectionBuddy
9
9
  # result = resource.get_validation_result(validation.identifier)
10
10
  #
11
11
  class VoterListResource < Resource
12
+ # Imports voters for a given vote
13
+ #
14
+ # @param vote_id [Integer] The ID of the vote to import voters for
15
+ # @param voters [Array<Hash>] Array of voter data to import
16
+ # @param append_mode [Boolean] Whether to append voters to existing list (default: false)
17
+ # @return [Importation] The importation response
18
+ def import(vote_id, voters, append_mode: false)
19
+ response = post_request("/api/v2/votes/voters/importations", vote_id: vote_id.to_i, voters: voters, append_mode: append_mode)
20
+
21
+ Importation.new(response)
22
+ end
23
+
12
24
  # Initiates a validation for a given vote
13
25
  #
14
26
  # @param vote_id [Integer] The ID of the vote to validate
@@ -6,6 +6,6 @@ module ElectionBuddy
6
6
  # @api public
7
7
  # @return [String] the current version of the gem
8
8
  # @example Get current version
9
- # ElectionBuddy::VERSION #=> "0.3.0"
10
- VERSION = "0.3.0"
9
+ # ElectionBuddy::VERSION #=> "0.4.0"
10
+ VERSION = "0.4.0"
11
11
  end
@@ -10,6 +10,7 @@ require "election_buddy/error"
10
10
  require "election_buddy/resource"
11
11
  require "election_buddy/resources/voter_list_resource"
12
12
  require "election_buddy/entities/validation"
13
+ require "election_buddy/entities/importation"
13
14
  require "election_buddy/error_formatter"
14
15
  require "election_buddy/configuration"
15
16
  require "election_buddy/entities/validation/result"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: electionbuddy-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alberto Rocha
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-11-18 00:00:00.000000000 Z
12
+ date: 2024-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -43,6 +43,7 @@ files:
43
43
  - lib/election_buddy.rb
44
44
  - lib/election_buddy/client.rb
45
45
  - lib/election_buddy/configuration.rb
46
+ - lib/election_buddy/entities/importation.rb
46
47
  - lib/election_buddy/entities/validation.rb
47
48
  - lib/election_buddy/entities/validation/line_error.rb
48
49
  - lib/election_buddy/entities/validation/line_errors.rb
@@ -79,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  - !ruby/object:Gem::Version
80
81
  version: '0'
81
82
  requirements: []
82
- rubygems_version: 3.5.16
83
+ rubygems_version: 3.2.33
83
84
  signing_key:
84
85
  specification_version: 4
85
86
  summary: Ruby SDK for the ElectionBuddy API.