3 # Système de gestion des adhésions de Nos oignons
4 # Copyright © 2013-2014 Nos oignons <contact@nos-oignons.net>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class MailmanMember < Struct.new(:member_id, :email, keyword_init: true)
26 Mailman::request(:delete, "/3.0/members/#{URI::encode_www_form_component(member_id)}")
31 def list_members(list)
32 s = request(:get, "/3.0/lists/#{URI::encode_www_form_component(list)}/roster/member")
34 r["entries"].collect { |entry|
35 MailmanMember.new(member_id: entry["member_id"], email: entry["email"])
39 def susbcribe_email(list, email)
40 list_id = list.gsub(/@/, '.')
41 request(:post, "/3.0/members", payload: {
48 headers: { content_type: :json },
52 def request(method, path, **args)
53 RestClient::Request.execute(
56 url: "#{rest_url}#{path}"
63 @rest_url if defined?(@rest_url)
65 @rest_url = ENV["NOS_OIGNONS_MAILMAN_REST_API_URL"]
67 cred_path = File.join("#{ENV["CREDENTIALS_DIRECTORY"]}", "mailman-rest-url")
69 @rest_url = File.open(cred_path).read
71 raise ArgumentError.new("Environment variable `NOS_OIGNONS_MAILMAN_REST_API_URL` not defined, and unable to read the file `$CREDENTIALS_DIRECTORY/mailman-rest-url` either")