Class: Firebase::Request
- Inherits:
-
Object
- Object
- Firebase::Request
- Defined in:
- lib/firebase/request.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
- .build_url(path) ⇒ Object
- .delete(path) ⇒ Object
- .get(path) ⇒ Object
- .patch(path, value) ⇒ Object
- .post(path, value) ⇒ Object
- .put(path, value) ⇒ Object
Instance Method Summary collapse
- #body ⇒ Object
- #code ⇒ Object
-
#initialize(response) ⇒ Request
constructor
A new instance of Request.
- #raw_body ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Request
Returns a new instance of Request.
59 60 61 |
# File 'lib/firebase/request.rb', line 59 def initialize(response) @response = response end |
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
57 58 59 |
# File 'lib/firebase/request.rb', line 57 def response @response end |
Class Method Details
.build_url(path) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/firebase/request.rb', line 31 def build_url(path) host = Firebase.base_uri path = "#{path}.json" query_string = Firebase.auth ? "?auth=#{Firebase.auth}" : "" url = URI.join(Firebase.base_uri, path, query_string) url.to_s end |
.delete(path) ⇒ Object
23 24 25 |
# File 'lib/firebase/request.rb', line 23 def delete(path) process(:delete, path) end |
.get(path) ⇒ Object
11 12 13 |
# File 'lib/firebase/request.rb', line 11 def get(path) process(:get, path) end |
.patch(path, value) ⇒ Object
27 28 29 |
# File 'lib/firebase/request.rb', line 27 def patch(path, value) process(:patch, path, :body => value.to_json) end |
.post(path, value) ⇒ Object
19 20 21 |
# File 'lib/firebase/request.rb', line 19 def post(path, value) process(:post, path, :body => value.to_json) end |
.put(path, value) ⇒ Object
15 16 17 |
# File 'lib/firebase/request.rb', line 15 def put(path, value) process(:put, path, :body => value.to_json) end |
Instance Method Details
#body ⇒ Object
63 64 65 66 67 |
# File 'lib/firebase/request.rb', line 63 def body JSON.parse(response.body, :quirks_mode => true) rescue JSON::ParserError => e response.body == 'null' ? nil : raise end |
#code ⇒ Object
77 78 79 |
# File 'lib/firebase/request.rb', line 77 def code response.code end |
#raw_body ⇒ Object
69 70 71 |
# File 'lib/firebase/request.rb', line 69 def raw_body response.body end |
#success? ⇒ Boolean
73 74 75 |
# File 'lib/firebase/request.rb', line 73 def success? [200, 204].include? response.code end |