class ApiClient

Attributes

http[R]
uri[R]

Public Class Methods

new() click to toggle source
# File lib/line-notify-client/api_client.rb, line 9
def initialize
  @uri = URI.parse("https://notify-api.line.me/api/notify")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  @http = http
end

Public Instance Methods

message(token, message) click to toggle source
# File lib/line-notify-client/api_client.rb, line 16
def message(token, message)
  token ||= ENV['LINE_NOTIFY_TOKEN']
  raise ArgumentError if token.nil? || message.nil?
  req = Net::HTTP::Post.new uri
  req["Authorization"] = "Bearer #{token}"
  req.set_form_data(message: message)
  res = http.start { |http| http.request req }
  JSON.parse(res.body)
end