0.0.1-beta.0.8 • Published 3 years ago

haraloyalty-sdk v0.0.1-beta.0.8

Weekly downloads
42
License
MIT
Repository
-
Last release
3 years ago

Haraloyalty JavaScript SDK

SDK for the Haraloyalty API

Full API docs are available here.

Changelog

View our Changelog for details about our releases.

Table Of Contents

Installation

With NPM:

$ npm install haraloyalty-sdk

CDN:

There is a minified UMD build available via CDN (see the Changelog for details about the latest release):

<script src="https://cdn-loyalty.xxx/sdk/v1/latest/index.umd.min.js"></script>

Builds

The JS Buy SDK has four build versions: ES, CommonJS, AMD, and UMD.

ES, CommonJS:

import HaraloyaltySdk from 'haraloyalty-sdk';

Examples

Initializing the haraloyaltySDK

import HaraloyaltySdk from 'haraloyalty-sdk';

// Initializing a sdk to return haraloyalty api
const sdk = HaraloyaltySdk.init({
  accessToken: 'haraloyalty-access-token',
  host: 'host haraloyalty api' // ex host.com
});

Fetching Segments

// Fetch all segments 
sdk.Segments.FetchAll().then((segments) => {
  // Do something with the segments
  console.log(segments);
});

// Fetch all segments with pagination ( page, limit )
sdk.Segments.Page(1)
            .Limit(20)
            .FetchAll()
            .then((segments) => {
  // Do something with the segments
  console.log(segments);
});

// Fetch all segments with search ( keyword )
sdk.Segments.Keyword('search-keyword')
            .FetchAll()
            .then((segments) => {
  // Do something with the segments
  console.log(segments);
});

// Fetch all segments with sort ( sort_by & sort_type )
sdk.Segments.SortBy('id')
            .SortType('DESC')
            .FetchAll()
            .then((segments) => {
  // Do something with the segments
  console.log(segments);
});

// Fetch a single segment by ID
const segmentId = 'Z2lkOi8';

sdk.Segments.Fetch(segmentId).then((segment) => {
  // Do something with the segment
  console.log(segment);
});

Store new Segments

// Store new segments 
const newSegment = {
    title: 'Segment name',
    ..
}

sdk.Segments.Create(newSegment);

Update Segment

// Update Segment by ID
const id = 'Z2lkOi8';
const input = {
    title: 'Segment name update',
    ...
};
sdk.Segments.Update(id, input);

Destroy Segment

// Destroy Segment by ID
const id = 'Z2lkOi8';
sdk.Segments.Delete(id);

Fetching Campaigns

// Fetch all Campaigns 
sdk.Campaigns.FetchAll().then((Campaigns) => {
  // Do something with the Campaigns
  console.log(Campaigns);
});

// Fetch all Campaigns with pagination ( page, limit )
sdk.Campaigns.Page(1)
            .Limit(20)
            .FetchAll()
            .then((Campaigns) => {
  // Do something with the Campaigns
  console.log(Campaigns);
});

// Fetch all Campaigns with search ( keyword )
sdk.Campaigns.Keyword('search-keyword')
            .FetchAll()
            .then((Campaigns) => {
  // Do something with the Campaigns
  console.log(Campaigns);
});

// Fetch all Campaigns with sort ( sort_by & sort_type )
sdk.Campaigns.SortBy('id')
            .SortType('DESC')
            .FetchAll()
            .then((Campaigns) => {
  // Do something with the Campaigns
  console.log(Campaigns);
});

// Fetch all Campaigns with Filter
const filter = {
        status: '1,2,3',
      };
sdk.Campaigns.Filter(filter)
            .FetchAll()
            .then((Campaigns) => {
  // Do something with the Campaigns
  console.log(Campaigns);
});

// Fetch a single Campaign by ID
const id = 'Z2lkOi8';

sdk.Campaigns.Fetch(id).then((Campaign) => {
  // Do something with the Campaign
  console.log(Campaign);
});

Store new Campaign

// Store new Campaigns 
const newCampaign = {
    title: 'Campaign name',
    ..
}

sdk.Campaigns.Create(newCampaign);

Update Campaign

// Update Campaigns by ID
const CampaignId = 'Z2lkOi8';
const input = {
    title: 'Campaign name update',
    ..
};
sdk.Campaigns.Update(CampaignId, input);

Report Campaign

// Report Campaigns by ID
const id = 'Z2lkOi8';
sdk.Reports
   .Campaign(id)
   .then((report) => {
      // Do something with the report
      console.log(report);
    });

Report Segment

const action = 'detail'; // 2 option : detail || detail_line
const dateOption = 'last30day'; // 6 option : yesterday || week || mtd || last7day || last30day || last90day
const id = id; // segment id 
sdk.Reports
   .Action(action)
   .DateOption(dateOption)
   .Segment(id)
   .then((report) => {
      // Do something with the report
      console.log(report);
    });

Report Dashboard

const action = 'common'; // 3 option : common || time || level
const dateOption = 'last30day'; // 6 option : yesterday || week || mtd || last7day || last30day || last90day
sdk.Reports
   .Action(action)
   .DateOption(dateOption)
   .Dashboard()
   .then((report) => {
      // Do something with the report
      console.log(report);
    });

Fetching Profiles

// Fetch all Profiles 
sdk.Profiles.FetchAll().then((Profiles) => {
  // Do something with the Profiles
  console.log(Profiles);
});

// Fetch all Profiles with pagination ( page, limit )
sdk.Profiles.Page(1)
            .Limit(20)
            .FetchAll()
            .then((Profiles) => {
  // Do something with the Profiles
  console.log(Profiles);
});

// Fetch all Profiles with search ( keyword )
sdk.Profiles.Keyword('search-keyword')
            .FetchAll()
            .then((Profiles) => {
  // Do something with the Profiles
  console.log(Profiles);
});

// Fetch all Profiles with sort ( sort_by & sort_type )
sdk.Profiles.SortBy('id')
            .SortType('DESC')
            .FetchAll()
            .then((Profiles) => {
  // Do something with the Profiles
  console.log(Profiles);
});

// Fetch a single Profile by ID
const id = 'Z2lkOi8';

sdk.Profiles.Fetch(id).then((Profile) => {
  // Do something with the Profile
  console.log(Profile);
});

Update Profile

// Update Profiles by ID
const ProfileId = 'Z2lkOi8';
const input = {
    title: 'Profile name update',
    ..
};
sdk.Profiles.Update(ProfileId, input);

Profile by Segment Setting

// Destroy Profiles by ID
const option = {
  customer_segment_id: 2021, // id of segment
  setting: { // segment setting
    include: [
      {
        field: "birth_month"
        logical: "AND"
        operator: "eq"
        value: 2
      }
    ],
    exclude: [
        field: "birth_month"
        logical: "AND"
        operator: "eq"
        value: 2
    ]
  }
};

sdk.Profiles
    .Segment(option)
    .then((profiles) => {
      // Do something with the Profile
      console.log(profiles);
    });

Config SMS

sdk.Configs
   .Sms()
   .then((config) => {
      // Do something with the config
      console.log(config);
    });

Config Email

sdk.Configs
   .Email()
   .then((config) => {
      // Do something with the config
      console.log(config);
    });

Config Zns ( Zalo )

sdk.Configs
   .Zns()
   .then((config) => {
      // Do something with the config
      console.log(config);
    });

Documentation

Contributing

For help on setting up the repo locally, building, testing, and contributing please see CONTRIBUTING.md.

Code of Conduct

All developers who wish to contribute through code or issues, take a look at the CODE_OF_CONDUCT.md.

License

MIT, see LICENSE.md for details.

0.0.1-beta.0.8

3 years ago

0.0.1-beta.0.6

3 years ago

0.0.1-beta.0.4

3 years ago

0.0.1-beta.0.5

3 years ago

0.0.1-beta.0.2

3 years ago

0.0.1-beta.0.3

3 years ago

0.0.1-beta.0.1

3 years ago

0.0.1-beta.0

3 years ago

0.0.1-beta

3 years ago

0.0.1-beta.1

3 years ago

1.0.0-beta

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago