Giter Site home page Giter Site logo

sailthru-php5-client's Introduction

sailthru-php5-client

Build Status Coverage Status

For installation instructions, documentation, and examples please visit: http://getstarted.sailthru.com/new-for-developers-overview/api-client-library/php5

A simple client library to remotely access the Sailthru REST API as per http://getstarted.sailthru.com/developers/api

By default, it will make request in JSON format.

Optional parameters for connection/read timeout settings

Increase timeout from 10 (default) to 30 seconds.

$client = new Sailthru_Client($this->api_key, $this->secret, $this->api_url, array('timeout' => 30000, 'connect_timeout' => 30000));

API Rate Limiting

Here is an example how to check rate limiting and throttle API calls based on that. For more information about Rate Limiting, see Sailthru Documentation

// get last rate limit info
$rate_limit_info = $sailthru_client->getLastRateLimitInfo("user", "POST");

// getRateLimitInfo returns null if given endpoint/method wasn't triggered previously
if ($rate_limit_info) {
    $limit = $rate_limit_info['limit'];
    $remaining = $rate_limit_info['remaining'];
    $reset_timestamp = $rate_limit_info['reset'];

    // throttle api calls based on last rate limit info
    if ($remaining <= 0) {
        $seconds_till_reset = $reset_timestamp - time();

        // sleep or perform other business logic before next user api call
        sleep($seconds_till_reset);
    }
}

Tests

You can run the tests locally with:

vendor/bin/phpunit

sailthru-php5-client's People

Contributors

cranberyxl avatar dannyo avatar dsposito avatar eonwhite avatar fkim-sailthru avatar georgekliao avatar hsuk-404 avatar infynyxx avatar jack-lewis-87 avatar jimmycdchen avatar jontas avatar kojoman avatar matthewgoslett avatar maxenglander avatar mm0 avatar mydagobah avatar nartmal avatar pweids avatar rossmotley avatar showerst avatar silverman63 avatar sinneduy avatar tystr avatar yavorm avatar zencephalon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sailthru-php5-client's Issues

PHP 7 plans?

Hi,

Are there any plans for a PHP 7 compatible client? Would it be a new library given the naming of this one?

Thanks,

Ross

Preview the template with parsed values

I know there is an API call how you can get the HTML of the template
as mentioned here:
http://docs.sailthru.com/api/template

$sailthru_client->getTemplate('welcome','24242');

But the template isn't parsed. Even if I have the variables locally at my CMS its a pain to parse the template and to replace each variable.
Its getting even worst if you think that there can be expressions like

while
for 
if

as mentioned here http://docs.sailthru.com/syntax/expressions.
Could you point me to some parser class that Sailthru is using in order to do the parsing locally it would be even better if there would be a way in the API to get the parsed template.

This is some sort of feature request.

No Hardbounce postback method

Hi,

It looks like there is no "receiveHardbouncePost" method analog to, for example, receiveOptoutPost() in the sailthru client. I've been testing the hardbounce postback and it appears that the authentication scheme currently used by sailthru should match that of the other postbacks, although documentation on their end seems a little out of sync with how things are actually done (they mainly talk about "triggermail" when referring to the PHP postback handler, which is no longer mentioned in their client libs list).

I'll aim to post a patch to add this shortly unless one of the original developers can do this faster than me.

Best,
Alan

Feature request: Extract HTTP logic into a new class

I think it would be a good thing to extract the following two methods into a new $transport object, which implements some sort of interface:

\Sailthru_Client::httpRequestCurl
\Sailthru_Client::httpRequestWithoutCurl

This will make it easier to:

  • Unit test the Sailthru_Client class without resorting to partial mocks
  • Add logging or other implementations (Guzzle? Buzz?)

We could provide two implementations in this codebase, curl and streams, which don't have any other dependencies.

The interface could potentially make use of the PSR7:

http://www.php-fig.org/psr/psr-7/

Sailthru_Client user agent reports PHP version

Hi,

First up, thanks so much for writing this library, it's made integrating Sailthru with Drupal a lot easier. I've put a module up on my Sandbox that wraps the library in a Drupal module: http://drupal.org/sandbox/serenecloud/1126772

Anyway, during this process I saw that the library as it stands reports the PHP version it's running on. I totally understand the desire for this to be known but it does mean the library is leaking information to a 3rd party, which isn't desirable from a security perspective.

Can we please have this as an option (defaulting to on if you want) so that we can decide if we want to share this information about our systems? I'm happy to roll a patch for this.

Thanks,
Ben

Method name typo

Line 1054:
public function getUseBySid($id, array $fields = array()) {
return $this->apiGet('user', array('id' => $id));
}

missing 'r', should be "getUserBySid"

Tag discovery not working in packagist

Hi, we have been trying to install this library via Composer.

Using dev-master as version works, but tags are not being discovered. If you have a look at https://packagist.org/packages/sailthru/sailthru-php5-client you will see that all the available packages are dev-* branches and the tags are not there.

My best guess is that your tag names convention using v1.09 instead of v1.0.9 is confusing either packagist or composer.

Would it be possible that you have a look at this so that we don't have to point at dev-master? Or what would be the way to install one of the tags?

Thanks

getUserByKey default response is not working properly

Hi,

In the following documentation: https://getstarted.sailthru.com/new-for-developers-overview/email-and-user-profiles/user/#User_Profile_Fields_Reference

We can read this in the documentation for the parameter "fields" : The default response consists of keys, vars, lists, engagement, and optout_email.

In the code, if the parameter "fields" is not set, its default value is an empty array.
public function getUserByKey($id, $key, array $fields = [ ])

The problem is, if you call that function using the default values, the payload will contain an empty fields array. The response is literally this:
[]

For the default response to work, the payload must not contain the fields parameters, but the way the function is done, it always include an empty fields array if it's not set. We can't access the default response because of that.

Unless that is wanted and the documentation is out of date. I'm not sure on that part, that's why I'm opening an issue so you can decide. :)

Thank you and have a nice day!

Release 1.2.4

The bug that was fixed in #72 is also affecting us. We can see that it has been merged successfully.
Please can a new release be tagged so we can continue work without having to fork or target dev-master.

Thank you

Client throws "empty response" exception for all curl errors

Hi,

When debugging a timeout from the Sailthru API, I noticed that currently the code is throwing an "empty response" exception for all curl errors:

        $response = curl_exec($ch);
        // ...

        if (!$response) {
            throw new Sailthru_Client_Exception(
                "Bad response received from $url",
                Sailthru_Client_Exception::CODE_RESPONSE_EMPTY
            );
        }

Here, $response is the response body or false to indicate an error from curl. It's easy to get the actual error with curl_error(), which could be added as a new exception type, something like: Sailthru_Client_Exception::CODE_HTTP_ERROR or similar. That would provide a much more helpful error for developers.

I'm happy to make a little PR for this, but wanted to check that it would be accepted, as it's a BC break of some sort.

Thanks,

Ross

Bad response due to CURLOPT_SSL_VERIFYPEER = true

Hi,
I was trying to get the template list and got this error message:
Sailthru_Client_Exception: Bad response received from https://api.sailthru.com/template?api_key=Key_removed&format=json&json=%5B%5D&sig=sig_removed in Sailthru_Client->httpRequestCurl() (line 1091 of C:\wamp\www\some_project_folders\Sailthru_Client.php).

After some investigation it turned out that this was due to CURLOPT_SSL_VERIFYPEER that needed to be turned off.
Adding this in line 1067 solved my problem:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

This is a dev testing project running win7/wamp.

Is there a better way to solve this without hacking your code?

Thanks,
Mike

Optional Parameter [test] should allow FALSE or 0

Recently encountered an issue in production when sending emails using the Sailthru PHP client.

In DEV + UAT I was sending emails with the optional parameter [test] set to 'TRUE', and this was working fine. In production however this attribute was set to 'FALSE'.

In the error logs, I see the following errors (client information has been stripped):

May 13 09:22:58 Sailthru Error - Code: 5 with error message: Signature hash does not match
May 13 09:25:18 Sailthru_Client_Exception: Bad response received from https://api.sailthru.com/send in Sailthru_Client->httpRequestCurl() (line 797 of /var/www/drupal-site-nzpost/sites/all/modules/custom/sailthru_client/lib/sailthru/Sailthru_Client.php).

Upon further investigation it looks like the hashing function fails to work when there is an attribute called 'test' with a value of 'FALSE'.

My question is, can the PHP lib for Sailthru be enhanced to support booleans (both TRUE and FALSE), for the optional attribute 'test'?

New release?

Hi there, latest release is 1.2.3, which is 10 commits behind master. Can you guys please create a new release? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.