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

View file

@ -10,7 +10,7 @@ class AdministrateurUsageStatisticsService
def update_administrateurs
Administrateur.includes(:user).find_each do |administrateur|
stats = administrateur_stats(administrateur)
api.identify(administrateur.email, stats)
api.update_contact(administrateur.email, stats)
end
api.run
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")
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_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/")
# Internal URLs

View file

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