Last active
June 11, 2016 13:45
-
-
Save crova/89c2f5e3040e0148d535771d40432d5e to your computer and use it in GitHub Desktop.
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
def single_shoot | |
@single_shoot = Shoot.find(params[:id]) | |
end | |
# fetchs SIB Campaigns | |
def fetch | |
# update/create | |
Shoot.delete_all | |
campaign_records.each do |record| | |
shoot = Shoot.find_or_create_by(id: record[:campaign_id]) | |
unless shoot.update(record) | |
# the data was invalid, so the shoot wasn't saved, do something about that here | |
end | |
end | |
redirect_to(:action => 'index') | |
end | |
def sib | |
@sib ||= Mailin.new("xxxx","xxxxx") | |
end | |
def shoot_criteria | |
{ "type"=>"classic", "status" => "sent", "page"=>1,"page_limit"=>1000 } | |
end | |
def shoots | |
@shoots ||= sib.get_campaigns_v2(shoot_criteria) | |
end | |
def needed_records | |
first_cut = shoots.dig('data') | |
final_cut = first_cut.dig('campaign_records') | |
end | |
def campaign_records | |
@campaign_records ||= needed_records.map | |
end |
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
create_table "shoots", force: :cascade do |t| | |
t.string "campaign_id" | |
t.string "campaign_name" | |
t.string "subject" | |
t.string "bat_sent" | |
t.string "type" | |
t.string "html_content" | |
t.date "entered" | |
t.date "modified" | |
t.string "status" | |
t.integer "sent" | |
t.integer "remaining" | |
t.string "listid" | |
t.string "exclude_list" | |
t.json "stats_by_domain" | |
t.date "scheduled_date" | |
t.string "filter" | |
t.string "tags" | |
t.string "header" | |
t.string "footer" | |
t.string "to_field" | |
t.string "from_name" | |
t.string "from_email" | |
t.string "form_name" | |
t.string "reply_to" | |
t.integer "delivered" | |
t.integer "unique_views" | |
t.integer "viewed" | |
t.integer "clicked" | |
t.integer "clicker" | |
t.integer "hard_bounce" | |
t.integer "soft_bounce" | |
t.integer "unsub" | |
t.integer "mirror_click" | |
t.integer "complaints" | |
t.integer "links_message" | |
t.integer "share_link" | |
t.integer "payout" | |
t.integer "ecpm" | |
t.integer "turnover" | |
t.integer "cost" | |
t.integer "margin" | |
t.integer "result" | |
t.integer "roi" | |
t.string "name" | |
t.string "segment" | |
t.string "deal" | |
t.string "partner" | |
t.datetime "created_at", null: false | |
t.datetime "updated_at", null: false | |
end |
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
irb(main):067:0> single | |
=> [{"id"=>200, | |
"campaign_name"=>"....", | |
"subject"=>".... !", | |
"bat_sent"=>"no", | |
"type"=>"classic", | |
"html_content"=>" | |
<body style=\"margin:0; padding:0;\"><!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<style type=\"text/css\">\nimg {\n\tbackground-position: center;\n\tmargin: auto;\n\tdisplay: block;\n}\n</style>\n</head>\n<body bgcolor=\"#ffffff\">\n </body>", "entered"=>"2016-05-16 02:28:26", | |
"modified"=>"2016-05-16 02:29:56", | |
"status"=>"Sent", | |
"sent"=>28914, | |
"remaining"=>0, | |
"listid"=>[103], "exclude_list"=>[5, 14, 37, 99], "stats_by_domain"=>{"bol.com.br"=>{"sent"=>4335, "delivered"=>4335, "viewed"=>145, "clicked"=>20, "hard_bounce"=>0, "unsub"=>5, "complaints"=>0, "unique_views"=>112, "unique_clicks"=>19, "soft_bounces"=>0}, "uol.com.br"=>{"sent"=>1838, "delivered"=>1838, "viewed"=>53, "clicked"=>5, "hard_bounce"=>0, "unsub"=>2, "complaints"=>0, "unique_views"=>44, "unique_clicks"=>5, "soft_bounces"=>0}, "gmail.com"=>{"sent"=>17274, "delivered"=>17271, "viewed"=>145, "clicked"=>10, "hard_bounce"=>3, "unsub"=>6, "complaints"=>0, "unique_views"=>131, "unique_clicks"=>9, "soft_bounces"=>0}, "globo.com"=>{"sent"=>59, "delivered"=>57, "viewed"=>2, "clicked"=>1, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>2, "unique_clicks"=>1, "soft_bounces"=>2}, "outlook.com"=>{"sent"=>1311, "delivered"=>1311, "viewed"=>12, "clicked"=>4, "hard_bounce"=>0, "unsub"=>1, "complaints"=>0, "unique_views"=>10, "unique_clicks"=>3, "soft_bounces"=>0}, "yahoo.com.br"=>{"sent"=>2641, "delivered"=>2641, "viewed"=>163, "clicked"=>18, "hard_bounce"=>0, "unsub"=>7, "complaints"=>2, "unique_views"=>142, "unique_clicks"=>17, "soft_bounces"=>0}, "ig.com.br"=>{"sent"=>102, "delivered"=>102, "viewed"=>4, "clicked"=>1, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>4, "unique_clicks"=>1, "soft_bounces"=>0}, "yahoo.com"=>{"sent"=>230, "delivered"=>230, "viewed"=>5, "clicked"=>0, "hard_bounce"=>0, "unsub"=>1, "complaints"=>0, "unique_views"=>5, "unique_clicks"=>0, "soft_bounces"=>0}, "msn.com"=>{"sent"=>61, "delivered"=>61, "viewed"=>3, "clicked"=>0, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>2, "unique_clicks"=>0, "soft_bounces"=>0}, "brturbo.com.br"=>{"sent"=>6, "delivered"=>6, "viewed"=>0, "clicked"=>0, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>0, "unique_clicks"=>0, "soft_bounces"=>0}, "claro.com.br"=>{"sent"=>2, "delivered"=>2, "viewed"=>0, "clicked"=>0, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>0, "unique_clicks"=>0, "soft_bounces"=>0}, "globomail.com"=>{"sent"=>35, "delivered"=>32, "viewed"=>0, "clicked"=>0, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>0, "unique_clicks"=>0, "soft_bounces"=>3}, "ymail.com"=>{"sent"=>78, "delivered"=>78, "viewed"=>7, "clicked"=>0, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>7, "unique_clicks"=>0, "soft_bounces"=>0}, "icloud.com"=>{"sent"=>60, "delivered"=>26, "viewed"=>9, "clicked"=>0, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>6, "unique_clicks"=>0, "soft_bounces"=>35}, "live.com"=>{"sent"=>581, "delivered"=>581, "viewed"=>5, "clicked"=>0, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>4, "unique_clicks"=>0, "soft_bounces"=>0}, "oi.com.br"=>{"sent"=>136, "delivered"=>132, "viewed"=>0, "clicked"=>1, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>0, "unique_clicks"=>1, "soft_bounces"=>4}, "outlook.com.br"=>{"sent"=>111, "delivered"=>111, "viewed"=>0, "clicked"=>0, "hard_bounce"=>0, "unsub"=>1, "complaints"=>0, "unique_views"=>0, "unique_clicks"=>0, "soft_bounces"=>0}, "ibest.com.br"=>{"sent"=>12, "delivered"=>5, "viewed"=>0, "clicked"=>0, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>0, "unique_clicks"=>0, "soft_bounces"=>7}, "zipmail.com.br"=>{"sent"=>13, "delivered"=>13, "viewed"=>0, "clicked"=>0, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>0, "unique_clicks"=>0, "soft_bounces"=>0}, "iclaro.com.br"=>{"sent"=>3, "delivered"=>3, "viewed"=>0, "clicked"=>0, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>0, "unique_clicks"=>0, "soft_bounces"=>0}, "facebook.com"=>{"sent"=>2, "delivered"=>2, "viewed"=>0, "clicked"=>0, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>0, "unique_clicks"=>0, "soft_bounces"=>0}, "superig.com.br"=>{"sent"=>5, "delivered"=>5, "viewed"=>0, "clicked"=>0, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>0, "unique_clicks"=>0, "soft_bounces"=>0}, "terra.com.br"=>{"sent"=>3, "delivered"=>3, "viewed"=>0, "clicked"=>0, "hard_bounce"=>0, "unsub"=>0, "complaints"=>0, "unique_views"=>0, "unique_clicks"=>0, "soft_bounces"=>0}}, "scheduled_date"=>"2016-05-16 02:33:42", "filter"=>[{"search"=>{"listid.id"=>{"$nin"=>[5, 14, 37, 99], "$in"=>[103]}, "deleteAt"=>{"$exists"=>false}}, "segment_data"=>[], "match"=>"or", "new"=>"true", "segments_query_txt"=>nil, "type"=>false}], "tags"=>"english", "header"=>"EXISTS", "footer"=>"EXISTS", "from_name"=>"... !", "from_email"=>"", "form_name"=>"", "reply_to"=>"...t", "delivered"=>28861, "unique_views"=>469, "viewed"=>553, "clicked"=>60, "clicker"=>56, "hard_bounce"=>3, "soft_bounce"=>51, "unsub"=>23, "mirror_click"=>20, "complaints"=>2, "links_message"=>{".."=>{"clicked"=>60}}, "to_field"=>"", "share_link"=>"...."}] |
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
(4.2ms) COMMIT | |
Shoot Load (0.4ms) SELECT "shoots".* FROM "shoots" WHERE "shoots"."campaign_id" = $1 LIMIT 1 [["campaign_id", "137"]] | |
(0.2ms) BEGIN | |
SQL (0.3ms) INSERT INTO "shoots" ("campaign_id", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["campaign_id", "137"], ["created_at", "2016-06-11 12:56:33.570804"], ["updated_at", "2016-06-11 12:56:33.570804"]] | |
(4.2ms) COMMIT | |
(0.2ms) BEGIN | |
SQL (1.6ms) UPDATE "shoots" SET "id" = $1, "campaign_name" = $2, "subject" = $3, "bat_sent" = $4, "type" = $5, "html_content" = $6, "entered" = $7, "modified" = $8, "status" = $9, "sent" = $10, "remaining" = $11, "listid" = $12, "exclude_list" = $13, "scheduled_date" = $14, "filter" = $15, "tags" = $16, "header" = $17, "footer" = $18, "from_name" = $19, "from_email" = $20, "form_name" = $21, "reply_to" = $22, "delivered" = $23, "unique_views" = $24, "viewed" = $25, "clicked" = $26, "clicker" = $27, "hard_bounce" = $28, "soft_bounce" = $29, "unsub" = $30, "mirror_click" = $31, "complaints" = $32, "to_field" = $33, "share_link" = $34, "stats_by_domain" = $35, "updated_at" = $36 WHERE "shoots"."id" = $37 [["id", 137], ["campaign_name", "Mundo de Opiniões - DGMax - Ativos ALL"], ["subject", "{PRENOM} Ganhe DINHEIRO para dar sua opinião, porque ela VALE MUITO !"], ["bat_sent", "yes"], ["type", "classic"], ["html_content", "<body style=\"margin:0; padding:0;\">\n<!-- Header Begins -->\n<center><p style=\"color: #FF161A;\n\tfont-family: Lucida Grande, Lucida Sans Unicode, Lucida Sans, DejaVu Sans, Verdana, sans-serif;\n\tfont-style: italic;\n\tfont-size: 40px;\n\ttext-shadow: 1px 2px 5px;\n\ttext-align:center;\n\tmargign:auto;\">A Boa do Dia !</p></center>\n\t <center><a style=\"\n\t width: 195px;\n background: #0AA7FF;\n background-image: -webkit-linear-gradient(top, #3498db, #2980b9);\n background-image: -moz-linear-gradient(top, #3498db, #2980b9);\n background-image: -ms-linear-gradient(top, #3498db, #2980b9);\n background-image: -o-linear-gradient(top, #3498db, #2980b9);\n background-image: linear-gradient(to bottom, #3498db, #2980b9);\n -webkit-border-radius: 28;\n -moz-border-radius: 28;\n border-radius: 28px;\n font-size: 20px;\n padding: 10px 20px 10px 20px;\n text-decoration: none;\n\tfont-family: Lucida Grande, Lucida Sans Unicode, Lucida Sans, DejaVu Sans, Verdana, sans-serif;\n\tfont-style: normal;\n\tborder-radius: 5px;\n\tfont-weight: bold;\n\tcolor: #F3F3F3;\n\ttext-decoration:none;\n\tmargin-right: 155px;\n\t \" href=\"[MIRROR]\">Navegador</a>\n\t <a style=\"\n\t background-color: #FF161A;\n\twidth: 195px;\n background-image: -webkit-linear-gradient(top, #FF161A, #FF161A);\n background-image: -moz-linear-gradient(top, #FF161A, #FF161A);\n background-image: -ms-linear-gradient(top, #FF161A, #FF161A);\n background-image: -o-linear-gradient(top, #FF161A, #FF161A);\n background-image: linear-gradient(to bottom, #FF161A, #FF161A);\n -webkit-border-radius: 28;\n -moz-border-radius: 28;\n border-radius: 28px;\n color: #f3f3f3;\n font-size: 20px;\n\t\t\tborder-radius: 5px;\n padding: 10px 20px 10px 20px;\n text-decoration: none;\n\tfont-family: Lucida Grande, Lucida Sans Unicode, Lucida Sans, DejaVu Sans, Verdana, sans-serif;\n\tfont-style: normal;\n\tfont-weight: bold;\n\ttext-decoration:none;\n\t \" href=\"[UNSUBSCRIBE]\">Descadastrar</a></center>\n\t\n <br />\n\t<br />\n\t<br />\n\n\t\n\n\t<center>\n\t<div>\n\t\n\n\n<center>\n<table width=\"600\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#FFFFFF\">\n\t<tr bgcolor=\"#000000\" >\n \t<td style=\"font-size:0; padding-left: 0px;\" colspan=\"2\" align=\"left\">\n \t<img src=\"http://webassets.ssisurveys.com/opinionworld/LP_images/LatAm/header_br.jpg\" border=\"0\" /> \n </td>\n </tr>\n\t<tr>\n \t<td style=\"text-align: center; font-size: 22px; font-family: Arial, Helvetica, sans-serif;\" colspan=\"2\">\n \t\t<font family=\"Arial\" color=\"#23368c\"><strong>PARTICIPE DE PESQUISAS PARA GANHAR PRÊMIOS!\n\t\t\t\t</strong></font>\n\t\t</td>\n\t</tr>\n <tr>\n \t<td style=\"text-align: center; font-size: 15.25px; font-family: Arial, Helvetica, sans-serif;\" colspan=\"2\">\n \t\t<font family=\"Arial\" color=\"#4b9c12\"><strong>Fazer o cadastro é fácil E gratuito - receba recompensas pelas suas opiniões.</strong></font>\n\t\t</td>\n\t</tr>\n\t<tr>\n \t<td style=\"text-align: left; font-size: 14px; font-family: Arial, Helvetica, sans-serif; padding: 0px 40px 5px 40px;\" colspan=\"2\">\n \t<p>Você pode ganhar ótimos PRÊMIOS quando compartilhar as suas opiniões em pesquisas importantes. Entre para a comunidade Mundo de Opiniões gratuitamente e \n ganhe prêmios pela sua participação!<br /><br />\n \n \t</p>\t\n\t\t</td>\n </tr>\n\t<tr style=\"padding-top: 5px;\">\n\t\t<td align=\"center\">\n <a href=\"http://lttrk1.com/?a=21477&c=2747&s1=\" target=\"_blank\"><img src=\"http://webassets.ssisurveys.com/opinionworld/LP_images/LatAm/button_br.jpg\" alt=\"Button\" border=\"0\" /></a>\n </td>\n\t</tr>\n <tr>\n\t\t<td> </td>\n\t</tr>\n\t<tr bgcolor=\"#5f5f5f\" style=\"padding-top: 5px; padding-bottom: 5px;\">\n\t\t<td colspan=\"3\" style=\"padding-right: 20px; font-size: 11px;\"><font color=\"#b4b4b4\" align=\"center\" face=\"Arial, Helvetica, sans-serif\">\n\t\t\t<p><center>*Os prêmios serão dados apenas a membros registrados da Mundo de Opiniões. <br />Obrigado por ser um membro da nossa comunidade!</center></p>\n\t\t<p><center><a href=\"http://content.mundodeopinioes.com.br/pt-BR/policies/privacy\" target=\"_blank\" style=\"color: #FFFFFF;\">Política de Privacidade</a> | <a href=\"http://content.mundodeopinioes.com.br/pt-BR/policies/terms\" target=\"_blank\" style=\"color: #FFFFFF;\">Termos e Condições</a> | <a href=\"http://www.mundodeopinioes.com.br/secured/my-account/my-profile?entity_id=%3C#DubKnowledge[1500/Entity id]>&pw=<#DubKnowledge[1201/Password]>\" target=\"_blank\" style=\"color: #FFFFFF;\">Descadastrar</a></center></p>\n\t\t<p><center>Copyright 2013 © Survey Sampling International, LLC. Todos os direitos reservados.</center></p></font>\t\n\t\t</td>\n\t</tr>\n\t\n</table>\n</center>\n\n\t\n\t\n\t</div>\n\t</center>\n\t<!-- Main Content Ends -->\n\t\n\t<!-- Footer Begins -->\n <center>\n<table width=\"600\" border=\"0\" margin=\"auto\">\n <tbody>\n <tr style=\"width:540px; text-align:center; margin:auto;\">\n <td><p style=\"color: #FF161A;\n\tfont-family: Lucida Grande, Lucida Sans Unicode, Lucida Sans, DejaVu Sans, Verdana, sans-serif;\n\tfont-style: italic;\n\tfont-size: 24px;\n\ttext-shadow: 1px 2px 5px;\">A Boa do Dia - Informações legais</p></td>\n </tr>\n\n\n <tr>\n <td><span style=\"color: grey;\n\tfont-family: Lucida Grande, Lucida Sans Unicode, Lucida Sans, DejaVu Sans, Verdana, sans-serif;\n\tfont-style: italic;\n\tfont-size: 10px;\n\ttext-align:justify;\">Conforme à lei de Liberdades e Informática, você tem direito de cancelar, modificar, atualizar e acessar suas informações quando quiser !<br />\n <br />\n A Boa do Dia é editado por Crova Media: 27, Rue Avaulée - 92240 - Malakoff - França\n <br />\n RCS Nanterre 802254284\n <br />\n Você pode nos escrever à qualquer momento no endereço acima ou pelo email: [email protected] !\n\t\n \n </td>\n </tr>\n </tbody>\n</table></center> \n\t</body>"], ["entered", "2016-04-25"], ["modified", "2016-04-25"], ["status", "Sent"], ["sent", 5677], ["remaining", 0], ["listid", "[33, 34, 75]"], ["exclude_list", "[5, 14, 37, 80, 81, 83, 84, 85, 60]"], ["scheduled_date", "2016-04-27"], ["filter", "[{\"search\"=>{\"listid.id\"=>{\"$nin\"=>[5, 14, 37, 80, 81, 83, 84, 85, 60], \"$in\"=>[33, 34, 75]}}, \"segment_data\"=>[], \"match\"=>\"or\", \"new\"=>\"true\", \"segments_query_txt\"=>nil, \"type\"=>false}]"], ["tags", "mundodeopinioes ativos dgmax ALL"], ["header", "EXISTS"], ["footer", "EXISTS"], ["from_name", "Mundo de Opiniões - A Boa do Dia !"], ["from_email", ""], ["form_name", ""], ["reply_to", "[email protected]"], ["delivered", 5579], ["unique_views", 1007], ["viewed", 1318], ["clicked", 151], ["clicker", 131], ["hard_bounce", 3], ["soft_bounce", 95], ["unsub", 14], ["mirror_click", 43], ["complaints", 2], ["to_field", ""], ["share_link", 0], ["stats_by_domain", "{\"yahoo.com.br\":{\"sent\":2214,\"delivered\":2214,\"viewed\":652,\"clicked\":62,\"hard_bounce\":0,\"unsub\":3,\"complaints\":2,\"unique_views\":505,\"unique_clicks\":55,\"soft_bounces\":0},\"hotmail.com\":{\"sent\":611,\"delivered\":607,\"viewed\":93,\"clicked\":20,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":85,\"unique_clicks\":19,\"soft_bounces\":4},\"gmail.com\":{\"sent\":1226,\"delivered\":1226,\"viewed\":199,\"clicked\":23,\"hard_bounce\":0,\"unsub\":4,\"complaints\":0,\"unique_views\":169,\"unique_clicks\":20,\"soft_bounces\":0},\"bol.com.br\":{\"sent\":723,\"delivered\":723,\"viewed\":123,\"clicked\":24,\"hard_bounce\":0,\"unsub\":2,\"complaints\":0,\"unique_views\":96,\"unique_clicks\":20,\"soft_bounces\":0},\"yahoo.com\":{\"sent\":93,\"delivered\":93,\"viewed\":32,\"clicked\":2,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":16,\"unique_clicks\":2,\"soft_bounces\":0},\"ig.com.br\":{\"sent\":63,\"delivered\":60,\"viewed\":11,\"clicked\":2,\"hard_bounce\":3,\"unsub\":0,\"complaints\":0,\"unique_views\":11,\"unique_clicks\":2,\"soft_bounces\":0},\"usp.br\":{\"sent\":4,\"delivered\":4,\"viewed\":1,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":1,\"unique_clicks\":0,\"soft_bounces\":0},\"ymail.com\":{\"sent\":38,\"delivered\":38,\"viewed\":5,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":5,\"unique_clicks\":0,\"soft_bounces\":0},\"uol.com.br\":{\"sent\":246,\"delivered\":246,\"viewed\":79,\"clicked\":10,\"hard_bounce\":0,\"unsub\":2,\"complaints\":0,\"unique_views\":61,\"unique_clicks\":8,\"soft_bounces\":0},\"globo.com\":{\"sent\":24,\"delivered\":24,\"viewed\":8,\"clicked\":2,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":4,\"unique_clicks\":1,\"soft_bounces\":0},\"icloud.com\":{\"sent\":44,\"delivered\":null,\"viewed\":0,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":0,\"unique_clicks\":0,\"soft_bounces\":44},\"oi.com.br\":{\"sent\":35,\"delivered\":35,\"viewed\":0,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":0,\"unique_clicks\":0,\"soft_bounces\":0},\"live.com\":{\"sent\":24,\"delivered\":24,\"viewed\":5,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":3,\"unique_clicks\":0,\"soft_bounces\":0},\"outlook.com\":{\"sent\":49,\"delivered\":49,\"viewed\":5,\"clicked\":1,\"hard_bounce\":0,\"unsub\":1,\"complaints\":0,\"unique_views\":5,\"unique_clicks\":1,\"soft_bounces\":0},\"terra.com.br\":{\"sent\":35,\"delivered\":3,\"viewed\":0,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":0,\"unique_clicks\":0,\"soft_bounces\":32},\"superig.com.br\":{\"sent\":7,\"delivered\":7,\"viewed\":2,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":1,\"unique_clicks\":0,\"soft_bounces\":0},\"brturbo.com.br\":{\"sent\":5,\"delivered\":5,\"viewed\":3,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":3,\"unique_clicks\":0,\"soft_bounces\":0},\"msn.com\":{\"sent\":2,\"delivered\":2,\"viewed\":0,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":0,\"unique_clicks\":0,\"soft_bounces\":0},\"ibest.com.br\":{\"sent\":10,\"delivered\":8,\"viewed\":2,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":2,\"unique_clicks\":0,\"soft_bounces\":2},\"zipmail.com.br\":{\"sent\":7,\"delivered\":7,\"viewed\":0,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":0,\"unique_clicks\":0,\"soft_bounces\":0},\"hotmail.com.br\":{\"sent\":7,\"delivered\":7,\"viewed\":1,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":1,\"unique_clicks\":0,\"soft_bounces\":0},\"outlook.com.br\":{\"sent\":3,\"delivered\":3,\"viewed\":0,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":0,\"unique_clicks\":0,\"soft_bounces\":0},\"globomail.com\":{\"sent\":18,\"delivered\":18,\"viewed\":0,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":0,\"unique_clicks\":0,\"soft_bounces\":0},\"rocketmail.com\":{\"sent\":6,\"delivered\":6,\"viewed\":3,\"clicked\":2,\"hard_bounce\":0,\"unsub\":1,\"complaints\":0,\"unique_views\":1,\"unique_clicks\":1,\"soft_bounces\":0},\"itelefonica.com.br\":{\"sent\":4,\"delivered\":2,\"viewed\":0,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":0,\"unique_clicks\":0,\"soft_bounces\":2},\"sanepar.com.br\":{\"sent\":4,\"delivered\":4,\"viewed\":0,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":0,\"unique_clicks\":0,\"soft_bounces\":0},\"iclaro.com.br\":{\"sent\":1,\"delivered\":1,\"viewed\":0,\"clicked\":0,\"hard_bounce\":0,\"unsub\":0,\"complaints\":0,\"unique_views\":0,\"unique_clicks\":0,\"soft_bounces\":0}}"], ["updated_at", "2016-06-11 12:56:33.583286"], ["id", 133]] |
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
irb(main):014:0> needed_records.map{|record| record['id']} | |
=> [279, 277, 276, 275, 274, 273, 272, 271, 270, 269, 268, 267, 266, 265, 264, 263, 262, 260, 259, 258, 257, 256, 255, 254, 253, 251, 250, 249, 248, 247, 246, 243, 242, 241, 240, 239, 238, 237, 236, 235, 234, 233, 232, 231, 230, 229, 228, 227, 226, 225, 224, 223, 222, 221, 220, 219, 218, 217, 216, 215, 214, 213, 212, 211, 210, 209, 208, 207, 206, 205, 204, 203, 202, 201, 200, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181, 180, 179, 178, 177, 176, 174, 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 146, 145, 144, 143, 142, 141, 140, 138, 137, 136, 135, 134, 133, 132, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 101, 100, 99, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 21, 20, 18, 17, 16, 15, 14, 13, 11, 10, 9, 8, 7, 6, 5, 1] |
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
# fetchs SIB Campaigns | |
def fetch | |
# update/create | |
campaign_records.each do |record| | |
shoot = Shoot.find_or_create_by(campaign_id: record["id"]) | |
unless shoot.update(record.except(:id)) | |
# the data was invalid, so the shoot wasn't saved, do something about that here | |
end | |
end | |
redirect_to(:action => 'index') | |
end |
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
irb(main):003:0> c = a.pluck('id', 'campaign_id') | |
(0.9ms) SELECT "shoots"."id", "shoots"."campaign_id" FROM "shoots" | |
=> [[277, "277"], [275, "275"], [274, "274"], [272, "272"], [271, "271"], [270, "270"], [269, "269"], [222, "222"], [267, "267"], [266, "266"], [264, "264"], [262, "262"], [260, "260"], [259, "259"], [258, "258"], [221, "221"], [256, "256"], [255, "255"], [254, "254"], [253, "253"], [250, "250"], [249, "249"], [248, "248"], [247, "247"], [193, "193"], [243, "243"], [242, "242"], [241, "241"], [240, "240"], [239, "239"], [237, "237"], [236, "236"], [235, "235"], [232, "232"], [231, "231"], [230, "230"], [229, "229"], [228, "228"], [226, "226"], [225, "225"], [223, "223"], [219, "219"], [218, "218"], [217, "217"], [216, "216"], [215, "215"], [213, "213"], [211, "211"], [210, "210"], [208, "208"], [206, "206"], [205, "205"], [203, "203"], [202, "202"], [200, "200"], [197, "197"], [195, "195"], [194, "194"], [191, "191"], [190, "190"], [189, "189"], [188, "188"], [161, "161"], [186, "186"], [185, "185"], [184, "184"], [181, "181"], [179, "179"], [178, "178"], [176, "176"], [173, "173"], [172, "172"], [170, "170"], [169, "169"], [168, "168"], [167, "167"], [165, "165"], [163, "163"], [162, "162"], [158, "158"], [157, "157"], [156, "156"], [155, "155"], [153, "153"], [152, "152"], [151, "151"], [149, "149"], [146, "146"], [145, "145"], [144, "144"], [143, "143"], [142, "142"], [220, "220"], [140, "140"], [138, "138"], [137, "137"], [136, "136"], [279, "279"], [276, "276"], [273, "273"], [268, "268"], [265, "265"], [263, "263"], [257, "257"], [251, "251"], [246, "246"], [238, "238"], [234, "234"], [233, "233"], [227, "227"], [224, "224"], [214, "214"], [212, "212"], [209, "209"], [207, "207"], [204, "204"], [201, "201"], [198, "198"], [196, "196"], [192, "192"], [187, "187"], [183, "183"], [182, "182"], [180, "180"], [177, "177"], [174, "174"], [171, "171"], [166, "166"], [164, "164"], [160, "160"], [154, "154"], [150, "150"], [148, "148"], [141, "141"], [135, "135"]] | |
irb(main):004:0> a.count | |
(0.6ms) SELECT COUNT(*) FROM "shoots" | |
=> 135 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/crova/89c2f5e3040e0148d535771d40432d5e#file-gistfile3-txt-L6
it should be
unless shoot.update(record.except("id"))