Giter Club home page Giter Club logo

warshmellow-gawkbox-assignment's Introduction

Remote Assignment V3

A REST API to get the following from Twitch v5 API:

Given a streamer’s username, get:

  1. user’s channel’s # of views
  2. user’s channel’s # of followers
  3. user’s channel’s game
  4. user’s channel’s language
  5. if the user is currently streaming
  6. user’s display name
  7. user’s bio
  8. user’s account creation date

We expose the following API:

GET /channels?id=
GET /streams?id=
GET /users?id=

channels will get you channel info, streams if the user is streaming, users for user info.

Getting started

Config

Config for the Twitch API is stored in a JSON file (e.g. twitch_config.json) of the following form:

{
  "client_id": "uo6dggojyb8d6soh92zknwmi5ej1q2",
  "accept_header": "application/vnd.twitchtv.v5+json",
  "get_channel_uri": "https://api.twitch.tv/kraken/channels/",
  "get_stream_uri": "https://api.twitch.tv/kraken/streams/",
  "get_user_uri": "https://api.twitch.tv/kraken/users/"
}

A sample config is included as twitch_config.json.

Build

Go get the repo with

go get -u github.com/warshmellow/warshmellow-gawkbox-assignment

Build with

go build

Start

Execute from the command line with the first argument being the path to the config file for Twitch API. This will start an HTTP Server listening on 8080.

./[executable] twitch_config.json

Try

Try the following request

GET http://localhost:8080/channels?id=98955702

This will get you channel info for user 98955702, aka "theDemodcracy".

API

Each endpoint uses an integer id query parameter. If you can't parse it, you'll receive a 400 Bad Request. If Twitch API itself gives an error, the API will return a 500.

Get Channel

GET /channels?id=

Given user id, get:

  1. user’s channel’s # of views
  2. user’s channel’s # of followers
  3. user’s channel’s game
  4. user’s channel’s language

Sample Successful Request

GET http://localhost:8080/channels?id=98955702

Sample Response

{"_id":98955702,"followers":16246,"game":"Destiny 2","language":"en","views":197480}

Sample Failed Request

GET http://localhost:8080/channels?id=1135165481

Response will be only the error Status Code from Twitch API. (e.g. 404)

Get Stream

GET /streams?id=

Given user id, get if the user is currently streaming. Note that if the user does not exist, you'll get streaming_now = false and a 200. This is consistent with Twitch API's Get Streams Endpoint.

Sample Successful Request

GET http://localhost:8080/streams?id=98955702

Sample Response

{"_id":98955702,"streaming_now":true}

Sample Failed Request

GET http://localhost:8080/channels?id=1135165481

Sample Response

{"_id":1135165481,"streaming_now":false}

Get User

GET /users?id=

Given user id, get:

  1. user’s display name
  2. user’s bio
  3. user’s account creation date

Sample Successful Request

GET http://localhost:8080/users?id=98955702

Sample Response

{
"_id":98955702,
"bio":"Variety speedrunner tries to live through memes to get all the PBs.",
"created_at":"2015-08-11T21:36:31.606157Z",
"display_name":"theDeModcracy"
}

Sample Failed Request

GET http://localhost:8080/users?id=1135165481

Response will be only the error Status Code from Twitch API. (e.g. 404)

Docker

Unfortunately I don't have access to a development machine allowing Docker. My development machine uses a version of Windows that doesn't allow the virtualization needed by Docker.

Further direction with Docker:

  1. Refactor the code to consume Twitch API config via environment variables
  2. Build the executable
  3. Put config as env. variables in Dockerfile
  4. Ship docker image with the executable

warshmellow-gawkbox-assignment's People

Contributors

warshmellow avatar

Watchers

James Cloos avatar  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.