Merge pull request #4380 from betagouv/feat/sendinblue-api-v3

Migrate Sendinblue API to v3
This commit is contained in:
Keirua 2019-10-22 10:27:44 +02:00 committed by GitHub
commit 2198f0c585
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 8 deletions

View file

@ -15,8 +15,8 @@ class Sendinblue::Api
client_key.present? client_key.present?
end end
def identify(email, attributes = {}) def update_contact(email, attributes = {})
req = api_request('identify', email: email, attributes: attributes) req = post_api_request('contacts', email: email, attributes: attributes, updateEnabled: true)
req.on_complete do |response| req.on_complete do |response|
if !response.success? if !response.success?
push_failure("Error while updating identity for administrateur '#{email}' in Sendinblue: #{response.response_code} '#{response.body}'") push_failure("Error while updating identity for administrateur '#{email}' in Sendinblue: #{response.response_code} '#{response.body}'")
@ -34,7 +34,7 @@ class Sendinblue::Api
private private
def hydra def hydra
@hydra ||= Typhoeus::Hydra.new @hydra ||= Typhoeus::Hydra.new(max_concurrency: 50)
end end
def push_failure(failure) def push_failure(failure)
@ -49,8 +49,8 @@ class Sendinblue::Api
end end
end end
def api_request(path, body) def post_api_request(path, body)
url = "#{SENDINBLUE_API_URL}/#{path}" url = "#{SENDINBLUE_API_V3_URL}/#{path}"
Typhoeus::Request.new( Typhoeus::Request.new(
url, url,
@ -62,12 +62,12 @@ class Sendinblue::Api
def headers def headers
{ {
'ma-key': client_key, 'api-key': client_key,
'Content-Type': 'application/json; charset=UTF-8' 'Content-Type': 'application/json; charset=UTF-8'
} }
end end
def client_key def client_key
Rails.application.secrets.sendinblue[:client_key] Rails.application.secrets.sendinblue[:api_v3_key]
end end
end end

View file

@ -10,7 +10,7 @@ class AdministrateurUsageStatisticsService
def update_administrateurs def update_administrateurs
Administrateur.includes(:user).find_each do |administrateur| Administrateur.includes(:user).find_each do |administrateur|
stats = administrateur_stats(administrateur) stats = administrateur_stats(administrateur)
api.identify(administrateur.email, stats) api.update_contact(administrateur.email, stats)
end end
api.run api.run
end end

View file

@ -7,6 +7,7 @@ API_GEO_SANDBOX_URL = ENV.fetch("API_GEO_SANDBOX_URL", "https://sandbox.geo.api.
HELPSCOUT_API_URL = ENV.fetch("HELPSCOUT_API_URL", "https://api.helpscout.net/v2") HELPSCOUT_API_URL = ENV.fetch("HELPSCOUT_API_URL", "https://api.helpscout.net/v2")
PIPEDRIVE_API_URL = ENV.fetch("PIPEDRIVE_API_URL", "https://api.pipedrive.com/v1") PIPEDRIVE_API_URL = ENV.fetch("PIPEDRIVE_API_URL", "https://api.pipedrive.com/v1")
SENDINBLUE_API_URL = ENV.fetch("SENDINBLUE_API_URL", "https://in-automate.sendinblue.com/api/v2") SENDINBLUE_API_URL = ENV.fetch("SENDINBLUE_API_URL", "https://in-automate.sendinblue.com/api/v2")
SENDINBLUE_API_V3_URL = ENV.fetch("SENDINBLUE_API_V3_URL", "https://api.sendinblue.com/v3")
UNIVERSIGN_API_URL = ENV.fetch("UNIVERSIGN_API_URL", "https://ws.universign.eu/tsa/post/") UNIVERSIGN_API_URL = ENV.fetch("UNIVERSIGN_API_URL", "https://ws.universign.eu/tsa/post/")
# Internal URLs # Internal URLs

View file

@ -55,6 +55,7 @@ defaults: &defaults
sendinblue: sendinblue:
enabled: <%= ENV['SENDINBLUE_ENABLED'] == 'enabled' %> enabled: <%= ENV['SENDINBLUE_ENABLED'] == 'enabled' %>
client_key: <%= ENV['SENDINBLUE_CLIENT_KEY'] %> client_key: <%= ENV['SENDINBLUE_CLIENT_KEY'] %>
api_v3_key: <%= ENV['SENDINBLUE_API_V3_KEY'] %>
matomo: matomo:
enabled: <%= ENV['MATOMO_ENABLED'] == 'enabled' %> enabled: <%= ENV['MATOMO_ENABLED'] == 'enabled' %>
client_key: <%= ENV['MATOMO_ID'] %> client_key: <%= ENV['MATOMO_ID'] %>