Class: Fluent::GoogleChatClient::Base
- Inherits:
-
Object
- Object
- Fluent::GoogleChatClient::Base
- Defined in:
- lib/fluent/plugin/google_chat_client.rb
Overview
The base framework of google_chat client
Direct Known Subclasses
Constant Summary collapse
- SCOPE =
'https://www.googleapis.com/auth/chat.bot'.freeze
Instance Attribute Summary collapse
-
#debug_dev ⇒ Object
Returns the value of attribute debug_dev.
-
#https_proxy ⇒ Object
Returns the value of attribute https_proxy.
-
#keyfile ⇒ Object
Returns the value of attribute keyfile.
-
#log ⇒ Object
Returns the value of attribute log.
Instance Method Summary collapse
-
#authorize ⇒ Google::Auth::UserRefreshCredentials
Ensure valid credentials, either by restoring from the saved credentials files or intitiating an OAuth2 authorization.
-
#initialize(keyfile = nil, https_proxy = nil) ⇒ Base
constructor
A new instance of Base.
- #post(params) ⇒ Object
- #proxy_class ⇒ Object
Constructor Details
#initialize(keyfile = nil, https_proxy = nil) ⇒ Base
Returns a new instance of Base.
35 36 37 38 39 |
# File 'lib/fluent/plugin/google_chat_client.rb', line 35 def initialize(keyfile = nil, https_proxy = nil) self.keyfile = keyfile if keyfile self.https_proxy = https_proxy if https_proxy @log = Logger.new('/dev/null') end |
Instance Attribute Details
#debug_dev ⇒ Object
Returns the value of attribute debug_dev.
17 18 19 |
# File 'lib/fluent/plugin/google_chat_client.rb', line 17 def debug_dev @debug_dev end |
#https_proxy ⇒ Object
Returns the value of attribute https_proxy.
18 19 20 |
# File 'lib/fluent/plugin/google_chat_client.rb', line 18 def https_proxy @https_proxy end |
#keyfile ⇒ Object
Returns the value of attribute keyfile.
18 19 20 |
# File 'lib/fluent/plugin/google_chat_client.rb', line 18 def keyfile @keyfile end |
#log ⇒ Object
Returns the value of attribute log.
17 18 19 |
# File 'lib/fluent/plugin/google_chat_client.rb', line 17 def log @log end |
Instance Method Details
#authorize ⇒ Google::Auth::UserRefreshCredentials
Ensure valid credentials, either by restoring from the saved credentials files or intitiating an OAuth2 authorization. If authorization is required, the user’s default browser will be launched to approve the request.
47 48 49 50 51 52 53 |
# File 'lib/fluent/plugin/google_chat_client.rb', line 47 def credentials = Google::Auth::ServiceAccountCredentials.make_creds( json_key_io: File.open(self.keyfile), scope: SCOPE ) credentials end |
#post(params) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fluent/plugin/google_chat_client.rb', line 68 def post(params) chat = Chat::HangoutsChatService.new chat. = = Chat::Message.new .text = params[:text].length > 4096 ? params[:text][0...4096] : params[:text] chat.( 'spaces/%s' % params[:space], ) end |
#proxy_class ⇒ Object
64 65 66 |
# File 'lib/fluent/plugin/google_chat_client.rb', line 64 def proxy_class @proxy_class ||= Net::HTTP end |