line-bot 0.1.8 → 1.0.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 (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,101 +0,0 @@
1
- require 'line/bot/message'
2
-
3
- module Line
4
- module Bot
5
- module Builder
6
- class MultipleMessage
7
-
8
- def initialize(client)
9
- @messages ||= []
10
- @client = client
11
- end
12
-
13
- def add_text(attrs = {})
14
- tap {
15
- message = Message::Text.new(
16
- text: attrs[:text],
17
- )
18
- push_message(message)
19
- }
20
- end
21
-
22
- def add_image(attrs = {})
23
- tap {
24
- message = Message::Image.new(
25
- image_url: attrs[:image_url],
26
- preview_url: attrs[:preview_url],
27
- )
28
- push_message(message)
29
- }
30
- end
31
-
32
- def add_video(attrs = {})
33
- tap {
34
- message = Message::Video.new(
35
- video_url: attrs[:video_url],
36
- preview_url: attrs[:preview_url],
37
- )
38
- push_message(message)
39
- }
40
- end
41
-
42
- def add_audio(attrs = {})
43
- tap {
44
- message = Message::Audio.new(
45
- audio_url: attrs[:audio_url],
46
- duration: attrs[:duration],
47
- )
48
- push_message(message)
49
- }
50
- end
51
-
52
- def add_location(attrs = {})
53
- tap {
54
- message = Message::Location.new(
55
- title: attrs[:title],
56
- latitude: attrs[:latitude],
57
- longitude: attrs[:longitude],
58
- )
59
- push_message(message)
60
- }
61
- end
62
-
63
- def add_sticker(attrs = {})
64
- tap {
65
- message = Message::Sticker.new(
66
- stkpkgid: attrs[:stkpkgid],
67
- stkid: attrs[:stkid],
68
- stkver: attrs[:stkver],
69
- )
70
- push_message(message)
71
- }
72
- end
73
-
74
- def push_message(message)
75
- raise ArgumentError, "Invalid argument: `message`" unless message.valid?
76
- @messages << message.content
77
- end
78
-
79
- def send(attrs = {})
80
- @client.send_message(attrs[:to_mid], self)
81
- end
82
-
83
- def event_type
84
- Line::Bot::EventType::MULTIPLE_MESSAGE
85
- end
86
-
87
- def content
88
- {
89
- messageNotified: 0,
90
- messages: @messages
91
- }
92
- end
93
-
94
- def valid?
95
- @messages.size > 0
96
- end
97
-
98
- end
99
- end
100
- end
101
- end
@@ -1,139 +0,0 @@
1
- require 'line/bot/message'
2
- require 'json'
3
-
4
- module Line
5
- module Bot
6
- module Builder
7
- class RichMessage
8
-
9
- def initialize(client)
10
- @actions ||= {}
11
- @listeners ||= []
12
- @client = client
13
- end
14
-
15
- def set_action(attrs = {})
16
- tap {
17
- attrs.each { |key, value|
18
- raise ArgumentError, 'Invalid arguments, :text, :link_url keys.' unless validate_action_attributes(value)
19
-
20
- @actions[key.to_s] = {
21
- type: 'web',
22
- text: value[:text].to_s,
23
- params: {
24
- linkUri: value[:link_url].to_s
25
- },
26
- }
27
- }
28
- }
29
- end
30
-
31
- def validate_action_attributes(attrs = {})
32
- attrs[:text] && attrs[:link_url]
33
- end
34
-
35
- def add_listener(attrs = {})
36
- tap {
37
- raise ArgumentError, 'Invalid arguments, :x, :y, :width, :height keys.' unless validate_listener_attributes(attrs)
38
-
39
- listener = {
40
- type: 'touch', # Fixed "touch".
41
- params: [attrs[:x].to_i, attrs[:y].to_i, attrs[:width].to_i, attrs[:height].to_i],
42
- action: attrs[:action].to_s,
43
- }
44
- @listeners << listener
45
- }
46
- end
47
-
48
- def validate_listener_attributes(attrs = {})
49
- attrs[:action] &&
50
- attrs[:x] &&
51
- attrs[:y] &&
52
- attrs[:width] &&
53
- attrs[:height]
54
- end
55
-
56
- # send rich message to line server and to users
57
- #
58
- # @param attrs [Hash]
59
- # @param attrs [:to_mid] [String or Array] line user's mids
60
- # @param attrs [:image_url] [String] image file's url
61
- # @param attrs [:alt_text] [String] alt text for image file's url
62
- # @raise [ArgumentError] Error raised when supplied argument are missing :to_mid, :image_url, :preview_url keys.
63
- #
64
- # @return [Net::HTTPResponse] response for a request to line server
65
- def send(attrs = {})
66
- @image_url = attrs[:image_url]
67
- @alt_text = attrs[:alt_text]
68
-
69
- @client.send_message(attrs[:to_mid], self)
70
- end
71
-
72
- def height
73
- height = 0
74
- @listeners.each { |listener|
75
- h = listener[:params][1] + listener[:params][3] # params.y + params.height
76
- height = h if height < h
77
- }
78
-
79
- height > 2080 ? 2080 : height
80
- end
81
-
82
- def event_type
83
- Line::Bot::EventType::MESSAGE
84
- end
85
-
86
- def content
87
- {
88
- contentType: Line::Bot::Message::ContentType::RICH_MESSAGE,
89
- toType: Line::Bot::Message::RecipientType::USER,
90
- contentMetadata: {
91
- DOWNLOAD_URL: @image_url,
92
- SPEC_REV: "1", # Fixed "1".
93
- ALT_TEXT: @alt_text,
94
- MARKUP_JSON: markup.to_json,
95
- },
96
- }
97
- end
98
-
99
- def valid?
100
- @image_url && @alt_text
101
- end
102
-
103
- def markup
104
- {
105
- canvas: {
106
- height: height,
107
- width: 1040, # Integer fixed value: 1040
108
- initialScene: 'scene1',
109
- },
110
- images: {
111
- image1: {
112
- x: 0,
113
- y: 0,
114
- w: 1040, # Integer fixed value: 1040
115
- h: height
116
- },
117
- },
118
- actions: @actions,
119
- scenes: {
120
- scene1: {
121
- draws: [
122
- {
123
- image: 'image1', # Use the image ID "image1".
124
- x: 0,
125
- y: 0,
126
- w: 1040, # Integer fixed value: 1040
127
- h: height
128
- },
129
- ],
130
- listeners: @listeners
131
- }
132
- }
133
- }
134
- end
135
-
136
- end
137
- end
138
- end
139
- end
@@ -1,15 +0,0 @@
1
- module Line
2
- module Bot
3
- module EventType
4
- MESSAGE = 138311608800106203
5
- MULTIPLE_MESSAGE = 140177271400161403
6
- end
7
-
8
- module Receive
9
- module EventType
10
- MESSAGE = 138311609000106303
11
- OPERATION = 138311609100106403
12
- end
13
- end
14
- end
15
- end
@@ -1,9 +0,0 @@
1
- require 'line/bot/message/content_type'
2
- require 'line/bot/message/text'
3
- require 'line/bot/message/image'
4
- require 'line/bot/message/video'
5
- require 'line/bot/message/audio'
6
- require 'line/bot/message/location'
7
- require 'line/bot/message/sticker'
8
- require 'line/bot/message/contact'
9
- require 'line/bot/message/recipient_type'
@@ -1,25 +0,0 @@
1
- require 'line/bot/message/base'
2
-
3
- module Line
4
- module Bot
5
- module Message
6
- class Audio < Line::Bot::Message::Base
7
-
8
- def content
9
- {
10
- contentType: ContentType::AUDIO,
11
- toType: recipient_type,
12
- originalContentUrl: attrs[:audio_url],
13
- contentMetadata: {
14
- AUDLEN: attrs[:duration].to_s,
15
- },
16
- }
17
- end
18
-
19
- def valid?
20
- attrs[:audio_url] && attrs[:duration]
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,35 +0,0 @@
1
- require 'line/bot/message/recipient_type'
2
-
3
- module Line
4
- module Bot
5
- module Message
6
- class Base
7
- attr_reader :attrs, :recipient_type
8
-
9
- def initialize(attrs = {})
10
- @attrs = attrs
11
- end
12
-
13
- def recipient_type
14
- @attrs[:recipient_type] ||= Line::Bot::Message::RecipientType::USER
15
- end
16
-
17
- def [](key)
18
- @attrs[key]
19
- end
20
-
21
- def event_type
22
- Line::Bot::EventType::MESSAGE
23
- end
24
-
25
- def content
26
- raise NotImplementedError, "Implement this method in a child class"
27
- end
28
-
29
- def valid?
30
- raise NotImplementedError, "Implement this method in a child class"
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,18 +0,0 @@
1
- require 'line/bot/message/base'
2
-
3
- module Line
4
- module Bot
5
- module Message
6
- class Contact < Line::Bot::Message::Base
7
-
8
- def content
9
- raise Line::Bot::API::NotSupportedError
10
- end
11
-
12
- def valid?
13
- raise Line::Bot::API::NotSupportedError
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,16 +0,0 @@
1
- module Line
2
- module Bot
3
- module Message
4
- module ContentType
5
- TEXT = 1
6
- IMAGE = 2
7
- VIDEO = 3
8
- AUDIO = 4
9
- LOCATION = 7
10
- STICKER = 8
11
- CONTACT = 10
12
- RICH_MESSAGE = 12
13
- end
14
- end
15
- end
16
- end
@@ -1,23 +0,0 @@
1
- require 'line/bot/message/base'
2
-
3
- module Line
4
- module Bot
5
- module Message
6
- class Image < Line::Bot::Message::Base
7
-
8
- def content
9
- {
10
- contentType: ContentType::IMAGE,
11
- toType: recipient_type,
12
- originalContentUrl: attrs[:image_url],
13
- previewImageUrl: attrs[:preview_url],
14
- }
15
- end
16
-
17
- def valid?
18
- attrs[:image_url] && attrs[:preview_url]
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,28 +0,0 @@
1
- require 'line/bot/message/base'
2
-
3
- module Line
4
- module Bot
5
- module Message
6
- class Location < Line::Bot::Message::Base
7
-
8
- def content
9
- {
10
- contentType: ContentType::LOCATION,
11
- toType: recipient_type,
12
- text: attrs[:address] || attrs[:title],
13
- location: {
14
- title: attrs[:title],
15
- address: attrs[:address],
16
- latitude: attrs[:latitude],
17
- longitude: attrs[:longitude],
18
- }
19
- }
20
- end
21
-
22
- def valid?
23
- attrs[:title] && attrs[:latitude] && attrs[:longitude]
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,9 +0,0 @@
1
- module Line
2
- module Bot
3
- module Message
4
- module RecipientType
5
- USER = 1
6
- end
7
- end
8
- end
9
- end
@@ -1,26 +0,0 @@
1
- require 'line/bot/message/base'
2
-
3
- module Line
4
- module Bot
5
- module Message
6
- class Sticker < Line::Bot::Message::Base
7
-
8
- def content
9
- {
10
- contentType: ContentType::STICKER,
11
- toType: recipient_type,
12
- contentMetadata: {
13
- STKPKGID: attrs[:stkpkgid].to_s,
14
- STKID: attrs[:stkid].to_s,
15
- STKVER: attrs[:stkver].to_s,
16
- },
17
- }
18
- end
19
-
20
- def valid?
21
- attrs[:stkpkgid] && attrs[:stkid] && attrs[:stkver]
22
- end
23
- end
24
- end
25
- end
26
- end