line-bot-api 1.30.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +49 -1
  3. data/README.md +250 -26
  4. data/lib/line/bot/v2/messaging_api/api/messaging_api_client.rb +269 -0
  5. data/lib/line/bot/v2/messaging_api/core.rb +39 -0
  6. data/lib/line/bot/v2/messaging_api/model/acquisition_condition_request.rb +77 -0
  7. data/lib/line/bot/v2/messaging_api/model/acquisition_condition_response.rb +78 -0
  8. data/lib/line/bot/v2/messaging_api/model/cash_back_fixed_price_info_request.rb +72 -0
  9. data/lib/line/bot/v2/messaging_api/model/cash_back_fixed_price_info_response.rb +78 -0
  10. data/lib/line/bot/v2/messaging_api/model/cash_back_percentage_price_info_request.rb +72 -0
  11. data/lib/line/bot/v2/messaging_api/model/cash_back_percentage_price_info_response.rb +72 -0
  12. data/lib/line/bot/v2/messaging_api/model/cash_back_price_info_request.rb +77 -0
  13. data/lib/line/bot/v2/messaging_api/model/cash_back_price_info_response.rb +77 -0
  14. data/lib/line/bot/v2/messaging_api/model/coupon_cash_back_reward_request.rb +72 -0
  15. data/lib/line/bot/v2/messaging_api/model/coupon_cash_back_reward_response.rb +72 -0
  16. data/lib/line/bot/v2/messaging_api/model/coupon_create_request.rb +139 -0
  17. data/lib/line/bot/v2/messaging_api/model/coupon_create_response.rb +67 -0
  18. data/lib/line/bot/v2/messaging_api/model/coupon_discount_reward_request.rb +72 -0
  19. data/lib/line/bot/v2/messaging_api/model/coupon_discount_reward_response.rb +72 -0
  20. data/lib/line/bot/v2/messaging_api/model/coupon_free_reward_request.rb +66 -0
  21. data/lib/line/bot/v2/messaging_api/model/coupon_free_reward_response.rb +66 -0
  22. data/lib/line/bot/v2/messaging_api/model/coupon_gift_reward_request.rb +66 -0
  23. data/lib/line/bot/v2/messaging_api/model/coupon_gift_reward_response.rb +66 -0
  24. data/lib/line/bot/v2/messaging_api/model/coupon_list_response.rb +73 -0
  25. data/lib/line/bot/v2/messaging_api/model/coupon_message.rb +91 -0
  26. data/lib/line/bot/v2/messaging_api/model/coupon_others_reward_request.rb +66 -0
  27. data/lib/line/bot/v2/messaging_api/model/coupon_others_reward_response.rb +66 -0
  28. data/lib/line/bot/v2/messaging_api/model/coupon_response.rb +169 -0
  29. data/lib/line/bot/v2/messaging_api/model/coupon_reward_request.rb +80 -0
  30. data/lib/line/bot/v2/messaging_api/model/coupon_reward_response.rb +80 -0
  31. data/lib/line/bot/v2/messaging_api/model/discount_explicit_price_info_request.rb +78 -0
  32. data/lib/line/bot/v2/messaging_api/model/discount_explicit_price_info_response.rb +84 -0
  33. data/lib/line/bot/v2/messaging_api/model/discount_fixed_price_info_request.rb +72 -0
  34. data/lib/line/bot/v2/messaging_api/model/discount_fixed_price_info_response.rb +78 -0
  35. data/lib/line/bot/v2/messaging_api/model/discount_percentage_price_info_request.rb +72 -0
  36. data/lib/line/bot/v2/messaging_api/model/discount_percentage_price_info_response.rb +72 -0
  37. data/lib/line/bot/v2/messaging_api/model/discount_price_info_request.rb +78 -0
  38. data/lib/line/bot/v2/messaging_api/model/discount_price_info_response.rb +78 -0
  39. data/lib/line/bot/v2/messaging_api/model/lottery_acquisition_condition_request.rb +78 -0
  40. data/lib/line/bot/v2/messaging_api/model/lottery_acquisition_condition_response.rb +78 -0
  41. data/lib/line/bot/v2/messaging_api/model/message.rb +1 -0
  42. data/lib/line/bot/v2/messaging_api/model/messaging_api_pager_coupon_list_response.rb +79 -0
  43. data/lib/line/bot/v2/messaging_api/model/normal_acquisition_condition_request.rb +66 -0
  44. data/lib/line/bot/v2/messaging_api/model/normal_acquisition_condition_response.rb +66 -0
  45. data/lib/line/bot/v2/messaging_api/model/referral_acquisition_condition_response.rb +66 -0
  46. data/lib/line/bot/version.rb +1 -1
  47. data/lib/line/bot.rb +0 -9
  48. data/line-bot-api.gemspec +1 -1
  49. data/sig/line/bot/v2/messaging_api/api/messaging_api_client.rbs +156 -0
  50. data/sig/line/bot/v2/messaging_api/model/acquisition_condition_request.rbs +43 -0
  51. data/sig/line/bot/v2/messaging_api/model/acquisition_condition_response.rbs +43 -0
  52. data/sig/line/bot/v2/messaging_api/model/cash_back_fixed_price_info_request.rbs +40 -0
  53. data/sig/line/bot/v2/messaging_api/model/cash_back_fixed_price_info_response.rbs +43 -0
  54. data/sig/line/bot/v2/messaging_api/model/cash_back_percentage_price_info_request.rbs +40 -0
  55. data/sig/line/bot/v2/messaging_api/model/cash_back_percentage_price_info_response.rbs +40 -0
  56. data/sig/line/bot/v2/messaging_api/model/cash_back_price_info_request.rbs +43 -0
  57. data/sig/line/bot/v2/messaging_api/model/cash_back_price_info_response.rbs +43 -0
  58. data/sig/line/bot/v2/messaging_api/model/coupon_cash_back_reward_request.rbs +40 -0
  59. data/sig/line/bot/v2/messaging_api/model/coupon_cash_back_reward_response.rbs +40 -0
  60. data/sig/line/bot/v2/messaging_api/model/coupon_create_request.rbs +76 -0
  61. data/sig/line/bot/v2/messaging_api/model/coupon_create_response.rbs +40 -0
  62. data/sig/line/bot/v2/messaging_api/model/coupon_discount_reward_request.rbs +40 -0
  63. data/sig/line/bot/v2/messaging_api/model/coupon_discount_reward_response.rbs +40 -0
  64. data/sig/line/bot/v2/messaging_api/model/coupon_free_reward_request.rbs +37 -0
  65. data/sig/line/bot/v2/messaging_api/model/coupon_free_reward_response.rbs +37 -0
  66. data/sig/line/bot/v2/messaging_api/model/coupon_gift_reward_request.rbs +37 -0
  67. data/sig/line/bot/v2/messaging_api/model/coupon_gift_reward_response.rbs +37 -0
  68. data/sig/line/bot/v2/messaging_api/model/coupon_list_response.rbs +43 -0
  69. data/sig/line/bot/v2/messaging_api/model/coupon_message.rbs +50 -0
  70. data/sig/line/bot/v2/messaging_api/model/coupon_others_reward_request.rbs +37 -0
  71. data/sig/line/bot/v2/messaging_api/model/coupon_others_reward_response.rbs +37 -0
  72. data/sig/line/bot/v2/messaging_api/model/coupon_response.rbs +91 -0
  73. data/sig/line/bot/v2/messaging_api/model/coupon_reward_request.rbs +43 -0
  74. data/sig/line/bot/v2/messaging_api/model/coupon_reward_response.rbs +43 -0
  75. data/sig/line/bot/v2/messaging_api/model/discount_explicit_price_info_request.rbs +43 -0
  76. data/sig/line/bot/v2/messaging_api/model/discount_explicit_price_info_response.rbs +46 -0
  77. data/sig/line/bot/v2/messaging_api/model/discount_fixed_price_info_request.rbs +40 -0
  78. data/sig/line/bot/v2/messaging_api/model/discount_fixed_price_info_response.rbs +43 -0
  79. data/sig/line/bot/v2/messaging_api/model/discount_percentage_price_info_request.rbs +40 -0
  80. data/sig/line/bot/v2/messaging_api/model/discount_percentage_price_info_response.rbs +40 -0
  81. data/sig/line/bot/v2/messaging_api/model/discount_price_info_request.rbs +43 -0
  82. data/sig/line/bot/v2/messaging_api/model/discount_price_info_response.rbs +43 -0
  83. data/sig/line/bot/v2/messaging_api/model/lottery_acquisition_condition_request.rbs +43 -0
  84. data/sig/line/bot/v2/messaging_api/model/lottery_acquisition_condition_response.rbs +43 -0
  85. data/sig/line/bot/v2/messaging_api/model/messaging_api_pager_coupon_list_response.rbs +43 -0
  86. data/sig/line/bot/v2/messaging_api/model/normal_acquisition_condition_request.rbs +37 -0
  87. data/sig/line/bot/v2/messaging_api/model/normal_acquisition_condition_response.rbs +37 -0
  88. data/sig/line/bot/v2/messaging_api/model/referral_acquisition_condition_response.rbs +37 -0
  89. metadata +81 -24
  90. data/lib/line/bot/v1/api/errors.rb +0 -23
  91. data/lib/line/bot/v1/api/version.rb +0 -23
  92. data/lib/line/bot/v1/api.rb +0 -33
  93. data/lib/line/bot/v1/client.rb +0 -1936
  94. data/lib/line/bot/v1/event/account_link.rb +0 -38
  95. data/lib/line/bot/v1/event/base.rb +0 -39
  96. data/lib/line/bot/v1/event/beacon.rb +0 -43
  97. data/lib/line/bot/v1/event/follow.rb +0 -30
  98. data/lib/line/bot/v1/event/join.rb +0 -29
  99. data/lib/line/bot/v1/event/leave.rb +0 -31
  100. data/lib/line/bot/v1/event/member_joined.rb +0 -29
  101. data/lib/line/bot/v1/event/member_left.rb +0 -31
  102. data/lib/line/bot/v1/event/message.rb +0 -51
  103. data/lib/line/bot/v1/event/postback.rb +0 -29
  104. data/lib/line/bot/v1/event/things.rb +0 -49
  105. data/lib/line/bot/v1/event/unfollow.rb +0 -31
  106. data/lib/line/bot/v1/event/unsend.rb +0 -31
  107. data/lib/line/bot/v1/event/video_play_complete.rb +0 -29
  108. data/lib/line/bot/v1/event.rb +0 -28
  109. data/lib/line/bot/v1/httpclient.rb +0 -91
  110. data/lib/line/bot/v1/util.rb +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af4ad962794c7d219f9acb71cbc6e4af3c0b9749087daba28d73d54d2075e0d5
4
- data.tar.gz: c219bdefdc560590bddc4f5887e1f219f498867efd0adbcf0e7f051d5dec35ef
3
+ metadata.gz: 6d6263a9bbf4c4a5a3d6a18965c1d81b96b91aeb88bcfd7edf4a1dbdeed1d16e
4
+ data.tar.gz: ed03051dcdd9b5bdd24382113758ae84d12e7ce42b900f75ced07efae11358c1
5
5
  SHA512:
6
- metadata.gz: de3b983cab0150be06eb0470679f9a737d039fca49c29c1b7984a0a1648b3576c839835fa2b085cb75b3cbe966ab8c2acf93048519a51b4cac16e82856e9cc2b
7
- data.tar.gz: e47210b21072b98f04ba084c90ac80eb66e32b8193ffa64abd85014718c29f2fdaf014de07146ca89a2fd8614be547b28f7a00cb45fc743a16e5e6cc64d1672a
6
+ metadata.gz: b5eb071cae7e4db290c9a6e8248cd6e288ae9881fb08c2be18811aa083bab6b11636e6e57ec96b662baa0163e50da68274c6a173f1a88af27da82eb4aa660632
7
+ data.tar.gz: c7e60c5813c0201f172f373b85d937a93f134b80044710a8289886da635ee0b95fe0ac5b56ca5c6a06acec8697152415f54516ac474898687d3a675913e64094
data/CONTRIBUTING.md CHANGED
@@ -9,6 +9,54 @@ It will be amazing if you could help us by doing any of the following:
9
9
  - Contribute your work by sending [a pull request](https://github.com/line/line-bot-sdk-ruby/pulls).
10
10
 
11
11
  ## Development
12
+ ### Install dependencies
13
+ Run `bundle install` to install all dependencies for development.
14
+
15
+ ### Understand the project structure
16
+ The project structure is as follows:
17
+ - `lib`: The main library code.
18
+ - `sig`: The RBS code.
19
+ - `sig-vendor`: The RBS code outside this repository.
20
+ - `spec`: The test code.
21
+ - `examples`: Example projects that use the library.
22
+ - `generator`: The code generator for the library.
23
+
24
+ ### Edit pebble template
25
+ Almost all code are generated with [pebble template](https://pebbletemplates.io/), based on [line-openapi](https://github.com/line/line-openapi)'s yaml.
26
+ Thus, you can't edit almost all code under `lib/line/bot/v2/<dir>.rb` and `sig/line/bot/v2/<dir>.rbs` directly.
27
+
28
+ You need to edit the pebble template under [resources](generator/src/main/resources) instead.
29
+
30
+ After editing the templates, run `generate-code.py` to generate the code, and then commit all affected files.
31
+ If not, CI status will be red.
32
+
33
+ When you update code, be sure to check consistencies between `lib/**.rb` and `sig/**.rbs`.
34
+
35
+ ### Add unit tests
36
+ We use [RSpec](https://rspec.info/) for unit tests.
37
+ Please add tests to the `spec` directory to verify your changes continuously.
38
+
39
+ Especially for bug fixes, please follow this flow for testing and development:
40
+ 1. Write a test before making changes to the library and confirm that the test fails.
41
+ 2. Modify the code of the library.
42
+ 3. Run the test again and confirm that it passes thanks to (2).
43
+
44
+ ### Run your code in your local
45
+ [Example projects](examples/v2) depend on this repository directly.
46
+ You can use new or fixed gem in example projects before submitting a pull request.
47
+
48
+ ### Run all CI tasks in your local
49
+ `Rakefile` defines almost all tasks.
50
+
51
+ You can run all tasks in your local by running `bundle exec rake ci` command.
52
+
53
+ ### Upgrade dependencies
54
+ The libraries that the library itself depends on are listed in the `line-bot-api.gemspec` file.
55
+ Those needed only for development are written in the `Gemfile`.
56
+ The versions in the gemspec file are set as low as possible, allowing users to specify higher versions in their application's Gemfile.
57
+
58
+ For files related to RBS, refer to `rbs_collections.yaml` and the `Steepfile`.
59
+ You can update by running `rbs collection update <LIB_NAME>`.
12
60
 
13
61
  ### YARD
14
62
 
@@ -41,5 +89,5 @@ For more details on how to write YARD doc comments, refer to YARD’s official [
41
89
 
42
90
  ### Contributor license agreement
43
91
 
44
- When you are sending a pull request and it's a non-trivial change beyond fixing typos, please make sure to sign [the ICLA (individual contributor license agreement)](https://cla-assistant.io/line/line-bot-sdk-ruby).
92
+ When you send a pull request and it's a non-trivial change beyond fixing typos, please make sure to sign [the ICLA (individual contributor license agreement)](https://cla-assistant.io/line/line-bot-sdk-ruby).
45
93
  Please [contact us](mailto:dl_oss_dev@linecorp.com) if you need the CCLA (corporate contributor license agreement).
data/README.md CHANGED
@@ -15,7 +15,8 @@ See the official API documentation for more information
15
15
 
16
16
  Also, generated documentation by YARD is available.
17
17
 
18
- - https://rubydoc.info/gems/line-bot-api
18
+ - https://line.github.io/line-bot-sdk-ruby/
19
+ - https://line.github.io/line-bot-sdk-ruby/_index.html
19
20
 
20
21
  ## Requirements
21
22
  This library requires Ruby 3.2 or later.
@@ -40,46 +41,79 @@ Or install it yourself as:
40
41
  gem install line-bot-api
41
42
  ```
42
43
 
44
+ ## Example projects
45
+ We provide examples to help you get started with the SDK.
46
+ They work in your local environment if you have owned your bot account.
47
+
48
+ Go the [examples](examples/v2) directory for more examples.
49
+
43
50
  ## Synopsis
51
+ ### RBS
52
+ This library provides [RBS](https://github.com/ruby/rbs) files for type checking.\
53
+ You can code with type support in the corresponding IDE or editor.
44
54
 
45
- Usage:
55
+ ### Basic Usage
46
56
 
47
57
  ```ruby
48
58
  # app.rb
49
59
  require 'sinatra'
50
- require 'line/bot'
60
+ require 'line-bot-api'
61
+
62
+ set :environment, :production
51
63
 
52
64
  def client
53
- @client ||= Line::Bot::Client.new { |config|
54
- config.channel_id = ENV["LINE_CHANNEL_ID"]
55
- config.channel_secret = ENV["LINE_CHANNEL_SECRET"]
56
- config.channel_token = ENV["LINE_CHANNEL_TOKEN"]
57
- }
65
+ @client ||= Line::Bot::V2::MessagingApi::ApiClient.new(
66
+ channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN")
67
+ )
68
+ end
69
+
70
+ def blob_client
71
+ @blob_client ||= Line::Bot::V2::MessagingApi::ApiBlobClient.new(
72
+ channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN")
73
+ )
74
+ end
75
+
76
+ def parser
77
+ @parser ||= Line::Bot::V2::WebhookParser.new(channel_secret: ENV.fetch("LINE_CHANNEL_SECRET"))
58
78
  end
59
79
 
60
80
  post '/callback' do
61
81
  body = request.body.read
62
-
63
82
  signature = request.env['HTTP_X_LINE_SIGNATURE']
64
- unless client.validate_signature(body, signature)
65
- error 400 do 'Bad Request' end
83
+
84
+ begin
85
+ events = parser.parse(body: body, signature: signature)
86
+ rescue Line::Bot::V2::WebhookParser::InvalidSignatureError
87
+ halt 400, { 'Content-Type' => 'text/plain' }, 'Bad Request'
66
88
  end
67
89
 
68
- events = client.parse_events_from(body)
69
90
  events.each do |event|
70
91
  case event
71
- when Line::Bot::Event::Message
72
- case event.type
73
- when Line::Bot::Event::MessageType::Text
74
- message = {
75
- type: 'text',
76
- text: event.message['text']
77
- }
78
- 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'])
92
+ when Line::Bot::V2::Webhook::MessageEvent
93
+ case event.message
94
+ when Line::Bot::V2::Webhook::TextMessageContent
95
+ case event.message.text
96
+ when 'profile'
97
+ if event.source.type == 'user'
98
+ profile_response = client.get_profile(user_id: event.source.user_id)
99
+ reply_text(event, "Display name: #{profile_response.display_name}\nStatus message: #{profile_response.status_message}")
100
+ else
101
+ reply_text(event, "Bot can't use profile API without user ID")
102
+ end
103
+ else
104
+ request = Line::Bot::V2::MessagingApi::ReplyMessageRequest.new(
105
+ reply_token: event.reply_token,
106
+ messages: [
107
+ Line::Bot::V2::MessagingApi::TextMessage.new(text: "[ECHO] #{event.message.text}")
108
+ ]
109
+ )
110
+ client.reply_message(reply_message_request: request)
111
+ end
112
+
113
+ when Line::Bot::V2::Webhook::ImageMessageContent, Line::Bot::V2::Webhook::VideoMessageContent
114
+ response = blob_client.get_message_content(message_id: event.message.message_id)
81
115
  tf = Tempfile.open("content")
82
- tf.write(response.body)
116
+ tf.write(response)
83
117
  end
84
118
  end
85
119
  end
@@ -89,16 +123,206 @@ post '/callback' do
89
123
  end
90
124
  ```
91
125
 
92
- ## Help and media
93
- FAQ: https://developers.line.biz/en/faq/
126
+ ### Main classes
127
+ You may use this classes to use LINE Messaging API features.
94
128
 
95
- News: https://developers.line.biz/en/news/
129
+ #### Webhook
130
+ - [Line::Bot::V2::WebhookParser](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/WebhookParser.html) ([LINE Developers](https://developers.line.biz/en/reference/messaging-api/#webhooks))
131
+ - [Line::Bot::V2::Webhook::Event](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/Webhook/Event.html) ([LINE Developers](https://developers.line.biz/en/reference/messaging-api/#webhook-event-objects))
132
+
133
+ ### Clients
134
+
135
+ | Class(YARD documentation) | API EndPoint | LINE Developers |
136
+ |----------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
137
+ | [Line::Bot::V2::ChannelAccessToken::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/ChannelAccessToken/ApiClient.html) | https://api.line.me/** (related to oauth) | https://developers.line.biz/en/reference/messaging-api/#channel-access-token |
138
+ | [Line::Bot::V2::Insight::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/Insight/ApiClient.html) | https://api.line.me/v2/bot/insight/** | https://developers.line.biz/en/reference/messaging-api/#get-insight |
139
+ | [Line::Bot::V2::Liff::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/Liff/ApiClient.html) | https://api.line.me/liff/** | https://developers.line.biz/en/reference/liff-server/#server-api |
140
+ | [Line::Bot::V2::ManageAudience::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/ManageAudience/ApiClient.html) | https://api.line.me/v2/bot/audienceGroup/** | https://developers.line.biz/en/reference/messaging-api/#manage-audience-group |
141
+ | [Line::Bot::V2::ManageAudience::ApiBlobClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/ManageAudience/ApiBlobClient.html) | https://api-data.line.me/v2/bot/audienceGroup/** | https://developers.line.biz/en/reference/messaging-api/#manage-audience-group |
142
+ | [Line::Bot::V2::MessagingApi::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/MessagingApi/ApiClient.html) | https://api.line.me/v2/bot/** | https://developers.line.biz/en/reference/messaging-api/<br/>https://developers.line.biz/en/reference/partner-docs/ |
143
+ | [Line::Bot::V2::MessagingApi::ApiBlobClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/MessagingApi/ApiBlobClient.html) | https://api-data.line.me/v2/bot/** | https://developers.line.biz/en/reference/messaging-api/ |
144
+ | [Line::Bot::V2::Module::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/Module/ApiClient.html) | https://api.line.me/v2/bot/** (related to module) | https://developers.line.biz/en/reference/partner-docs/#module |
145
+ | [Line::Bot::V2::ModuleAttach::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/ModuleAttach/ApiClient.html) | https://manager.line.biz/module/auth/v1/token/** | https://developers.line.biz/en/reference/partner-docs/#module |
146
+ | [Line::Bot::V2::Shop::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/Shop/ApiClient.html) | https://api.line.me/shop/** | https://developers.line.biz/en/reference/partner-docs/#mission-stickers |
147
+
148
+ ### Use HTTP Information
149
+ You may need to store the ```x-line-request-id``` header obtained as a response from several APIs.\
150
+ In this case, please use ```*_with_http_info``` methods. You can get headers and status codes.\
151
+ The `x-line-accepted-request-id` or `content-type` header can also be obtained in the same way. Note header name must be lowercase.
152
+
153
+ ```ruby
154
+ push_request = Line::Bot::V2::MessagingApi::PushMessageRequest.new(
155
+ to: event.source.user_id,
156
+ messages: [
157
+ Line::Bot::V2::MessagingApi::TextMessage.new(text: "[^Request ID] #{headers['x-line-request-id']}")
158
+ ]
159
+ )
160
+ _body, _status_code, headers = client.push_message_with_http_info(push_message_request: push_request)
161
+
162
+ puts headers['x-line-request-id']
163
+ puts headers['x-line-accepted-request-id']
164
+ puts headers['content-type']
165
+ ```
166
+
167
+ ### Error handling
168
+ If an API call fails, the SDK does not generate an Error in Ruby; use the status code for proper error handling.
169
+ Error details are stored in body.
170
+
171
+ ```ruby
172
+ require 'json'
173
+ require 'line-bot-api'
174
+
175
+ def client
176
+ @client ||= Line::Bot::V2::MessagingApi::ApiClient.new(
177
+ channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN"),
178
+ )
179
+ end
180
+
181
+ def main
182
+ dummy_message = Line::Bot::V2::MessagingApi::TextMessage.new(
183
+ text: "Hello, world!",
184
+ )
185
+
186
+ valid_request = Line::Bot::V2::MessagingApi::ValidateMessageRequest.new(
187
+ messages: [dummy_message, dummy_message, dummy_message, dummy_message, dummy_message],
188
+ )
189
+ body, status_code, _headers = client.validate_push_with_http_info(validate_message_request: valid_request)
190
+ handle_response(body, status_code)
191
+
192
+ invalid_request = Line::Bot::V2::MessagingApi::ValidateMessageRequest.new(
193
+ messages: [dummy_message, dummy_message, dummy_message, dummy_message, dummy_message, dummy_message],
194
+ )
195
+ body, status_code, _headers = client.validate_push_with_http_info(validate_message_request: invalid_request)
196
+ handle_response(body, status_code)
197
+ end
198
+
199
+ def handle_response(body, status_code)
200
+ case status_code
201
+ when 200
202
+ puts "Valid"
203
+ when 400..499
204
+ puts "Invalid: #{JSON.parse(body)}"
205
+ else
206
+ puts "Other Status: #{status_code}"
207
+ end
208
+ end
209
+
210
+ main
211
+ ```
212
+
213
+ ### Use with Hash / JSON
214
+ You can use Hash instead of the SDK classes.
215
+ So you can also use Hash parsed from JSON as a parameter.
216
+
217
+ This is useful, for example, in migrating from v1 or building Flex Message.
218
+
219
+ **But this is not recommended because you lose type checking by RBS.**
220
+
221
+ ```ruby
222
+ client = Line::Bot::V2::MessagingApi::ApiClient.new(
223
+ channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN"),
224
+ )
225
+
226
+ request = {
227
+ to: "U4af4980629...",
228
+ messages: [
229
+ {
230
+ type: "flex",
231
+ alt_text: "This is a Flex Message",
232
+ contents: {
233
+ type: "bubble",
234
+ body: {
235
+ type: "box",
236
+ layout: "horizontal",
237
+ contents: [
238
+ {
239
+ type: "text",
240
+ text: "Hello"
241
+ }
242
+ ]
243
+ }
244
+ }
245
+ }
246
+ ]
247
+ }
248
+ client.push_message(push_message_request: request)
249
+
250
+ # or
251
+
252
+ request = JSON.parse(
253
+ <<~JSON
254
+ {
255
+ "to": "U4af4980629...",
256
+ "messages": [
257
+ {
258
+ "type": "flex",
259
+ "alt_text": "This is a Flex Message",
260
+ "contents": {
261
+ "type": "bubble",
262
+ "body": {
263
+ "type": "box",
264
+ "layout": "horizontal",
265
+ "contents": [
266
+ {
267
+ "type": "text",
268
+ "text": "Hello"
269
+ }
270
+ ]
271
+ }
272
+ }
273
+ }
274
+ ]
275
+ }
276
+ JSON
277
+ )
278
+ client.push_message(push_message_request: request)
279
+ ```
280
+
281
+ #### Convert to SDK classes
282
+ You can convert Hash / JSON to SDK classes using `#create` method.
283
+
284
+ ```ruby
285
+ json = <<~JSON
286
+ {
287
+ "to": "U4af4980629...",
288
+ "messages": [
289
+ {
290
+ "type": "flex",
291
+ "alt_text": "This is a Flex Message",
292
+ "contents": {
293
+ "type": "bubble",
294
+ "body": {
295
+ "type": "box",
296
+ "layout": "horizontal",
297
+ "contents": [
298
+ {
299
+ "type": "text",
300
+ "text": "Hello"
301
+ }
302
+ ]
303
+ }
304
+ }
305
+ }
306
+ ]
307
+ }
308
+ JSON
309
+ request = Line::Bot::V2::MessagingApi::PushMessageRequest.create(
310
+ JSON.parse(json)
311
+ )
312
+ ```
96
313
 
97
314
  ## Versioning
98
315
  This project respects semantic versioning.
99
316
 
100
317
  See https://semver.org/
101
318
 
319
+ ### v1 and v2
320
+ v1 and v2 are completely different implementations. Migration to v2 is strongly recommended.
321
+ Please refer to [Migration guide](migration_from_v1_to_v2_guide.md) for migration procedure.
322
+
323
+ ## Media
324
+ News: https://developers.line.biz/en/news/
325
+
102
326
  ## Contributing
103
327
  Please check [CONTRIBUTING](CONTRIBUTING.md) before making a contribution.
104
328