Giter Club home page Giter Club logo

remote's Introduction

Remote

Remote is a server that manages a list of Users. Each User has points (A positive :integer). By default, the points will be between 0 and 100; however, an admin can configure the range in Remote's configuration files (See docs).

The server will periodically update every User record with a new randomly generated :integer within the configured range. The interval between updates defaults to every 60 seconds; however, an admin can change it in Remote's configuration files (See docs).

Remote holds a :max_number in the state. Each time the Users points are updated the :max_number is updated with a random value within the configured range.

Remoteexposes an API with a single endpoint some_domain.com (See below for details).

Remote API

Request

A call to the Remote API will return a list with the configured number of Users (id and points) with a timestamp representing the utc_datetime of the last call to the API. The default number of Users is two (2).

Path Description Arguments
some_domain.com Returns JSON object with a list of User objects and the timestamp for the last call None

Response

{
 "timestamp":"2022-01-12T02:27:23.466953Z",
 "users":[
 {"id":1,"points":10},
 {"id":2,"points":57}
 ]
}

If an error occurs, you will receive one of the following responses.

{"errors":"Internal Server Error"}
{"errors":"Not Found"}
{"error":"User query failed!"}

Setting up Remote Locally

Start by cloning the repository on GitHub, or you can visit the page and download it directly.

$ git clone https://github.com/abarr/remote

The remainder of the instructions assumes you have Erlang, Elixir and Postgres installed and configured on your machine. If not, head over to the official Elixir and Postgres sites for instructions.

Once you have Remote in a local directory cd ~/remote and run the following commands:

  • Install dependencies with mix deps.get
  • Create and migrate your database with mix ecto.setup
  • Start Phoenix endpoint with mix phx.server or inside IEx with iex -S mix phx.server

Now you can visit localhost:3000 from your browser. If you have run the application with the default configuration and call the API within the first 60 seconds, your response will be as follows.

{"timestamp":null, "users": []}

This result occurs because the initial value of Users points is 0, and there are no Users with a points value greater than the :max_number. After the configured interval has passed, you will receive results showing the UTC timestamp for the last call to the API and the first two Users with a points value greater than the :max_number held in the state.

{"timestamp":"2022-01-12T02:19:23.853512Z","users":[{"id":1,"points":97},{"id":3,"points":92}]}

If there is only one or no Users with points values greater than :max_number, you will receive a list of one or an empty list, respectively.

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.