Giter Club home page Giter Club logo

perl-webservice-async-segment's Introduction

perl-WebService-Async-Segment

Unofficial support for segment.com API. It provides a Future-based async wrapper for Segment HTTP API. Supports standard fields both in snake_case and camelCase.

Using


use WebService::Async::Segment;
use IO::Async::Loop;

my $segment = WebService::Async::Segment->new(
    write_key=>'SOURCE_WRITE_KEY'
);

my $loop = IO::Async::Loop->new;
$loop->add($segment);

my $customer = $segment->new_customer(
    user_id => 'some_id',
    traits => {
        email => '[email protected]',
    }
);

### API calls api call (non-blocking)
$customer->identify();
$customer->track( event => 'buy', properties => {...} );

### API calls api call (blocking)
$customer->identify()->get;
$customer->track( event => 'buy', properties => {...} )->get;

Notes

  • Segment HTTP API accepts fields in camelCase only (e.g. userId and sentAt); the wrapper accepts these fields both in camelCase and snake_case (e.g. user_id and sent_at). Automatic conversion from snake_case to camelCase is performed on standard API fields only; custom fields are kept untouched. For exmaple:
$segment->new_customer(
    user_id => 'some_id',                     #standard field, will be converted to userId
    traits => {
        first_name => 'Matt',                 #standard field, will be converted to firstName
        my_company_attr => 'custom field'     #non-standard filed, will be sent without change
    }
);
  • Please note that all api call subroutines (WebService::Async::Segment::method_call, WebService::Async::Segment::Customer::identify and WebService::Async::Segment::Customer::track) are asynchronous, returning a Future object instead of waiting for the tasks to be finished.

perl-webservice-async-segment's People

Contributors

kirill-deriv avatar tom-binary avatar felipe-deriv avatar mat-fs 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.