ActiveCampaign / activecampaign-api-php

MIT License
115 stars 76 forks source link

Iterator interface would be nice for responses with arrays #67

Open grimmdude opened 7 years ago

grimmdude commented 7 years ago

It would be helpful if the response object implemented an iterator interface when the data includes an array so that something like this would work as expected:

$lists = api("list/list", array("ids" => "all");
if ($lists->success) {
    foreach($lists as $list) {
        echo $list->id;
    }
}

Intuitively that would just iterate through the lists, but currently it includes all visible properties of the object so you can't really use it like that. I realize that iterating over $lists->{0} will work instead, but just thought I would suggest this improvement. Thanks!

-Garrett

grimmdude commented 7 years ago

Actually, even iterating over $lists->{0} doesn't seem to work as expected. If there is only one list this will be a flat object, not an array with a single object in it.

grimmdude commented 7 years ago

Last message I promise.

Just realized $lists->{0} will always only return one item, but according to the API docs (http://www.activecampaign.com/api/example.php?call=list_list) property0 is an array. 😕

-Garrett