I have a User form class which has elements and I am trying to add Regex validator.
Here is what I have tried
$inputFilter->add([
"name" => "password",
"required" => true,
"filters" => [
],
"validators" => [
[
"name" => new Regex(["pattern" => "/^[a-zA-Z0-9_]+$/"]),
],
[
"name" => "NotEmpty",
],
[
"name" => "StringLength",
"options" => [
"min" => 6,
"max" => 64
],
],
],
]);
But it throws
Object of class Zend\Validator\Regex could not be converted to string
Can anyone help me out?
You can add input filter specifications for the validator, the following should work
$inputFilter->add([
"name" => "password",
"required" => true,
"filters" => [
],
"validators" => [
// add validator(s) using input filter specs
[
"name" => "Regex",
"options" => [
"pattern" => "/^[a-zA-Z0-9_]+$/"
],
],
[
"name" => "NotEmpty",
],
[
"name" => "StringLength",
"options" => [
"min" => 6,
"max" => 64
],
],
],
]);
If you really want to instantiate the object (using the new Regex(...) as in your original code), you can do that this way instead
$inputFilter->add([
"name" => "password",
"required" => true,
"filters" => [
],
"validators" => [
// add a regex validator instance
new Regex(["pattern" => "/^[a-zA-Z0-9_]+$/"]),
// add using input filter specs ...
[
"name" => "NotEmpty",
],
[
"name" => "StringLength",
"options" => [
"min" => 6,
"max" => 64
],
],
],
]);
You may also find this zf blog post useful Validate data using zend-inputfilter, as well as the official zend-input-filter docs
I've been trying to create a MPA(multi-product ad) for some time now, but it keeps giving me the following error "Call to action link should be same as link of the post".
I've used the following format:
{
"object_story_spec" => {
"page_id" => 321954304600161,
"instagram_actor_id" => "874410812666052",
"link_data" => {
"multi_share_optimized" => true,
"multi_share_end_card" => true,
"message" => "Test message ad in adset",
"caption" => nil,
"link" => "http://www.adwyze.com?utm_source=facebook&utm_medium=ocpm&utm_campaign=TestforJson-06Dec2017-16h48m&utm_term=all-MF-18-65-06Dec2017-16h48m&utm_content=test_testadinadset-00-CarouselAd-06Dec2017-19h44m&utm_id=2b301660-01c2-4c21-9fe1-06863dbaac92",
"child_attachments" => [{
"link" => "http://www.adwyze.com?utm_source=facebook&utm_medium=ocpm&utm_campaign=Test for Json-06Dec2017-16h48m&utm_term=all-MF-18-65-06Dec2017-16h48m&utm_content=test_test ad in adset-00-CarouselAd-06Dec2017-19h44m&utm_id=2b301660-01c2-4c21-9fe1-06863dbaac92",
"name" => "TEst ad in adset",
"description" => nil,
"picture" => "https://adcreation-m.s3-ap-south-1.amazonaws.com/1512559029_test.jpg",
"call_to_action" => {
"type" => "SHOP_NOW",
"value" => {
"link" => "http://www.adwyze.com?utm_source=facebook&utm_medium=ocpm&utm_campaign=TestforJson-06Dec2017-16h48m&utm_term=all-MF-18-65-06Dec2017-16h48m&utm_content=test_testadinadset-00-CarouselAd-06Dec2017-19h44m&utm_id=2b301660-01c2-4c21-9fe1-06863dbaac92"
}
}
}, {
"link" => "http://www.adwyze.com?utm_source=facebook&utm_medium=ocpm&utm_campaign=Test for Json-06Dec2017-16h48m&utm_term=all-MF-18-65-06Dec2017-16h48m&utm_content=test_test ad in adset-00-CarouselAd-06Dec2017-19h44m&utm_id=2b301660-01c2-4c21-9fe1-06863dbaac92",
"name" => "TEst",
"description" => nil,
"picture" => "https://adcreation-m.s3-ap-south-1.amazonaws.com/1512559033_test.jpg",
"call_to_action" => {
"type" => "SHOP_NOW",
"value" => {
"link" => "http://www.adwyze.com?utm_source=facebook&utm_medium=ocpm&utm_campaign=TestforJson-06Dec2017-16h48m&utm_term=all-MF-18-65-06Dec2017-16h48m&utm_content=test_testadinadset-00-CarouselAd-06Dec2017-19h44m&utm_id=2b301660-01c2-4c21-9fe1-06863dbaac92"
}
}
}]
}
}
}
I've made sure that in "child_attachments". "link" and "call_to_action.value.link" have the same value, but I keep getting the same error. I've also tried escaping the links, removing spaces etc. I've been seeing this behaviour since 10 hours or so.
Despite's OP incorrect link values in the child_attachment and call_to_action, this has been confirmed by Facebook as a valid bug:
https://developers.facebook.com/bugs/310154929502029/
https://developers.facebook.com/bugs/1909897769263210/
I'm guessing OP was testing a lot of different combinations and this one he posted happened to have different values.
Hopefully this will be fixed soon.
Hoping someone could explain the proper process for this. I have a data structure like this:
[
{
Author => "101",
WK1 => "",
WK10 => "",
WK11 => "",
WK12 => "",
WK13 => "",
WK14 => "X",
WK15 => "",
},
{
Author => "102",
WK1 => "",
WK10 => "",
WK11 => "",
WK12 => "X",
WK13 => "X",
WK14 => "",
WK15 => "",
WK2 => "X",
WK3 => "X",
WK4 => "",
},
{
Author => "101",
WK1 => "",
WK10 => "",
WK11 => "",
WK12 => "",
WK13 => "",
WK14 => "X",
WK15 => "X",
},
]
WK keys may or may not exist. The Author key will always exist, and I’m trying to merge those duplicates. Overwriting values is ok (if defined).
Should I try map (not sure how), or would it be better to create a new hash using the Author as key, pushing the other values into an array? Something like
foreach $x (#$data) {
%new_hash = ...
...
}
scratching head
It sounds like you are starting with something like the following:
my $records = [
{ Author => "101", WK1 => "", WK2 => "X", WK3 => "X" },
{ Author => "101", WK1 => "X", WK2 => "", WK4 => "X" },
{ Author => "102", WK1 => "", WK2 => "", WK3 => "X" },
];
It sounds like you want to produce the following:
my $records_by_author = (
"101" => { Author => "101", WK1 => "X", WK2 => "", WK3 => "X", WK4 => "X" },
"102" => { Author => "102", WK1 => "", WK2 => "", WK3 => "X" },
);
The following will do that:
my %records_by_author;
for my $record (#$records) {
my $author = $record->{Author};
$records_by_author{$author} = {
( $records_by_author{$author} ? %{ $records_by_author{$author} } : () ),
%$record,
};
}
If instead you want the following output:
my $records = [
{ Author => "101", WK1 => "X", WK2 => "", WK3 => "X", WK4 => "X" },
{ Author => "102", WK1 => "", WK2 => "", WK3 => "X" },
];
Just add the following:
$records = [ values(%records_by_author) ];
It you want this output and you want to preserve the original order, let me know.
I suggest merging along the lines of the code below. From each anonymous hash in #$data, grab the author identifier and then update the merged WK values where we never overwrite a non-empty string with an empty one.
You could do the same with map, and that would be a worthwhile exercise. It seems to read much more naturally as nested structural loops.
my %authorwk;
for (my $i = 0; #$data; ++$i) {
local $_ = shift #$data;
die "$0: missing Author in record $i" unless exists $_->{Author};
my $author = $_->{Author};
while (my($wk,$present) = each %$_) {
next unless $wk =~ /^WK/;
$authorwk{$author}{$wk} = $present
if $present || !exists $authorwk{$author}{$wk};
}
}
map is inappropriate here: a series of slice assignments is all that is necessary
It looks like this. Note that the only duplicate author 101 has an identical set of keys in both instances, so I've added key WK7 to the first instance and WK8 to the second so that you can see that they are both added to the result
use strict;
use warnings 'all';
my $data = [
{
Author => 101,
WK7 => "7", WK1 => "", WK10 => "", WK11 => "",
WK12 => "", WK13 => "", WK14 => "X", WK15 => "",
},
{
Author => 102,
WK1 => "", WK10 => "", WK11 => "", WK12 => "X",
WK13 => "X", WK14 => "", WK15 => "", WK2 => "X",
WK3 => "X", WK4 => "",
},
{
Author => 101,
WK8 => "8", WK1 => "", WK10 => "", WK11 => "",
WK12 => "", WK13 => "", WK14 => "X", WK15 => "X",
},
];
my %authors;
for my $item ( #$data ) {
my $author = $item->{Author};
#{ $authors{$author} }{keys %$item} = values %$item;
}
use Data::Dump;
dd \%authors;
output
{
101 => {
Author => 101,
WK1 => "",
WK10 => "",
WK11 => "",
WK12 => "",
WK13 => "",
WK14 => "X",
WK15 => "X",
WK7 => 7,
WK8 => 8,
},
102 => {
Author => 102,
WK1 => "",
WK10 => "",
WK11 => "",
WK12 => "X",
WK13 => "X",
WK14 => "",
WK15 => "",
WK2 => "X",
WK3 => "X",
WK4 => "",
},
}
I could NOT get back the email information anymore with Omniauth.
I think the problem is duing to the API 2.4,
But I don't get how could I the the expected information
Devise config
config.omniauth :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], {
:scope => 'email',
:info_fields => 'id,email,gender,link,locale,name,timezone,updated_time,verified',
strategy_class: OmniAuth::Strategies::Facebook,
:provider_ignores_state => true}
Returned information not including email information
:1> env['omniauth.auth']
{
"provider" => "facebook",
"uid" => "xxxx",
"info" => {
"name" => "Eric Hsu",
"image" => "http://graph.facebook.com/xxxx/picture?type=square"
},
"credentials" => {
"token" => "CAAh",
"expires_at" => 1443066205,
"expires" => true
},
"extra" => {
"raw_info" => {
"name" => "Eric Hsu",
"id" => "xxxx"
}
}
}
I found the problem is that the dependency between FB API and omniauth-facebook version.
current i installed the gem omniauth-facebook (2.0.1)
Unfortunately, I cannot use positional operators since there is a bug that doesn't allow deeper than 1 embedded document: https://jira.mongodb.org/browse/SERVER-831
So this wont work (using the Mongodb Ruby driver):
stat_profile.update({ profile_id: profile.id, providers: { '$elemMatch' => { provider_name: 'foo', dates: { '$elemMatch' => { date: 20130911, relationships: { '$elemMatch' => { relationship_type: 'friend' } } } } } } },
{ '$set' => { 'providers.$.dates.$.relationships.$.ids' => [1,2,3] } })
Given the following collection. Relationships is embedded in dates, dates is embedded in providers.
How do I update the ids field?
{
"_id" => BSON::ObjectId('523048983858f61767000008'),
"profile_id" => 3,
"providers" => [
[0] {
"provider_name" => "foo",
"dates" => [
[0] {
"date" => 20130911,
"relationships" => [
[0] {
"relationship_type" => "acquaintance",
"count" => 0
},
[1] {
"relationship_type" => "friend",
"count" => 0,
"males_count" => 0,
"females_count" => 0,
"top_ten_countries" => [],
"ids" => []
}
]
}
]
}
]
}