Code Monkey home page Code Monkey logo

variscite_dart's Introduction

Также доступно на русском языке

Variscite Dart

Pub Package GitHub License

Part of "Variscite" project. Here is also API and client app

Library for Dart programming language for work with Variscite API. Written poorly with Dart and uses this libraries:

  • dio - library for working with HTTP, creating and sending requests to API
  • geojson_vi - library for working with GeoJSON objects, namely for constructing them from JSON
  • equatable - auxiliary library for more convenient comparation of API objects

Library implements all API endpoints of version 0.3, you can find list of all methods in file lib/src/api.dart

Examples

Group creation and login:

import 'package:variscite_dart/variscite_dart.dart';

void main() async {
    // At the start, it is necessary to initialize VarisciteApi
    // class. It performs all functions, related to API
    final api = VarisciteApi();

    // Creation of group with name "New group" and admin password
    // "qwerty"
    final group = await api.createNewGroup(
        GroupCreationBody(name: 'New group', passcode: 'qwerty'),
    );

    // Logging in group with name "Admin" and passcode "qwerty"
    // If passcode doesn't exists, user won't have admins rights
    final user = await api.loginUsingInviteCode(
        group.inviteCode,
        UserLoginBody(name: 'Admin', passcode: 'qwerty'),
    );

    // Setting up user token, token is needed for any of farther
    // actions, related to group
    api.setToken(user.token);
}

Retrieving group information and list of users:

import 'package:variscite_dart/variscite_dart.dart';

void main() async {
    final api = VarisciteApi(token: 'super.secret.token');

    // Retrieving group information: name, invite code, id
    final groupInfo = await api.getCurrentGroupInfo();

    // Retrieving list of users, each element contains name,
    // rights information (admin or not) and user id
    final users = await api.getUsersList();
}

Working with geographical structures:

import 'package:variscite_dart/variscite_dart.dart';

void main() async {
    final api = VarisciteApi(token: 'super.secret.token');

    // Retrieving list of all structures, each element contains
    // structure' id and id of user created it, additional fields
    // (they can be edited separately) and most important -
    // GeoJSON object (it has FeatureCollection type)
    final structures = await api.getAllStructures();

    // Creating Map object that contains GeoJSON object
    final feature = {
        'type': 'FeatureCollection',
        'features': [
            {
                'type': 'Feature',
                'properties': {},
                'geometry': {
                'type': 'Polygon',
                    'coordinates': [
                        [
                            [34.453125, 54.007768],
                            [40.78125, 54.007768],
                            [40.78125, 57.326521],
                            [34.453125, 57.326521],
                            [34.453125, 54.007768],
                        ],
                    ],
                },
            },
        ],
    };
    // Transforming Map<String, dynamic> into GeoJSONFeatureCollection
    final collectionGeoJSON = GeoJSONFeatureCollection.fromMap(feature);

    // Creating structure from GeoJSON object, storing it into
    // database
    final newStruct = await api.addNewStructure(collectionGeoJSON);
}

Working with geolocation:

import 'package:variscite_dart/variscite_dart.dart';

void main() async {
    final api = VarisciteApi(token: 'super.secret.token');

    // Retrieving geolocation of all users with open geolocation
    // in group
    final allLocations = await api.getAllGeolocation();
    // If you need to remove geolocation of current user
    // (user that sended request), you can achive it by passing
    // "excludeUser: true" argument
    final almostAllLocations = await api.getAllGeolocation(excludeUser: true);

    // Updating geolocation of current user
    await api.editCurrentUserGeolocation(GeolocationPosition(
        latitude: 37.478860,
        longitude: 55.670802,
    ));
}

Specifying address of your own API:

import 'package:variscite_dart/variscite_dart.dart';

void main() async {
    // In this case reqiests will be sended to https://example.com
    final api = VarisciteApi(serviceUrl: 'https://example.com');
}

variscite_dart's People

Contributors

uslashvlad avatar

Watchers

 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.