Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate clients from LINE OpenAPI #296

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
49 changes: 49 additions & 0 deletions .github/workflows/generate-clients.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Generate clients from LINE OpenAPI

on:
workflow_dispatch:
inputs:
version:
type: string
required: true
description: "Version"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Update submodules
run: git submodule update --remote --recursive
- uses: ruby/setup-ruby@v1
with:
ruby-version: "2.7"
- run: echo "OPENAPI_GENERATOR_VERSION=6.6.0" >> $GITHUB_ENV
- run: echo "GEM_VERSION=${{ inputs.version }}" >> $GITHUB_ENV
- uses: actions/cache@v3
id: openapi-generator-cache
env:
cache-name: openapi-generator-cache
with:
path: ~/bin/openapitools
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.OPENAPI_GENERATOR_VERSION }}
- if: steps.openapi-generator-cache.outputs.cache-hit != 'true'
run: |
mkdir -p ~/bin/openapitools
curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator-cli.sh > ~/bin/openapitools/openapi-generator-cli
chmod u+x ~/bin/openapitools/openapi-generator-cli
echo "~/bin/openapitools/" >> $GITHUB_PATH
- run: bin/generate-clients
- run: sed -i -r "s/[0-9]+\.[0-9]+\.[0-9]+/${{ env.GEM_VERSION }}/" lib/line/client/version.rb
- run: |
git config user.name github-actions
git config user.email [email protected]
git checkout -b generate-clients-v$GEM_VERSION
git add .
git commit -m "Generate clients: v$GEM_VERSION"
git push origin generate-clients-v$GEM_VERSION
gh pr create -B ${{ github.ref_name }} --title "Generate clients: v$GEM_VERSION" --body "" --label "auto-generated code"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@
/pkg/
/spec/reports/
/tmp/

# OpenAPI Generator
/lib/clients/*/spec/
/lib/clients/*/.gitlab-ci.yml
/lib/clients/*/.openapi-generator-ignore
/lib/clients/*/.rspec
/lib/clients/*/.rubocop.yml
/lib/clients/*/.travis.yml
/lib/clients/*/Gemfile
/lib/clients/*/git_push.sh
/lib/clients/*/line_client_*.gemspec
/lib/clients/*/Rakefile
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "line-openapi"]
path = line-openapi
url = https://github.com/line/line-openapi
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: 2.7
Exclude:
- 'examples/**/*'
- 'lib/clients/**/*'
NewCops: disable

Gemspec/RequiredRubyVersion:
Expand Down
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@ source 'https://rubygems.org'
gemspec

group :development, :test do
# ref: http://docs.rubocop.org/en/latest/installation/
gem 'rubocop', '~> 1.56.0', require: false
gem 'yard', '~> 0.9.20'
end
120 changes: 51 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
# LINE Messaging API SDK for Ruby

[![Gem-version](https://img.shields.io/gem/v/line-bot-api.svg)](https://rubygems.org/gems/line-bot-api) [![Build Status](https://travis-ci.org/line/line-bot-sdk-ruby.svg?branch=master)](https://travis-ci.org/line/line-bot-sdk-ruby)
[![Gem version](https://img.shields.io/gem/v/line-bot-api.svg)](https://rubygems.org/gems/line-bot-api) [![Build status](https://github.com/line/line-bot-sdk-ruby/actions/workflows/pull_request.yml/badge.svg)](https://github.com/line/line-bot-sdk-ruby/actions/workflows/pull_request.yml)


## Introduction
The LINE Messaging API SDK for Ruby makes it easy to develop bots using LINE Messaging API, and you can create a sample bot within minutes.
Using the LINE Messaging API SDK for Ruby, you can easily use the Messaging API and other APIs provided by the LINE Platform to build your own applications.

## Documentation

See the official API documentation for more information
For documentation on each client, such as the Messaging API, see the README in each directory:

- English: https://developers.line.biz/en/docs/messaging-api/overview/
- Japanese: https://developers.line.biz/ja/docs/messaging-api/overview/
- [LINE::Client::ChannelAccessToken](lib/clients/channel-access-token/README.md)
- [LINE::Client::Insight](lib/clients/insight/README.md)
- [LINE::Client::Liff](lib/clients/liff/README.md)
- [LINE::Client::ManageAudience](lib/clients/manage-audience/README.md)
- [LINE::Client::MessagingApi](lib/clients/messaging-api/README.md)
- [LINE::Client::Module](lib/clients/module/README.md)
- [LINE::Client::ModuleAttach](lib/clients/module-attach/README.md)
- [LINE::Client::Shop](lib/clients/shop/README.md)
- [LINE::Client::Webhook](lib/clients/webhook/README.md)

Also, generated documentation by YARD is available.
You can also refer to the documentation generated by YARD:

- https://rubydoc.info/gems/line-bot-api

For more information on the APIs provided by the LINE Platform, see the [LINE Developers site](https://developers.line.biz/en/).

## Requirements

- Ruby 2.7.0 or later

## Installation

Add this line to your application's Gemfile:
Expand All @@ -27,92 +38,63 @@ gem 'line-bot-api'

And then execute:

```sh
bundle
```
$ bundle install

Or install it yourself as:

```sh
gem install line-bot-api
```

## Synopsis
$ gem install line-bot-api

Usage:
## Usage

```ruby
# app.rb
require 'sinatra'
require 'line/bot'

def client
@client ||= Line::Bot::Client.new { |config|
config.channel_id = ENV["LINE_CHANNEL_ID"]
config.channel_secret = ENV["LINE_CHANNEL_SECRET"]
config.channel_token = ENV["LINE_CHANNEL_TOKEN"]
}
LINE::Client::MessagingApi.configure do |config|
config.access_token = 'YOUR_BEARER_TOKEN'
end

post '/callback' do
body = request.body.read

signature = request.env['HTTP_X_LINE_SIGNATURE']
unless client.validate_signature(body, signature)
error 400 do 'Bad Request' end
end

events = client.parse_events_from(body)
events.each do |event|
case event
when Line::Bot::Event::Message
case event.type
when Line::Bot::Event::MessageType::Text
message = {
type: 'text',
text: event.message['text']
}
client.reply_message(event['replyToken'], message)
when Line::Bot::Event::MessageType::Image, Line::Bot::Event::MessageType::Video
response = client.get_message_content(event.message['id'])
tf = Tempfile.open("content")
tf.write(response.body)
end
end
end

# Don't forget to return a successful response
"OK"
end
api_instance = LINE::Client::MessagingApi::MessagingApiApi.new
result = api_instance.get_webhook_endpoint
result.endpoint # "https://example.com/test"
result.active # true
```

## Help and media
FAQ: https://developers.line.biz/en/faq/

Community Q&A: https://www.line-community.me/questions
For more information on how to use this library, see the [Documentation](#documentation).

News: https://developers.line.biz/en/news/
## Related sites

Twitter: @LINE_DEV
| Site | URL |
| ------------- | ----------------------------------------------- |
| FAQ | https://developers.line.biz/en/faq/ |
| Community Q&A | https://www.line-community.me/questions |
| News | https://developers.line.biz/en/news/ |
| Twitter | [@LINE_DEV_EN](https://twitter.com/LINE_DEV_EN) |

## Versioning
This project respects semantic versioning.

See https://semver.org/
The versioning policy for this project follows Semantic Versioning:

- [Semantic Versioning](https://semver.org/)

## Breaking changes

The LINE SDK development team has decided to generate codes based on the [LINE OpenAPI](https://github.com/line/line-openapi) specification. As a result, the version 2 series of the LINE Messaging API SDK for Ruby is not compatible with the version 1 series.

We plan to maintain only the version 2 series from now on. The 1 series can still be used, but we recommend using the 2 series to take advantage of the latest features.

## Contributing
Please check [CONTRIBUTING](CONTRIBUTING.md) before making a contribution.

Bug reports and pull requests are welcome on GitHub at https://github.com/line/line-bot-sdk-ruby. See [CONTRIBUTING](CONTRIBUTING.md) before you make a contribution.

## License

```
Copyright (C) 2016 LINE Corp.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
31 changes: 31 additions & 0 deletions bin/generate-clients
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env ruby

require_relative '../lib/line/client/version'

clients = [
'channel-access-token',
'insight',
'liff',
'manage-audience',
'messaging-api',
'module-attach',
'module',
'shop',
'webhook'
]

def to_pascal_case(str)
str.split('-').map(&:capitalize).join
end

clients.each do |client|
command = "openapi-generator generate \
-i line-openapi/#{client}.yml \
-g ruby \
-t src/main/resources/ruby-client \
-o lib/clients/#{client} \
--additional-properties=moduleName=LINE::Client::#{to_pascal_case(client)} \
--additional-properties=gemVersion=#{ENV.fetch('GEM_VERSION')} \
--http-user-agent LINE-BotSDK-Ruby/#{ENV.fetch('GEM_VERSION')}"
system(command, exception: true)
end
7 changes: 3 additions & 4 deletions examples/echobot/Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
source 'https://rubygems.org'

gem 'line-bot-api', path: '../../'
gem 'puma'
gem 'sinatra'
gem 'line-bot-api'
40 changes: 40 additions & 0 deletions examples/echobot/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
PATH
remote: ../..
specs:
line-bot-api (2.0.0)
typhoeus (~> 1.0, >= 1.0.1)

GEM
remote: https://rubygems.org/
specs:
ethon (0.16.0)
ffi (>= 1.15.0)
ffi (1.15.5)
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
nio4r (2.5.9)
puma (6.3.1)
nio4r (~> 2.0)
rack (2.2.8)
rack-protection (3.1.0)
rack (~> 2.2, >= 2.2.4)
ruby2_keywords (0.0.5)
sinatra (3.1.0)
mustermann (~> 3.0)
rack (~> 2.2, >= 2.2.4)
rack-protection (= 3.1.0)
tilt (~> 2.0)
tilt (2.2.0)
typhoeus (1.4.0)
ethon (>= 0.9.0)

PLATFORMS
x86_64-darwin-20

DEPENDENCIES
line-bot-api!
puma
sinatra

BUNDLED WITH
2.3.3
29 changes: 23 additions & 6 deletions examples/echobot/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
# Echo Bot

An example LINE bot just to echo messages
A simple bot application that uses the LINE Messaging API SDK for Ruby to return text messages sent by a user.

## Getting started
## Usage

```ruby
```bash
$ export LINE_CHANNEL_SECRET=YOUR_CHANNEL_SECRET
$ export LINE_CHANNEL_TOKEN=YOUR_CHANNEL_ACCESS_TOKEN
$ bundle install
$ bundle exec ruby app.rb
```

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/line/line-bot-sdk-ruby. See [CONTRIBUTING](../../CONTRIBUTING.md) before you make a contribution.

## License

```
Copyright (C) 2016 LINE Corp.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
https://your.base.url:4567/callback
```
Loading