DeviantArtFs 4.0.0-beta1

This is a prerelease version of DeviantArtFs.
There is a newer version of this package available.
See the version list below for details.
dotnet add package DeviantArtFs --version 4.0.0-beta1                
NuGet\Install-Package DeviantArtFs -Version 4.0.0-beta1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DeviantArtFs" Version="4.0.0-beta1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DeviantArtFs --version 4.0.0-beta1                
#r "nuget: DeviantArtFs, 4.0.0-beta1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DeviantArtFs as a Cake Addin
#addin nuget:?package=DeviantArtFs&version=4.0.0-beta1&prerelease

// Install DeviantArtFs as a Cake Tool
#tool nuget:?package=DeviantArtFs&version=4.0.0-beta1&prerelease                

DeviantArtFs

A .NET / F# library to interact with the DeviantArt / Sta.sh API.

If you're using this library in a .NET Framework project and it doesn't run, make sure that the dependencies (FSharp.Core, FSharp.Json, FSharp.Control.AsyncSeq) are installed via NuGet.

Notes

Each request that can be made to DeviantArt is represented by a module somewhere in the DeviantArtFs.Requests namespace. These modules have static methods that take an IDeviantArtAccessToken (see "Authentication" below) and usually at least one other parameter. The main method is usually named AsyncExecute and returns an async workflow, the result of which is an F# record type that lines up with the original JSON.

Many objects in the DeviantArt API have optional fields, which are difficult to represent in languages such as F# that expect a fixed schema. DeviantArtFs represents these optional fields with F# option types.

For requests that return an object with a single field that is either a string or a list, DeviantArtFs will flatten the response to just the string or list itself.

Using the library from C# or VB.NET

Since F# async workflows and option types can be awkward to work with in other .NET languages, DeviantArtFs also exposes its functionality through alternate methods and interfaces. Modules with an AsyncExecute method also have an ExecuteAsync method that returns a Task<T>, and each record type has an explicit interface implementation that exposes the same fields, but with nullable types instead of option types. (Keep in mind that this is an explicit interface implementation, which has implications for JSON serialization.) This approach results in a lot of boilerplate code, but provides a consistent pattern.

Deleted Deviations and Status Updates

Deviation and DeviantArtStatus objects can represent a deviation or status update that has been deleted; this is why most of the fields on those two types are marked optional. Check the is_deleted field (or IsDeleted property) before attempting to access any of the other fields.

Pagination

Some of the DeviantArt endpoints support pagination. For endpoints that use offset-based pagination, the AsyncExecute and ExecuteAsync methods take a parameter of the type IDeviantArtPagingParams:

public interface IDeviantArtPagingParams
{
    int Offset { get; }
    int? Limit { get; }
}

(The type DeviantArtPagingParams implements this interface.)

To request the maximum page size for a particular request, use int.MaxValue as the Limit property. (The limits for each request are hardcoded into DeviantArtFs, so it will never request more data than DeviantArt allows.)

Methods that use cursor-based pagination will take a string or string option parameter instead.

Modules for endpoints that support pagination also have ToAsyncSeq and ToArrayAsync methods, which can be used to fetch an arbitary amount of data as needed. (Keep in mind that some of the endpoints, like /browse/newest, might return a theoretically unlimited amount of data!)

Partial updates

Stash.Update and User.ProfileUpdate allow you to choose which fields to update on the object. DeviantArtFs uses a discriminated union (DeviantArtFieldChange<T>) to represent these updates:

new DeviantArtFs.Requests.Stash.UpdateRequest(4567890123456789L) {
    Title = DeviantArtFieldChange<string>.NewUpdateToValue("new title"),
    Description = DeviantArtFieldChange<string>.NoChange
}

Note that DeviantArt allows a null value for some fields, but not others.

Currently unsupported features

  • The following fields in the deviation object are not supported:
    • challenge
    • challenge_entry
    • motion_book
  • The profile_pic field in the user.profile expansion is not supported due to circular type definitions. Get it from the full profile object instead.

Usage

Example (C#):

int offset = 0;
while (true) {
    var req = new DeviantArtFs.Requests.Gallery.GalleryAllViewRequest();
    var paging = new DeviantArtPagingParams {
        Offset = offset,
        Limit = 24
    };
    IBclDeviantArtPagedResult<IBclDeviation> resp =
        await DeviantArtFs.Requests.Gallery.GalleryAllView.ExecuteAsync(token, paging, req);
    foreach (var d in resp.Results) {
        Console.WriteLine($"{d.Author.Username}: ${d.Title}");
    }
    offset = resp.NextOffset ?? 0;
    if (!resp.HasMore) break;
}

Example (F#):

let mutable offset = 0
let mutable more = true
while more do
    let req = new DeviantArtFs.Requests.Gallery.GalleryAllViewRequest()
    let paging = new DeviantArtPagingParams(Offset = 0, Limit = Nullable 24)
    let! (resp: DeviantArtPagedResult<Deviation>) = DeviantArtFs.Requests.Gallery.GalleryAllView.AsyncExecute token paging req
    for d in resp.Results do
        printf "%s: %s" d.author.username d.title
    offset <- resp.next_offset |> Option.defaultValue 0
    more <- resp.has_more

See ENDPOINTS.md for more information.

Common parameters

Several endpoints support common object expansion (e.g. user.details, user.geo) and/or mature content filtering. To use these features of the DeviantArt API, wrap the token using DeviantArtCommonParameters.Wrap. For example:

var commonParameters = new DeviantArtCommonParameters {
    Expand = DeviantArtObjectExpansion.UserDetails | DeviantArtObjectExpansion.UserGeo,
    MatureContent = true
};
var new_token = commonParameters.WrapToken(token);
var me = await Requests.User.Whoami.ExecuteAsync(new_token);

Examples

The Examples folder in the source code repository contains small applications that use DeviantArtFs:

  • RecentSubmissions.CSharp: A C# console application that shows the most recent submission, journal, and status for a user, along with any favorites or comments. (WinForms is needed for the login window, however.) Uses the Implicit grant and stores tokens in a file.
  • RecentSubmissions.FSharp: As above, but in F#, to demonstrate how DeviantArtFs has both F#-style and .NET-style functions and types.
  • GalleryViewer: A VB.NET app that lets you see the "All" view of someone's gallery and read the descriptions of individual submissions. Uses the Client Credentials grant and stores tokens in a file.
  • WebApp: An ASP.NET Core 2.1 app written in C# that lets you view someone's gallery folders and corresponding submission thumbnails. Uses the Client Credentials grant and stores tokens in a database.

Authentication

See also: https://www.deviantart.com/developers/authentication

Both Authorization Code (recommended) and Implicit grant types are supported. If you are writing a Windows desktop application, you can use the forms in the DeviantArtFs.WinForms package to get a code or token from the user using either grant type.

The DeviantArtAuth class provides methods to support the Authorization Code grant type (getting tokens from an authorization code and refreshing tokens).

If you need to store the access token somewhere (such as in a database or file), create your own class that implements the IDeviantArtAccessToken or IDeviantArtRefreshToken interface.

Since version 1.1, DeviantArtFs supports automatic refreshing of tokens when it recieves an HTTP 401 response. (An InvalidRefreshTokenException is thrown if the token cannot be refreshed.) If you'd like to take advantage of it, implement the interface IDeviantArtAutomaticRefreshToken. The method UpdateTokenAsync should update the tokens both in the object itself and in the backing store. You can find example implementations in WebApp (TokenWrapper.cs) and GalleryViewer (AccessToken.vb).

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DeviantArtFs:

Package Downloads
DeviantArtFs.Stash.Marshal

An F#/.NET library to interact with the Sta.sh API and manage state (.NET Standard 2.0)

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
11.0.0 87 10/28/2024
11.0.0-beta2 70 10/28/2024
10.1.0-beta2 92 10/20/2024
10.1.0-beta1 76 9/21/2024
10.0.0 125 8/8/2024
10.0.0-rc1 98 8/8/2024
9.2.1-rc1 82 8/7/2024
9.2.0 111 6/19/2024
9.2.0-beta1 97 6/19/2024
9.1.1 123 4/27/2024
9.1.0-rc1 213 11/27/2023
9.0.0 274 11/22/2023
9.0.0-beta4 145 5/30/2023
9.0.0-beta2 111 5/28/2023
8.0.0 466 5/30/2021
8.0.0-beta4 283 5/30/2021
8.0.0-beta3 337 5/30/2021
8.0.0-beta2 238 5/30/2021
7.0.1 405 1/11/2021
7.0.0 384 1/9/2021
7.0.0-beta1 296 1/9/2021
6.0.2 369 1/5/2021
6.0.1 435 12/28/2020
6.0.0 346 12/27/2020
6.0.0-beta2 331 12/26/2020
6.0.0-beta1 323 12/26/2020
5.0.0 520 2/11/2020
5.0.0-beta1 438 2/11/2020
4.0.0 506 1/23/2020
4.0.0-beta2 453 1/23/2020
4.0.0-beta1 462 1/22/2020
3.0.0 555 1/17/2020
2.2.0 558 1/6/2020
2.1.0 534 9/9/2019
2.0.0-beta3 507 3/9/2019
2.0.0-beta2 486 3/8/2019
2.0.0-beta1 481 3/6/2019
1.1.0-beta1 476 3/5/2019
1.0.0 703 2/10/2019
0.9.0 1,352 1/29/2019
0.8.0 695 1/28/2019
0.7.3 717 1/22/2019
0.7.2 696 1/22/2019
0.7.1 1,359 1/19/2019
0.7.0 731 1/18/2019
0.6.0 1,391 1/14/2019
0.5.0 1,361 1/11/2019
0.4.0 1,383 1/3/2019
0.3.0 1,386 12/31/2018
0.2.0-alpha 1,185 12/27/2018
0.1.0-alpha 621 12/21/2018

4.0.0: Some minor cleanup; remove deprecated fields