diff --git a/composer.json b/composer.json index 7866820..5fa39d0 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "require": { "php": ">=5.5", "guzzlehttp/guzzle": "^6.3", - "monolog/monolog": "^1.0" + "monolog/monolog": "^2.0" }, "require-dev": { "phpunit/phpunit": "^6.0" @@ -20,4 +20,4 @@ }, "minimum-stability": "dev", "prefer-stable": true -} \ No newline at end of file +} diff --git a/src/ConvertKit_API.php b/src/ConvertKit_API.php index c49a29e..4ddee17 100644 --- a/src/ConvertKit_API.php +++ b/src/ConvertKit_API.php @@ -417,6 +417,45 @@ public function get_subscriber( $subscriber_id ) { } + /** + * Update subscriber + * + * @param int $subscriber_id Subscriber ID. + * @param array $data Subscriber data. + * @return false|int + */ + public function update_subscriber( $subscriber_id, $data ) { + + if( !is_int($subscriber_id) || $subscriber_id < 1 ) { + throw new \InvalidArgumentException; + } + + $request = $this->api_version . sprintf( '/subscribers/%s', $subscriber_id ); + + $options = array( + 'api_secret' => $this->api_secret, + ); + + if ( array_key_exists( 'first_name', $data ) ) { + $options['first_name'] = $data['first_name']; + unset( $data['first_name'] ); + } + + if ( array_key_exists( 'email_address', $data ) ) { + $options['email_address'] = $data['email_address']; + unset( $data['email_address'] ); + } + + if ( $data ) { + $options['fields'] = $data; + } + + $this->create_log(sprintf("PUT update subscriber: %s, %s, %s", $request, json_encode($options), $subscriber_id)); + + return $this->make_request( $request, 'PUT', $options ); + + } + /** * Get a list of the tags for a subscriber. *