Skip to content

Commit

Permalink
Update README [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
sagikazarmark committed Jun 14, 2016
1 parent 7cdfccc commit 128fd40
Showing 1 changed file with 66 additions and 13 deletions.
79 changes: 66 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ $ composer require gravatarphp/gravatar

## Usage

Create a `UrlBuilder` instance and use it for creating URLs:
Create a `UrlBuilder` instance and use it for creating URLs.

``` php
use Gravatar\UrlBuilder;

// Use HTTPS, true by default
$urlBuilder = new UrlBuilder(false);

$urlBuilder->useHttps(true);
// Defaults: no default parameter, use HTTPS
$urlBuilder = new UrlBuilder([], true);

// Returns https://secure.gravatar.com/avatar/EMAIL_HASH
$urlBuilder->avatar('[email protected]');
Expand All @@ -44,13 +42,14 @@ $urlBuilder->vcard('[email protected]');
$urlBuilder->qrCode('[email protected]');
```

Or use the static version:

Or use the static version.

``` php
use Gravatar\StaticUrlBuilder as Gravatar;

// True by default
Gravatar::useHttps(true);
// Optional
Gravatar::configure([], true);

// Returns https://secure.gravatar.com/avatar/EMAIL_HASH
Gravatar::avatar('[email protected]');
Expand All @@ -65,16 +64,16 @@ Gravatar::vcard('[email protected]');
Gravatar::qrCode('[email protected]');
```

You can also use the `SingleUrlBuilder` which accepts an email in its constructor:

You can also use the `SingleUrlBuilder` which accepts an email in its constructor.

``` php
use Gravatar\SingleUrlBuilder;

// Email
// Use HTTPS, true by default
$urlBuilder = new UrlBuilder('[email protected]', false);

$urlBuilder->useHttps(true);
// No default parameters (optional)
// Use HTTPS (optional)
$urlBuilder = new SingleUrlBuilder('[email protected]', [], true);

// Returns https://secure.gravatar.com/avatar/EMAIL_HASH
$urlBuilder->avatar();
Expand All @@ -89,9 +88,63 @@ $urlBuilder->vcard();
$urlBuilder->qrCode();
```


In all three URL Bulders you can override the globally used protocol (HTTP, HTTPS) by setting the last parameter to
true/false.

``` php
use Gravatar\UrlBuilder;

$urlBuilder = new UrlBuilder();

// Returns http://www.gravatar.com/avatar/EMAIL_HASH
$urlBuilder->avatar('[email protected]', [], false);

// Returns http://www.gravatar.com/EMAIL_HASH
$urlBuilder->profile('[email protected]', false);

// Returns http://www.gravatar.com/EMAIL_HASH.vcf
$urlBuilder->vcard('[email protected]', false);

// Returns http://www.gravatar.com/EMAIL_HASH.qr
$urlBuilder->qrCode('[email protected]', false);
```


Last, but not least, you can pass default parameters to the builders...

``` php
use Gravatar\UrlBuilder;
use Gravatar\StaticUrlBuilder as Gravatar;
use Gravatar\SingleUrlBuilder;

$urlBuilder = new UrlBuilder([
'size' => 500,
]);

$urlBuilder = new SingleUrlBuilder(
'[email protected]',
[
'size' => 500,
]
);

Gravatar::configure([
'size' => 500,
]);
```


...and use them to generate avatar URLs.

``` php
// Returns https://secure.gravatar.com/avatar/EMAIL_HASH?size=500&r=g
$urlBuilder->avatar('[email protected]', ['r' => 'g']);
```


**Note:** Parameters are not sanitized or validated in anyway. For valid parameters check the [Gravatar documentation](http://gravatar.com/site/implement/).


**Note:** Profile, vCard and QR Code requests will only work with the primary email address. This is a limitation of Gravatar. However the builder won't complain, since it doesn't know if it is your primary address or not. For more tips and details check the [Gravatar documentation](http://gravatar.com/site/implement/).

Expand Down

0 comments on commit 128fd40

Please sign in to comment.