mailerlite/mailerlite-api-v2-php-sdk

No segments support

zeve-zz opened this issue · 17 comments

it looks like the segments api is not actually implemented (but the documentation gives examples)

$segmentsApi = (new \MailerLiteApi\MailerLite(api_key_here))->segments();

results in:

Call to undefined method MailerLiteApi\MailerLite::segments

hello @zeve-zz ,

Please make sure you're using the latest version because I just tried out the segments and they do work in the latest version

test.php

<?php
include 'vendor/autoload.php';

$groupsApi = (new \MailerLiteApi\MailerLite('your-api-key'))->segments();
var_dump($groupsApi);              
➜  mailerlite-api-v2-php-sdk git:(master) ✗ php test.php
object(MailerLiteApi\Api\Segments)#4 (6) {
  ["endpoint":protected]=>
  string(8) "segments"
  ["restClient":protected]=>
  object(MailerLiteApi\Common\RestClient)#2 (3) {
    ["httpClient"]=>
    NULL
    ["apiKey"]=>
    string(12) "your-api-key"
    ["baseUrl"]=>
    string(34) "https://api.mailerlite.com/api/v2/"
  }
  ["_limit":"MailerLiteApi\Common\ApiAbstract":private]=>
  NULL
  ["_offset":"MailerLiteApi\Common\ApiAbstract":private]=>
  NULL
  ["_order":"MailerLiteApi\Common\ApiAbstract":private]=>
  NULL
  ["_where":"MailerLiteApi\Common\ApiAbstract":private]=>
  NULL
}

@dominykasmailer yes i am using the latest build in master that is available here on GitHub, and, using the vendor file that the documentation links here (http://bit.ly/ml-php-sdk-0_1_10).

there is still no segment support. if you look at the segments.php file, it looks to just be:

`<?php

namespace MailerLiteApi\Api;

use MailerLiteApi\Common\ApiAbstract;

class Segments extends ApiAbstract {

protected $endpoint = 'segments';

}`

please test against the actual release here

@zeve-zz yes that's the correct contents of Segments file

This is the master branch code
https://github.com/mailerlite/mailerlite-api-v2-php-sdk/blob/master/src/MailerLite.php#L100

Make sure your file contents match the #100 line in the src/MailerLite.php file

I just cloned the master and it works like it should with segments

@dominykasmailer it matches. what else can i check?

starting with line 97
/**
* @return \MailerLiteApi\Api\Segments
*/
public function segments()
{
return new \MailerLiteApi\Api\Segments($this->restClient);
}

@zeve-zz
test.php

<?php
include 'vendor/autoload.php';

$client = (new \MailerLiteApi\MailerLite('your-api-key'));
var_dump(get_class_methods($client));

My output is this:

➜  mailerlite-api-v2-php-sdk git:(master) ✗ php index.php
array(10) {
  [0]=>
  string(11) "__construct"
  [1]=>
  string(6) "groups"
  [2]=>
  string(6) "fields"
  [3]=>
  string(11) "subscribers"
  [4]=>
  string(9) "campaigns"
  [5]=>
  string(5) "stats"
  [6]=>
  string(8) "settings"
  [7]=>
  string(11) "woocommerce"
  [8]=>
  string(8) "segments"
  [9]=>
  string(10) "getBaseUrl"
}

What's your output?

@dominykasmailer

array(6) {
[0]=>
string(11) "__construct"
[1]=>
string(6) "groups"
[2]=>
string(6) "fields"
[3]=>
string(11) "subscribers"
[4]=>
string(9) "campaigns"
[5]=>
string(10) "getBaseUrl"
}

@zeve-zz
that's because you're using an old version

Check if you don't have multiple installations or you're in the wrong directory :)

@dominykasmailer i am using the version available here :/

there's nothing else on the server.

simply downloaded the src from here, and the vendor file available in that link, and uploaded it. nothing else is happening.

@zeve-zz the link you provided includes 0.1.10 in the name
Can you try to download version 0.2.3 from here?
https://github.com/mailerlite/mailerlite-api-v2-php-sdk/archive/0.2.3.zip

@dominykasmailer the link i included came from the readme on the master branch:

Manual (preferable for shared hostings)

This way is preferable only if you are using shared hosting and do not have a possibility to use Composer. You will need to download this archive, extract it and place its contents in root folder of your project. The next step is the same as using Composer, you will need to require vendor/autoload.php file in your index.php and lets dive in!

@zeve-zz then my only guess is that you're using some package that can't get the 0.2.x version because of some dependencies :)

Try and tell me the output:
composer require mailerlite/mailerlite-api-v2-php-sdk:0.2.3

@dominykasmailer i am not using composer.

@zeve-zz oh I understood now.

He's the version with vendor/composer install

mailerlite-api-v2-php-sdk-0-2-3.zip

@dominykasmailer i see what is going on.

i have a folder called MailerLite, and within it are folders 'api', 'common', 'exceptions', 'vendor', and MailerLite.php.

vendor is a folder downloaded from the link that is in the readme file

but the MailerLite within the vendor folder looks to be outdated. for example, there is no 'segments.php' file within vendor->mailerlite->mailerlite-api-v2-php-sdk->src->api

same thing for the link you just sent me. and no line 100 within that. please take a look. am i totally misunderstanding how this should work?

@zeve-zz sorry that was the wrong archive.

mailerlite-sdk.zip

This is the latest one with composer's vendor

@dominykasmailer now it works. thanks. i think the documentation needs to be updated. you're linking to an old vendor archive which is why this started

@zeve-zz yes apparently we are, thanks and sorry!