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
@@ -1,22 +0,0 @@
1
- require 'line/bot/message/base'
2
-
3
- module Line
4
- module Bot
5
- module Message
6
- class Text < Line::Bot::Message::Base
7
-
8
- def content
9
- {
10
- contentType: ContentType::TEXT,
11
- toType: recipient_type,
12
- text: attrs[:text]
13
- }
14
- end
15
-
16
- def valid?
17
- !attrs[:text].nil?
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,23 +0,0 @@
1
- require 'line/bot/message/base'
2
-
3
- module Line
4
- module Bot
5
- module Message
6
- class Video < Line::Bot::Message::Base
7
-
8
- def content
9
- {
10
- contentType: ContentType::VIDEO,
11
- toType: recipient_type,
12
- originalContentUrl: attrs[:video_url],
13
- previewImageUrl: attrs[:preview_url],
14
- }
15
- end
16
-
17
- def valid?
18
- attrs[:video_url] && attrs[:preview_url]
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,3 +0,0 @@
1
- require 'line/bot/operation/op_type'
2
- require 'line/bot/operation/added_as_friend'
3
- require 'line/bot/operation/blocked_account'
@@ -1,10 +0,0 @@
1
- require 'line/bot/operation/base'
2
-
3
- module Line
4
- module Bot
5
- module Operation
6
- class AddedAsFriend < Line::Bot::Operation::Base
7
- end
8
- end
9
- end
10
- end
@@ -1,17 +0,0 @@
1
- module Line
2
- module Bot
3
- module Operation
4
- class Base
5
- attr_reader :attrs
6
-
7
- def initialize(attrs = {})
8
- @attrs = attrs
9
- end
10
-
11
- def [](key)
12
- @attrs[key]
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,10 +0,0 @@
1
- require 'line/bot/operation/base'
2
-
3
- module Line
4
- module Bot
5
- module Operation
6
- class BlockedAccount < Line::Bot::Operation::Base
7
- end
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module Line
2
- module Bot
3
- module Operation
4
- module OpType
5
- ADDED_AS_FRIEND = 4
6
- BLOCKED_ACCOUNT = 8
7
- end
8
- end
9
- end
10
- end
@@ -1,69 +0,0 @@
1
- module Line
2
- module Bot
3
- module Receive
4
- class Message
5
- attr_reader :id, :from_mid, :to_mid, :from_channel_id, :to_channel_id, :event_type, :created_time, :content
6
-
7
- def initialize(attrs)
8
- @id = attrs['content']['id']
9
- @from_mid = attrs['content']['from']
10
- @to_mid = attrs['content']['to']
11
-
12
- @from_channel_id = attrs['fromChannel']
13
- @to_channel_id = attrs['toChannel']
14
-
15
- @event_type = attrs['eventType']
16
-
17
- (time, usec) = attrs['content']['createdTime'].to_i.divmod(1000)
18
- @created_time = Time.at(time, usec)
19
-
20
- @content = create_content(attrs['content'])
21
- end
22
-
23
- def create_content(attrs)
24
- case attrs['contentType']
25
- when Line::Bot::Message::ContentType::TEXT
26
- return Line::Bot::Message::Text.new(
27
- text: attrs['text'],
28
- )
29
- when Line::Bot::Message::ContentType::IMAGE
30
- return Line::Bot::Message::Image.new(
31
- image_url: attrs['originalContentUrl'],
32
- preview_url: attrs['previewImageUrl'],
33
- )
34
- when Line::Bot::Message::ContentType::VIDEO
35
- return Line::Bot::Message::Video.new(
36
- video_url: attrs['originalContentUrl'],
37
- preview_url: attrs['previewImageUrl'],
38
- )
39
- when Line::Bot::Message::ContentType::AUDIO
40
- return Line::Bot::Message::Audio.new(
41
- audio_url: attrs['originalContentUrl'],
42
- duration: attrs['contentMetadata']['duration'].to_i,
43
- )
44
- when Line::Bot::Message::ContentType::LOCATION
45
- return Line::Bot::Message::Location.new(
46
- title: attrs['location']['title'],
47
- address: attrs['location']['address'],
48
- latitude: attrs['location']['latitude'],
49
- longitude: attrs['location']['longitude'],
50
- )
51
- when Line::Bot::Message::ContentType::STICKER
52
- return Line::Bot::Message::Sticker.new(
53
- stkpkgid: attrs['contentMetadata']['STKPKGID'],
54
- stkid: attrs['contentMetadata']['STKID'],
55
- stkver: attrs['contentMetadata']['STKVER'],
56
- )
57
- when Line::Bot::Message::ContentType::CONTACT
58
- return Line::Bot::Message::Contact.new(
59
- mid: attrs['contentMetadata']['mid'],
60
- display_name: attrs['contentMetadata']['displayName'],
61
- )
62
- else
63
- end
64
- end
65
-
66
- end
67
- end
68
- end
69
- end
@@ -1,42 +0,0 @@
1
- require 'line/bot/operation/op_type'
2
-
3
- module Line
4
- module Bot
5
- module Receive
6
- class Operation
7
- attr_reader :id, :from_mid, :to_mid, :from_channel_id, :to_channel_id, :event_type, :content
8
-
9
- def initialize(attrs)
10
- @id = attrs['id']
11
- @from_mid = attrs['content']['params'].first
12
- @to_mid = attrs['to']
13
-
14
- @from_channel_id = attrs['fromChannel']
15
- @to_channel_id = attrs['toChannel']
16
-
17
- @event_type = attrs['eventType']
18
- @content = create_content(attrs['content'])
19
- end
20
-
21
- def create_content(attrs)
22
- case attrs['opType']
23
- when Line::Bot::Operation::OpType::ADDED_AS_FRIEND
24
- return Line::Bot::Operation::AddedAsFriend.new(
25
- revision: attrs['revision'],
26
- op_type: attrs['opType'],
27
- params: attrs['params'],
28
- )
29
- when Line::Bot::Operation::OpType::BLOCKED_ACCOUNT
30
- return Line::Bot::Operation::BlockedAccount.new(
31
- revision: attrs['revision'],
32
- op_type: attrs['opType'],
33
- params: attrs['params'],
34
- )
35
- else
36
- end
37
- end
38
-
39
- end
40
- end
41
- end
42
- end
@@ -1,35 +0,0 @@
1
- require 'line/bot/receive/message'
2
- require 'json'
3
- require 'rack'
4
-
5
- module Line
6
- module Bot
7
- module Receive
8
- class Request < Rack::Request
9
-
10
- def data
11
- @data ||= parse_data_from_body
12
- end
13
-
14
- def parse_data_from_body
15
- body.rewind
16
- json = JSON.parse(body.read)
17
- result = json['result']
18
-
19
- result.map { |item| create_message_or_operation(item) }
20
- end
21
-
22
- def create_message_or_operation(data)
23
- case data['eventType'].to_i
24
- when Line::Bot::Receive::EventType::MESSAGE
25
- return Line::Bot::Receive::Message.new(data)
26
- when Line::Bot::Receive::EventType::OPERATION
27
- return Line::Bot::Receive::Operation.new(data)
28
- end
29
- end
30
-
31
- end
32
-
33
- end
34
- end
35
- end
@@ -1,22 +0,0 @@
1
- require 'json'
2
-
3
- module Line
4
- module Bot
5
- module Response
6
- module User
7
-
8
- class Contact
9
- attr_reader :mid, :display_name, :picture_url, :status_message
10
-
11
- def initialize(attrs)
12
- @mid = attrs['mid']
13
- @display_name = attrs['displayName']
14
- @picture_url = attrs['pictureUrl']
15
- @status_message = attrs['statusMessage']
16
- end
17
- end
18
-
19
- end
20
- end
21
- end
22
- end
@@ -1,30 +0,0 @@
1
- require 'json'
2
- require 'line/bot/response/user/contact'
3
-
4
- module Line
5
- module Bot
6
- module Response
7
- module User
8
- class Profile
9
- attr_reader :start, :count, :total, :contacts, :display
10
-
11
- def initialize(response)
12
- json = JSON.parse(response.body)
13
-
14
- @start = json['start']
15
- @count = json['count']
16
- @total = json['total']
17
- @contacts = create_contacts(json['contacts']) || []
18
- @display = json['display']
19
- end
20
-
21
- def create_contacts(contacts)
22
- contacts.map { |c|
23
- Contact.new(c)
24
- }
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,16 +0,0 @@
1
- module Line
2
- module Bot
3
- module Utils
4
-
5
- # @return [Boolean]
6
- def validate_mids(mids)
7
- return false unless mids.is_a?(String) || mids.is_a?(Array)
8
- mids = [mids] if mids.is_a?(String)
9
-
10
- return false unless mids.size > 0
11
-
12
- true
13
- end
14
- end
15
- end
16
- end