pacely / mailchimp-api-v3

API client for Mailchimp API v3
MIT License
96 stars 37 forks source link

Error initiating: Call to undefined method Mailchimp\MailchimpFacade::request() #14

Closed longestdrive closed 8 years ago

longestdrive commented 8 years ago

Hi I'm having trouble initiating this package correctly in laravel 5.1. Probably a PICNIC error but need some help!

I've installed the package, added the service provider and facade per the docs. I've published the config file and added my apikey.

However trying the sample code for a simple request of lists I'm coming up with this error:

Call to undefined method Mailchimp\MailchimpFacade::request()

Here's my code:

$mc = new MC;

    $result = $mc->request( 'lists' , [
        'fields' => 'lists.id,lists.name,lists.stats.member_count' ,
        'offset' => 0 ,
        'count' => 10
    ] );

    ddd($result);

If I try and initiate mailchimp direct I am able to get the list as expected but that appears to be bypassing the package and I'd rather use the facade and not have to worry about pulling the apikey etc.

This works:

$mc = new \Mailchimp\Mailchimp('xxxxx xxxxx');

    $result = $mc->request( 'lists' , [
        'fields' => 'lists.id,lists.name,lists.stats.member_count' ,
        'offset' => 0 ,
        'count' => 10
    ] );

What am I doing wrong? How can I use the facade correctly?

Thanks

longestdrive commented 8 years ago

Hi

After a bit of fiddling I got this to work by doing the following:

change my code to:

$result = MC::request( 'lists' , [
        'fields' => 'lists.id,lists.name,lists.stats.member_count' ,
        'offset' => 0 ,
        'count' => 10
    ] );

    ddd($result);

This then gave a Mailchimp class not found error. After a bit of fiddling I changed the serviceprovider to the following:

public function register()
    {
        $this->app->bind('Mailchimp', function ($app) {
            $config = $app['config']['mailchimp'];

            return new Mailchimp($config['apikey']);
        });
    }

And it now works - Is this correct though - by changing the namespace in the service provider will this break in further releases or is something wrong in my configuration?

Thanks

SolStis86 commented 8 years ago

There is a bug in the MailchimpFacade.php - needs to return "Mailchimp\Mailchimp" rathern than just "Mailchimp"

aididjaafar commented 8 years ago

I encountered the same problem.