Class: FORCAST::Telegram::Send
- Inherits:
-
Object
- Object
- FORCAST::Telegram::Send
- Defined in:
- lib/forcast/utils/telegram.rb
Instance Attribute Summary collapse
-
#chat_id ⇒ Object
Returns the value of attribute chat_id.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#json_send ⇒ Object
Returns the value of attribute json_send.
-
#metodo ⇒ Object
Returns the value of attribute metodo.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #constructor ⇒ Object
- #getUpdates ⇒ Object
-
#initialize(chat_id) ⇒ Send
constructor
A new instance of Send.
-
#sendMessage(message) ⇒ Object
Mostrar usuarios.
- #sendPhoto(url_imagen, message) ⇒ Object
- #valid_json?(json) ⇒ Boolean
Constructor Details
#initialize(chat_id) ⇒ Send
Returns a new instance of Send.
10 11 12 |
# File 'lib/forcast/utils/telegram.rb', line 10 def initialize(chat_id) self.chat_id = chat_id.to_s end |
Instance Attribute Details
#chat_id ⇒ Object
Returns the value of attribute chat_id.
8 9 10 |
# File 'lib/forcast/utils/telegram.rb', line 8 def chat_id @chat_id end |
#headers ⇒ Object
Returns the value of attribute headers.
4 5 6 |
# File 'lib/forcast/utils/telegram.rb', line 4 def headers @headers end |
#json_send ⇒ Object
Returns the value of attribute json_send.
6 7 8 |
# File 'lib/forcast/utils/telegram.rb', line 6 def json_send @json_send end |
#metodo ⇒ Object
Returns the value of attribute metodo.
7 8 9 |
# File 'lib/forcast/utils/telegram.rb', line 7 def metodo @metodo end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/forcast/utils/telegram.rb', line 5 def url @url end |
Instance Method Details
#constructor ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/forcast/utils/telegram.rb', line 48 def constructor yield self.headers = {} resp = SERVIDORTELEGRAM.conexion(self.metodo, self.headers, self.url, self.json_send) puts resp return true if resp[1].blank? json_recived = {} logger.info "[TELEGRAM] "+resp[1].to_s if resp[0] && self.valid_json?(resp[1]) json_recived = JSON.parse(resp[1]) unless json_recived.is_a?(Array) unless json_recived["error"].nil? logger.info "[TELEGRAM] "+json_recived["error"].to_s return false end end return json_recived else return false end end |
#getUpdates ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/forcast/utils/telegram.rb', line 14 def getUpdates json_recived = constructor do self.metodo = :get self.url = "/getUpdates" self.json_send = {} end end |
#sendMessage(message) ⇒ Object
Mostrar usuarios
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/forcast/utils/telegram.rb', line 23 def sendMessage() json_recived = constructor do self.metodo = :post self.url = "/sendMessage?" self.url += "chat_id="+self.chat_id.to_s self.url += "&text="+ self.url += "&parse_mode=HTML" self.json_send = {} end end |
#sendPhoto(url_imagen, message) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/forcast/utils/telegram.rb', line 35 def sendPhoto(url_imagen,) json_recived = constructor do self.metodo = :post self.url = "/sendPhoto?" self.url += "chat_id="+self.chat_id.to_s self.url += "&photo="+url_imagen self.url += "&caption="+ self.url += "&parse_mode=HTML" self.json_send = {} end end |
#valid_json?(json) ⇒ Boolean
70 71 72 73 74 75 76 77 78 |
# File 'lib/forcast/utils/telegram.rb', line 70 def valid_json?(json) begin JSON.parse(json) return true rescue JSON::ParserError => e puts e return false end end |