Skip to content

Instantly share code, notes, and snippets.

@crova
Created June 8, 2016 23:35
Show Gist options
  • Save crova/968b9e799aae8f29be43fca5bf2bbb0f to your computer and use it in GitHub Desktop.
Save crova/968b9e799aae8f29be43fca5bf2bbb0f to your computer and use it in GitHub Desktop.
how to ignore non-existant attributes ?
# Single Campaign Information
def single_shoot_fetch
sib = Mailin.new("xxx","xxx")
data = { "id" => 200 }
data.to_s
result = sib.get_campaign_v2(data)
single_shoot = result.to_h
Deliv.create(single_shoot)
end
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"=>"...."}]
Started GET "/access/single_shoot_fetch" for 127.0.0.1 at 2016-06-09 01:28:59 +0200
Processing by AccessController#single_shoot_fetch as HTML
(0.1ms) BEGIN
SQL (0.2ms) INSERT INTO `delivs` (`created_at`, `updated_at`) VALUES ('2016-06-08 23:28:59', '2016-06-08 23:28:59')
(7.2ms) COMMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment