Coder Social home page Coder Social logo

bluesky-net's Introduction

NuGet GitHub license

N|Solid

Bluesky.Net

Unofficial .NET implementation of atproto.com

About the target framework

To simplify the development, first versions will target only NET7.0+

Eventually the library will support NET standard 2.0

About the results

The api implements a basic discriminated union pattern for all the results.

The first option of the result is what you expect, the second an error if the HTTP status code is > 2xx

How to use it

1- Install the nuget package

Install-Package Bluesky.Net

2- Add the SDK to your services collection

services.AddBluesky();

3- The SDK can be configured

services
    .AddBluesky(options => {
        options.TrackSession = false;
    });

4- Inject the IBlueskyApi in your code

public class MyClass
{
    private readonly IBlueskyApi _bluesky;
    public MyClass(IBlueskyApi bluesky)
    {
        _bluesky = bluesky;
    } 
}

5 - Call the api

Login command = new("YOUR_HANDLE", "YOUR_PASSWORD");
Multiple<Session, Error> result = await _bluesky.Login(command, CancellationToken.None);

result
    .Switch(
        session => Console.WriteLine(session.Email),
        error => Console.WriteLine(JsonSerializer.Serialize(error)
    );    

6 - Create a post

Multiple<Did, Error> resolvedHandle = await api.ResolveHandle(session.Handle, CancellationToken.None);
        
string text =
        @"Link to Google This post is created with Bluesky.Net. A library to interact with Bluesky. A mention to myself and an emoji '๐ŸŒ…'";
    int mentionStart = text.IndexOf("myself", StringComparison.InvariantCulture);
    int mentionEnd = mentionStart + Encoding.Default.GetBytes("myself").Length;
    CreatePost post = new(
        text,
        new Link("www.google.com", 0, "Link to Google".Length),
        new Mention(resolvedHandle.AsT0, mentionStart, mentionEnd));

    //Create a post
    Multiple<CreatePostResponse, Error> created = await api.CreatePost(post, CancellationToken.None);    

Retries

You can easily plug retries with Polly when registering the api. Install the nuget package

Install-Package Microsoft.Extensions.Http.Polly

Configure your retries:

services
  .AddBluesky()
  .AddPolicyHandler(
      HttpPolicyExtensions
        .HandleTransientHttpError()
        .OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.ServiceUnavailable)
        .WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2,retryAttempt))));

bluesky-net's People

Contributors

dariogriffo avatar

Watchers

 avatar

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.