Class: Line::Bot::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/line/bot/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



6
7
8
9
10
# File 'lib/line/bot/client.rb', line 6

def initialize(options = {})
  @certentials = options if options.is_a?(Certentials)
  @certentials = Certentials.new(options) if options.is_a?(Hash)
  yield(self) if block_given?
end

Instance Attribute Details

#certentialsObject

Returns the value of attribute certentials.



4
5
6
# File 'lib/line/bot/client.rb', line 4

def certentials
  @certentials
end

Instance Method Details

#get_image(id, preview = false) ⇒ Object



12
13
14
15
16
# File 'lib/line/bot/client.rb', line 12

def get_image(id, preview = false)
  url = "#{API::ENDPOINT}/bot/message/#{id}/content"
  url = "#{url}/preview" if preview
  HTTP.get(url, @certentials.header)
end

#send_image(to_mid, image_url, preview_url) ⇒ Object



22
23
24
# File 'lib/line/bot/client.rb', line 22

def send_image(to_mid, image_url, preview_url)
  send_message(to_mid, Message::Image.new( image_url: image_url, preview_url: preview_url) )
end

#send_message(to_mid, message) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/line/bot/client.rb', line 26

def send_message(to_mid, message)
  request = Request.new do |config|
    config.to_mid = to_mid
    config.certentials = @certentials
    config.endpoint = API::ENDPOINT
    config.endpoint_path = "/events"
    config.message = message
    config.event_type = Line::Bot::EventType::MESSAGE
  end

  request.post
end

#send_text(to_mid, message) ⇒ Object



18
19
20
# File 'lib/line/bot/client.rb', line 18

def send_text(to_mid, message)
  send_message(to_mid, Message::Text.new(text: message))
end