line-bot 0.1.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +43 -221
  3. data/lib/line/bot.rb +15 -8
  4. data/lib/line/bot/api.rb +15 -2
  5. data/lib/line/bot/api/errors.rb +14 -1
  6. data/lib/line/bot/api/version.rb +15 -1
  7. data/lib/line/bot/client.rb +89 -164
  8. data/lib/line/bot/event.rb +22 -0
  9. data/lib/line/bot/event/base.rb +30 -0
  10. data/lib/line/bot/event/beacon.rb +22 -0
  11. data/lib/line/bot/event/follow.rb +22 -0
  12. data/lib/line/bot/event/join.rb +22 -0
  13. data/lib/line/bot/event/leave.rb +22 -0
  14. data/lib/line/bot/event/message.rb +43 -0
  15. data/lib/line/bot/event/postback.rb +22 -0
  16. data/lib/line/bot/event/unfollow.rb +22 -0
  17. data/lib/line/bot/httpclient.rb +14 -0
  18. data/lib/line/bot/request.rb +19 -23
  19. data/line-bot.gemspec +3 -7
  20. metadata +20 -78
  21. data/lib/line/bot/builder/multiple_message.rb +0 -101
  22. data/lib/line/bot/builder/rich_message.rb +0 -139
  23. data/lib/line/bot/event_type.rb +0 -15
  24. data/lib/line/bot/message.rb +0 -9
  25. data/lib/line/bot/message/audio.rb +0 -25
  26. data/lib/line/bot/message/base.rb +0 -35
  27. data/lib/line/bot/message/contact.rb +0 -18
  28. data/lib/line/bot/message/content_type.rb +0 -16
  29. data/lib/line/bot/message/image.rb +0 -23
  30. data/lib/line/bot/message/location.rb +0 -28
  31. data/lib/line/bot/message/recipient_type.rb +0 -9
  32. data/lib/line/bot/message/sticker.rb +0 -26
  33. data/lib/line/bot/message/text.rb +0 -22
  34. data/lib/line/bot/message/video.rb +0 -23
  35. data/lib/line/bot/operation.rb +0 -3
  36. data/lib/line/bot/operation/added_as_friend.rb +0 -10
  37. data/lib/line/bot/operation/base.rb +0 -17
  38. data/lib/line/bot/operation/blocked_account.rb +0 -10
  39. data/lib/line/bot/operation/op_type.rb +0 -10
  40. data/lib/line/bot/receive/message.rb +0 -69
  41. data/lib/line/bot/receive/operation.rb +0 -42
  42. data/lib/line/bot/receive/request.rb +0 -35
  43. data/lib/line/bot/response/user/contact.rb +0 -22
  44. data/lib/line/bot/response/user/profile.rb +0 -30
  45. data/lib/line/bot/utils.rb +0 -16
@@ -0,0 +1,22 @@
1
+ # Copyright 2016 LINE
2
+ #
3
+ # LINE Corporation licenses this file to you under the Apache License,
4
+ # version 2.0 (the "License"); you may not use this file except in compliance
5
+ # with the License. You may obtain a copy of the License at:
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+
15
+ require 'line/bot/event/base'
16
+ require 'line/bot/event/beacon'
17
+ require 'line/bot/event/follow'
18
+ require 'line/bot/event/join'
19
+ require 'line/bot/event/leave'
20
+ require 'line/bot/event/message'
21
+ require 'line/bot/event/postback'
22
+ require 'line/bot/event/unfollow'
@@ -0,0 +1,30 @@
1
+ # Copyright 2016 LINE
2
+ #
3
+ # LINE Corporation licenses this file to you under the Apache License,
4
+ # version 2.0 (the "License"); you may not use this file except in compliance
5
+ # with the License. You may obtain a copy of the License at:
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+
15
+ module Line
16
+ module Bot
17
+ module Event
18
+ class Base
19
+ def initialize(src)
20
+ @src = src
21
+ end
22
+
23
+ def [](key)
24
+ @src[key]
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ # Copyright 2016 LINE
2
+ #
3
+ # LINE Corporation licenses this file to you under the Apache License,
4
+ # version 2.0 (the "License"); you may not use this file except in compliance
5
+ # with the License. You may obtain a copy of the License at:
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+
15
+ module Line
16
+ module Bot
17
+ module Event
18
+ class Beacon < Base
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # Copyright 2016 LINE
2
+ #
3
+ # LINE Corporation licenses this file to you under the Apache License,
4
+ # version 2.0 (the "License"); you may not use this file except in compliance
5
+ # with the License. You may obtain a copy of the License at:
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+
15
+ module Line
16
+ module Bot
17
+ module Event
18
+ class Follow < Base
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # Copyright 2016 LINE
2
+ #
3
+ # LINE Corporation licenses this file to you under the Apache License,
4
+ # version 2.0 (the "License"); you may not use this file except in compliance
5
+ # with the License. You may obtain a copy of the License at:
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+
15
+ module Line
16
+ module Bot
17
+ module Event
18
+ class Join < Base
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # Copyright 2016 LINE
2
+ #
3
+ # LINE Corporation licenses this file to you under the Apache License,
4
+ # version 2.0 (the "License"); you may not use this file except in compliance
5
+ # with the License. You may obtain a copy of the License at:
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+
15
+ module Line
16
+ module Bot
17
+ module Event
18
+ class Leave < Base
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,43 @@
1
+ # Copyright 2016 LINE
2
+ #
3
+ # LINE Corporation licenses this file to you under the Apache License,
4
+ # version 2.0 (the "License"); you may not use this file except in compliance
5
+ # with the License. You may obtain a copy of the License at:
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+
15
+ module Line
16
+ module Bot
17
+ module Event
18
+ module MessageType
19
+ Text = 'text'
20
+ Image = 'image'
21
+ Video = 'video'
22
+ Audio = 'audio'
23
+ Location = 'location'
24
+ Sticker = 'sticker'
25
+ Unsupport = 'unsupport'
26
+ end
27
+
28
+ class Message < Base
29
+ def type
30
+ begin
31
+ Line::Bot::Event::MessageType.const_get(@src['message']['type'].capitalize)
32
+ rescue NameError => e
33
+ Line::Bot::Event::MessageType::Unsupport
34
+ end
35
+ end
36
+
37
+ def message
38
+ @src['message']
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,22 @@
1
+ # Copyright 2016 LINE
2
+ #
3
+ # LINE Corporation licenses this file to you under the Apache License,
4
+ # version 2.0 (the "License"); you may not use this file except in compliance
5
+ # with the License. You may obtain a copy of the License at:
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+
15
+ module Line
16
+ module Bot
17
+ module Event
18
+ class Postback < Base
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # Copyright 2016 LINE
2
+ #
3
+ # LINE Corporation licenses this file to you under the Apache License,
4
+ # version 2.0 (the "License"); you may not use this file except in compliance
5
+ # with the License. You may obtain a copy of the License at:
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+
15
+ module Line
16
+ module Bot
17
+ module Event
18
+ class Unfollow < Base
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,17 @@
1
+ # Copyright 2016 LINE
2
+ #
3
+ # LINE Corporation licenses this file to you under the Apache License,
4
+ # version 2.0 (the "License"); you may not use this file except in compliance
5
+ # with the License. You may obtain a copy of the License at:
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+
1
15
  require 'line/bot/api/version'
2
16
  require 'json'
3
17
  require 'net/http'
@@ -1,5 +1,18 @@
1
+ # Copyright 2016 LINE
2
+ #
3
+ # LINE Corporation licenses this file to you under the Apache License,
4
+ # version 2.0 (the "License"); you may not use this file except in compliance
5
+ # with the License. You may obtain a copy of the License at:
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+
1
15
  require 'line/bot/api/version'
2
- require 'line/bot/utils'
3
16
  require 'json'
4
17
  require 'net/http'
5
18
  require 'uri'
@@ -7,9 +20,7 @@ require 'uri'
7
20
  module Line
8
21
  module Bot
9
22
  class Request
10
- attr_accessor :endpoint, :endpoint_path, :credentials, :to_mid, :message, :to_channel_id, :httpclient
11
-
12
- include Line::Bot::Utils
23
+ attr_accessor :endpoint, :endpoint_path, :credentials, :to, :reply_token, :messages, :httpclient
13
24
 
14
25
  # Initializes a new Request
15
26
  #
@@ -18,33 +29,22 @@ module Line
18
29
  yield(self) if block_given?
19
30
  end
20
31
 
21
- # @return [Array]
22
- def to
23
- to_mid.is_a?(String) ? [to_mid] : to_mid
24
- end
25
-
26
- # @return [Line::Bot::Message::Base#content]
27
- def content
28
- message.content
29
- end
30
-
31
32
  # @return [Hash]
32
33
  def payload
33
34
  payload = {
34
35
  to: to,
35
- toChannel: to_channel_id,
36
- eventType: message.event_type.to_s,
37
- content: content
36
+ replyToken: reply_token,
37
+ messages: messages
38
38
  }
39
39
 
40
- payload.to_json
40
+ payload.delete_if{|k, v| v.nil?}.to_json
41
41
  end
42
42
 
43
43
  # @return [Hash]
44
44
  def header
45
45
  header = {
46
46
  'Content-Type' => 'application/json; charset=UTF-8',
47
- 'User-Agent' => "LINE-BotSDK/#{Line::Bot::API::VERSION}",
47
+ 'User-Agent' => "LINE-BotSDK-Ruby/#{Line::Bot::API::VERSION}",
48
48
  }
49
49
  hash = credentials.inject({}) { |h, (k, v)| h[k] = v.to_s; h }
50
50
 
@@ -53,8 +53,6 @@ module Line
53
53
 
54
54
  # Get content of specified URL.
55
55
  #
56
- # @raise [ArgumentError]
57
- #
58
56
  # @return [Net::HTTPResponse]
59
57
  def get
60
58
  assert_for_getting_message
@@ -76,8 +74,6 @@ module Line
76
74
  end
77
75
 
78
76
  def assert_for_posting_message
79
- raise ArgumentError, 'Wrong argument type `to_mid`' unless validate_mids(to)
80
- raise ArgumentError, 'Invalid argument `message`' unless message.valid?
81
77
  raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String)
82
78
  end
83
79
 
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["LINE Corporation"]
10
10
  spec.email = ["hirohisa.kawasaki@gmail.com"]
11
11
 
12
- spec.description = "Line::Bot::API - SDK of the LINE BOT API"
13
- spec.summary = spec.description
12
+ spec.description = "Line::Bot::API - SDK of the LINE Messaging API for Ruby"
13
+ spec.summary = "SDK of the LINE Messaging API"
14
14
  spec.homepage = "https://github.com/line/line-bot-sdk-ruby"
15
15
  spec.license = "Apache-2.0"
16
16
 
@@ -20,13 +20,9 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.required_ruby_version = '>= 2.0.0'
22
22
 
23
- spec.add_dependency 'rack', '>= 1.6'
24
-
23
+ spec.add_development_dependency 'rake', "~> 10.4"
25
24
  spec.add_development_dependency "bundler", "~> 1.11"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
25
  spec.add_development_dependency "webmock", "~> 1.24"
28
- spec.add_development_dependency "rest-client", "~> 1.8"
29
- spec.add_development_dependency "httpclient", "~> 2.8"
30
26
  spec.add_development_dependency "addressable", "~> 2.3"
31
27
  spec.add_development_dependency "rspec", "~> 3.0"
32
28
  end
metadata CHANGED
@@ -1,57 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: line-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - LINE Corporation
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-17 00:00:00.000000000 Z
11
+ date: 2016-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rack
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '1.6'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '1.6'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
14
+ name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '1.11'
19
+ version: '10.4'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '1.11'
26
+ version: '10.4'
41
27
  - !ruby/object:Gem::Dependency
42
- name: rake
28
+ name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '10.0'
33
+ version: '1.11'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '10.0'
40
+ version: '1.11'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: webmock
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,34 +52,6 @@ dependencies:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
54
  version: '1.24'
69
- - !ruby/object:Gem::Dependency
70
- name: rest-client
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.8'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.8'
83
- - !ruby/object:Gem::Dependency
84
- name: httpclient
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '2.8'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '2.8'
97
55
  - !ruby/object:Gem::Dependency
98
56
  name: addressable
99
57
  requirement: !ruby/object:Gem::Requirement
@@ -122,7 +80,7 @@ dependencies:
122
80
  - - "~>"
123
81
  - !ruby/object:Gem::Version
124
82
  version: '3.0'
125
- description: Line::Bot::API - SDK of the LINE BOT API
83
+ description: Line::Bot::API - SDK of the LINE Messaging API for Ruby
126
84
  email:
127
85
  - hirohisa.kawasaki@gmail.com
128
86
  executables: []
@@ -136,34 +94,18 @@ files:
136
94
  - lib/line/bot/api.rb
137
95
  - lib/line/bot/api/errors.rb
138
96
  - lib/line/bot/api/version.rb
139
- - lib/line/bot/builder/multiple_message.rb
140
- - lib/line/bot/builder/rich_message.rb
141
97
  - lib/line/bot/client.rb
142
- - lib/line/bot/event_type.rb
98
+ - lib/line/bot/event.rb
99
+ - lib/line/bot/event/base.rb
100
+ - lib/line/bot/event/beacon.rb
101
+ - lib/line/bot/event/follow.rb
102
+ - lib/line/bot/event/join.rb
103
+ - lib/line/bot/event/leave.rb
104
+ - lib/line/bot/event/message.rb
105
+ - lib/line/bot/event/postback.rb
106
+ - lib/line/bot/event/unfollow.rb
143
107
  - lib/line/bot/httpclient.rb
144
- - lib/line/bot/message.rb
145
- - lib/line/bot/message/audio.rb
146
- - lib/line/bot/message/base.rb
147
- - lib/line/bot/message/contact.rb
148
- - lib/line/bot/message/content_type.rb
149
- - lib/line/bot/message/image.rb
150
- - lib/line/bot/message/location.rb
151
- - lib/line/bot/message/recipient_type.rb
152
- - lib/line/bot/message/sticker.rb
153
- - lib/line/bot/message/text.rb
154
- - lib/line/bot/message/video.rb
155
- - lib/line/bot/operation.rb
156
- - lib/line/bot/operation/added_as_friend.rb
157
- - lib/line/bot/operation/base.rb
158
- - lib/line/bot/operation/blocked_account.rb
159
- - lib/line/bot/operation/op_type.rb
160
- - lib/line/bot/receive/message.rb
161
- - lib/line/bot/receive/operation.rb
162
- - lib/line/bot/receive/request.rb
163
108
  - lib/line/bot/request.rb
164
- - lib/line/bot/response/user/contact.rb
165
- - lib/line/bot/response/user/profile.rb
166
- - lib/line/bot/utils.rb
167
109
  - line-bot.gemspec
168
110
  homepage: https://github.com/line/line-bot-sdk-ruby
169
111
  licenses:
@@ -185,8 +127,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
127
  version: '0'
186
128
  requirements: []
187
129
  rubyforge_project:
188
- rubygems_version: 2.5.1
130
+ rubygems_version: 2.4.5
189
131
  signing_key:
190
132
  specification_version: 4
191
- summary: Line::Bot::API - SDK of the LINE BOT API
133
+ summary: SDK of the LINE Messaging API
192
134
  test_files: []