GithubHelp home page GithubHelp logo

classmethod / niseline Goto Github PK

View Code? Open in Web Editor NEW
6.0 5.0 0.0 1.35 MB

NiseLine is inspired by LocalStack. Goal of this tool is to create a mock service for LINE.

License: MIT License

Shell 0.09% Dockerfile 0.20% JavaScript 0.59% TypeScript 95.88% HTML 0.49% CSS 0.15% EJS 2.60%
line linebot line-api api liff liff-sdk

niseline's Introduction

NiseLine

NiseLine

NiseLine is inspired by LocalStack. Goal of this tool is to create a mock service for LINE.

Getting Started

Launch NiseLine server by Docker image.

docker run -d -p 3000:3000 dyoshikawa/niseline:latest

And install NiseLiff SDK.

npm i @niseline/niseliff

Use NiseLiff SDK in your client app!

import { buildNiseliff } from '@niseline/niseliff'
import React from 'react'
import ReactDOM from 'react-dom'

const liff = buildNiseliff({
  liffId: 'DUMMY_LIFF_ID',
})

liff
  .init({
    liffId: 'DUMMY_LIFF_ID',
  })
  .then(() => {
    ReactDOM.render(
      <React.StrictMode>Your client app</React.StrictMode>,
      document.getElementById('root')
    )
  })

NiseLiff SDK

Setup

Install @niseline/niseliff.

npm i @niseline/niseliff

Usage

With npm package of LIFF SDK

You can use with npm package of LIFF SDK. Switch between the real LIFF SDK and the NiseLiff SDK for each environment. In this example, the NiseLiff SDK is used only in the local environment.

// /path/to/config.ts

export const env: 'local' | 'development' | 'staging' | 'production' = 'local'
// /path/to/liff.ts

import * as config from '/path/to/config'
import realLiff, { Liff } from '@line/liff'
import { buildNiseliff } from '@niseline/niseliff'

const liff =
  config.env === 'local' ? buildNiseliff({ liffId: 'DUMMY_LIFF_ID' }) : realLiff
export default liff
// /path/to/index.tsx

import liff from '/path/to/liff'
import React from 'react'
import ReactDOM from 'react-dom'

liff.init({ liffId: 'DUMMY_LIFF_ID' }).then(() => {
  ReactDOM.render(
    <React.StrictMode>Your client app</React.StrictMode>,
    document.getElementById('root')
  )
})

With CDN of LIFF SDK

You can also use with CDN of LIFF SDK. If you use typescript, it is recommended that you install the @line/liff package. The actual runtime is a CDN, but the type definitions are available from the npm package.

// /path/to/config.ts

export const env: 'local' | 'development' | 'staging' | 'production' = 'local'
// /path/to/index.tsx

import * as config from '/path/to/config'
import { Liff } from '@line/liff'
import { buildNiseliff } from '@niseline/niseliff'
import React from 'react'
import ReactDOM from 'react-dom'

declare global {
  var liff: Liff
}

if (config.env === 'local') {
  window.liff = buildNiseliff({
    liffId: 'DUMMY_LIFF_ID',
  })
}

window.liff
  .init({
    liffId: 'DUMMY_LIFF_ID',
  })
  .then(() => {
    ReactDOM.render(
      <React.StrictMode>Your client app</React.StrictMode>,
      document.getElementById('root')
    )
  })

Features

NiseLine Server

Setup

Pull and run dyoshikawa/niseline.

Docker

docker run -d -p 3000:3000 dyoshikawa/niseline:latest
curl http://localhost:3000/niseline/api/ping
# => {"ping":"pong"}

Docker Compose

# docker-compose.yml
version: '3'
services:
  niseline:
    image: dyoshikawa/niseline:latest
    ports:
      - 3000:3000
docker compose up -d
curl http://localhost:3000/niseline/api/ping
# => {"ping":"pong"}

Usage

curl --request POST \
  --url http://localhost:3000/niseline/api/users \
  --header 'content-type: application/json' \
  --data '{"id": "FOO_ID","name": "Foo","picture": "http://example.com/foo.jpg","email": "[email protected]"}'
# => null

curl -v -X POST 'http://localhost:3000/oauth2/v2.1/verify' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'id_token=FOO_ID' \
  --data-urlencode 'client_id=1234567890'
# => {"iss":"https://example.com","sub":"FOO_ID","aud":"1234567890","exp":1504169092,"iat":1504263657,"nonce":"0987654asdf","amr":["pwd"],"name":"Foo","picture":"http://example.com/foo.jpg","email":"[email protected]"}

Features

Login API

Messaging API

niseline's People

Contributors

cm-dyoshikawa avatar dyoshikawa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.