### [Percy::Client on GitHub ](🔗)
Ruby API client library for [Percy](🔗).
NOTE: This is the low-level Percy API client---you probably want to use the [Capybara client](🔗) or the Ruby [command-line interface](🔗) instead.
Add this line to your application's Gemfile:
And then run:
Or install it yourself with `
gem install percy-client`.
Alternatively, you can set the `
PERCY_TOKEN` environment variable. Each repository has it's own write-only token, which can be found in Percy _Settings_ page for the repo.
There are four steps to working with Percy:
Create a build.
Create a snapshot for each HTML page, and indicate the resources that this page loads.
Upload any missing resources.
Finalize the build.
### Create a build
Or, to use the current Git repository name:
## Create a snapshot
is_root: true` param indicates the resource that is the main HTML resource of this snapshot, ie. the page that should be rendered. There must be exactly one root resource in a snapshot.
The API will automatically guess the resource mimetype based on the extension. If the URL doesn't have an extension, you can pass the `
mimetype: 'text/html'` param to the `
Percy::Client::Resource` object to explicitly set it.
Unlike calling `
finalize_build` later, the call to `
finalize_snapshot` is not strictly required. It is recommended, however, so that Percy can start processing the snapshot earlier and the build can be processed faster. If not called, Percy will wait to process snapshots until the build is finalized.
## Upload any missing resources
For performance reasons, resources are uploaded after the snapshot is created. Each snapshot API call returns a list of resource SHAs that have never been uploaded before and the client must followup and upload all the "missing" resources. This way, resources are only ever uploaded once and never re-uploaded unless they change.
The client uploads the "missing" resources:
## Finalize the build
Once all missing resources from all snapshots are uploaded, the client can finalize the build.
Done! After this, the build will finishing processing, creating screenshots and visual diffs, and the build can be viewed in Percy.
# Environment variables
You can set Percy [Environment variables](🔗) and they will override environment discovery.
[percy-client releases on GitHub](🔗)
Fork it (<https://github.com/percy/percy-client/fork>)
Create your feature branch (`
git checkout -b my-new-feature`)
Commit your changes (`
git commit -am 'Add some feature'`)
Push to the branch (`
git push origin my-new-feature`)
Create a new Pull Request