Class: ApiClient
- Inherits:
-
Object
- Object
- ApiClient
- Defined in:
- lib/line-notify-client/api_client.rb
Defined Under Namespace
Classes: ArgumentError
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize ⇒ ApiClient
constructor
A new instance of ApiClient.
- #message(token, message) ⇒ Object
Constructor Details
#initialize ⇒ ApiClient
Returns a new instance of ApiClient.
8 9 10 11 12 13 |
# File 'lib/line-notify-client/api_client.rb', line 8 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 |
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
7 8 9 |
# File 'lib/line-notify-client/api_client.rb', line 7 def http @http end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/line-notify-client/api_client.rb', line 7 def uri @uri end |
Instance Method Details
#message(token, message) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/line-notify-client/api_client.rb', line 15 def (token, ) token ||= ENV['LINE_NOTIFY_TOKEN'] raise ArgumentError if token.nil? || .nil? req = Net::HTTP::Post.new uri req["Authorization"] = "Bearer #{token}" req.set_form_data(message: ) res = http.start { |http| http.request req } return res.body end |