Giter Site home page Giter Site logo

hamzaalmashrqi / wp-json-api-flutter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from woosignal/wp-json-api-flutter

1.0 0.0 0.0 57 KB

WordPress and WooCommerce JSON API for Flutter Mobile. Register Users, Login (with email or username), Get Users Info, Update Users Info, Update Users Password + more.

Home Page: https://woosignal.com

License: BSD 2-Clause "Simplified" License

Dart 100.00%

wp-json-api-flutter's Introduction

WordPress and WooCommerce JSON API Dart package for Flutter

Official WooSignal package

API features:

WordPress

  • Register/Sign Up API for Users
  • Login (with email or username)
  • Get Users Info
  • Update Users Info
  • Update Users Password

WooCommerce

  • Get Customers Info (Billing and Shipping)
  • Update Customers details

To use this API you must have the WP JSON API Plugin installed first on your WordPress site, you can download it via the WooSignal website.

Getting Started

In your flutter project add the dependency:

dependencies:
  ...
  wp_json_api: ^0.1.4

Usage example

Import wp_json_api.dart

import 'package:wp_json_api/wp_json_api.dart';

Example using Wp JSON API

import 'package:wp_json_api/wp_json_api.dart';
...

void main() {

WPJsonAPI.instance.initWith(baseUrl: "https://mysite.com");

...

Call a method from the request callback

try {
WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
          .api((request) => request.wpLogin(
            email: email,
            password: password
          ));
} on Exception catch (e) {
    print(e);
}

Available API Requests

WordPress - Get Nonce

  • Used for returning a valid nonce
WPNonceResponse wpNonceResponse = await WPJsonAPI.instance
          .api((request) => request.wpNonce());

WordPress - Verify Nonce

  • Used for verifying register and login request
WPNonceVerifiedResponse wpNonceVerifiedResponse = await WPJsonAPI.instance
          .api((request) => request.wpNonceVerify(
            nonce: nonce
          ));

WordPress - Login with email

  • Used to login a user
WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
      .api((request) => request.wpLogin(
          email: email,
          password: password,
          authType: WPAuthType.WpEmail
      ));

WordPress - Login with username

  • Used to login a user
WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
      .api((request) => request.wpLogin(
          username: username,
          password: password,
          authType: WPAuthType.WpUsername
      ));

WordPress - Register

  • Used to register a user
  • The username parameter is required, ensure that this is unique
WPUserRegisterResponse wpUserRegisterResponse = await WPJsonAPI.instance
      .api((request) => request.wpRegister(
          email: email,
          password: password,
          username: username
      ));

WordPress - Get Users Info

  • Used to get a WordPress users info
  • The first parameter is the userToken which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
WPUserInfoResponse wpUserInfoResponse = await WPJsonAPI.instance
        .api((request) => request.wpGetUserInfo(
            userToken
          ));

WordPress - Update Users Info

  • Used to update a WordPress users info
  • The first parameter is the userToken which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
WPUserInfoUpdatedResponse wpUserInfoUpdatedResponse = await WPJsonAPI.instance
        .api((request) => request.wpUpdateUserInfo(
          userToken,
          firstName: firstName,
          lastName: lastName,
          displayName: displayName
      ));

WordPress - Update users password

  • Used to update a users password
  • The first parameter is the userToken which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
WPUserResetPasswordResponse wpUserResetPasswordResponse = await WPJsonAPI.instance
        .api((request) => request.wpResetPassword(
            userToken,
            password: password
        ));

WooCommerce - Get users info in WooCommerce

  • Used to get WooCommerce info for a given user
  • The first parameter is the userToken which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
WCCustomerInfoResponse wcCustomerInfoResponse = await WPJsonAPI.instance
          .api((request) => request.wcCustomerInfo(
          userToken
      ));

WooCommerce - Update users info in WooCommerce

  • Used to update a users WooCommerce details
  • All the parameter are optional so if you wanted to just update the name, you could just add first_name and last_name
  • The first parameter is the userToken which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
WCCustomerUpdatedResponse wcCustomerUpdatedResponse = await WPJsonAPI.instance
        .api((request) => request.wcUpdateCustomerInfo(
            userToken,
            firstName: firstName,
            lastName: lastName,
            displayName: displayName,
            billingFirstName: billingFirstName,
            billingLastName: billingLastName,
            billingCompany: billingCompany,
            billingAddress1: billingAddress1,
            billingAddress2: billingAddress2,
            billingCity: billingCity,
            billingState: billingState,
            billingPostcode: billingPostcode,
            billingCountry: billingCountry,
            billingEmail: billingEmail,
            billingPhone: billingPhone,
            shippingFirstName: shippingFirstName,
            shippingLastName: shippingLastName,
            shippingCompany: shippingCompany,
            shippingAddress1: shippingAddress1,
            shippingAddress2: shippingAddress2,
            shippingCity: shippingCity,
            shippingState: shippingState,
            shippingPostcode: shippingPostcode,
            shippingCountry: shippingCountry,
            shippingEmail: shippingEmail,
            shippingPhone: shippingPhone
        ));

For help getting started with WooSignal, view our online documentation, which offers a more detailed guide.

Usage

To use this plugin, add wp_json_api as a dependency in your pubspec.yaml file.

Note

Install WordPress plugin "WP JSON API" 2.0.x or later for version 0.1.4

Disclaimer: This plugin is not affiliated with or supported by Automattic, Inc. All logos and trademarks are the property of their respective owners.

wp-json-api-flutter's People

Contributors

agordn52 avatar

Stargazers

Hamza Almashrqi 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.