How do I know the argument should be an object and not array? - podio

$new_contact = PodioContact::create(
2144836,
new PodioContact(
array('name' => $name,'title'=>$title, 'organization'=>$org, 'phone' => $phone, 'mail' => $email)
)
);
Above is the method of creating a new contact. It accepts 2 arguments, first is a integer for workspace id, the second one is an Contact object which holds the contact details.
Referring to here https://developers.podio.com/doc/contacts/create-space-contact-65590, I clearly know what should be the first argument, which was the workspace id.
However the second argument is stated as $attributes = array() in the API Doc which is an array. I ASSUMED this to be a key value array of the contact's properties. I proceeded to pass a key value array into the second argument like so:
$new_contact = PodioContact::create(
2144836,
array('name' => $name,'title'=>$title, 'organization'=>$org, 'phone' => $phone, 'mail' => $email)
);
It kept failing to work. After struggling and wasting 1 hour. I simply tried to pass an Contact Object as the second argument as shown in the beginning of this post. So with this trial and error and wasting a large amount of time, I discovered what should be the second argument by luck.
So my question is, why is the API Doc showing the second argument should be an array? Is the documentation wrong or am I missing something? Could you please tell me if I did anything wrong here so I don't have to trial and error and waste 1~2hours to figure out the second argument.

It's really much the same thing. When you pass in a Podio* object as the attributes parameter podio-php will serialize it by calling the as_json method on that object (and it'll then be an associative array). If you kick podio-php into a debug mode you can see exactly what's being sent over the wire: http://podio.github.io/podio-php/debug/

Related

Errors using Metamodel::ConcreteRoleHOW.new_type

There does not seem to be a way to use new_type in MetamodelConcreteRoleHOW, which as its name implies should be used to create new instances of a Role. The main problem is when you try to mix-in new roles, as implied by the signature ( method new_type(:#roles, :$name = '<anon>', :$ver, :$auth, :$repr, :$api)):
my $a = Metamodel::ConcreteRoleHOW.new_type(name => "Bar", roles => [Iterable]);
$a.^compose;
say $a.^roles;
# Error: «Cannot iterate object with P6opaque representation (Array)␤
Using another Positional, a list, yields a different error:
my $a = Metamodel::ConcreteRoleHOW.new_type(name => "Bar", roles => (Iterable));
$a.^compose;
say $a.^roles
# « Cannot iterate over a Iterable type object␤»
Beats me what kind of positional could I use there. To be sure, this is implemented in NQP, so maybe I should be defining an NQP array. But I really have no idea. Any help will be appreciated.
Edit. First, the error happens when you call compose. Second, you effectively have to use an NQP array as Raiph says
use nqp;
my $roles := nqp::list(Iterable);
my $a = Metamodel::ConcreteRoleHOW.new_type(name => "Bar", roles => $roles);
$a.^compose;
say $a.^is_composed();
say $a.^roles # OUTPUT: «1␤(Mu)␤»
compose works now, and it is actually composed, but the roles composed still show only the ur-role, Mu, not Iterable which is the one that should have been added to it. Any idea?

Automapper Constructor Parameters

I've just started using this and immediately ran into a problem mapping a parameter to a a constructor parameter.
I've tried every example I can find on SO but none seem to work and the documentation doesn't mention this feature as far as I can see.
The examples show:
Mapper.CreateMap<UserProfile, UserProfileModel>().ConstructUsing(x => new UserProfileModel(x.Id);
I can't figure out the syntax to get access to the Id property on the UserProfile object.
Another example shows:
Mapper.CreateMap<TypeOneDto, TypeOne>().ConstructUsing((Func<ResolutionContext, TypeOne>) (r => new TypeOne()));
On using any of these lambdas I just have access to the ResolutionContext not the parent object?
Any Ideas?

RavenDB - Get IDs of root property within a non-root level property

With RavenDB, is it possible to get the IDs of a property within another property? For example, if Foo has a list of Bar objects, and each Bar object has a SnuhId property, can I use an Include that gets the IDs of each Snuh property?
I tried the query below, but I get a RavenDB exception: index out of range. In this query, ApplicationServer is a root element, and it has a list of ApplicationsWithOverrideGroup objects. Each of those objects has an ApplicationId property. It's the ApplicationId that I want to get in the include.
IEnumerable<ApplicationServer> appServers = QueryAndCacheEtags(session =>
session.Advanced.LuceneQuery<ApplicationServer>()
.Include(x => x.CustomVariableGroupIds)
// This is the line I'm trying to make work:
.Include(x => (from item in x.ApplicationsWithOverrideGroup select item.ApplicationId).ToList())
).Cast<ApplicationServer>();
Either of these approaches appears to be working. Need to thoroughly test.
.Include(x => x.ApplicationsWithOverrideGroup)
or
.Include(x => x.ApplicationsWithOverrideGroup[0].ApplicationId)
If that first option is indeed working, then a property, specified in an Include(), will include the ID properties within it. Is that right?
I'm not sure if both of those are really working, but they seem to be. If they both work, I wonder if one is better than the other...
Ok, that's NOT WORKING. The NumberOfRequests is increasing, which I'm guessing means the number of trips to the DB is increasing, instead of just what's in the session.
Ok, none of those suggestions worked in the question above. I think what has to be done is to include the IDs of the nested properties in the root object.
And that's what I did, and I was able to get the NumberOfRequests on the session object down to one. Curiously, I had to change this:
// Not using this, at least for now, because it increased the NumberOfRequests on the session...
appServer.CustomVariableGroups = new ObservableCollection<CustomVariableGroup>(
QueryAndCacheEtags(session => session.Load<CustomVariableGroup>(appServer.CustomVariableGroupIds)).Cast<CustomVariableGroup>());
To this:
// ... however, this kept the NumberOfRequests to just one. Not sure why the difference.
appServer.CustomVariableGroups = new ObservableCollection<CustomVariableGroup>();
foreach (string groupId in appServer.CustomVariableGroupIds)
{
appServer.CustomVariableGroups.Add(QuerySingleResultAndCacheEtag(session => session.Load<CustomVariableGroup>(groupId)) as CustomVariableGroup);
}

Finding user that have at least one tag object in linq?

I have an object User.
User 1..N Tags(string).
For instance, i have a List of Tag object. How can i query the User to find all the user that have at least 1 Tag in side the list of tags?
Thanks in advance :)
Assuming your code snippet means you have a property Tags of type Foo<string> where Foo is some sequence type, you could just use:
var taggedUsers = users.Where(user => tags.Any(tag => user.Tags.Contains(tag));
(Actually, that's assuming you have a list of strings as Tags - the question is somewhat unclear. However, hopefully it'll be enough to sort you out.)
EDIT: Okay, with the details in the comments, I think you probably just need:
var taggedUsers = users.Where(user => tags.Any(tag => user.Tags
.Select(t => t.Value)
.Contains(tag));

RhinoMocks expecting call with the exact value

Sometimes Rhino.Mocks is driving me mad, 'cause there's not enough documentation on topics that, I suppose, are relatively easy.
What I want to do is to expect call to AddContact("test", contact). So for the second parameter I must use parameter constraint Property.AllPropertiesMatch(contact). But what should I use for the first one?
_contactManagerMock
.Expect(m => m.AddContact(null, null))
.Constraints(??????????, Property.AllPropertiesMatch(contact));
What goes instead of "??????????"
I was looking for this as well, here is a more detailed answer.
This is an example of how to use the AllPropertyMatch in Rhino.Mocks. I tested this in Rhino.Mocks 3.6.
//arrange
var contactManagerMock = MockRepository.GenerateMock<IManager>();
contactManagerMock.Expect(m => m.AddContact(
Arg.Is("test"),
Arg<Contact>.Matches(Property.AllPropertiesMatch(contact))))
//Act
//Perform action here that should result in the above expected call
//Assert
contactManagerMock.VerifyAllExpectations();
This says to expect the AddContact method to be called. The first parameter should be a string with the value 'test' the second should be an object of type Contact that has all the same properties as the instance of contact.
Calling VerifyAllExpectations performs the assertion.
More info on the Rhino.Mocks site.