Skip to content

Instantly share code, notes, and snippets.

@crova
crova / ALL TAGS - Aggregate Results
Created January 13, 2018 18:40
Sendinblue API Reponses on 13/01/2018
#Furthermore, even the API Response with ALL Tags and Aggregated values don't match:
data = {"aggregate" => 1, "days" => 13}
result = m.get_statistics(data)
{"code"=>"success", "message"=>"Data retrieved", "data"=>{"requests"=>256575, "delivered"=>254322, "bounces"=>2462, "spamreports"=>10, "blocked"=>269, "invalid"=>25, "deferred"=>2205, "opens"=>55479, "unique_opens"=>33164, "clicks"=>3822, "unique_clicks"=>2896, "range"=>"2017-12-31|2018-01-13"}}
@crova
crova / Desired object irb
Created January 10, 2018 17:57
Best way to create objects to be displayed on a view for the following "master" object
2.3.3 :045 > y = x['stats_by_domain']
=> "{\"gmail.com\"=>{\"sent\"=>42053, \"delivered\"=>42038, \"viewed\"=>7725, \"clicked\"=>608, \"hard_bounce\"=>1, \"unsub\"=>33, \"complaints\"=>0, \"unique_views\"=>5469, \"unique_clicks\"=>546, \"soft_bounces\"=>14}, \"yahoo.com.br\"=>{\"sent\"=>1872, \"delivered\"=>1872, \"viewed\"=>420, \"clicked\"=>25, \"hard_bounce\"=>0, \"unsub\"=>3, \"complaints\"=>0, \"unique_views\"=>300, \"unique_clicks\"=>22, \"soft_bounces\"=>0}, \"hotmail.com\"=>{\"sent\"=>2677, \"delivered\"=>1991, \"viewed\"=>363, \"clicked\"=>48, \"hard_bounce\"=>0, \"unsub\"=>3, \"complaints\"=>0, \"unique_views\"=>290, \"unique_clicks\"=>43, \"soft_bounces\"=>686}, \"ymail.com\"=>{\"sent\"=>24, \"delivered\"=>24, \"viewed\"=>1, \"clicked\"=>0, \"hard_bounce\"=>0, \"unsub\"=>0, \"complaints\"=>0, \"unique_views\"=>1, \"unique_clicks\"=>0, \"soft_bounces\"=>0}, \"live.com\"=>{\"sent\"=>43, \"delivered\"=>36, \"viewed\"=>1, \"clicked\"=>0, \"hard_bounce\"=>0, \"unsub\"=>0, \"complaints\"=>0, \"unique_vi
@crova
crova / dbase_schema.rb
Created January 8, 2018 14:56
Can't figure why I end up with multiple records for the same date
reate_table "sib_transacs", force: :cascade do |t|
t.integer "requests"
t.integer "delivered"
t.integer "bounces"
t.integer "spamreports"
t.integer "blocked"
t.integer "invalid_sent"
t.integer "deferred"
t.integer "opens"
t.integer "unique_opens"
@crova
crova / controller.rb
Created January 4, 2018 13:43
Update routine not evaluating the field "date" and end up creating a new record instead of updating the existing one on the database
def sib
@sib ||= Mailin.new("URL","APIKEY")
end
def shoot_criteria_gmail_e_cia_collecte
{ "aggregate" => 0, "tag" => "WM-ABD-2018-GMAIL-E-CIA-COLLECTE", "days" => 3 }
end
def shoots_gmail_e_cia_collecte
@shoots_gmail_e_cia_collecte ||= sib.get_statistics(shoot_criteria_gmail_e_cia_collecte)
end
@crova
crova / Above file returns following error
Last active January 2, 2018 19:51
Can't figure what is going on here
undefined method `tag' for [:requests, 0]:Array
@crova
crova / _menu.html.erb
Created January 2, 2018 13:11
Can't see why the dropdown menu works for a few items and not others
<!DOCTYPE html>
<html>
<head>
<title>The Nuclear Shelter</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
@crova
crova / camps_to_update_controller.rb
Created December 13, 2017 11:40
Why this works for one Model (SibTransac) and don't work for the other (DbCampaign)?!
def update
def db_campaign
@db_campaign = DbCampaign.find_by_id(params[:id])
end
respond_to do |format|
@db_campaign = DbCampaign.find_by_id(params[:id])
if @db_campaign.update(db_campaign_params)
format.html { redirect_to @db_campaign, notice: 'Campaign was successfully updated.' }
format.json { render :show, status: :ok, location: @db_campaign }
calculate_kpi
@crova
crova / API response
Last active December 11, 2017 18:00
Problem with table name "invalid"! How to save "invalid" from API response to the column "invalid_sent" from database
{"requests"=>5851, "delivered"=>5656, "bounces"=>194, "invalid"=>11, "deferred"=>46, "opens"=>2705, "unique_opens"=>1500, "clicks"=>158, "unique_clicks"=>140, "date"=>"2017-11-25", "tag"=>"WM-ABD-2018-GMAIL-E-CIA"}
@crova
crova / db_campaigns_controller.rb
Created December 8, 2017 18:14
How to create a scope for this query?
def index
# Set Scenario for the Dashboard
#
# Excludes campaigns that belongs to "Un Jour Une Astuce" program
ids_to_exclude = [864, 5, 7, 866, 8, 994, 868, 14, 870, 15, 17, 11, 16, 21, 23, 24, 25, 31, 20, 871, 29, 30, 27, 38, 1540, 34, 35, 37, 33, 872, 41, 43, 65, 42, 46, 47, 48, 995, 45, 873, 51, 53, 874, 50, 875, 58, 876, 59, 55, 877, 63, 878, 64, 61, 879, 68, 69, 67, 880, 73, 885, 74, 71, 881, 77, 79, 76, 882, 83, 883, 84, 81, 884, 101, 886, 103, 99, 887, 106, 107, 996, 105, 888, 110, 111, 127, 109, 889, 116, 1653, 1566, 113, 890, 119, 120, 891, 118, 892, 124, 125, 126, 123, 893, 132, 894, 129, 895, 135, 136, 146, 134, 896, 141, 897, 906, 138, 898, 145, 899, 143, 900, 151, 1571, 157, 149, 902, 154, 155, 156, 153, 904, 907, 161, 193, 1631, 909, 166, 911, 1482, 164, 1636, 169, 170, 171, 168, 913, 174, 176, 1497, 173, 1638, 179, 180, 563, 178, 915, 183, 184, 1588, 182, 917, 187, 188, 564, 186, 919, 192, 921, 190, 923, 197, 925, 195, 927, 202, 929, 200, 931, 206, 935, 204, 937, 209, 210, 224,
@crova
crova / db_campaigns_controller.rb
Created December 8, 2017 16:14
orate and crate not being calculated
def update
respond_to do |format|
@single_shoot = DbCampaign.find_by_id(params[:id])
if @single_shoot.update(db_campaign_params)
format.html { redirect_to @single_shoot, notice: 'Campaign was successfully updated.' }
format.json { render :show, status: :ok, location: @single_shoot }
calculate_kpi
else
format.html { render :edit }
format.json { render json: @single_shoot.errors, status: :unprocessable_entity }