Coder Social home page Coder Social logo

test-api-message-sender's Introduction

The task

We need to create a prototype of a service. The service to need to emulate sending of messages to popular messengers (Viber, Telegram, WhatsApp).

The app should be able to do the following:

  • take messages though its API and send to messengers (with user identifier);
  • be able to schedule sending on specific date and time;
  • if delivery failed - re-send it N times;
  • no possibility of a message sent more than once to a single recipient;
  • ability to send the same message to different recipients in just one incoming api request;

Project Overview

  1. Sidekiq is used to queue and send requests in background (also allows scheduling). While Rails API part is free to take new requests.
  2. Redis is used by Sidekiq to store all of its job and operational data.
  3. Posgtres is used to have historical requests' data in persistent storage.
  4. Grape allows for easier and faster of API making, validation of incoming requests.
  5. AASM is for taking advantage of finite state machine pattern. Allows dynamically change request statuses and persist it in database.
  6. httparty allows to make requests to api stubs. This way stubs emulate behaviour of a fake live service.

Setup

1. Versions

Make sure you have the latest stable ruby version which is currently for this project - 2.7.0

In addition, you need to install Redis (currently it's redis-5.0.7 used). Redis is used by background worker Sidekiq.

2. Bundle up

Go to the project's directory in your command line bundle install or simply bundle.

Launch the project

1. Database setup

Find database.yml.sample and configure your own database.yml out of it.

Then run:

bundle exec rails db:create && bundle exec rails db:migrate

2. Launch the apps

Run the following to start Redis:

redis-server

Launch Rails app:

bundle exec rails s

Launch Sidekiq:

bundle exec sidekiq -C ./config/sidekiq.yml

How to use API

To send requests to API you can use Postman's desktop app.

To see what is going on with requests you can go to http://localhost:3000/sidekiq (the 'Live poll' button can be handy too).

Request fields

Parameter Type Required?
message string yes
send_to array yes
schedule_at array no
messenger_type string yes
phone_number string yes

JSON body example:

{
  "message": "Some message",
  "send_to": [
    {
      "messenger_type": "viber",
      "phone_number": "79991234567891"
    },
    {
      "messenger_type": "whatsapp",
      "phone_number": "79998976543212"
    }	
  ]
}

or with schedule_at option:

{
  "message": "Some message",
  "schedule_at": "2020-02-02 21:33:57.917883 +0300",
  "send_to": [
    {
      "messenger_type": "viber",
      "phone_number": "79991234567891"
    }		
  ]
}

Note: 20% of the time messengers' stubs will return error which is on purpose. It emulates the case when a service is unavailable so request can be retried again but no more than 4 times (set by default).

test-api-message-sender's People

Contributors

adancedwin 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.