World Conquest Chronicles

World Conquest Chronicles

VK Group Stats, v1.0.0, alpha

GET /groups

Service for a collecting of a VK groups stats.

Alpha of a major release. Implement an authentication, the back-end API and a counters update by schedule.

Features

  • an authentication via VK;
  • users:
    • data:
      • MongoDB ObjectId;
      • VK ID;
    • operations:
      • automatically addition on an authentication;
  • groups:
    • data:
      • MongoDB ObjectId;
      • user ObjectId;
      • VK screen name;
    • operations (for a current user):
      • getting of all;
      • addition of one;
      • deletion of one;
  • counters:
    • data:
      • MongoDB ObjectId;
      • group ObjectId;
      • addition timestamp;
      • group members counter;
    • operations (for a specified group):
      • getting of all in a descending order;
      • getting of all in a descending order beginning with a specified timestamp;
      • addition of one (automatically via VK API);
      • deletion of all;
  • automatically addition of counters via VK API for all added groups by schedule.

Technologies

  • ECMAScript 2015;
  • Node.js;
  • Express;
  • MongoDB.

Usage

$ npm start

Environment variables:

  • VK_GROUP_STATS_SERVER_PORT — the server port (default: 3000);
  • VK_GROUP_STATS_MONGODB_HOST — the MongoDB host (default: localhost);
  • VK_GROUP_STATS_MONGODB_DATABASE — the MongoDB database (default: vk-group-stats);
  • VK_GROUP_STATS_MONGODB_PORT — the MongoDB port (default: 27017);
  • VK_GROUP_STATS_SESSION_SECURE — use secure sessions (TRUE to an use);
  • VK_GROUP_STATS_SESSION_SECRET — the sessions secret (default: a random UUID v4);
  • VK_GROUP_STATS_VK_APP_ID — the VK app ID (default: 5878021);
  • VK_GROUP_STATS_VK_APP_SECRET — the VK app secret;
  • VK_GROUP_STATS_VK_APP_CALLBACK — the VK app callback for an authentication (default: http://localhost:3000/authentication/vk/callback);
  • VK_GROUP_STATS_SCHEDULING — scheduling settings (use the cron utility format; default: 0 0 * * *, i.e. once every day).

API

API description in the Swagger format:

swagger: '2.0'
info:
  title: vk-group-stats
  version: 1.0.0
basePath: /api/v1
schemes:
- http
- https
consumes:
- application/x-www-form-urlencoded
- application/json
produces:
- application/json
paths:
  /groups:
    get:
      responses:
        200:
          description: OK
          schema:
            type: object
            properties:
              data:
                type: array
                items:
                  $ref: '#/definitions/group'
            required:
            - data
        401:
          description: Unauthorized
          schema:
            $ref: '#/definitions/error'
        500:
          description: Internal Server Error
          schema:
            $ref: '#/definitions/error'
    post:
      parameters:
      - $ref: '#/parameters/group_form'
      responses:
        200:
          description: OK
          schema:
            type: object
            properties:
              data:
                $ref: '#/definitions/group'
            required:
            - data
        400:
          description: Bad Request
          schema:
            $ref: '#/definitions/error'
        401:
          description: Unauthorized
          schema:
            $ref: '#/definitions/error'
        500:
          description: Internal Server Error
          schema:
            $ref: '#/definitions/error'
  /groups/{group_id}:
    parameters:
    - $ref: '#/parameters/group_id'
    delete:
      responses:
        200:
          description: OK
          schema:
            $ref: '#/definitions/ok'
        400:
          description: Bad Request
          schema:
            $ref: '#/definitions/error'
        401:
          description: Unauthorized
          schema:
            $ref: '#/definitions/error'
        500:
          description: Internal Server Error
          schema:
            $ref: '#/definitions/error'
  /groups/{group_id}/counters:
    parameters:
    - $ref: '#/parameters/group_id'
    get:
      parameters:
      - $ref: '#/parameters/start_timestamp'
      responses:
        200:
          description: OK
          schema:
            type: object
            properties:
              data:
                type: array
                items:
                  $ref: '#/definitions/counter'
            required:
            - data
        400:
          description: Bad Request
          schema:
            $ref: '#/definitions/error'
        401:
          description: Unauthorized
          schema:
            $ref: '#/definitions/error'
        500:
          description: Internal Server Error
          schema:
            $ref: '#/definitions/error'
    post:
      responses:
        200:
          description: OK
          schema:
            type: object
            properties:
              data:
                $ref: '#/definitions/counter'
            required:
            - data
        400:
          description: Bad Request
          schema:
            $ref: '#/definitions/error'
        401:
          description: Unauthorized
          schema:
            $ref: '#/definitions/error'
        500:
          description: Internal Server Error
          schema:
            $ref: '#/definitions/error'
    delete:
      responses:
        200:
          description: OK
          schema:
            $ref: '#/definitions/ok'
        400:
          description: Bad Request
          schema:
            $ref: '#/definitions/error'
        401:
          description: Unauthorized
          schema:
            $ref: '#/definitions/error'
        500:
          description: Internal Server Error
          schema:
            $ref: '#/definitions/error'
parameters:
  group_id:
    name: group_id
    in: path
    required: true
    type: string
    format: mongodb-objectid
    pattern: ^[0-9A-Fa-f]+$
    minLength: 24
    maxLength: 24
  group_form:
    name: body
    in: body
    required: true
    schema:
      $ref: '#/definitions/group_form'
  start_timestamp:
    name: start_timestamp
    in: query
    type: string
    format: iso8601-timestamp
    pattern: ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$
definitions:
  group_form:
    type: object
    properties:
      screen_name:
        type: string
    required:
    - screen_name
  group:
    type: object
    properties:
      _id:
        $ref: '#/definitions/mongodb-objectid'
      user_id:
        $ref: '#/definitions/mongodb-objectid'
      screen_name:
        type: string
    required:
    - _id
    - user_id
    - screen_name
  counter:
    type: object
    properties:
      _id:
        $ref: '#/definitions/mongodb-objectid'
      group_id:
        $ref: '#/definitions/mongodb-objectid'
      timestamp:
        type: string
        description: date and time in ISO 8601 format
        pattern: ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$
      value:
        type: integer
        minimum: 0
    required:
    - _id
    - group_id
    - timestamp
    - value
  ok:
    type: object
    properties:
      data:
        type: boolean
        description: always true
    required:
    - data
  error:
    type: object
    properties:
      errors:
        type: array
        minItems: 1
        items:
          type: object
          properties:
            message:
              type: string
            field:
              type: string
          required:
          - message
    required:
    - errors
  mongodb-objectid:
    type: string
    pattern: ^[0-9A-Fa-f]+$
    minLength: 24
    maxLength: 24

Repository

Link: https://github.com/thewizardplusplus/vk-group-stats/tree/v1.0.0-alpha.

Content: code.

License: MIT.

Screenshots

POST /groups

POST /groups

DELETE /groups/{group_id}

DELETE /groups/{group_id}

GET /groups/{group_id}/counters

GET /groups/{group_id}/counters

POST /groups/{group_id}/counters

POST /groups/{group_id}/counters

DELETE /groups/{group_id}/counters

DELETE /groups/{group_id}/counters