Selaa lähdekoodia

Updating readme

Jon Wenmoth 12 vuotta sitten
vanhempi
commit
47238f4e47
1 muutettua tiedostoa jossa 116 lisäystä ja 15 poistoa
  1. 116 15
      README.md

+ 116 - 15
README.md

@@ -11,6 +11,7 @@ websites that demand javascript support and also supports screen captures.
 
 * Introduction
 * Examples
+* Changelog
 * Troubleshooting
 
 
@@ -33,7 +34,7 @@ through PhantomJS then this is not for you. Check out [PhantomJS runner](https:/
 2.0 Examples
 ------------
 
-Load a URL and return the response:
+Request a URL and output the reponse:
 
 ```php
 <?php
@@ -43,9 +44,17 @@ use JonnyW\PhantomJs\Client;
 $client = Client::getInstance();
 
 /** 
- * @see JonnyW\PhantomJs\Response 
+ * @see JonnyW\PhantomJs\Message\Request 
  **/
-$response = $client->open('http://www.google.com');
+$request = $client->getMessageFactory()->createRequest('GET', 'http://google.com');
+
+/** 
+ * @see JonnyW\PhantomJs\Message\Response 
+ **/
+$response = $client->getMessageFactory()->createResponse();
+
+// Send the request
+$client->send($request, $response);
 
 if($response->getStatus() === 200) {
 	
@@ -54,7 +63,7 @@ if($response->getStatus() === 200) {
 }
 ```
 
-Load a URL, save a screen capture to provided location and return the response:
+Request a URL, save a screen capture to provided location and return the response:
 
 ```php
 <?php
@@ -64,9 +73,65 @@ use JonnyW\PhantomJs\Client;
 $client = Client::getInstance();
 
 /** 
- * @see JonnyW\PhantomJs\Response 
+ * @see JonnyW\PhantomJs\Message\Request 
  **/
-$response = $client->capture('http://www.google.com', '/path/to/save/screen/capture.png');
+$request = $client->getMessageFactory()->createRequest('GET', 'http://google.com');
+
+/** 
+ * @see JonnyW\PhantomJs\Message\Response 
+ **/
+$response = $client->getMessageFactory()->createResponse();
+
+// Send the request
+$client->send($request, $response, '/path/to/save/screen/capture.png');
+```
+
+Send post request with data:
+
+```php
+<?php
+
+use JonnyW\PhantomJs\Client;
+
+$client = Client::getInstance();
+
+/** 
+ * @see JonnyW\PhantomJs\Message\Request 
+ **/
+$request = $client->getMessageFactory()->createRequest();
+
+$request->setMethod('POST');
+$request->setUrl('http://google.com');
+
+$request->setRequestData(array(
+	'name' 	=> 'Test',
+	'email' => 'test@jonnyw.me'
+));
+
+/** 
+ * @see JonnyW\PhantomJs\Message\Response 
+ **/
+$response = $client->getMessageFactory()->createResponse();
+
+// Send the request
+$client->send($request, $response);
+```
+
+Set a request header:
+
+```php
+<?php
+
+use JonnyW\PhantomJs\Client;
+
+$client = Client::getInstance();
+
+/** 
+ * @see JonnyW\PhantomJs\Message\Request 
+ **/
+$request = $client->getMessageFactory()->createRequest();
+
+$request->addHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.2 Safari/534.34');
 ```
 
 Get a response header:
@@ -79,9 +144,17 @@ use JonnyW\PhantomJs\Client;
 $client = Client::getInstance();
 
 /** 
- * @see JonnyW\PhantomJs\Response 
+ * @see JonnyW\PhantomJs\Message\Request 
  **/
-$response = $client->open('http://www.google.com');
+$request = $client->getMessageFactory()->createRequest('GET', 'http://google.com');
+
+/** 
+ * @see JonnyW\PhantomJs\Message\Response 
+ **/
+$response = $client->getMessageFactory()->createResponse();
+
+// Send the request
+$client->send($request, $response, '/path/to/save/screen/capture.png');
 
 echo $response->getHeader('Cache-Control');
 ```
@@ -96,16 +169,22 @@ use JonnyW\PhantomJs\Client;
 $client = Client::getInstance();
 
 /** 
- * @see JonnyW\PhantomJs\Response 
+ * @see JonnyW\PhantomJs\Message\Request 
  **/
-$response = $client->open('http://www.google.com');
+$request = $client->getMessageFactory()->createRequest('GET', 'http://google.com');
 
-if($response->isRedirect()) {
+/** 
+ * @see JonnyW\PhantomJs\Message\Response 
+ **/
+$response = $client->getMessageFactory()->createResponse();
+
+// Send the request
+$client->send($request, $response);
 
-	$response = $client->open(
-		$response->getRedirectUrl()
-	);
+if($response->isRedirect()) {
+	echo $response->getRedirectUrl();
 }
+
 ```
 
 Define a new path to the PhantomJS executable:
@@ -130,9 +209,27 @@ $client = Client::getInstance();
 $client->setTimeout(10000); // In milleseconds
 ```
 
-3.0 Troubleshooting
+3.0 Changelog
+------------
+
+### V2.0.0
+
+Version 2.0.0 changes the way requests are made. Requests now require you 
+to inject a request and response instance into the send method. The examples 
+above illustrate how to make requests in version 2.0.0 and will not work 
+for older versions.
+
+* Requests now require you to inject a request and response instance when sending.
+* Added message factory that can also be injected into client when instantiated.
+* Customers headers can be set in requests.
+* Request method can be set. Supports: OPTIONS, GET, HEAD, POST, PUT, DELETE, PATCH.
+* Request data can be set. Useful when making post requests.
+
+4.0 Troubleshooting
 ------------
 
+If you are using V1.0.0 then the examples above won't work for you. It is reccommend that you upgrade to the latest version.
+
 Look at the response class (JonnyW\PhantomJs\Response) to see what data you have access to.
 
 An explanation of the errors that are thrown by the client:
@@ -145,6 +242,10 @@ The command sent to the PhantomJS executable failed. This should be very rare an
 
 The URL you are providing is an invalid format. It is very loose verification.
 
+### InvalidMethodException
+
+The request method you are providing is invalid.
+
 ### NoPhantomJsException
 
 The PhantomJS executable cannot be found or it is not executable. Check the path and permissions.