Class: FORCAST::Firebase::Notificacion

Inherits:
Object
  • Object
show all
Defined in:
lib/forcast/utils/firebase.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNotificacion

Returns a new instance of Notificacion.



9
10
11
# File 'lib/forcast/utils/firebase.rb', line 9

def initialize
  self.headers = {}
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



4
5
6
# File 'lib/forcast/utils/firebase.rb', line 4

def headers
  @headers
end

#json_sendObject

Returns the value of attribute json_send.



6
7
8
# File 'lib/forcast/utils/firebase.rb', line 6

def json_send
  @json_send
end

#metodoObject

Returns the value of attribute metodo.



7
8
9
# File 'lib/forcast/utils/firebase.rb', line 7

def metodo
  @metodo
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/forcast/utils/firebase.rb', line 5

def url
  @url
end

Instance Method Details

#constructorObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/forcast/utils/firebase.rb', line 21

def constructor 
    yield
    resp = SERVIDORNOTIFICACION.conexion(self.metodo, self.headers, self.url, self.json_send)
    return true if resp[1].blank?
    json_recived = {}
    puts resp
    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 "[FIREBASE] "+json_recived["error"].to_s
          return false
        end
      end
      return  json_recived
    else
      return false
    end
end

#enviarNotificacion(token, title, body) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/forcast/utils/firebase.rb', line 13

def enviarNotificacion(token,title,body)
  json_recived = constructor do
      self.metodo = :post
      self.url = "/sendPushNotification/"
      self.json_send = {:token => token, :title => title, :body => body}
  end
end

#parser(varible, key1 = '') ⇒ Object



51
52
53
54
55
56
57
# File 'lib/forcast/utils/firebase.rb', line 51

def parser(varible, key1 = '')
  if key1 == ''
    return JSON.pretty_generate(FORCAST::Server.response_to_json(varible))
  else
    return FORCAST::Server.response_to_json(varible).map {|i| i[key1]}
  end
end

#valid_json?(json) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
47
48
49
# File 'lib/forcast/utils/firebase.rb', line 41

def valid_json?(json)
  begin
    JSON.parse(json)
    return true
  rescue JSON::ParserError => e
    puts e
    return false
  end
end