edify-cli 0.2.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 317616031e24d8053b85bd553df6792682fec679b3093ec860c695b2485d0166
4
+ data.tar.gz: 1c1844d0d4c9c60e440290e595eeb25528dabbf349468d78ee09bd1e9feda8d7
5
+ SHA512:
6
+ metadata.gz: e9b63b488cdc2987bf1db7657f9052af99000cb92163e4bfc0e3b9ae662e48ee8906bced9cc77abdc60b6c8d1b930127aea6afee2d0fab808577128d481031ba
7
+ data.tar.gz: 858451e4d0425995af124f6af27f917503398b123b83c8c602cbb4c157cb7d897e9785222b2d399f33a9144a563eb21fbfbcc7d2761fa5050e2b8443de08ef9d
data/CHANGELOG.md ADDED
@@ -0,0 +1,31 @@
1
+ # Changelog
2
+
3
+ All notable changes to edify-cli are recorded here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions follow [Semantic Versioning](https://semver.org/).
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [0.2.0] - 2026-11-23
8
+
9
+ ### Added
10
+
11
+ - `edify songs recent [--weeks N] [--limit N] [--song-type T]`: the hymns your unit has sung recently, most sung first, with the types each was sung as (#9).
12
+ - `edify meetings list [--from DATE] [--to DATE]`: your unit's meetings and their speakers (#9).
13
+ - `edify meetings show DATE`: one meeting's program, talks and songs, or "No meeting on DATE." when there isn't one (#9).
14
+
15
+ ### Changed
16
+
17
+ - Dates given to `meetings` commands are checked as `YYYY-MM-DD` before any request is made (#9).
18
+
19
+ ## [0.1.0] - 2026-11-23
20
+
21
+ ### Added
22
+
23
+ - `edify login`: save a personal access token, checked against the server. Press Enter at the URL prompt to use https://www.edifyapp.org (#3, #7).
24
+ - `edify speakers stale [--months N] [--limit N] [--group G]`: members who haven't spoken recently, longest-waiting first, with gender and age group (#3).
25
+ - `edify version` and `edify help`.
26
+ - `--json` on data commands, `EDIFY_TOKEN` and `EDIFY_URL` overrides, and API errors on stderr with exit status 1 (#2, #3).
27
+ - The login is saved with owner-only permissions, and the token is sent only over HTTPS, except to localhost (#2).
28
+
29
+ [Unreleased]: https://github.com/edifyapporg/edify-cli/compare/v0.2.0...HEAD
30
+ [0.2.0]: https://github.com/edifyapporg/edify-cli/compare/v0.1.0...v0.2.0
31
+ [0.1.0]: https://github.com/edifyapporg/edify-cli/releases/tag/v0.1.0
data/LICENSE.md ADDED
@@ -0,0 +1,14 @@
1
+ Copyright 2026 Mark Oveson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
5
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
6
+ persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
9
+ Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # edify-cli
2
+
3
+ A command-line client for the [Edify](https://github.com/edifyapporg/edify) API, for ward leaders, power users and coding agents.
4
+
5
+ It only reads from the API and formats the answer. Who can see what, and which members are included, is decided by the Edify server.
6
+
7
+ ## Install
8
+
9
+ Requires Ruby 4.0 or newer. The gem is not on RubyGems yet. Download `edify-cli-<version>.gem` from the [latest release](https://github.com/edifyapporg/edify-cli/releases/latest), then:
10
+
11
+ ```sh
12
+ gem install ./edify-cli-0.2.0.gem
13
+ ```
14
+
15
+ Each release lists the gem's SHA-256 checksum, and [CHANGELOG.md](CHANGELOG.md) says what changed. To build from source instead, check out a release tag and run `gem build edify-cli.gemspec`.
16
+
17
+ ## Log in
18
+
19
+ 1. In Edify ([www.edifyapp.org](https://www.edifyapp.org)), open **Settings > API Tokens**, create a token, and copy it. It is shown only once.
20
+ 2. Run:
21
+
22
+ ```sh
23
+ edify login
24
+ ```
25
+
26
+ Press Enter to use the production server, `https://www.edifyapp.org`, or type another Edify server's URL. Then paste the token. The CLI checks them against the server and saves them to `~/.config/edify/config.yml` (or `$XDG_CONFIG_HOME/edify/config.yml`), readable only by you.
27
+
28
+ To skip the prompts: `edify login --token edify_...` (add `--url http://localhost:3000` for a development server).
29
+
30
+ To stop using a token, revoke it in Edify under **Settings > API Tokens**.
31
+
32
+ ## Commands
33
+
34
+ ### `edify speakers stale`
35
+
36
+ Members of your unit who have not spoken in sacrament meeting recently, longest-waiting first. Members already scheduled to speak, and members whose invitations are paused, are left out.
37
+
38
+ ```sh
39
+ $ edify speakers stale --months 12 --group youth
40
+ Not spoken since 2025-11-23, the last 12 months (youth only):
41
+ NAME GENDER GROUP LAST_TALK
42
+ Roe, Samuel male youth never
43
+ Poe, Ada female youth 2024-06-02
44
+ ```
45
+
46
+ | Option | Meaning |
47
+ |---|---|
48
+ | `--months N` | How many months counts as stale, 1 to 120 (default 12) |
49
+ | `--limit N` | Most members to list, 1 to 200 (default 25) |
50
+ | `--group G` | Only `primary`, `youth` or `adult` |
51
+ | `--json` | Print the API's JSON instead of a table |
52
+
53
+ Needs a bishopric or clerk role in Edify.
54
+
55
+ ### `edify songs recent`
56
+
57
+ The hymns your unit has sung in sacrament meeting over the last few weeks, ending today: most sung first, then most recently sung, with the types each was sung as. Prelude and postlude are not counted.
58
+
59
+ ```sh
60
+ $ edify songs recent --weeks 8 --song-type sacrament_hymn
61
+ Sung since 2026-09-28, the last 8 weeks (sacrament_hymn only):
62
+ TITLE TIMES LAST_SUNG TYPES
63
+ As Bread Is Broken #1007 1 2026-11-22 sacrament_hymn
64
+ ```
65
+
66
+ | Option | Meaning |
67
+ |---|---|
68
+ | `--weeks N` | How many weeks back to count, 1 to 104 (default 12) |
69
+ | `--limit N` | Most hymns to list, 1 to 200 (default 50) |
70
+ | `--song-type T` | Only `opening_hymn`, `sacrament_hymn`, `congregational_hymn`, `musical_number` or `closing_hymn` |
71
+ | `--json` | Print the API's JSON instead of a table |
72
+
73
+ ### `edify meetings list` and `edify meetings show DATE`
74
+
75
+ `list` shows your unit's meetings and their speakers. `--from` defaults to today and `--to` to 84 days later, and the range may cover at most 366 days. `show` prints one meeting: who presides, conducts, leads the music and prays, its talks in order and its songs in program order.
76
+
77
+ ```sh
78
+ $ edify meetings list --from 2026-11-01 --to 2026-11-30
79
+ $ edify meetings show 2026-11-08
80
+ ```
81
+
82
+ Dates are written `YYYY-MM-DD`. Both commands take `--json`.
83
+
84
+ Songs and meetings are available to every role in your unit.
85
+
86
+ ### Other commands
87
+
88
+ - `edify version`
89
+ - `edify help [COMMAND]`
90
+
91
+ ## For scripts and coding agents
92
+
93
+ - Every data command takes `--json`, which prints the API's response unchanged.
94
+ - `EDIFY_TOKEN` (and `EDIFY_URL`, if not the production server) override the saved login, so a script can run without `edify login`.
95
+ - Errors go to stderr with exit status 1. The message is the API's own, for example `months must be a whole number from 1 to 120.`
96
+
97
+ ## Security
98
+
99
+ - The token is sent only as an `Authorization: Bearer` header, and only over HTTPS. Plain `http://` is allowed just for `localhost`, for development.
100
+ - The saved config file is created with mode `0600` in a `0700` directory.
101
+ - Tokens are read-only, and Edify never returns member notes, phone numbers, email addresses, ages or birthdates through the API.
102
+
103
+ ## Development
104
+
105
+ ```sh
106
+ bundle install
107
+ bundle exec rake # specs and RuboCop
108
+ ```
109
+
110
+ Edify issue: [edifyapporg/edify#320](https://github.com/edifyapporg/edify/issues/320). Part of [#315](https://github.com/edifyapporg/edify/issues/315).
111
+
112
+ Record each user-visible change under **Unreleased** in [CHANGELOG.md](CHANGELOG.md) in the PR that makes it.
113
+
114
+ ## Releasing
115
+
116
+ Versions follow [Semantic Versioning](https://semver.org/): a new command or option is a minor release (0.2.0 to 0.3.0), and a fix is a patch release (0.2.0 to 0.2.1).
117
+
118
+ 1. **Release PR.** On a branch, bump `Edify::VERSION` in `lib/edify/version.rb`. In `CHANGELOG.md`, rename **Unreleased** to the new version with the release date, add an empty **Unreleased** above it, and update the comparison links at the bottom. Open a PR and merge it.
119
+ 2. **Tag the merge.** On an up-to-date `main`, confirm `edify version` prints the new version, then:
120
+
121
+ ```sh
122
+ git tag -a v0.3.0 -m "edify-cli 0.3.0" && git push origin v0.3.0
123
+ ```
124
+ 3. **Build from the tag** and note the checksum:
125
+
126
+ ```sh
127
+ gem build edify-cli.gemspec && shasum -a 256 edify-cli-0.3.0.gem
128
+ ```
129
+ 4. **Publish the GitHub release** with the version's changelog section and the checksum as notes, and the gem attached:
130
+
131
+ ```sh
132
+ gh release create v0.3.0 --verify-tag --title "edify-cli 0.3.0" --notes-file NOTES.md edify-cli-0.3.0.gem
133
+ ```
134
+ 5. **Check it.** Download the attached gem with `gh release download v0.3.0`, compare its checksum, and install it into a throwaway `GEM_HOME` to confirm `edify version`.
135
+
136
+ A published version is never changed or reused. A mistake is fixed in a new patch release.
137
+
138
+ ## License
139
+
140
+ MIT. See [LICENSE.md](LICENSE.md).
data/exe/edify ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "edify/cli"
4
+
5
+ Edify::CLI.start(ARGV)
data/lib/edify/cli.rb ADDED
@@ -0,0 +1,66 @@
1
+ require "thor"
2
+
3
+ require_relative "version"
4
+ require_relative "config"
5
+ require_relative "client"
6
+ require_relative "table"
7
+ require_relative "commands/helpers"
8
+ require_relative "commands/meetings"
9
+ require_relative "commands/songs"
10
+ require_relative "commands/speakers"
11
+
12
+ module Edify
13
+ # The `edify` command. Every command reads from the Edify API with a personal access token, created in Edify under
14
+ # Settings > API Tokens, and only formats what the API returns.
15
+ class CLI < Thor
16
+ include Commands::Helpers
17
+
18
+ def self.exit_on_failure?
19
+ true
20
+ end
21
+
22
+ desc "login", "Save your Edify server URL and API token"
23
+ long_desc <<~DESC
24
+ Asks for your Edify server's URL (press Enter for #{Config::DEFAULT_URL}) and a personal access token (create one
25
+ in Edify under Settings > API Tokens), checks them against the server, and saves them where only you can read
26
+ them. Use --url and --token to skip the prompts.
27
+ DESC
28
+ option :url, desc: "Your Edify server (default #{Config::DEFAULT_URL})"
29
+ option :token, desc: "A personal access token from Settings > API Tokens"
30
+ def login
31
+ url = options[:url] || ask("Edify URL:", default: Config::DEFAULT_URL)
32
+ token = options[:token] || ask("API token (from Settings > API Tokens):", echo: false)
33
+ say "" unless options[:token]
34
+
35
+ check_login(url.to_s.strip, token.to_s.strip)
36
+ config.save(url: url.to_s.strip.chomp("/"), token: token.to_s.strip)
37
+ say "Logged in to #{url.to_s.strip.chomp('/')}. Saved to #{config.path}."
38
+ end
39
+
40
+ desc "version", "Show the edify-cli version"
41
+ def version
42
+ say VERSION
43
+ end
44
+
45
+ desc "speakers SUBCOMMAND", "Questions about speakers"
46
+ subcommand "speakers", Commands::Speakers
47
+
48
+ desc "songs SUBCOMMAND", "Questions about songs"
49
+ subcommand "songs", Commands::Songs
50
+
51
+ desc "meetings SUBCOMMAND", "Questions about meetings"
52
+ subcommand "meetings", Commands::Meetings
53
+
54
+ private
55
+
56
+ # The API has no "who am I" endpoint yet, so a one-row request stands in. An invalid token is refused. A valid
57
+ # token whose role cannot see speakers is still saved, since it may be meant for other commands.
58
+ def check_login(url, token)
59
+ raise Thor::Error, "Both a URL and a token are needed." if url.empty? || token.empty?
60
+
61
+ Client.new(url: url, token: token).get("speakers/stale", limit: 1)
62
+ rescue Client::Error => e
63
+ raise Thor::Error, e.message unless e.code == "forbidden"
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,87 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "openssl"
4
+ require "uri"
5
+
6
+ module Edify
7
+ # A thin client for Edify's JSON API (`/api/v1`). It sends the token as a Bearer header and turns the API's
8
+ # `{ "error": { "code", "message" } }` responses, and network failures, into Client::Error. It holds no business
9
+ # logic: what a command shows is exactly what the API returned.
10
+ class Client
11
+ class Error < StandardError
12
+ attr_reader :code
13
+
14
+ def initialize(message, code:)
15
+ super(message)
16
+ @code = code
17
+ end
18
+ end
19
+
20
+ # Plain HTTP would send the token in the clear, so it is allowed only to the local machine.
21
+ LOCAL_HOSTS = %w[localhost 127.0.0.1 ::1 [::1]].freeze
22
+
23
+ attr_reader :base_url
24
+
25
+ def initialize(url:, token:)
26
+ @base_url = url.to_s.strip.chomp("/")
27
+ @token = token
28
+ check_url!
29
+ end
30
+
31
+ # @param path [String] relative to /api/v1, e.g. "speakers/stale"
32
+ # @param params [Hash] query parameters; nil values are left out
33
+ # @return [Hash] the parsed JSON body of a successful response
34
+ # @raise [Error] for an error response or a network failure
35
+ def get(path, params = {})
36
+ uri = URI("#{base_url}/api/v1/#{path}")
37
+ query = params.compact
38
+ uri.query = URI.encode_www_form(query) unless query.empty?
39
+ handle(perform(uri))
40
+ end
41
+
42
+ private
43
+
44
+ attr_reader :token
45
+
46
+ def check_url!
47
+ uri = URI(base_url)
48
+ raise Error.new("#{base_url} is not a valid Edify URL.", code: "invalid_url") unless uri.host
49
+ return if uri.scheme == "https" || (uri.scheme == "http" && LOCAL_HOSTS.include?(uri.host))
50
+
51
+ raise Error.new("Use an https:// URL. Plain http is allowed only for localhost, so the token is never " \
52
+ "sent unencrypted.", code: "insecure_url")
53
+ rescue URI::InvalidURIError
54
+ raise Error.new("#{base_url} is not a valid Edify URL.", code: "invalid_url")
55
+ end
56
+
57
+ def perform(uri)
58
+ request = Net::HTTP::Get.new(uri)
59
+ request["Authorization"] = "Bearer #{token}"
60
+ request["Accept"] = "application/json"
61
+ request["User-Agent"] = "edify-cli/#{VERSION}"
62
+
63
+ Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https", open_timeout: 10, read_timeout: 30) do |http|
64
+ http.request(request)
65
+ end
66
+ rescue SocketError, SystemCallError, Net::OpenTimeout, Net::ReadTimeout, OpenSSL::SSL::SSLError => e
67
+ raise Error.new("Could not reach #{base_url}: #{e.message}", code: "connection_failed")
68
+ end
69
+
70
+ def handle(response)
71
+ body = parse(response)
72
+ return body if response.is_a?(Net::HTTPSuccess) && body
73
+
74
+ error = body.is_a?(Hash) ? body["error"] : nil
75
+ raise Error.new(error["message"], code: error["code"]) if error.is_a?(Hash) && error["message"]
76
+
77
+ raise Error.new("Edify answered HTTP #{response.code} without an API error. Is #{base_url} an Edify server?",
78
+ code: "http_#{response.code}")
79
+ end
80
+
81
+ def parse(response)
82
+ JSON.parse(response.body.to_s)
83
+ rescue JSON::ParserError
84
+ nil
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,48 @@
1
+ require "json"
2
+
3
+ module Edify
4
+ module Commands
5
+ # Shared by every command class: reading the saved login, calling the API, and printing JSON. Errors become
6
+ # Thor::Error, which Thor prints to stderr before exiting with status 1.
7
+ module Helpers
8
+ NOT_LOGGED_IN = "Not logged in. Run `edify login`, or set EDIFY_TOKEN.".freeze
9
+ RELOGIN_HINT = "Your token may have been revoked or expired. Create a new one in Edify under " \
10
+ "Settings > API Tokens, then run `edify login`.".freeze
11
+
12
+ private
13
+
14
+ def config
15
+ @config ||= Config.new
16
+ end
17
+
18
+ def client
19
+ raise Thor::Error, NOT_LOGGED_IN unless config.configured?
20
+
21
+ @client ||= Client.new(url: config.url, token: config.token)
22
+ rescue Client::Error => e
23
+ raise Thor::Error, e.message
24
+ end
25
+
26
+ # @param not_found [String, nil] a message to show instead of the API's generic one when it answers not_found
27
+ # @param params [Hash] query parameters; nil values are left out
28
+ # @return [Hash] the API's response body
29
+ def api_get(path, not_found: nil, **params)
30
+ client.get(path, params)
31
+ rescue Client::Error => e
32
+ raise Thor::Error, error_message(e, not_found)
33
+ end
34
+
35
+ def error_message(error, not_found)
36
+ case error.code
37
+ when "invalid_token" then "#{error.message}\n#{RELOGIN_HINT}"
38
+ when "not_found" then not_found || error.message
39
+ else error.message
40
+ end
41
+ end
42
+
43
+ def print_json(body)
44
+ say JSON.pretty_generate(body)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,90 @@
1
+ module Edify
2
+ module Commands
3
+ class Meetings < Thor
4
+ include Helpers
5
+
6
+ # Checked before any request, so a date argument can never put anything else into a request path.
7
+ ISO_DATE = /\A\d{4}-\d{2}-\d{2}\z/
8
+ CONTRIBUTOR_LABELS = {
9
+ "presider" => "Presiding",
10
+ "conductor" => "Conducting",
11
+ "chorister" => "Chorister",
12
+ "organist" => "Organist",
13
+ "opening_prayer" => "Opening prayer",
14
+ "closing_prayer" => "Closing prayer",
15
+ }.freeze
16
+
17
+ def self.exit_on_failure?
18
+ true
19
+ end
20
+
21
+ desc "list", "List meetings and their speakers"
22
+ long_desc <<~DESC
23
+ Lists your unit's meetings from --from (default today) through --to (default 84 days later; at most 366 days
24
+ in all), earliest first, with each meeting's type and speakers.
25
+ DESC
26
+ option :from, desc: "First date, YYYY-MM-DD (default today)"
27
+ option :to, desc: "Last date, YYYY-MM-DD (default 84 days after --from)"
28
+ option :json, type: :boolean, default: false, desc: "Print the API's JSON instead of a table"
29
+ def list
30
+ check_date!(:from, options[:from]) if options[:from]
31
+ check_date!(:to, options[:to]) if options[:to]
32
+
33
+ body = api_get("meetings", from: options[:from], to: options[:to])
34
+ return print_json(body) if options[:json]
35
+
36
+ say "Meetings from #{body['from']} through #{body['to']}:"
37
+ meetings = body.fetch("meetings")
38
+ return say("No meetings in that time.") if meetings.empty?
39
+
40
+ rows = meetings.map { |m| [m["date"], humanize(m["meeting_type"]), m["speakers"].join("; ")] }
41
+ say Table.render(%w[DATE TYPE SPEAKERS], rows)
42
+ end
43
+
44
+ desc "show DATE", "Show one meeting: who takes part, its talks and its songs"
45
+ long_desc <<~DESC
46
+ Shows your unit's meeting on DATE (YYYY-MM-DD): its type, who presides, conducts, leads the music and prays,
47
+ its talks in order and its songs in program order.
48
+ DESC
49
+ option :json, type: :boolean, default: false, desc: "Print the API's JSON instead of the summary"
50
+ def show(date)
51
+ check_date!(:date, date)
52
+
53
+ body = api_get("meetings/#{date}", not_found: "No meeting on #{date}.")
54
+ return print_json(body) if options[:json]
55
+
56
+ say "#{body['date']} #{humanize(body['meeting_type'])}"
57
+ say_section("Program", contributor_lines(body["contributors"]))
58
+ say_section("Talks", body["talks"].map { |t| talk_line(t) })
59
+ say_section("Songs", body["songs"].map { |s| "#{humanize(s['song_type'])}: #{s['title']}" })
60
+ end
61
+
62
+ private
63
+
64
+ def check_date!(name, value)
65
+ return if value.to_s.match?(ISO_DATE)
66
+
67
+ raise Thor::Error, "#{name == :date ? 'DATE' : "--#{name}"} must be a date written as YYYY-MM-DD."
68
+ end
69
+
70
+ def contributor_lines(contributors)
71
+ CONTRIBUTOR_LABELS.filter_map { |key, label| "#{label}: #{contributors[key]}" if contributors[key] }
72
+ end
73
+
74
+ def talk_line(talk)
75
+ details = [talk["purpose"], talk["topic"] && "\"#{talk['topic']}\""].compact
76
+ [talk["speaker"], *details].join(" - ")
77
+ end
78
+
79
+ def say_section(title, lines)
80
+ say ""
81
+ say "#{title}:"
82
+ say(lines.empty? ? " (none)" : lines.map { |line| " #{line}" }.join("\n"))
83
+ end
84
+
85
+ def humanize(value)
86
+ value.to_s.tr("_", " ").capitalize
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,41 @@
1
+ module Edify
2
+ module Commands
3
+ class Songs < Thor
4
+ include Helpers
5
+
6
+ SONG_TYPES = %w[opening_hymn sacrament_hymn congregational_hymn musical_number closing_hymn].freeze
7
+
8
+ def self.exit_on_failure?
9
+ true
10
+ end
11
+
12
+ desc "recent", "List the hymns sung recently, most sung first"
13
+ long_desc <<~DESC
14
+ Lists the hymns your unit has sung in sacrament meeting over the last --weeks weeks, ending today: most sung
15
+ first, then most recently sung, with the types each was sung as. Prelude and postlude are not counted.
16
+ DESC
17
+ option :weeks, type: :numeric, desc: "How many weeks back to count (1-104, default 12)"
18
+ option :limit, type: :numeric, desc: "Most hymns to list (1-200, default 50)"
19
+ option :song_type, enum: SONG_TYPES, desc: "Count only songs sung as this type"
20
+ option :json, type: :boolean, default: false, desc: "Print the API's JSON instead of a table"
21
+ def recent
22
+ body = api_get("songs/recent", weeks: options[:weeks], limit: options[:limit], song_type: options[:song_type])
23
+ return print_json(body) if options[:json]
24
+
25
+ say heading(body)
26
+ songs = body.fetch("songs")
27
+ return say("Nothing sung in that time.") if songs.empty?
28
+
29
+ rows = songs.map { |s| [s["title"], s["times_sung"], s["last_sung"], s["song_types"].join(", ")] }
30
+ say Table.render(%w[TITLE TIMES LAST_SUNG TYPES], rows)
31
+ end
32
+
33
+ private
34
+
35
+ def heading(body)
36
+ type = body["song_type"] ? " (#{body['song_type']} only)" : ""
37
+ "Sung since #{body['since']}, the last #{body['weeks']} weeks#{type}:"
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ module Edify
2
+ module Commands
3
+ class Speakers < Thor
4
+ include Helpers
5
+
6
+ def self.exit_on_failure?
7
+ true
8
+ end
9
+
10
+ desc "stale", "List members who have not spoken recently, longest-waiting first"
11
+ long_desc <<~DESC
12
+ Lists members of your unit who have not spoken in sacrament meeting for --months months, or never have,
13
+ longest-waiting first. Members already scheduled to speak, and members whose invitations are paused, are
14
+ left out. Shows names, gender, age group and last-talk dates only.
15
+ DESC
16
+ option :months, type: :numeric, desc: "How many months counts as stale (1-120, default 12)"
17
+ option :limit, type: :numeric, desc: "Most members to list (1-200, default 25)"
18
+ option :group, enum: %w[primary youth adult], desc: "Only this age group"
19
+ option :json, type: :boolean, default: false, desc: "Print the API's JSON instead of a table"
20
+ def stale
21
+ body = api_get("speakers/stale", months: options[:months], limit: options[:limit], group: options[:group])
22
+ return print_json(body) if options[:json]
23
+
24
+ say heading(body)
25
+ speakers = body.fetch("speakers")
26
+ return say("Nobody to list.") if speakers.empty?
27
+
28
+ rows = speakers.map { |s| [s["name"], s["gender"], s["group"], s["last_talk_date"] || "never"] }
29
+ say Table.render(%w[NAME GENDER GROUP LAST_TALK], rows)
30
+ end
31
+
32
+ private
33
+
34
+ def heading(body)
35
+ group = body["group"] ? " (#{body['group']} only)" : ""
36
+ "Not spoken since #{body['spoken_before']}, the last #{body['months']} months#{group}:"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,68 @@
1
+ require "fileutils"
2
+ require "yaml"
3
+
4
+ module Edify
5
+ # The server URL and API token the CLI uses. They are saved by `edify login` to
6
+ # $XDG_CONFIG_HOME/edify/config.yml (normally ~/.config/edify/config.yml) in a directory only the owner can enter
7
+ # and a file only the owner can read, since the token can read the user's ward data. The EDIFY_URL and EDIFY_TOKEN
8
+ # environment variables take precedence over the file, for scripts and coding agents. With no URL from either, the
9
+ # CLI uses the production Edify server.
10
+ class Config
11
+ # The www host, because the bare domain redirects to it and the client does not follow redirects.
12
+ DEFAULT_URL = "https://www.edifyapp.org".freeze
13
+
14
+ # @param env [Hash] the environment, ENV by default
15
+ # @return [String]
16
+ def self.default_path(env = ENV)
17
+ base = env["XDG_CONFIG_HOME"].to_s.empty? ? File.join(Dir.home, ".config") : env["XDG_CONFIG_HOME"]
18
+ File.join(base, "edify", "config.yml")
19
+ end
20
+
21
+ attr_reader :path
22
+
23
+ def initialize(path: nil, env: ENV)
24
+ @env = env
25
+ @path = path || self.class.default_path(env)
26
+ end
27
+
28
+ # @return [String]
29
+ def url
30
+ present(env["EDIFY_URL"]) || stored["url"] || DEFAULT_URL
31
+ end
32
+
33
+ # @return [String, nil]
34
+ def token
35
+ present(env["EDIFY_TOKEN"]) || stored["token"]
36
+ end
37
+
38
+ # A URL always has a value, so a token is all a login needs.
39
+ def configured?
40
+ !token.nil?
41
+ end
42
+
43
+ # Writes the URL and token, creating the file with owner-only permissions and tightening them if it already
44
+ # existed with looser ones.
45
+ def save(url:, token:)
46
+ directory = File.dirname(path)
47
+ FileUtils.mkdir_p(directory, mode: 0o700)
48
+ File.chmod(0o700, directory)
49
+ File.open(path, File::WRONLY | File::CREAT | File::TRUNC, 0o600) do |file|
50
+ file.write(YAML.dump("url" => url, "token" => token))
51
+ end
52
+ File.chmod(0o600, path)
53
+ @stored = nil
54
+ end
55
+
56
+ private
57
+
58
+ attr_reader :env
59
+
60
+ def stored
61
+ @stored ||= File.exist?(path) ? YAML.safe_load_file(path) || {} : {}
62
+ end
63
+
64
+ def present(value)
65
+ value unless value.to_s.strip.empty?
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,16 @@
1
+ module Edify
2
+ # Formats rows as a plain-text table with a header row and columns padded to the widest value.
3
+ module Table
4
+ module_function
5
+
6
+ # @param headers [Array<String>]
7
+ # @param rows [Array<Array>]
8
+ # @return [String]
9
+ def render(headers, rows)
10
+ cells = [headers, *rows].map { |row| row.map(&:to_s) }
11
+ widths = headers.each_index.map { |column| cells.map { |row| row[column].length }.max }
12
+ cells.map { |row| row.each_with_index.map { |cell, column| cell.ljust(widths[column]) }.join(" ").rstrip }
13
+ .join("\n")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Edify
2
+ VERSION = "0.2.0".freeze
3
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: edify-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Oveson
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: thor
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: "1.3"
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ -
25
+ - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: "1.3"
28
+ description: "Ask an Edify server about speakers and music from the command line, using a personal access token. Readable tables by default, JSON with --json."
29
+ executables:
30
+ - edify
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CHANGELOG.md
35
+ - LICENSE.md
36
+ - README.md
37
+ - exe/edify
38
+ - lib/edify/cli.rb
39
+ - lib/edify/client.rb
40
+ - lib/edify/commands/helpers.rb
41
+ - lib/edify/commands/meetings.rb
42
+ - lib/edify/commands/songs.rb
43
+ - lib/edify/commands/speakers.rb
44
+ - lib/edify/config.rb
45
+ - lib/edify/table.rb
46
+ - lib/edify/version.rb
47
+ homepage: "https://github.com/edifyapporg/edify-cli"
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ source_code_uri: "https://github.com/edifyapporg/edify-cli"
52
+ changelog_uri: "https://github.com/edifyapporg/edify-cli/blob/main/CHANGELOG.md"
53
+ rubygems_mfa_required: "true"
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ -
60
+ - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "4.0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ -
66
+ - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ requirements: []
70
+ rubygems_version: 4.1.0
71
+ specification_version: 4
72
+ summary: Command-line client for the Edify API
73
+ test_files: []