Giter VIP home page Giter VIP logo

kanka's Introduction

kanka

PkgGoDev Build Status Coverage Status Go Report Card

Manage your Kanka campaign or build tools for other creators with the thoroughly tested and documented kanka package.

The kanka package provides a client to handle all communication with the Kanka API.

The package is structured into convenient and discoverable services for managing characters, locations, organizations, events, and much more.

Installation

If you do not have Go installed yet, you can find installation instructions here.

To pull the most recent version of kanka, use go get.

go get github.com/Henry-Sarabia/kanka

Then import the package into your project as you normally would.

import "github.com/Henry-Sarabia/kanka"

Usage

Creating A Client

To use the kanka package, you need a Kanka API key. If you do not have a key yet, you can follow the instructions here to get one.

Create a client with your API key to start communicating with the Kanka API.

c, err := kanka.NewClient("YOUR_API_KEY", nil)

If you need to use a preconfigured HTTP client, simply pass its address to the NewClient function.

c, err := kanka.NewClient("YOUR_API_KEY", &custom)

Services

The client contains a separate service for working with each of the Kanka API endpoints. Each service has a set of functions to retrieve, list, create, update, or delete campaign data.

To start communicating with the Kanka API, choose a service and call one of its functions.

Take the Campaigns service for this example.

To retrieve a list of the current user's campaigns, use the Index function.

cmps, err := c.Campaigns.Index()

You now have access to a list of the user's campaigns via cmps.

Retrieving An Entity

To retrieve a specific entity from a campaign, use the Get function.

Take the Quests service for example.

For this service, Get requires a campaign ID and quest ID.

qst, err := c.Quests.Get(cmpID, qstID)

The result is stored in qst of type Quest.

Retrieving A List Of Entities

To retrieve a list of a campaign's entities of a certain type, use the Index function.

Take Locations for example.

For this service, Index requires only a campaign ID.

locs, err := c.Locations.Index(cmpID, nil)

If you want to limit the results to only the locations that have been updated since a specific time, provide that time to the Index function.

t := time.Date(2019, time.November, 4, 11, 0, 0, 0, time.UTC)

locs, err := c.Locations.Index(cmpID, t)

The result is stored in locs of type []Location.

Creating An Entity

To create a new entity, use the Create function.

Take Characters for example.

For this service, Create requires a campaign ID and the data for the new character in the form of type SimpleCharacter.

ch := SimpleCharacter{
    Name: "Daenerys Targaryen",
    Sex: "Female",
    Title: "Mother of Dragons",
}

_, err := c.Characters.Create(cmpID, ch)

The Create functions return the newly created entity back to the caller.

This example simply discards the value.

Updating An Entity

To update an existing entity, use the Update function.

Take Items for example.

For this service, Update requires a campaign ID, an item ID, and the data for the new item in the form of type SimpleItem.

item := SimpleItem{
    Name: "Bag of Holding",
    Size: "15 pounds",
    Price: "300 gold",
}

_, err := c.Items.Update(cmpID, item)

The Update functions return the updated entity back to the caller.

This example simply discards the value.

Deleting An Entity

To delete an entity, use the Delete function.

Take Journals for example.

For this service, Delete requires a campaign ID and a journal ID.

err := c.Journals.Delete(cmpID, jrnID)

Rate Limits, Errors, And You

The Kanka API is rate limited. For the most accurate and updated information, please visit the Kanka documentation.

If one of your requests to the Kanka API fails due to the rate limit or other temporary reason, the error returned can be asserted for the Temporary behavior.

For more information about temporary errors, please visit Dave Cheney's blog.

Contributions

If you would like to contribute to this project, please adhere to the following guidelines.

  • Submit an issue describing the problem.
  • Fork the repo and add your contribution.
  • Add appropriate tests.
  • Run go fmt, go vet, and golint.
  • Prefer idiomatic Go over non-idiomatic code.
  • Follow the basic Go conventions found here.
  • If in doubt, try to match your code to the current codebase.
  • Create a pull request with a description of your changes.

kanka's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

kanka's Issues

Incorrect test cases for Entity services

One case (Status OK, valid response, invalid entID) from two service functions (Create and Update) are not correctly testing for an invalid entID.

The following services are affected from the same or similar bug:

  • Attributes
  • EntityEvents
  • EntityInventories
  • EntityNotes
  • EntityTags
  • Relations

Unexport ServerError

Custom error types should only be exported for a specific reason. This repository does not have any reason to export it.

Add README

Write and add a README explaining the following aspects of the package:

  • Installation
  • Usage
  • Examples

Fix gofmt errors

Every test file needs to be formatted with the gofmt simplify tag.

Incorrect documentation for compound-word services

Services with names comprised of compound words have grammatical errors in their type's documentation.

The following services are affected with the same or similar errors:

  • EntityEvent
  • EntityInventory
  • EntityNote
  • EntityTag
  • MapPoint
  • QuestCharacter

Support Go modules

As soon as this project reaches v1.0.0, it will become its own Go module.

Add LICENSE

I plan to maintain the project as open source under the MIT license.

The license needs to be added to the repository.

Implement request retry functionality

The Kanka API allows 30 request per minute (increased to 90 for Patreons). Kanka will throttle a user's requests if they exceed this limit.

A retry option should be implemented into the Client so a user can opt into automatically retrying their requests in the event of receiving a 421 or 429 HTTP response code.

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.