Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ok #5

Open
wants to merge 6 commits into
base: feature/support-composer
Choose a base branch
from
Open

Ok #5

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# Simple cURL Library

![](https://badgen.net/github/release/andhikayuana/curl-lib?icon=github&color=green)
![](https://badgen.net/packagist/v/andhikayuana/curl-lib?color=orange)
![](https://badgen.net/packagist/license/andhikayuana/curl-lib)

Simple wrapper for cURL using PHP.

> **_NOTE:_** Supported composer package from [v2.0.0](https://github.com/andhikayuana/curl-lib/tree/v2.0.0), If you need native version you can check [v1.0.0](https://github.com/andhikayuana/curl-lib/tree/v1.0.0)
> **_NOTE:_** Supported composer package from v2.0.0, If you need native version you can check [v1.0.0](https://github.com/andhikayuana/curl-lib/tree/v1.0.0)

## Installation

```bash
composer require andhikayuana/curl-lib
```


## Usage

Create instance
```php
require 'vendor/autoload.php';

$curl = new \Yuana\Curl();
```

Expand Down Expand Up @@ -85,4 +90,8 @@ Feel free to check [CONTRIBUTING.md](./CONTRIBUTING.md) file
## Todos

- [ ] Proxy
- [x] Composer Package
- [x] Composer Package

## Donation

[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/T6T02OS5W)
139 changes: 68 additions & 71 deletions src/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,80 +5,77 @@
/**
* Simple wrapper for cURL
* @author Yuana <[email protected]>
* @since March, 3 2017
* @since November, 15 2020
* @license MIT
*
* --------------------------------------
* How to use with native PHP
*
* require 'Curl.php';
* and make instance :
*
* $curl = new Curl();
* $curl->get('http://api.halo.com/users,array(
* 'users_id' => 3
* ));
* --------------------------------------
*
* --------------------------------------
* How to use this library for Codeigniter
* --------------------------------------
*
* copy Curl.php to `application/libraries`
*
* load the library
* `$this->load->library('curl');`
* --------------------------------------
*
* HEADERS
* add some header like this
* $this->curl->headers = array(
* 'X-API-KEY' => 'randomapikeyhere',
* 'some-header-key' => 'some-header-value'
* );
*
* POST
* $res = $this->curl->post('http://api.domain.com/login', array(
* 'email' => '[email protected]',
* 'password' => 'helloworld'
* ));
*
* var_dump($res);
*
* GET
* $res = $this->curl->get('http://api.domain.com/trips', array(
* 'trips_id' => 2
* ));
*
* var_dump($res);
*
* another method
* PUT
* $this->curl->put($url, array('field' => 'val'));
*
* DELETE
* $this->curl->delete($url, array('field' => 'val'));
*
* TIMEOUT [default 30 sec.]
* $this->curl->timeout = 60;
*
* REDIRECT [default TRUE]
* $this->curl->isRedirect = false;
*
* HEADERS
* $this->curl->headers = array(
* 'Authorization' => 'Bearer yourtokenhere'
* );
*
* UPLOAD
* $this->curl->upload('http://api.domain.com/upload', array(
*
* =================================================
*
* Create instance
* ```php
* require 'vendor/autoload.php';
*
* $curl = new \Yuana\Curl();
* ```
*
* HTTP GET method
* ```php
* $res = $curl->get('http://api.halo.com/users');
*
* // using query
* // http://api.halo.com/users?users_id=2
* $res = $curl->get('http://api.halo.com/users', [
* 'users_id' => 2
* ]);
* ```
*
* HTTP POST method
* ```php
* $res = $curl->post('http://api.halo.com/login', [
* 'username' => 'yuana',
* 'password' => 'yourpassword'
* ]);
* ```
*
* HTTP PUT method
* ```php
* $res = $curl->put('http://api.halo.com/users', [
* 'users_id' => 3,
* 'users_name' => 'Yuana Andhika',
* 'users_dept' => 'Android Developer'
* ]);
* ```
*
* HTTP DELETE method
* ```php
* $res = $curl->delete('http://api.halo.com/users', [
* 'users_id' => 3
* ]);
* ```
*
* Uploading file
* ```php
* $res = $curl->upload('http://api.domain.com/upload', [
* 'fieldA' => '/path/to/file/fileA.jpg',
* 'fieldB' => '/path/to/file/fileB.jpg',
* ));
*
* TODO :
* 1. proxy
* 2. composer package
* ]);
* ```
*
* Configuration
* ```php
* //override timeout [default 30]
* $curl->timeout = 25;
*
* //override redirection [default true]
* $curl->isRedirect = false;
*
* //override user agent [default from http user agent]
* $curl->userAgent = 'Android App 1.1';
*
* //override headers
* $curl->headers = [
* 'Authorization' => 'Bearer yourtokenhere'
* ];
* ```
*/
class Curl {

Expand Down