From 6f51004163ed645dbbdb843e0d580f155159321c Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Thu, 26 May 2016 00:27:52 -0500 Subject: [PATCH 01/17] upgraded to the latest phpunit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 60e9890..e7d8656 100755 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "guzzle/guzzle": "~3.7" }, "require-dev": { - "phpunit/phpunit": "~3.7.0" + "phpunit/phpunit": "5.3.*" }, "homepage": "http://keen.io", "autoload": { From 3339a0fc37a2007396991bbf74e515159bd4b6a5 Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Thu, 26 May 2016 00:30:59 -0500 Subject: [PATCH 02/17] implemented get saved queries Added the request structure to retrieve an array of saved queries available to the user on this project --- src/Client/KeenIOClient.php | 1 + src/Client/Resources/keen-io-3_0.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Client/KeenIOClient.php b/src/Client/KeenIOClient.php index 4dc8d76..1821c05 100755 --- a/src/Client/KeenIOClient.php +++ b/src/Client/KeenIOClient.php @@ -18,6 +18,7 @@ * @method array getProjects(array $args = array()) {@command KeenIO getProjects} * @method array getProject(array $args = array()) {@command KeenIO getProject} * @method array getProperty(array $args = array()) {@command KeenIO getProperty} + * @method array getQueries(array $args = array()) {@command KeenIO getProperty} * @method array getEventSchemas(array $args = array()) {@command KeenIO getEventSchemas} * @method array deleteEvents(array $args = array()) {@command KeenIO deleteEvents} * @method array deleteEventProperties(array $args = array()) {@command KeenIO deleteEventProperties} diff --git a/src/Client/Resources/keen-io-3_0.php b/src/Client/Resources/keen-io-3_0.php index afce41c..9770cd7 100755 --- a/src/Client/Resources/keen-io-3_0.php +++ b/src/Client/Resources/keen-io-3_0.php @@ -52,6 +52,22 @@ ), ), + 'getQueries' => array( + 'uri' => 'projects/{projectId}/queries/saved', + 'description' => 'Returns the saved queries accessible to the API user on the specified project.', + 'httpMethod' => 'GET', + 'parameters' => array( + 'masterKey' => array( + 'location' => 'header', + 'description' => 'The Master API Key.', + 'sentAs' => 'Authorization', + 'pattern' => '/^([[:alnum:]])+$/', + 'type' => 'string', + 'required' => true, + ), + ), + ), + 'getCollections' => array( 'uri' => 'projects/{projectId}/events', 'description' => 'GET returns schema information for all the event collections in this project, including properties and their type. It also returns links to sub-resources.', From be3c3592eeed6153fc641befcfe92543d2599ab3 Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Thu, 26 May 2016 00:41:34 -0500 Subject: [PATCH 03/17] implemented getting a named query Added the request structure to retrieve a named query available to the user on a project --- src/Client/KeenIOClient.php | 1 + src/Client/Resources/keen-io-3_0.php | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Client/KeenIOClient.php b/src/Client/KeenIOClient.php index 1821c05..711bb57 100755 --- a/src/Client/KeenIOClient.php +++ b/src/Client/KeenIOClient.php @@ -19,6 +19,7 @@ * @method array getProject(array $args = array()) {@command KeenIO getProject} * @method array getProperty(array $args = array()) {@command KeenIO getProperty} * @method array getQueries(array $args = array()) {@command KeenIO getProperty} + * @method array getQuery(array $args = array()) {@command KeenIO getProperty} * @method array getEventSchemas(array $args = array()) {@command KeenIO getEventSchemas} * @method array deleteEvents(array $args = array()) {@command KeenIO deleteEvents} * @method array deleteEventProperties(array $args = array()) {@command KeenIO deleteEventProperties} diff --git a/src/Client/Resources/keen-io-3_0.php b/src/Client/Resources/keen-io-3_0.php index 9770cd7..b76c4c3 100755 --- a/src/Client/Resources/keen-io-3_0.php +++ b/src/Client/Resources/keen-io-3_0.php @@ -68,6 +68,27 @@ ), ), + 'getQuery' => array( + 'uri' => 'projects/{projectId}/queries/saved/{query_name}', + 'description' => 'Returns the detailed information about the specified query, as well as links to retrieve results.', + 'httpMethod' => 'GET', + 'parameters' => array( + 'masterKey' => array( + 'location' => 'header', + 'description' => 'The Master API Key.', + 'sentAs' => 'Authorization', + 'pattern' => '/^([[:alnum:]])+$/', + 'type' => 'string', + 'required' => true, + ), + 'query_name' => array( + 'location' => 'uri', + 'description' => 'The saved query.', + 'required' => true, + ), + ), + ), + 'getCollections' => array( 'uri' => 'projects/{projectId}/events', 'description' => 'GET returns schema information for all the event collections in this project, including properties and their type. It also returns links to sub-resources.', From 1eeb7b4a3eea1e5a9c6e0b1ba706856613f254ea Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Thu, 26 May 2016 00:49:59 -0500 Subject: [PATCH 04/17] implemented getting the query results Added the request structure to retrieve the results for a specific named query --- src/Client/KeenIOClient.php | 1 + src/Client/Resources/keen-io-3_0.php | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Client/KeenIOClient.php b/src/Client/KeenIOClient.php index 711bb57..7c4ad06 100755 --- a/src/Client/KeenIOClient.php +++ b/src/Client/KeenIOClient.php @@ -20,6 +20,7 @@ * @method array getProperty(array $args = array()) {@command KeenIO getProperty} * @method array getQueries(array $args = array()) {@command KeenIO getProperty} * @method array getQuery(array $args = array()) {@command KeenIO getProperty} + * @method array getQueryResults(array $args = array()) {@command KeenIO getProperty} * @method array getEventSchemas(array $args = array()) {@command KeenIO getEventSchemas} * @method array deleteEvents(array $args = array()) {@command KeenIO deleteEvents} * @method array deleteEventProperties(array $args = array()) {@command KeenIO deleteEventProperties} diff --git a/src/Client/Resources/keen-io-3_0.php b/src/Client/Resources/keen-io-3_0.php index b76c4c3..8a5d228 100755 --- a/src/Client/Resources/keen-io-3_0.php +++ b/src/Client/Resources/keen-io-3_0.php @@ -89,6 +89,27 @@ ), ), + 'getQueryResults' => array( + 'uri' => 'projects/{projectId}/queries/saved/{query_name}/result', + 'description' => 'Returns the results of executing the specified query.', + 'httpMethod' => 'GET', + 'parameters' => array( + 'masterKey' => array( + 'location' => 'header', + 'description' => 'The Master API Key.', + 'sentAs' => 'Authorization', + 'pattern' => '/^([[:alnum:]])+$/', + 'type' => 'string', + 'required' => true, + ), + 'query_name' => array( + 'location' => 'uri', + 'description' => 'The saved query.', + 'required' => true, + ), + ), + ), + 'getCollections' => array( 'uri' => 'projects/{projectId}/events', 'description' => 'GET returns schema information for all the event collections in this project, including properties and their type. It also returns links to sub-resources.', From b3ab87fe6c57b6b034212bd0a0736b0f4a665d1e Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Mon, 30 May 2016 23:04:55 -0500 Subject: [PATCH 05/17] implemented the query delete method --- src/Client/KeenIOClient.php | 1 + src/Client/Resources/keen-io-3_0.php | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Client/KeenIOClient.php b/src/Client/KeenIOClient.php index 7c4ad06..a3d8e7b 100755 --- a/src/Client/KeenIOClient.php +++ b/src/Client/KeenIOClient.php @@ -20,6 +20,7 @@ * @method array getProperty(array $args = array()) {@command KeenIO getProperty} * @method array getQueries(array $args = array()) {@command KeenIO getProperty} * @method array getQuery(array $args = array()) {@command KeenIO getProperty} + * @method array deleteQuery(array $args = array()) {@command KeenIO getProperty} * @method array getQueryResults(array $args = array()) {@command KeenIO getProperty} * @method array getEventSchemas(array $args = array()) {@command KeenIO getEventSchemas} * @method array deleteEvents(array $args = array()) {@command KeenIO deleteEvents} diff --git a/src/Client/Resources/keen-io-3_0.php b/src/Client/Resources/keen-io-3_0.php index 8a5d228..a8d7d2e 100755 --- a/src/Client/Resources/keen-io-3_0.php +++ b/src/Client/Resources/keen-io-3_0.php @@ -89,6 +89,27 @@ ), ), + 'deleteQuery' => array( + 'uri' => 'projects/{projectId}/queries/saved/{query_name}', + 'description' => 'Deletes the specified query.', + 'httpMethod' => 'DELETE', + 'parameters' => array( + 'masterKey' => array( + 'location' => 'header', + 'description' => 'The Master API Key.', + 'sentAs' => 'Authorization', + 'pattern' => '/^([[:alnum:]])+$/', + 'type' => 'string', + 'required' => true, + ), + 'query_name' => array( + 'location' => 'uri', + 'description' => 'The saved query.', + 'required' => true, + ), + ), + ), + 'getQueryResults' => array( 'uri' => 'projects/{projectId}/queries/saved/{query_name}/result', 'description' => 'Returns the results of executing the specified query.', From fe97aa20cac16b7977a132291a04501835b1c6bd Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Wed, 1 Jun 2016 23:29:13 -0500 Subject: [PATCH 06/17] implemented creating queries --- src/Client/KeenIOClient.php | 1 + src/Client/Resources/keen-io-3_0.php | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Client/KeenIOClient.php b/src/Client/KeenIOClient.php index a3d8e7b..714c434 100755 --- a/src/Client/KeenIOClient.php +++ b/src/Client/KeenIOClient.php @@ -20,6 +20,7 @@ * @method array getProperty(array $args = array()) {@command KeenIO getProperty} * @method array getQueries(array $args = array()) {@command KeenIO getProperty} * @method array getQuery(array $args = array()) {@command KeenIO getProperty} + * @method array createQuery(array $args = array()) {@command KeenIO getProperty} * @method array deleteQuery(array $args = array()) {@command KeenIO getProperty} * @method array getQueryResults(array $args = array()) {@command KeenIO getProperty} * @method array getEventSchemas(array $args = array()) {@command KeenIO getEventSchemas} diff --git a/src/Client/Resources/keen-io-3_0.php b/src/Client/Resources/keen-io-3_0.php index a8d7d2e..bbb9409 100755 --- a/src/Client/Resources/keen-io-3_0.php +++ b/src/Client/Resources/keen-io-3_0.php @@ -89,6 +89,32 @@ ), ), + 'createQuery' => array( + 'uri' => 'projects/{projectId}/queries/saved/{query_name}', + 'description' => 'Creates the described query.', + 'httpMethod' => 'PUT', + 'parameters' => array( + 'masterKey' => array( + 'location' => 'header', + 'description' => 'The Master API Key.', + 'sentAs' => 'Authorization', + 'pattern' => '/^([[:alnum:]])+$/', + 'type' => 'string', + 'required' => true, + ), + 'query_name' => array( + 'location' => 'uri', + 'description' => 'The desired name of the query.', + 'required' => true, + ), + 'query' => array( + 'location' => 'body', + 'type' => 'array', + 'filters' => array('json_encode'), + ), + ), + ), + 'deleteQuery' => array( 'uri' => 'projects/{projectId}/queries/saved/{query_name}', 'description' => 'Deletes the specified query.', From fa1ae1e74f61a163cbc2c77b89c184eee446bb2c Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Thu, 2 Jun 2016 23:54:22 -0500 Subject: [PATCH 07/17] implemented the organization operations to create a new project --- docs/create-project.php | 16 ++++++++++++++++ src/Client/KeenIOClient.php | 26 ++++++++++++++++++++++++-- src/Client/Resources/keen-io-3_0.php | 21 +++++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 docs/create-project.php diff --git a/docs/create-project.php b/docs/create-project.php new file mode 100644 index 0000000..5ce5101 --- /dev/null +++ b/docs/create-project.php @@ -0,0 +1,16 @@ + $org_id, + 'organizationKey' => $org_key +]); + +$results = $client->createProject(['name' => 'Awesome Project', 'users' => ['email' => 'test@test.com']]); + +print_r($results); \ No newline at end of file diff --git a/src/Client/KeenIOClient.php b/src/Client/KeenIOClient.php index 714c434..e04061c 100755 --- a/src/Client/KeenIOClient.php +++ b/src/Client/KeenIOClient.php @@ -54,7 +54,9 @@ public static function factory($config = array()) 'masterKey' => null, 'writeKey' => null, 'readKey' => null, - 'projectId' => null + 'projectId' => null, + 'organizationKey' => null, + 'organizationId' => null ); // Create client configuration @@ -64,7 +66,7 @@ public static function factory($config = array()) // Because each API Resource uses a separate type of API Key, we need to expose them all in // `commands.params`. Doing it this way allows the Service Definitions to set what API Key is used. $parameters = array(); - foreach (array('masterKey', 'writeKey', 'readKey') as $key) { + foreach (array('masterKey', 'writeKey', 'readKey', 'organizationKey') as $key) { $parameters[$key] = $config->get($key); } @@ -153,6 +155,26 @@ public function getProjectId() return $this->getConfig('projectId'); } + /** + * Sets the Organization Id used by the Keen IO Client + * + * @param string $organizationId + */ + public function setOrganizationId($organizationId) + { + $this->getConfig()->set('organizationId', $organizationId); + } + + /** + * Gets the Organization Id being used by the Keen IO Client + * + * @return string|null Value of the OrganizationId or NULL + */ + public function getOrganizationId() + { + return $this->getConfig('organizationId'); + } + /** * Sets the API Write Key used by the Keen IO Client * diff --git a/src/Client/Resources/keen-io-3_0.php b/src/Client/Resources/keen-io-3_0.php index bbb9409..94d62a6 100755 --- a/src/Client/Resources/keen-io-3_0.php +++ b/src/Client/Resources/keen-io-3_0.php @@ -20,6 +20,27 @@ ), ), + 'createProject' => array( + 'uri' => 'organizations/{organizationId}/projects', + 'description' => 'Creates a project for the specified organization and returns the project id for later usage.', + 'httpMethod' => 'POST', + 'parameters' => array( + 'organizationKey' => array( + 'location' => 'header', + 'description' => 'The Organization Key.', + 'sentAs' => 'Authorization', + 'pattern' => '/^([[:alnum:]])+$/', + 'type' => 'string', + 'required' => true, + ), + 'project_data' => array( + 'location' => 'body', + 'type' => 'array', + 'filters' => array('json_encode'), + ), + ), + ), + 'getProjects' => array( 'uri' => 'projects', 'description' => 'Returns the projects accessible to the API user, as well as links to project sub-resources for discovery.', From de30ace1238effef370555e96601d7774ec99fe8 Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Fri, 3 Jun 2016 00:58:25 -0500 Subject: [PATCH 08/17] added a query name filter the query name has to be alphanumeric, underscores or dashes, everything else is simply removed --- src/Client/KeenIOClient.php | 8 ++++++++ src/Client/Resources/keen-io-3_0.php | 1 + 2 files changed, 9 insertions(+) diff --git a/src/Client/KeenIOClient.php b/src/Client/KeenIOClient.php index e04061c..d23f7c9 100755 --- a/src/Client/KeenIOClient.php +++ b/src/Client/KeenIOClient.php @@ -417,4 +417,12 @@ protected static function parseConfig($config, $default) return $config; } + + public static function cleanQueryName($raw) + { + $filtered = str_replace(' ', '-', $raw); + $filtered = preg_replace("/[^A-Za-z0-9_\-]/", "", $filtered); + + return $filtered; + } } diff --git a/src/Client/Resources/keen-io-3_0.php b/src/Client/Resources/keen-io-3_0.php index 94d62a6..107ad72 100755 --- a/src/Client/Resources/keen-io-3_0.php +++ b/src/Client/Resources/keen-io-3_0.php @@ -126,6 +126,7 @@ 'query_name' => array( 'location' => 'uri', 'description' => 'The desired name of the query.', + 'filters' => array(["method" => '\KeenIO\Client\KeenIOClient::cleanQueryName', "args" => ["@value"]]), 'required' => true, ), 'query' => array( From 20dec9cf5d985be1efb69cfda73826009d44da6d Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Fri, 3 Jun 2016 01:04:51 -0500 Subject: [PATCH 09/17] implemented updating queries --- src/Client/Resources/keen-io-3_0.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Client/Resources/keen-io-3_0.php b/src/Client/Resources/keen-io-3_0.php index 107ad72..b07f66a 100755 --- a/src/Client/Resources/keen-io-3_0.php +++ b/src/Client/Resources/keen-io-3_0.php @@ -137,6 +137,33 @@ ), ), + 'updateQuery' => array( + 'uri' => 'projects/{projectId}/queries/saved/{query_name}', + 'description' => 'Creates the described query.', + 'httpMethod' => 'PUT', + 'parameters' => array( + 'masterKey' => array( + 'location' => 'header', + 'description' => 'The Master API Key.', + 'sentAs' => 'Authorization', + 'pattern' => '/^([[:alnum:]])+$/', + 'type' => 'string', + 'required' => true, + ), + 'query_name' => array( + 'location' => 'uri', + 'description' => 'The desired name of the query.', + 'filters' => array(["method" => '\KeenIO\Client\KeenIOClient::cleanQueryName', "args" => ["@value"]]), + 'required' => true, + ), + 'query' => array( + 'location' => 'body', + 'type' => 'array', + 'filters' => array('json_encode'), + ), + ), + ), + 'deleteQuery' => array( 'uri' => 'projects/{projectId}/queries/saved/{query_name}', 'description' => 'Deletes the specified query.', From b97c2f4182e5d24a1fda10967cfb92d344f84d2e Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Fri, 3 Jun 2016 01:10:29 -0500 Subject: [PATCH 10/17] wrote samples for all the functionality --- docs/create-query.php | 30 ++++++++++++++++++++++++++++++ docs/delete-query.php | 16 ++++++++++++++++ docs/get-collection.php | 16 ++++++++++++++++ docs/get-collections.php | 16 ++++++++++++++++ docs/get-project.php | 16 ++++++++++++++++ docs/get-projects.php | 15 +++++++++++++++ docs/get-property.php | 16 ++++++++++++++++ docs/get-queries.php | 16 ++++++++++++++++ docs/get-query-results.php | 20 ++++++++++++++++++++ docs/get-query.php | 20 ++++++++++++++++++++ docs/update-query.php | 30 ++++++++++++++++++++++++++++++ 11 files changed, 211 insertions(+) create mode 100644 docs/create-query.php create mode 100644 docs/delete-query.php create mode 100644 docs/get-collection.php create mode 100644 docs/get-collections.php create mode 100644 docs/get-project.php create mode 100644 docs/get-projects.php create mode 100644 docs/get-property.php create mode 100644 docs/get-queries.php create mode 100644 docs/get-query-results.php create mode 100644 docs/get-query.php create mode 100644 docs/update-query.php diff --git a/docs/create-query.php b/docs/create-query.php new file mode 100644 index 0000000..9626770 --- /dev/null +++ b/docs/create-query.php @@ -0,0 +1,30 @@ + $project_id, + 'masterKey' => $master_key +]); + +$query = [ + "analysis_type" => "count", + "event_collection" => "api_request", + "filters" => + [ + [ + "property_name" => "user_agent", + "operator" => "ne", + "property_value"=> "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)" + ] + ], + "timeframe" => "this_2_weeks" +]; + +$results = $client->createQuery(['query_name' => 'my new query', 'query' => $query]); + +print_r($results); \ No newline at end of file diff --git a/docs/delete-query.php b/docs/delete-query.php new file mode 100644 index 0000000..c85182a --- /dev/null +++ b/docs/delete-query.php @@ -0,0 +1,16 @@ + $project_id, + 'masterKey' => $master_key +]); + +$results = $client->deleteQuery(['query_name' => 'transactions']); + +print_r($results); \ No newline at end of file diff --git a/docs/get-collection.php b/docs/get-collection.php new file mode 100644 index 0000000..748fb8e --- /dev/null +++ b/docs/get-collection.php @@ -0,0 +1,16 @@ + $project_id, + 'masterKey' => $master_key +]); + +$results = $client->getCollection(['event_collection' => 'account']); + +print_r($results); \ No newline at end of file diff --git a/docs/get-collections.php b/docs/get-collections.php new file mode 100644 index 0000000..613d741 --- /dev/null +++ b/docs/get-collections.php @@ -0,0 +1,16 @@ + $project_id, + 'masterKey' => $master_key +]); + +$results = $client->getCollections(); + +print_r($results); \ No newline at end of file diff --git a/docs/get-project.php b/docs/get-project.php new file mode 100644 index 0000000..40d866e --- /dev/null +++ b/docs/get-project.php @@ -0,0 +1,16 @@ + $project_id, + 'masterKey' => $master_key +]); + +$results = $client->getProject(); + +print_r($results); \ No newline at end of file diff --git a/docs/get-projects.php b/docs/get-projects.php new file mode 100644 index 0000000..04f6cf8 --- /dev/null +++ b/docs/get-projects.php @@ -0,0 +1,15 @@ + $master_key +]); + +$results = $client->getProjects(); + +print_r($results); \ No newline at end of file diff --git a/docs/get-property.php b/docs/get-property.php new file mode 100644 index 0000000..f3440bb --- /dev/null +++ b/docs/get-property.php @@ -0,0 +1,16 @@ + $project_id, + 'masterKey' => $master_key +]); + +$results = $client->getProperty(['event_collection' => 'account', 'property_name' => 'account_id']); + +print_r($results); \ No newline at end of file diff --git a/docs/get-queries.php b/docs/get-queries.php new file mode 100644 index 0000000..c20d650 --- /dev/null +++ b/docs/get-queries.php @@ -0,0 +1,16 @@ + $project_id, + 'masterKey' => $master_key +]); + +$results = $client->getQueries(); + +print_r($results); \ No newline at end of file diff --git a/docs/get-query-results.php b/docs/get-query-results.php new file mode 100644 index 0000000..3640334 --- /dev/null +++ b/docs/get-query-results.php @@ -0,0 +1,20 @@ + $project_id, + 'masterKey' => $master_key +]); + +$queries = $client->getQueries(); + +$query_name = $queries[0]['query_name']; + +$results = $client->getQueryResults(['query_name' => $query_name]); + +print_r($results); \ No newline at end of file diff --git a/docs/get-query.php b/docs/get-query.php new file mode 100644 index 0000000..762ec02 --- /dev/null +++ b/docs/get-query.php @@ -0,0 +1,20 @@ + $project_id, + 'masterKey' => $master_key +]); + +$queries = $client->getQueries(); + +$query_name = $queries[0]['query_name']; + +$results = $client->getQuery(['query_name' => $query_name]); + +print_r($results); \ No newline at end of file diff --git a/docs/update-query.php b/docs/update-query.php new file mode 100644 index 0000000..4421ac8 --- /dev/null +++ b/docs/update-query.php @@ -0,0 +1,30 @@ + $project_id, + 'masterKey' => $master_key +]); + +$query = [ + "analysis_type" => "count", + "event_collection" => "api_request", + "filters" => + [ + [ + "property_name" => "user_agent", + "operator" => "ne", + "property_value"=> "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)" + ] + ], + "timeframe" => "this_1_weeks" +]; + +$results = $client->updateQuery(['query_name' => 'updated query', 'query' => $query]); + +print_r($results); \ No newline at end of file From fa06175b62a9d8d73f5caf28ecd82ab884878f8b Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Sat, 11 Jun 2016 13:39:56 -0500 Subject: [PATCH 11/17] bumped the minimum PHP version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e7d8656..56691bc 100755 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "chat": "https://www.hipchat.com/gIdidQscL" }, "require": { - "php": ">=5.3.3", + "php": ">=5.6.0", "ext-mcrypt": "*", "guzzle/guzzle": "~3.7" }, From 89d578d59402720c7f667f99d9ee6b252e82278d Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Sun, 12 Jun 2016 16:51:42 -0500 Subject: [PATCH 12/17] bumped the PHP version for travis --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 47cbdb3..b9db119 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: php php: - - "5.5" - - "5.4" - - "5.3" + - "7.0" + - "5.6" before_script: - composer self-update - composer install --prefer-source From b290406e9e1ec0b3d971ad32b3011c45fe18c0c5 Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Wed, 29 Jun 2016 12:57:44 -0500 Subject: [PATCH 13/17] adding 'Saved' to method names to match docs --- src/Client/KeenIOClient.php | 10 +++++----- src/Client/Resources/keen-io-3_0.php | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Client/KeenIOClient.php b/src/Client/KeenIOClient.php index d23f7c9..dace2e6 100755 --- a/src/Client/KeenIOClient.php +++ b/src/Client/KeenIOClient.php @@ -18,11 +18,11 @@ * @method array getProjects(array $args = array()) {@command KeenIO getProjects} * @method array getProject(array $args = array()) {@command KeenIO getProject} * @method array getProperty(array $args = array()) {@command KeenIO getProperty} - * @method array getQueries(array $args = array()) {@command KeenIO getProperty} - * @method array getQuery(array $args = array()) {@command KeenIO getProperty} - * @method array createQuery(array $args = array()) {@command KeenIO getProperty} - * @method array deleteQuery(array $args = array()) {@command KeenIO getProperty} - * @method array getQueryResults(array $args = array()) {@command KeenIO getProperty} + * @method array getSavedQueries(array $args = array()) {@command KeenIO getProperty} + * @method array getSavedQuery(array $args = array()) {@command KeenIO getProperty} + * @method array createSavedQuery(array $args = array()) {@command KeenIO getProperty} + * @method array deleteSavedQuery(array $args = array()) {@command KeenIO getProperty} + * @method array getSavedQueryResults(array $args = array()) {@command KeenIO getProperty} * @method array getEventSchemas(array $args = array()) {@command KeenIO getEventSchemas} * @method array deleteEvents(array $args = array()) {@command KeenIO deleteEvents} * @method array deleteEventProperties(array $args = array()) {@command KeenIO deleteEventProperties} diff --git a/src/Client/Resources/keen-io-3_0.php b/src/Client/Resources/keen-io-3_0.php index b07f66a..05ffe61 100755 --- a/src/Client/Resources/keen-io-3_0.php +++ b/src/Client/Resources/keen-io-3_0.php @@ -73,7 +73,7 @@ ), ), - 'getQueries' => array( + 'getSavedQueries' => array( 'uri' => 'projects/{projectId}/queries/saved', 'description' => 'Returns the saved queries accessible to the API user on the specified project.', 'httpMethod' => 'GET', @@ -89,7 +89,7 @@ ), ), - 'getQuery' => array( + 'getSavedQuery' => array( 'uri' => 'projects/{projectId}/queries/saved/{query_name}', 'description' => 'Returns the detailed information about the specified query, as well as links to retrieve results.', 'httpMethod' => 'GET', @@ -110,7 +110,7 @@ ), ), - 'createQuery' => array( + 'createSavedQuery' => array( 'uri' => 'projects/{projectId}/queries/saved/{query_name}', 'description' => 'Creates the described query.', 'httpMethod' => 'PUT', @@ -137,7 +137,7 @@ ), ), - 'updateQuery' => array( + 'updateSavedQuery' => array( 'uri' => 'projects/{projectId}/queries/saved/{query_name}', 'description' => 'Creates the described query.', 'httpMethod' => 'PUT', @@ -164,7 +164,7 @@ ), ), - 'deleteQuery' => array( + 'deleteSavedQuery' => array( 'uri' => 'projects/{projectId}/queries/saved/{query_name}', 'description' => 'Deletes the specified query.', 'httpMethod' => 'DELETE', @@ -185,7 +185,7 @@ ), ), - 'getQueryResults' => array( + 'getSavedQueryResults' => array( 'uri' => 'projects/{projectId}/queries/saved/{query_name}/result', 'description' => 'Returns the results of executing the specified query.', 'httpMethod' => 'GET', From a3a71d49b559657fc341001953fd9fd606e2ca10 Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Wed, 29 Jun 2016 12:57:56 -0500 Subject: [PATCH 14/17] updating the underlying docs --- docs/{create-query.php => create-saved-query.php} | 2 +- docs/{delete-query.php => delete-saved-query.php} | 2 +- docs/{get-queries.php => get-saved-queries.php} | 2 +- docs/{get-query-results.php => get-saved-query-results.php} | 4 ++-- docs/{get-query.php => get-saved-query.php} | 4 ++-- docs/{update-query.php => update-saved-query.php} | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) rename docs/{create-query.php => create-saved-query.php} (87%) rename docs/{delete-query.php => delete-saved-query.php} (79%) rename docs/{get-queries.php => get-saved-queries.php} (88%) rename docs/{get-query-results.php => get-saved-query-results.php} (74%) rename docs/{get-query.php => get-saved-query.php} (75%) rename docs/{update-query.php => update-saved-query.php} (87%) diff --git a/docs/create-query.php b/docs/create-saved-query.php similarity index 87% rename from docs/create-query.php rename to docs/create-saved-query.php index 9626770..f8102ff 100644 --- a/docs/create-query.php +++ b/docs/create-saved-query.php @@ -25,6 +25,6 @@ "timeframe" => "this_2_weeks" ]; -$results = $client->createQuery(['query_name' => 'my new query', 'query' => $query]); +$results = $client->createSavedQuery(['query_name' => 'my new query', 'query' => $query]); print_r($results); \ No newline at end of file diff --git a/docs/delete-query.php b/docs/delete-saved-query.php similarity index 79% rename from docs/delete-query.php rename to docs/delete-saved-query.php index c85182a..68a68a1 100644 --- a/docs/delete-query.php +++ b/docs/delete-saved-query.php @@ -11,6 +11,6 @@ 'masterKey' => $master_key ]); -$results = $client->deleteQuery(['query_name' => 'transactions']); +$results = $client->deleteSavedQuery(['query_name' => 'transactions']); print_r($results); \ No newline at end of file diff --git a/docs/get-queries.php b/docs/get-saved-queries.php similarity index 88% rename from docs/get-queries.php rename to docs/get-saved-queries.php index c20d650..3c8b023 100644 --- a/docs/get-queries.php +++ b/docs/get-saved-queries.php @@ -11,6 +11,6 @@ 'masterKey' => $master_key ]); -$results = $client->getQueries(); +$results = $client->getSavedQueries(); print_r($results); \ No newline at end of file diff --git a/docs/get-query-results.php b/docs/get-saved-query-results.php similarity index 74% rename from docs/get-query-results.php rename to docs/get-saved-query-results.php index 3640334..a9c1ea9 100644 --- a/docs/get-query-results.php +++ b/docs/get-saved-query-results.php @@ -11,10 +11,10 @@ 'masterKey' => $master_key ]); -$queries = $client->getQueries(); +$queries = $client->getSavedQueries(); $query_name = $queries[0]['query_name']; -$results = $client->getQueryResults(['query_name' => $query_name]); +$results = $client->getSavedQueryResults(['query_name' => $query_name]); print_r($results); \ No newline at end of file diff --git a/docs/get-query.php b/docs/get-saved-query.php similarity index 75% rename from docs/get-query.php rename to docs/get-saved-query.php index 762ec02..5820fa0 100644 --- a/docs/get-query.php +++ b/docs/get-saved-query.php @@ -11,10 +11,10 @@ 'masterKey' => $master_key ]); -$queries = $client->getQueries(); +$queries = $client->getSavedQueries(); $query_name = $queries[0]['query_name']; -$results = $client->getQuery(['query_name' => $query_name]); +$results = $client->getSavedQuery(['query_name' => $query_name]); print_r($results); \ No newline at end of file diff --git a/docs/update-query.php b/docs/update-saved-query.php similarity index 87% rename from docs/update-query.php rename to docs/update-saved-query.php index 4421ac8..b146121 100644 --- a/docs/update-query.php +++ b/docs/update-saved-query.php @@ -25,6 +25,6 @@ "timeframe" => "this_1_weeks" ]; -$results = $client->updateQuery(['query_name' => 'updated query', 'query' => $query]); +$results = $client->updateSavedQuery(['query_name' => 'updated query', 'query' => $query]); print_r($results); \ No newline at end of file From 605af5713266da8f934f7a3aa1cf828bceb59609 Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Fri, 1 Jul 2016 11:58:19 -0500 Subject: [PATCH 15/17] added commentary on plugins --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index f7f84df..59eb2d9 100755 --- a/README.md +++ b/README.md @@ -57,6 +57,10 @@ that matches that version. That Service Description defines the operations avail Currently the Keen IO Webservice Client only supports - and automatically defaults - to the current version (`3.0`) of the API. +##### More details about the client + +Since the Keen client extends the [Guzzle](http://guzzlephp.org/) client, you get all the power and flexibility of that behind the scenes. If you need more complex logging, backoff/retry handling, or asynchronous requests, check out their [Plugins](http://guzzle3.readthedocs.io/docs.html#plugins). + ###### Example ```php use KeenIO\Client\KeenIOClient; From 598d502ac39c591a2d27d756bfc3161e2a52bac2 Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Tue, 5 Jul 2016 09:39:50 -0500 Subject: [PATCH 16/17] removed the example usage --- docs/create-project.php | 16 ---------------- docs/create-saved-query.php | 30 ------------------------------ docs/delete-saved-query.php | 16 ---------------- docs/get-collection.php | 16 ---------------- docs/get-collections.php | 16 ---------------- docs/get-project.php | 16 ---------------- docs/get-projects.php | 15 --------------- docs/get-property.php | 16 ---------------- docs/get-saved-queries.php | 16 ---------------- docs/get-saved-query-results.php | 20 -------------------- docs/get-saved-query.php | 20 -------------------- docs/update-saved-query.php | 30 ------------------------------ 12 files changed, 227 deletions(-) delete mode 100644 docs/create-project.php delete mode 100644 docs/create-saved-query.php delete mode 100644 docs/delete-saved-query.php delete mode 100644 docs/get-collection.php delete mode 100644 docs/get-collections.php delete mode 100644 docs/get-project.php delete mode 100644 docs/get-projects.php delete mode 100644 docs/get-property.php delete mode 100644 docs/get-saved-queries.php delete mode 100644 docs/get-saved-query-results.php delete mode 100644 docs/get-saved-query.php delete mode 100644 docs/update-saved-query.php diff --git a/docs/create-project.php b/docs/create-project.php deleted file mode 100644 index 5ce5101..0000000 --- a/docs/create-project.php +++ /dev/null @@ -1,16 +0,0 @@ - $org_id, - 'organizationKey' => $org_key -]); - -$results = $client->createProject(['name' => 'Awesome Project', 'users' => ['email' => 'test@test.com']]); - -print_r($results); \ No newline at end of file diff --git a/docs/create-saved-query.php b/docs/create-saved-query.php deleted file mode 100644 index f8102ff..0000000 --- a/docs/create-saved-query.php +++ /dev/null @@ -1,30 +0,0 @@ - $project_id, - 'masterKey' => $master_key -]); - -$query = [ - "analysis_type" => "count", - "event_collection" => "api_request", - "filters" => - [ - [ - "property_name" => "user_agent", - "operator" => "ne", - "property_value"=> "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)" - ] - ], - "timeframe" => "this_2_weeks" -]; - -$results = $client->createSavedQuery(['query_name' => 'my new query', 'query' => $query]); - -print_r($results); \ No newline at end of file diff --git a/docs/delete-saved-query.php b/docs/delete-saved-query.php deleted file mode 100644 index 68a68a1..0000000 --- a/docs/delete-saved-query.php +++ /dev/null @@ -1,16 +0,0 @@ - $project_id, - 'masterKey' => $master_key -]); - -$results = $client->deleteSavedQuery(['query_name' => 'transactions']); - -print_r($results); \ No newline at end of file diff --git a/docs/get-collection.php b/docs/get-collection.php deleted file mode 100644 index 748fb8e..0000000 --- a/docs/get-collection.php +++ /dev/null @@ -1,16 +0,0 @@ - $project_id, - 'masterKey' => $master_key -]); - -$results = $client->getCollection(['event_collection' => 'account']); - -print_r($results); \ No newline at end of file diff --git a/docs/get-collections.php b/docs/get-collections.php deleted file mode 100644 index 613d741..0000000 --- a/docs/get-collections.php +++ /dev/null @@ -1,16 +0,0 @@ - $project_id, - 'masterKey' => $master_key -]); - -$results = $client->getCollections(); - -print_r($results); \ No newline at end of file diff --git a/docs/get-project.php b/docs/get-project.php deleted file mode 100644 index 40d866e..0000000 --- a/docs/get-project.php +++ /dev/null @@ -1,16 +0,0 @@ - $project_id, - 'masterKey' => $master_key -]); - -$results = $client->getProject(); - -print_r($results); \ No newline at end of file diff --git a/docs/get-projects.php b/docs/get-projects.php deleted file mode 100644 index 04f6cf8..0000000 --- a/docs/get-projects.php +++ /dev/null @@ -1,15 +0,0 @@ - $master_key -]); - -$results = $client->getProjects(); - -print_r($results); \ No newline at end of file diff --git a/docs/get-property.php b/docs/get-property.php deleted file mode 100644 index f3440bb..0000000 --- a/docs/get-property.php +++ /dev/null @@ -1,16 +0,0 @@ - $project_id, - 'masterKey' => $master_key -]); - -$results = $client->getProperty(['event_collection' => 'account', 'property_name' => 'account_id']); - -print_r($results); \ No newline at end of file diff --git a/docs/get-saved-queries.php b/docs/get-saved-queries.php deleted file mode 100644 index 3c8b023..0000000 --- a/docs/get-saved-queries.php +++ /dev/null @@ -1,16 +0,0 @@ - $project_id, - 'masterKey' => $master_key -]); - -$results = $client->getSavedQueries(); - -print_r($results); \ No newline at end of file diff --git a/docs/get-saved-query-results.php b/docs/get-saved-query-results.php deleted file mode 100644 index a9c1ea9..0000000 --- a/docs/get-saved-query-results.php +++ /dev/null @@ -1,20 +0,0 @@ - $project_id, - 'masterKey' => $master_key -]); - -$queries = $client->getSavedQueries(); - -$query_name = $queries[0]['query_name']; - -$results = $client->getSavedQueryResults(['query_name' => $query_name]); - -print_r($results); \ No newline at end of file diff --git a/docs/get-saved-query.php b/docs/get-saved-query.php deleted file mode 100644 index 5820fa0..0000000 --- a/docs/get-saved-query.php +++ /dev/null @@ -1,20 +0,0 @@ - $project_id, - 'masterKey' => $master_key -]); - -$queries = $client->getSavedQueries(); - -$query_name = $queries[0]['query_name']; - -$results = $client->getSavedQuery(['query_name' => $query_name]); - -print_r($results); \ No newline at end of file diff --git a/docs/update-saved-query.php b/docs/update-saved-query.php deleted file mode 100644 index b146121..0000000 --- a/docs/update-saved-query.php +++ /dev/null @@ -1,30 +0,0 @@ - $project_id, - 'masterKey' => $master_key -]); - -$query = [ - "analysis_type" => "count", - "event_collection" => "api_request", - "filters" => - [ - [ - "property_name" => "user_agent", - "operator" => "ne", - "property_value"=> "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)" - ] - ], - "timeframe" => "this_1_weeks" -]; - -$results = $client->updateSavedQuery(['query_name' => 'updated query', 'query' => $query]); - -print_r($results); \ No newline at end of file From 9054b95fdc48692d485479d365aa01c7a02ffc4f Mon Sep 17 00:00:00 2001 From: Keith Casey Date: Tue, 5 Jul 2016 10:08:56 -0500 Subject: [PATCH 17/17] added Saved Query examples --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index 59eb2d9..995144f 100755 --- a/README.md +++ b/README.md @@ -179,6 +179,44 @@ $allowedOperations = ['read']; $scopedKey = $client->createScopedKey($filters, $allowedOperations); ``` +#### Using saved queries + +[Saved Queries](https://keen.io/docs/api/?php#saved-queries) allow you to perform with exactly the same parameters every time with minimal effort. It's effectively a bookmark or macro to analysis that you can jump to or share without configuring each time. While you can create and access them via the Dashboard, the PHP library gives you the same ability. + +######Example: Creating a Saved Query +```php +$client = KeenIOClient::factory([ + 'projectId' => $project_id, + 'masterKey' => $master_key +]); + +$query = [ + "analysis_type" => "count", + "event_collection" => "api_requests", + "filters" => + [ + [ + "property_name" => "user_agent", + "operator" => "ne", + "property_value"=> "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)" + ] + ], + "timeframe" => "this_2_weeks" +]; + +$results = $client->createSavedQuery(['query_name' => 'total-API-requests', 'query' => $query]); +``` + +######Example: Retrieving a Saved Query +```php +$client = KeenIOClient::factory([ + 'projectId' => $project_id, + 'masterKey' => $master_key +]); + +$results = $client->getSavedQuery(['query_name' => 'total-API-requests']); +``` + Questions & Support ------------------- If you have any questions, bugs, or suggestions, please