Created
May 27, 2017 04:17
-
-
Save momota10s/706bb2a443a27dd21438756244b2016a to your computer and use it in GitHub Desktop.
sample ruby code of mailgun tracking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "time" | |
require 'active_support/all' | |
require 'rest-client' | |
require 'json' | |
def get_logs(start_time, end_time) | |
response = RestClient.get "https://api:key-***********"\ | |
"@api.mailgun.net/v3/influencerone.jp/events", | |
:params => { | |
:'begin' => "#{start_time}", | |
:'end' => "#{end_time}", | |
:'ascending' => "yes", | |
:'limit' => 3, | |
:'pretty' => "yes", | |
:'recipient' => "test@example.com" | |
} | |
return response | |
end | |
now = Time.now | |
yesterday = now - 1.days | |
start_time = yesterday.beginning_of_day.to_i | |
end_time = yesterday.end_of_day.to_i | |
logs = get_logs(start_time, end_time) | |
logs_json = JSON.parse(logs) | |
logs_json['items'].each do |item| | |
puts item['id'] | |
puts item['timestamp'].to_i | |
puts Time.at(item['timestamp'].to_i) | |
puts item['recipient'] | |
puts item['event'] | |
puts item['message']['headers']['message-id'] | |
puts item.dig('message', 'headers', 'subject') | |
puts '---------------------------' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment