Code Monkey home page Code Monkey logo

unsplash_client's Introduction

pub.dev package page GitHub Actions CI GitHub Stars

Unsplash provides free high-resolution photos. This is a client for their REST API.


If you're looking for a database solution, check out cbl, another project of mine. It brings Couchbase Lite to standalone Dart and Flutter, with support for:

  • Full-Text Search,
  • Expressive Queries,
  • Data Sync,
  • Change Notifications

and more.


Limitations

Endpoints that act on behalf of a user are not implemented, yet.If that is something you need, please comment on this issue.

Requirements

You need to register as a developer and create an Unsplash app to access the API.

Getting started

Create an UnsplashClient

Use the credentials for your app, obtained from the developer portal, to create an UnsplashClient:

final client = UnsplashClient(
  settings: ClientSettings(credentials: AppCredentials(
    accessKey: '...',
    secretKey: '...',
  )),
);

⚠️ When you are done using a client instance, make sure to call it's close method.

Get a random photo

// Call `goAndGet` to execute the [Request] returned from `random`
// and throw an exception if the [Response] is not ok.
final photos = await client.photos.random(count: 1).goAndGet();

// The api returns a `Photo` which contains metadata about the photo and urls to download it.
final photo = photos.first;

Photo variants

A Photo comes with a set of urls for variants of the photo of different sizes, such as regular and thumb:

final thumb = photo.urls.thumb;

If the provided variants are not a good fit for your use, you can generate urls where you specify size, quality, fit and other parameters.

Call the extension method Uri.resizePhoto on photo.urls.raw to generate an Uri for a custom variant:

final custom = photo.urls.raw.resizePhoto(width: 400, height: 400);

Example

The example is a simple CLI app that fetches a few random photos.


Gabriel TerwestenGitHub @blaugoldTwitter @GTerwestenMedium @gabriel.terwesten

unsplash_client's People

Contributors

blaugold avatar jonmountjoy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

unsplash_client's Issues

Track download wrong url

Related to the guidelines about tracking downloads it must call a specific endpoint.

https://help.unsplash.com/en/articles/2511245-unsplash-api-guidelines

What we have:
Screenshot 2023-12-27 at 20 42 28

Related to the guideline:

{
  "id": "LBI7cgq3pbM",
  "width": 5245,
  "height": 3497,
  "color": "#60544D",
  "urls": { ... },
  "user": { ... },
  "links": {
    "self": "https://api.unsplash.com/photos/LBI7cgq3pbM",
    "html": "https://unsplash.com/photos/LBI7cgq3pbM",
    "download": "https://unsplash.com/photos/LBI7cgq3pbM/download", // don't use this property
    "download_location": "https://api.unsplash.com/photos/LBI7cgq3pbM/download?ixid=MnwxMTc4ODl8MHwxfHNlYXJjaHwxfHxwdXBweXxlbnwwfHx8fDE2MTc3NTA2MTM" // use this one ;)
  }
}

Maybe instead of String id, we need to have String download_location

Temporary fix:

Request<TrackPhotoDownload> download(String downloadLocation) {
  final url = Uri.parse(downloadLocation);

  return Request(
    client: _client,
    httpRequest: http.Request('GET', url),
    isPublicAction: true,
    bodyDeserializer: (dynamic json) => TrackPhotoDownload.fromJson(json as Map<String, dynamic>),
  );
}

Add close method

The http.Client used internally by UnsplashClient should be closed when it is done being used.

UnsplashClient should expose a close method which disposes allocated resources such as http.Client. After this method has been called the client must not be used any more, which should be enforced.

  • Implement close
  • Tests
  • Update examples
  • Update README

Support endpoints which require resource owner

  • API for OAuth authentication

Endpoints

  • Get the user’s profile
  • Update the current user’s profile
  • Update a photo
  • Like a photo
  • Unlike a photo
  • Create a new collection
  • Update an existing collection
  • Delete a collection
  • Add a photo to a collection
  • Remove a photo from a collection

Store JSON source with models

The models only expose fields which are documented in the API docs, but users of the library might want to access undocumented fields.

To support this, models should have a source property which stores the JSON data which was used to create them.
This property is nullable because a model is not always built from an API response, for example when updating a resource.
Equality and hash code should not take this property into account, to avoid breaking existing code.

Unsplash API changes

Review the Unsplash API changelog and implement changes.

Dependency Conflict

Note: I haven't posted that many issues in GitHub. Let me know if I'm missing sth.

I'm getting the below error when running the flutter packages get

[habitize3] flutter packages get
Running "flutter pub get" in habitize3...
Because every version of flutter_test from sdk depends on collection 1.14.11 and every version of unsplash_client depends on collection ^1.14.12, flutter_test from sdk is incompatible with unsplash_client.

So, because habitize3 depends on both unsplash_client ^0.1.1 and flutter_test any from sdk, version solving failed.
pub get failed (1; So, because habitize3 depends on both unsplash_client ^0.1.1 and flutter_test any from sdk, version solving failed.)
exit code 1

Even when deleting flutter_test I'm getting conflict w/ collection

[habitize3] flutter packages get
Running "flutter pub get" in habitize3...
Because every version of flutter from sdk depends on collection 1.14.11 and every version of unsplash_client depends on collection ^1.14.12, flutter from sdk is incompatible with unsplash_client.

So, because habitize3 depends on both unsplash_client ^0.1.1 and flutter any from sdk, version solving failed.
pub get failed (1; So, because habitize3 depends on both unsplash_client ^0.1.1 and flutter any from sdk, version solving failed.)
exit code 1

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.