Giter Site home page Giter Site logo

wallhavenclient's Introduction

NuGet version (WallHavenClient) Nuget .NET License

WallHavenClient

WallHavenClient is a simple wrapper around the WallHaven API. There's a fluent query builder to simplify getting you the wallpapers you want.

I've wrote this as a very quick thing to run in a background app to keep my desktop wallpaper updating on an interval.

Getting Started

Install Nuget Package into test project:

dotnet add package WallHavenClient

Then once the package is installed you need to add the using statements

using WallHavenClient;

And from here you simply add the following to your DI

services.AddHttpClient<IWallHavenClient, WallHavenClient>();

And add some app settings:

  "WallHaven": {
    "APIKey": "", // Optional - Only used on NSFW Requests
    "BaseUrl": "https://wallhaven.cc/api/v1/"
  }

And bind this to the configuration object, and add that as a Singleton. Or however you want to get config, there's a few ways now.

Config config = new();
hostContext.Configuration.GetSection("WallHaven").Bind(config);
services.AddSingleton(config);

Contributions

Currently in a very early version/stage of this project. Open to PRs and critique, it's not the cleanest code but it does the job. Please raise issues and feel free to submit PRs (happy to discuss in an issue first to avoid wasted effort).

Examples

var _searchParams = new SearchParamsBuilder()
                  .WithMinimumResolution(3440, 1440)
                  .IncludeGeneral(true)
                  .IncludeAnime(false)
                  .IncludePeople(false)
                  .IncludeSafe(true)
                  .IncludeSketchy(false)
                  .IncludeNSFW(false)
                  .OrderBy(OrderBy.desc)
                  .SortBy(Sorting.date_added)
                  .Build();

var result = await _wallHavenClient.Search(_searchParams);

Which should return you a result like :

{
  "id": "e7ww6r",
  "url": "https://wallhaven.cc/w/e7ww6r",
  "short_url": "https://whvn.cc/e7ww6r",
  "uploader": null,
  "views": 5,
  "favorites": 3,
  "source": "https://www.artstation.com/pan",
  "purity": "sfw",
  "category": "general",
  "dimension_x": 3840,
  "dimension_y": 2160,
  "resolution": "3840x2160",
  "ratio": "1.78",
  "file_size": 7417712,
  "file_type": "image/jpeg",
  "created_at": "2021-09-03 20:05:14",
  "colors": [
    "#424153",
    "#000000",
    "#999999",
    "#663399",
    "#663300"
  ],
  "path": "https://w.wallhaven.cc/full/e7/wallhaven-e7ww6r.jpg",
  "thumbs": {
    "large": "https://th.wallhaven.cc/lg/e7/e7ww6r.jpg",
    "original": "https://th.wallhaven.cc/orig/e7/e7ww6r.jpg",
    "small": "https://th.wallhaven.cc/small/e7/e7ww6r.jpg"
  },
  "tags": null
}

wallhavenclient's People

Contributors

bigtalljosh avatar

Stargazers

 avatar

Watchers

 avatar  avatar

wallhavenclient's Issues

Make the Fluent API enforce the required options

There's a few ways we can do this, probably using interfaces. Would provide a better experience if it naturally chained the required options then put the optional or defaulted ones at the end.

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.