From 3c5d76ddc772166266c864cb784207dbaeba32ee Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Mon, 26 May 2014 01:52:10 -0700 Subject: [PATCH] Fix #57: Add documentation --- docs/Gemfile | 4 + docs/build.sh | 1 + docs/config.rb | 19 ++++ docs/source/index.md | 265 +++++++++++++++++++++++++++++++++++++++++++ docs/watch.sh | 1 + 5 files changed, 290 insertions(+) create mode 100644 docs/Gemfile create mode 100644 docs/build.sh create mode 100644 docs/config.rb create mode 100644 docs/source/index.md create mode 100644 docs/watch.sh diff --git a/docs/Gemfile b/docs/Gemfile new file mode 100644 index 0000000..23bb872 --- /dev/null +++ b/docs/Gemfile @@ -0,0 +1,4 @@ +gem "middleman" +gem "middleman-livereload" +gem "middleman-syntax" +gem "redcarpet" diff --git a/docs/build.sh b/docs/build.sh new file mode 100644 index 0000000..7a685a8 --- /dev/null +++ b/docs/build.sh @@ -0,0 +1 @@ +bundle exec middleman build --clean --verbose diff --git a/docs/config.rb b/docs/config.rb new file mode 100644 index 0000000..d589ec9 --- /dev/null +++ b/docs/config.rb @@ -0,0 +1,19 @@ +activate :syntax +activate :relative_assets +set :markdown_engine, :redcarpet +set :markdown, + :disable_indented_code_blocks => true, + :fenced_code_blocks => true, + :no_intra_emphasis => true, + :prettify => true, + :smartypants => true, + :tables => true, + :with_toc_data => true + +set :css_dir, 'css' +set :js_dir, 'js' + +configure :build do + activate :minify_css + activate :minify_javascript +end diff --git a/docs/source/index.md b/docs/source/index.md new file mode 100644 index 0000000..9803042 --- /dev/null +++ b/docs/source/index.md @@ -0,0 +1,265 @@ +--- +title: PHP Curl Class Documentation + +language_tabs: + - php + +toc_footers: + - PHP Curl Class on Github +--- + +# Introduction + +PHP Curl Class is an object-oriented wrapper of the PHP cURL extension. + +# Install + +## Composer + +Install using Composer. + +```shell +$ composer require php-curl-class/php-curl-class +``` + +## Include + +Include PHP Curl Class. + +```php +get('https://www.example.com/', array( + 'q' => 'keyword', +)); +``` + +## POST + +```php +post('https://www.example.com/login/', array( + 'username' => 'myusername', + 'password' => 'mypassword', +)); +``` + +## PUT + +```php +put('https://api.example.com/user/', array( + 'first_name' => 'Zach', + 'last_name' => 'Borboa', +)); +``` + +## PATCH + +```php +patch('https://api.example.com/profile/', array( + 'image' => '@path/to/file.jpg', +)); +``` + +```php +patch('https://api.example.com/profile/', array( + 'image' => new CURLFile('path/to/file.jpg'), +)); +``` + +## DELETE + +```php +delete('https://api.example.com/user/', array( + 'id' => '1234', +)); +``` + +## HEAD + +```php +head('https://www.example.com/song.mp3'); +``` + +## OPTIONS + +```php +options('https://www.example.com/'); +``` + +## Curl Options + +```php +setOpt(CURLOPT_AUTOREFERER, true); +$curl->get('https://www.example.com/302'); +``` + +```php +setOpt(CURLOPT_ENCODING , 'gzip'); +$curl->get('https://www.example.com/image.png'); +``` + +## Authentication + +```php +setBasicAuthentication('username', 'password'); +``` + +## User Agent + +```php +setUserAgent(''); +``` + +## Referrer + +```php +setReferrer(''); +``` + +## Cookies + +```php +setCookie('key', 'value'); +``` + +## Request header + +```php +setHeader('X-Requested-With', 'XMLHttpRequest'); +$curl->get('https://www.example.com/'); + +// Case-insensitive access to headers. +echo $curl->request_headers['X-Requested-With'] . "\n"; // XMLHttpRequest +echo $curl->request_headers['x-ReQUeStED-wiTH'] . "\n"; // XMLHttpRequest +``` + +## Response header + +```php +get('https://www.example.com/image.png'); + +// Case-insensitive access to headers. +echo $curl->response_headers['Content-Type'] . "\n"; // image/png +echo $curl->response_headers['CoNTeNT-TyPE'] . "\n"; // image/png +``` + +## Response body + +```php +get('https://www.example.com/'); + +echo $curl->response; +``` + +## Curl object + +> Example access to curl object. + +```php +setOpt(CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1'); +// or +curl_set_opt($curl->curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1'); +``` + +```php +close(); +// or +curl_close($curl->curl); +``` + +## Errors +```php +get('https://www.example.com/404'); + +if ($curl->error) { + echo 'Error code: ' . $curl->error_code . "\n"; // 404 + echo 'Error message: ' . $curl->error_message . "\n"; // HTTP/1.1 404 Not Found +} +else { + echo $curl->response; +} +``` + +## Parallel Requests + +```php +success(function($instance) { + echo 'call was successful. response was' . "\n"; + echo $instance->response . "\n"; +}); +$curl->error(function($instance) { + echo 'call was unsuccessful.' . "\n"; + echo 'error code:' . $instance->error_code . "\n"; + echo 'error message:' . $instance->error_message . "\n"; +}); +$curl->complete(function($instance) { + echo 'call completed' . "\n"; +}); + +$curl->get(array( + 'https://duckduckgo.com/', + 'https://search.yahoo.com/search', + 'https://www.bing.com/search', + 'http://www.dogpile.com/search/web', + 'https://www.google.com/search', + 'https://www.wolframalpha.com/input/', +), array( + 'q' => 'hello world', +)); +``` diff --git a/docs/watch.sh b/docs/watch.sh new file mode 100644 index 0000000..0537149 --- /dev/null +++ b/docs/watch.sh @@ -0,0 +1 @@ +bundle exec middleman server