Skip to content

Commit 0c16cb2

Browse files
committed
Resolve conflicts
2 parents 83a3042 + f8da531 commit 0c16cb2

File tree

15 files changed

+177
-209
lines changed

15 files changed

+177
-209
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
steps:
2121
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
22-
- uses: ruby/setup-ruby@eaecf785f6a34567a6d97f686bbb7bccc1ac1e5c # v1.237.0
22+
- uses: ruby/setup-ruby@e34163cd15f4bb403dcd72d98e295997e6a55798 # v1.238.0
2323
with:
2424
bundler-cache: true
2525
ruby-version: 3.3

.github/workflows/pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2424
with:
2525
submodules: true
26-
- uses: ruby/setup-ruby@eaecf785f6a34567a6d97f686bbb7bccc1ac1e5c # v1.237.0
26+
- uses: ruby/setup-ruby@e34163cd15f4bb403dcd72d98e295997e6a55798 # v1.238.0
2727
with:
2828
ruby-version: ${{ matrix.ruby }}
2929
- uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ GEM
5858
prism (1.4.0)
5959
public_suffix (6.0.1)
6060
racc (1.8.1)
61-
rack (3.1.13)
61+
rack (3.1.14)
6262
rainbow (3.1.1)
6363
rake (13.2.1)
6464
rb-fsevent (0.11.2)
@@ -81,7 +81,7 @@ GEM
8181
diff-lcs (>= 1.2.0, < 2.0)
8282
rspec-support (~> 3.13.0)
8383
rspec-support (3.13.2)
84-
rubocop (1.75.4)
84+
rubocop (1.75.5)
8585
json (~> 2.3)
8686
language_server-protocol (~> 3.17.0.2)
8787
lint_roller (~> 1.1.0)

README.md

Lines changed: 60 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,57 @@
1-
# Overview
2-
**v1.30.0 is a transitional version for v2.0.0.**
1+
# LINE Messaging API SDK for Ruby
32

4-
- The previous code released up to v1.29.1 will be called "v1",
5-
- The new code released as v2.0.0 and later versions will be called "v2".
3+
[![Gem-version](https://img.shields.io/gem/v/line-bot-api.svg)](https://rubygems.org/gems/line-bot-api)
64

7-
**v1.30.0 includes both the v1 and v2 codebases.**
85

9-
**v2 has significant breaking changes** because it's a completely new implementation with an entirely different interface.
10-
As a result, any implementation based on the previous codebase will no longer function.
6+
## Introduction
7+
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.
118

12-
**New users should always use v2.**
13-
And **we strongly recommend migrating to v2.**
9+
## Documentation
1410

15-
## Why you should use v2
16-
### Support All Messaging API Features
17-
**v2 now supports every API endpoints and Webhook event types that were previously unimplemented.**
18-
Future API additions will be rapidly integrated, ensuring your application always stays up-to-date with the latest features by using `line-bot-api` gem.
11+
See the official API documentation for more information
1912

20-
Because v2 is automatically generated from [https://github.com/line/line-openapi](https://github.com/line/line-openapi), same with SDKs provided for other programming languages.
13+
- English: https://developers.line.biz/en/docs/messaging-api/overview/
14+
- Japanese: https://developers.line.biz/ja/docs/messaging-api/overview/
2115

22-
### RBS Support for Enhanced Development Experience
23-
**v2 comes with [RBS (Ruby Signature)](https://github.com/ruby/rbs) support**, enabling you to leverage type checking and other type-based development features for a more robust coding experience.
16+
Also, generated documentation by YARD is available.
2417

25-
# Migration Guide: From v1 to v2
18+
- https://rubydoc.info/gems/line-bot-api
2619

27-
Users can perform the migration step at their own pace. Follow these steps:
20+
## Requirements
21+
This library requires Ruby 3.2 or later.
2822

29-
1. Upgrade the `line-bot-api` gem to `1.30.0`.
30-
2. Migrate v1 code to v2 code. All v1 code issues deprecation warnings, so please migrate until they are gone. Since v1.30.0 includes all v1 and v2 code, you don't have to replace everything at once. You can switch gradually.
31-
3. Once all code is switched, upgrade `line-bot-api` to `2.0.0` or above.
23+
## Installation
3224

33-
## Change all v1 implementations to v2 implementations in v1.30.0
34-
**v1.30.0 includes both the v1 and v2 codebases.**
25+
Add this line to your application's Gemfile:
3526

36-
When you use the v1 code in v1.30.0, you will see deprecation warnings such as:
37-
38-
```
39-
[DEPRECATION] Line::Bot::Client#push_message is deprecated. Please use Line::Bot::V2::MessagingApi::ApiClient#push_message instead.
27+
```ruby
28+
gem 'line-bot-api'
4029
```
4130

42-
These warnings indicate which methods to use in the new v2 code.
43-
44-
Alternatively, the YARD documentation/comments also clearly indicate where to migrate.
45-
```rb
46-
# https://github.com/line/line-bot-sdk-ruby/blob/fb449ba19201a57c5f58dcd19ea67c5a53b0a0fe/lib/line/bot/v1/client.rb#L277-L288
47-
48-
# @deprecated
49-
# This is deprecated.
50-
# Please use {Line::Bot::V2::MessagingApi::ApiClient#push_message} instead.
51-
#
52-
# Push messages to a user using user_id.
53-
#
54-
# @param user_id [String] User Id
55-
# @param messages [Hash, Array] Message Objects
56-
# @param headers [Hash] HTTP Headers
57-
# @param payload [Hash] Additional request body
58-
# @return [Net::HTTPResponse]
59-
def push_message(user_id, messages, headers: {}, payload: {})
60-
```
31+
And then execute:
6132

62-
**Once v1 code usage is completely removed in v1.30.0, please switch to v2.0.0 >= version immediately.**
63-
Starting with v2.0.0, v1 code is not included.
64-
65-
## Suppress deprecation warnings
66-
You can suppress the deprecation warning by setting any value to `ENV['SUPRESS_V1_DEPRECATION_WARNINGS']`.
33+
```sh
34+
bundle
35+
```
6736

37+
Or install it yourself as:
6838

69-
However, it's not recommended to always use it as it could lead to migration errors.
39+
```sh
40+
gem install line-bot-api
41+
```
7042

71-
## Migration examples
72-
Only typical examples are shown here.
73-
Please refer to Examples in the next chapter for more examples.
43+
## Synopsis
7444

75-
### Calling API
76-
#### v1
77-
```rb
78-
client = Line::Bot::Client.new do |config|
79-
config.channel_token = ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN")
80-
end
45+
Usage:
8146

82-
response = client.push_message(
83-
'U1234567890abcdef1234567890abcdef',
84-
[
85-
{
86-
type: 'text',
87-
text: 'Hello, this is a test message!'
88-
}
89-
]
90-
)
91-
92-
puts response.class # => Net::HTTPResponse
93-
```
94-
#### v2 (without Hash)
95-
```rb
96-
client = Line::Bot::V2::MessagingApi::ApiClient.new(
97-
channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN")
98-
)
99-
100-
message = Line::Bot::V2::TextMessage.new( # No need to pass `type: "text"`
101-
text: 'Hello, this is a test message!'
102-
)
103-
104-
request = Line::Bot::V2::PushMessageRequest.new(
105-
to: 'U1234567890abcdef1234567890abcdef',
106-
messages: [
107-
message
108-
]
109-
)
110-
111-
response, status_code, response_headers = client.push_message_with_http_info(
112-
push_message_request: request
113-
)
114-
115-
puts response.class # => Line::Bot::V2::PushMessageResponse
116-
```
117-
#### v2 (with Hash)
118-
It's slightly convenient for migration, but the benefits of using the SDK are minimal. We recommend using the v2 code.
119-
120-
```rb
121-
client = Line::Bot::V2::MessagingApi::ApiClient.new(
122-
channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN")
123-
)
124-
125-
request = Line::Bot::V2::PushMessageRequest.new(
126-
to: 'U1234567890abcdef1234567890abcdef',
127-
messages: [
128-
{
129-
type: 'text',
130-
text: 'Hello, this is a test message!'
131-
}
132-
]
133-
)
134-
135-
response, status_code, response_headers = client.push_message_with_http_info(
136-
push_message_request: request
137-
)
138-
139-
puts response.class # => Line::Bot::V2::PushMessageResponse
140-
```
141-
### Handling Webhook
142-
#### v1
143-
```rb
144-
require 'sinatra'
145-
require 'line/bot'
47+
```ruby
48+
# app.rb
49+
require 'sinatra'
50+
require 'line/bot'
14651

14752
def client
14853
@client ||= Line::Bot::Client.new { |config|
54+
config.channel_id = ENV["LINE_CHANNEL_ID"]
14955
config.channel_secret = ENV["LINE_CHANNEL_SECRET"]
15056
config.channel_token = ENV["LINE_CHANNEL_TOKEN"]
15157
}
@@ -156,11 +62,10 @@ post '/callback' do
15662

15763
signature = request.env['HTTP_X_LINE_SIGNATURE']
15864
unless client.validate_signature(body, signature)
159-
halt 400, {'Content-Type' => 'text/plain'}, 'Bad Request'
65+
error 400 do 'Bad Request' end
16066
end
16167

16268
events = client.parse_events_from(body)
163-
16469
events.each do |event|
16570
case event
16671
when Line::Bot::Event::Message
@@ -171,76 +76,45 @@ post '/callback' do
17176
text: event.message['text']
17277
}
17378
client.reply_message(event['replyToken'], message)
79+
when Line::Bot::Event::MessageType::Image, Line::Bot::Event::MessageType::Video
80+
response = client.get_message_content(event.message['id'])
81+
tf = Tempfile.open("content")
82+
tf.write(response.body)
17483
end
17584
end
17685
end
17786

87+
# Don't forget to return a successful response
17888
"OK"
17989
end
18090
```
181-
#### v2
182-
```rb
183-
require 'sinatra'
184-
require 'line-bot-api'
18591

186-
set :environment, :production
92+
## Help and media
93+
FAQ: https://developers.line.biz/en/faq/
18794

188-
def client
189-
@client ||= Line::Bot::V2::MessagingApi::ApiClient.new(
190-
channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN")
191-
)
192-
end
95+
News: https://developers.line.biz/en/news/
19396

194-
def parser
195-
@parser ||= Line::Bot::V2::WebhookParser.new(channel_secret: ENV.fetch("LINE_CHANNEL_SECRET"))
196-
end
97+
## Versioning
98+
This project respects semantic versioning.
19799

198-
post '/callback' do
199-
body = request.body.read
200-
signature = request.env['HTTP_X_LINE_SIGNATURE']
100+
See https://semver.org/
201101

202-
begin
203-
events = parser.parse(body: body, signature: signature)
204-
rescue Line::Bot::V2::WebhookParser::InvalidSignatureError
205-
halt 400, { 'Content-Type' => 'text/plain' }, 'Bad Request'
206-
end
207-
208-
events.each do |event|
209-
case event
210-
when Line::Bot::V2::Webhook::MessageEvent
211-
case event.message
212-
when Line::Bot::V2::Webhook::TextMessageContent
213-
message = event.message.text
214-
request = Line::Bot::V2::MessagingApi::ReplyMessageRequest.new(
215-
reply_token: event.reply_token,
216-
messages: [
217-
Line::Bot::V2::MessagingApi::TextMessage.new(text: message)
218-
]
219-
)
220-
client.reply_message(reply_message_request: request)
221-
end
222-
end
223-
end
224-
225-
"OK"
226-
end
102+
## Contributing
103+
Please check [CONTRIBUTING](CONTRIBUTING.md) before making a contribution.
227104

105+
## License
106+
```
107+
Copyright (C) 2016 LINE Corp.
108+
109+
Licensed under the Apache License, Version 2.0 (the "License");
110+
you may not use this file except in compliance with the License.
111+
You may obtain a copy of the License at
112+
113+
http://www.apache.org/licenses/LICENSE-2.0
114+
115+
Unless required by applicable law or agreed to in writing, software
116+
distributed under the License is distributed on an "AS IS" BASIS,
117+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
118+
See the License for the specific language governing permissions and
119+
limitations under the License.
228120
```
229-
230-
# Examples
231-
There are several examples available for v2 to assist you in your implementation.
232-
233-
- Simple Echo Bot
234-
- A straightforward example demonstrating an echo bot implementation.
235-
- [https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/echobot](https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/echobot)
236-
237-
- Rich Menu
238-
- An example for implementing and managing rich menus as described in the [Messaging API - Using Rich Menus](https://developers.line.biz/en/docs/messaging-api/using-rich-menus/).
239-
- [https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/rich_menu](https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/rich_menu)
240-
241-
- Webhook Handling
242-
- A comprehensive example covering Webhook handling and various API capabilities.
243-
- [https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/kitchensink](https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/kitchensink)
244-
245-
# Feedbacks & Contributions
246-
We welcome [feedback](https://github.com/line/line-bot-sdk-ruby/issues) and [contributions](https://github.com/line/line-bot-sdk-ruby/blob/master/CONTRIBUTING.md).

examples/v2/audience/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
## Getting started
66
Update User ID of `app.rb` and `audience.txt' to your own.
77

8-
```ruby
8+
```sh
99
$ export LINE_CHANNEL_SECRET=YOUR_CHANNEL_SECRET
1010
$ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_CHANNEL_ACCESS_TOKEN
1111
$ bundle install

examples/v2/channel_access_token/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Getting started
66

7-
```ruby
7+
```sh
88
$ export LINE_CHANNEL_ID=YOUR_CHANNEL_ID
99
$ export LINE_CHANNEL_SECRET=YOUR_CHANNEL_SECRET
1010
$ bundle install

examples/v2/echobot/Gemfile.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ PATH
22
remote: ../../..
33
specs:
44
line-bot-api (0.0.1.pre.test)
5-
multipart-post (~> 2.4.1)
5+
base64 (~> 0.2)
6+
multipart-post (~> 2.4)
67

78
GEM
89
remote: https://rubygems.org/

examples/v2/echobot/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
An example LINE bot just to echo messages
33

44
## Getting started
5-
```ruby
5+
This projects tries to set `${APP_BASE_URL}/callback` as webhook URL automatically on starting app.
6+
7+
```sh
68
$ export LINE_CHANNEL_SECRET=YOUR_CHANNEL_SECRET
79
$ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_CHANNEL_ACCESS_TOKEN
810
$ bundle install
11+
$ export APP_BASE_URL="https://your.base.url:4567"
912
$ bundle exec ruby app.rb
1013
```
1114

12-
```
13-
https://127.0.0.1:4567/callback
14-
```

0 commit comments

Comments
 (0)