Class: FORCAST::Firebase::Database
- Inherits:
-
Object
- Object
- FORCAST::Firebase::Database
- Defined in:
- lib/forcast/utils/firebase_database.rb
Instance Attribute Summary collapse
-
#_method ⇒ Object
Returns the value of attribute _method.
-
#data ⇒ Object
Returns the value of attribute data.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#path ⇒ Object
Returns the value of attribute path.
-
#query_options ⇒ Object
Returns the value of attribute query_options.
Instance Method Summary collapse
- #constructor ⇒ Object
- #delete(path, query_options: {}) ⇒ Object
- #get(path, query_options: {}) ⇒ Object
-
#initialize ⇒ Database
constructor
A new instance of Database.
- #parser(variable, key1 = '') ⇒ Object
- #push(path, data, query_options: {}) ⇒ Object
- #set(path, data, query_options: {}) ⇒ Object
- #update(path, data, query_options: {}) ⇒ Object
- #valid_json?(json) ⇒ Boolean
Constructor Details
#initialize ⇒ Database
13 14 15 |
# File 'lib/forcast/utils/firebase_database.rb', line 13 def initialize self.headers = {} end |
Instance Attribute Details
#_method ⇒ Object
Returns the value of attribute _method.
8 9 10 |
# File 'lib/forcast/utils/firebase_database.rb', line 8 def _method @_method end |
#data ⇒ Object
Returns the value of attribute data.
10 11 12 |
# File 'lib/forcast/utils/firebase_database.rb', line 10 def data @data end |
#headers ⇒ Object
Returns the value of attribute headers.
7 8 9 |
# File 'lib/forcast/utils/firebase_database.rb', line 7 def headers @headers end |
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/forcast/utils/firebase_database.rb', line 9 def path @path end |
#query_options ⇒ Object
Returns the value of attribute query_options.
11 12 13 |
# File 'lib/forcast/utils/firebase_database.rb', line 11 def @query_options end |
Instance Method Details
#constructor ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/forcast/utils/firebase_database.rb', line 60 def constructor yield if self._method == :get || self._method == :delete resp = SERVER_FIREBASE_DATABASE.send(self._method, self.path) else if self._method == :update self.data.merge!({:updated_at => Time.now.to_i}) else self.data.merge!({:created_at => Time.now.to_i}) end resp = SERVER_FIREBASE_DATABASE.send(self._method, self.path, self.data, self.) end puts "[FIREBASE] URI:"+resp.response.http_header.request_uri.to_s puts "[FIREBASE] METHOD:"+resp.response.http_header.request_method.to_s puts "[FIREBASE] BODY:"+resp.body.to_s resp = resp.body.to_json if self.valid_json?(resp) json_recived = JSON.parse(resp) return json_recived else return false end end |
#delete(path, query_options: {}) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/forcast/utils/firebase_database.rb', line 44 def delete(path,query_options: {}) json_recived = constructor do self._method = :delete self.path = path self. = end end |
#get(path, query_options: {}) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/forcast/utils/firebase_database.rb', line 52 def get(path,query_options: {}) json_recived = constructor do self._method = :get self.path = path self. = end end |
#parser(variable, key1 = '') ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/forcast/utils/firebase_database.rb', line 94 def parser(variable, key1 = '') if key1 == '' return JSON.pretty_generate(FORCAST::Server.response_to_json(variable)) else return FORCAST::Server.response_to_json(variable).map {|i| i[key1]} end end |
#push(path, data, query_options: {}) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/forcast/utils/firebase_database.rb', line 17 def push(path,data,query_options: {}) json_recived = constructor do self._method = :push self.path = path self.data = data self. = end end |
#set(path, data, query_options: {}) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/forcast/utils/firebase_database.rb', line 26 def set(path,data,query_options: {}) json_recived = constructor do self._method = :set self.path = path self.data = data self. = end end |
#update(path, data, query_options: {}) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/forcast/utils/firebase_database.rb', line 35 def update(path,data,query_options: {}) json_recived = constructor do self._method = :update self.path = path self.data = data self. = end end |
#valid_json?(json) ⇒ Boolean
84 85 86 87 88 89 90 91 92 |
# File 'lib/forcast/utils/firebase_database.rb', line 84 def valid_json?(json) begin JSON.parse(json) return true rescue JSON::ParserError => e puts e return false end end |