Giter VIP home page Giter VIP logo

badgeup-dotnet-client's Introduction

BadgeUp .NET Client

Official .NET client for working with BadgeUp, a user engagement and gamification service.

Build Status Build status

Quickstart

Install

Install the package from nuget here.

Example Use

The BadgeUp .NET client is initialized with an API key which can be generated in the BadgeUp dashboard.

using BadgeUp;
using BadgeUp.Responses;
using BadgeUp.Types;
using System;

// instantiate the client
var client = new BadgeUpClient("<api key here>");

// create an event
var badgeupEvent = new Event("some_user", "jump", new Modifier { Inc = 1 });

// optionally provide a DateTimeOffset for when the event occurred
badgeupEvent.Timestamp = DateTimeOffset.Parse("2017-01-01T18:00:00+05:30");

//send an event
EventResponse response = await client.Event.Send(badgeupEvent);

// loop through all the progress results
foreach (var eventResult in response.Results)
{
    foreach (var prog in eventResult.Progress)
    {
        // check if this is a newly-earned achievement
        if (prog.IsComplete && prog.IsNew)
        {
            string earnedAchievementId = prog.EarnedAchievementId;
            string achievementId = prog.AchievementId;
            System.Console.WriteLine($"Achievement with ID {prog.AchievementId} Earned!");

            // from here you can use AchievementId and EarnedAchievementId to get the original achievement and awards objects
            var earnedAchievement = await client.EarnedAchievement.GetById(earnedAchievementId);
            var achievement = await client.Achievement.GetById(achievementId);

            // get associated award information
            foreach (var awardId in achievement.Awards)
            {
                var award = await client.Award.GetById(awardId);
                // in the dashboard set the award to `{ "points": 5 }`
                int points = award.Data["points"].ToObject<int>();
                System.Console.WriteLine($"Points awarded: {points}");
            }
        }
    }
}

Custom Meta Fields

To help relate BadgeUp resources to your product's internal resources, BadgeUp generally allows you to set custom fields in meta.

// you can get custom metadata fields for an achievement
string internalId = achievement.Meta.GetCustomField<string>("internal_id");
int fieldValueAsInteger = achievement.Meta.GetCustomField<int>("some_age_field");
MyClass fieldValueAsSpecificType = achievement.Meta.GetCustomField<MyClass>("custom_field_name");

Development

dotnet restore

Testing

dotnet test

Support

If you find an problem with this module, please file an issue. This library targets compatibility with .NET 4.6 and .NET Core v1.1 (LTS).

Release Instructions

dotnet build --configuration Release
dotnet pack --output nupkgs --include-symbols --include-source --configuration Release
dotnet nuget push .\BadgeUpClient\nupkgs\BadgeUpClient.0.0.1.nupkg --api-key <key> --source https://api.nuget.org/v3/index.json

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.