firebase 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +3 -0
- data/Gemfile.lock +52 -20
- data/README.md +12 -14
- data/VERSION +1 -1
- data/firebase.gemspec +4 -2
- data/lib/firebase.rb +68 -22
- data/lib/firebase/request.rb +34 -59
- data/lib/firebase/response.rb +28 -0
- data/spec/firebase_request_spec.rb +10 -14
- data/spec/firebase_spec.rb +27 -29
- metadata +5 -3
    
        data/CHANGELOG
    ADDED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,32 +1,64 @@ | |
| 1 1 | 
             
            GEM
         | 
| 2 2 | 
             
              remote: http://rubygems.org/
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                 | 
| 5 | 
            -
                 | 
| 6 | 
            -
             | 
| 4 | 
            +
                addressable (2.3.5)
         | 
| 5 | 
            +
                builder (3.2.2)
         | 
| 6 | 
            +
                diff-lcs (1.2.5)
         | 
| 7 | 
            +
                ethon (0.6.1)
         | 
| 8 | 
            +
                  ffi (>= 1.3.0)
         | 
| 7 9 | 
             
                  mime-types (~> 1.18)
         | 
| 8 | 
            -
                 | 
| 9 | 
            -
             | 
| 10 | 
            -
                 | 
| 10 | 
            +
                faraday (0.8.8)
         | 
| 11 | 
            +
                  multipart-post (~> 1.2.0)
         | 
| 12 | 
            +
                ffi (1.9.3)
         | 
| 13 | 
            +
                git (1.2.6)
         | 
| 14 | 
            +
                github_api (0.10.1)
         | 
| 15 | 
            +
                  addressable
         | 
| 16 | 
            +
                  faraday (~> 0.8.1)
         | 
| 17 | 
            +
                  hashie (>= 1.2)
         | 
| 18 | 
            +
                  multi_json (~> 1.4)
         | 
| 19 | 
            +
                  nokogiri (~> 1.5.2)
         | 
| 20 | 
            +
                  oauth2
         | 
| 21 | 
            +
                hashie (2.0.5)
         | 
| 22 | 
            +
                highline (1.6.20)
         | 
| 23 | 
            +
                httpauth (0.2.0)
         | 
| 24 | 
            +
                jeweler (1.8.8)
         | 
| 25 | 
            +
                  builder
         | 
| 11 26 | 
             
                  bundler (~> 1.0)
         | 
| 12 27 | 
             
                  git (>= 1.2.5)
         | 
| 28 | 
            +
                  github_api (= 0.10.1)
         | 
| 29 | 
            +
                  highline (>= 1.6.15)
         | 
| 30 | 
            +
                  nokogiri (= 1.5.10)
         | 
| 13 31 | 
             
                  rake
         | 
| 14 32 | 
             
                  rdoc
         | 
| 15 | 
            -
                json (1. | 
| 16 | 
            -
                 | 
| 17 | 
            -
             | 
| 18 | 
            -
                 | 
| 33 | 
            +
                json (1.8.1)
         | 
| 34 | 
            +
                jwt (0.1.8)
         | 
| 35 | 
            +
                  multi_json (>= 1.5)
         | 
| 36 | 
            +
                mime-types (1.25)
         | 
| 37 | 
            +
                multi_json (1.8.2)
         | 
| 38 | 
            +
                multi_xml (0.5.5)
         | 
| 39 | 
            +
                multipart-post (1.2.0)
         | 
| 40 | 
            +
                nokogiri (1.5.10)
         | 
| 41 | 
            +
                oauth2 (0.9.2)
         | 
| 42 | 
            +
                  faraday (~> 0.8)
         | 
| 43 | 
            +
                  httpauth (~> 0.2)
         | 
| 44 | 
            +
                  jwt (~> 0.1.4)
         | 
| 45 | 
            +
                  multi_json (~> 1.0)
         | 
| 46 | 
            +
                  multi_xml (~> 0.5)
         | 
| 47 | 
            +
                  rack (~> 1.2)
         | 
| 48 | 
            +
                rack (1.5.2)
         | 
| 49 | 
            +
                rake (10.1.0)
         | 
| 50 | 
            +
                rdoc (4.0.1)
         | 
| 19 51 | 
             
                  json (~> 1.4)
         | 
| 20 | 
            -
                rspec (2. | 
| 21 | 
            -
                  rspec-core (~> 2. | 
| 22 | 
            -
                  rspec-expectations (~> 2. | 
| 23 | 
            -
                  rspec-mocks (~> 2. | 
| 24 | 
            -
                rspec-core (2. | 
| 25 | 
            -
                rspec-expectations (2. | 
| 26 | 
            -
                  diff-lcs ( | 
| 27 | 
            -
                rspec-mocks (2. | 
| 28 | 
            -
                typhoeus (0.6. | 
| 29 | 
            -
                  ethon (~> 0. | 
| 52 | 
            +
                rspec (2.14.1)
         | 
| 53 | 
            +
                  rspec-core (~> 2.14.0)
         | 
| 54 | 
            +
                  rspec-expectations (~> 2.14.0)
         | 
| 55 | 
            +
                  rspec-mocks (~> 2.14.0)
         | 
| 56 | 
            +
                rspec-core (2.14.7)
         | 
| 57 | 
            +
                rspec-expectations (2.14.4)
         | 
| 58 | 
            +
                  diff-lcs (>= 1.1.3, < 2.0)
         | 
| 59 | 
            +
                rspec-mocks (2.14.4)
         | 
| 60 | 
            +
                typhoeus (0.6.6)
         | 
| 61 | 
            +
                  ethon (~> 0.6.1)
         | 
| 30 62 |  | 
| 31 63 | 
             
            PLATFORMS
         | 
| 32 64 | 
             
              ruby
         | 
    
        data/README.md
    CHANGED
    
    | @@ -9,18 +9,17 @@ See a [video demo](https://vimeo.com/41494336?utm_source=internal&utm_medium=ema | |
| 9 9 |  | 
| 10 10 | 
             
            ### Installation
         | 
| 11 11 |  | 
| 12 | 
            -
             | 
| 13 12 | 
             
            ```
         | 
| 14 13 | 
             
            gem install firebase
         | 
| 15 14 | 
             
            ```
         | 
| 16 | 
            -
             | 
| 17 15 | 
             
            ### Usage
         | 
| 18 16 |  | 
| 19 | 
            -
             | 
| 20 17 | 
             
            ```ruby
         | 
| 21 | 
            -
             | 
| 18 | 
            +
            base_uri = 'https://<your-firebase>.firebaseio.com/'
         | 
| 22 19 |  | 
| 23 | 
            -
             | 
| 20 | 
            +
            firebase = Firebase.new(base_uri)
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            response = firebase.push("todos", { :name => 'Pick the milk', :priority => 1 })
         | 
| 24 23 | 
             
            response.success? # => true
         | 
| 25 24 | 
             
            response.code # => 200
         | 
| 26 25 | 
             
            response.body # => { 'name' => "-INOQPH-aV_psbk3ZXEX" }
         | 
| @@ -29,20 +28,19 @@ response.raw_body # => '{"name":"-INOQPH-aV_psbk3ZXEX"}' | |
| 29 28 |  | 
| 30 29 | 
             
            If you have a read-only namespace, set your secret key as follows:
         | 
| 31 30 | 
             
            ```ruby
         | 
| 32 | 
            -
            Firebase.base_uri  | 
| 33 | 
            -
            Firebase.auth = 'yoursecretkey'
         | 
| 31 | 
            +
            firebase = Firebase.new(base_uri, secret_key)
         | 
| 34 32 |  | 
| 35 | 
            -
            response =  | 
| 33 | 
            +
            response = firebase.push("todos", { :name => 'Pick the milk', :priority => 1 })
         | 
| 36 34 | 
             
            ```
         | 
| 37 35 |  | 
| 38 | 
            -
             | 
| 39 36 | 
             
            So far, supported methods are:
         | 
| 40 37 |  | 
| 41 38 | 
             
            ```ruby
         | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 39 | 
            +
            set(path, data)
         | 
| 40 | 
            +
            get(path)
         | 
| 41 | 
            +
            push(path, data)
         | 
| 42 | 
            +
            delete(path)
         | 
| 43 | 
            +
            update(path, data)
         | 
| 46 44 | 
             
            ```
         | 
| 47 45 |  | 
| 48 46 | 
             
            More features are coming soon.
         | 
| @@ -52,6 +50,6 @@ More information about Firebase and the Firebase API is available at the | |
| 52 50 |  | 
| 53 51 | 
             
            ### Copyright
         | 
| 54 52 |  | 
| 55 | 
            -
            Copyright (c)  | 
| 53 | 
            +
            Copyright (c) 2013 Oscar Del Ben. See LICENSE.txt for
         | 
| 56 54 | 
             
            further details.
         | 
| 57 55 |  | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.1. | 
| 1 | 
            +
            0.1.6
         | 
    
        data/firebase.gemspec
    CHANGED
    
    | @@ -5,11 +5,11 @@ | |
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |s|
         | 
| 7 7 | 
             
              s.name = "firebase"
         | 
| 8 | 
            -
              s.version = "0.1. | 
| 8 | 
            +
              s.version = "0.1.6"
         | 
| 9 9 |  | 
| 10 10 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 11 | 
             
              s.authors = ["Oscar Del Ben"]
         | 
| 12 | 
            -
              s.date = "2013-11- | 
| 12 | 
            +
              s.date = "2013-11-23"
         | 
| 13 13 | 
             
              s.description = "Firebase wrapper for Ruby"
         | 
| 14 14 | 
             
              s.email = "info@oscardelben.com"
         | 
| 15 15 | 
             
              s.extra_rdoc_files = [
         | 
| @@ -19,6 +19,7 @@ Gem::Specification.new do |s| | |
| 19 19 | 
             
              s.files = [
         | 
| 20 20 | 
             
                ".document",
         | 
| 21 21 | 
             
                ".rspec",
         | 
| 22 | 
            +
                "CHANGELOG",
         | 
| 22 23 | 
             
                "Gemfile",
         | 
| 23 24 | 
             
                "Gemfile.lock",
         | 
| 24 25 | 
             
                "LICENSE.txt",
         | 
| @@ -28,6 +29,7 @@ Gem::Specification.new do |s| | |
| 28 29 | 
             
                "firebase.gemspec",
         | 
| 29 30 | 
             
                "lib/firebase.rb",
         | 
| 30 31 | 
             
                "lib/firebase/request.rb",
         | 
| 32 | 
            +
                "lib/firebase/response.rb",
         | 
| 31 33 | 
             
                "spec/firebase_request_spec.rb",
         | 
| 32 34 | 
             
                "spec/firebase_spec.rb",
         | 
| 33 35 | 
             
                "spec/spec_helper.rb"
         | 
    
        data/lib/firebase.rb
    CHANGED
    
    | @@ -1,49 +1,95 @@ | |
| 1 | 
            +
            class Firebase
         | 
| 1 2 |  | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 4 | 
            -
              autoload :Request, 'firebase/request'
         | 
| 3 | 
            +
              require 'firebase/request'
         | 
| 4 | 
            +
              require 'firebase/response'
         | 
| 5 5 |  | 
| 6 6 | 
             
              class << self
         | 
| 7 | 
            -
                attr_accessor :base_uri, :auth
         | 
| 8 7 |  | 
| 9 | 
            -
                def  | 
| 10 | 
            -
                  if other | 
| 11 | 
            -
                    other | 
| 8 | 
            +
                def format_uri(other)
         | 
| 9 | 
            +
                  if other
         | 
| 10 | 
            +
                    other.end_with?("/") ? other : other + '/'
         | 
| 12 11 | 
             
                  end
         | 
| 13 | 
            -
             | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def base_uri=(other)
         | 
| 15 | 
            +
                  deprecate
         | 
| 16 | 
            +
                  default_instance.request.base_uri = format_uri(other)
         | 
| 14 17 | 
             
                end
         | 
| 15 18 |  | 
| 16 19 | 
             
                def auth=(auth)
         | 
| 17 | 
            -
                   | 
| 20 | 
            +
                  deprecate
         | 
| 21 | 
            +
                  default_instance.request.auth = auth
         | 
| 18 22 | 
             
                end
         | 
| 19 23 |  | 
| 20 | 
            -
                # Writes and returns the data
         | 
| 21 | 
            -
                #   Firebase.set('users/info', { 'name' => 'Oscar' }) => { 'name' => 'Oscar' }
         | 
| 22 24 | 
             
                def set(path, data)
         | 
| 23 | 
            -
                   | 
| 25 | 
            +
                  deprecate
         | 
| 26 | 
            +
                  default_instance.set(path, data)
         | 
| 24 27 | 
             
                end
         | 
| 25 28 |  | 
| 26 | 
            -
                # Returns the data at path
         | 
| 27 29 | 
             
                def get(path)
         | 
| 28 | 
            -
                   | 
| 30 | 
            +
                  deprecate
         | 
| 31 | 
            +
                  default_instance.get(path)
         | 
| 29 32 | 
             
                end
         | 
| 30 33 |  | 
| 31 | 
            -
                # Writes the data, returns the key name of the data added
         | 
| 32 | 
            -
                #   Firebase.push('users', { 'age' => 18}) => {"name":"-INOQPH-aV_psbk3ZXEX"}
         | 
| 33 34 | 
             
                def push(path, data)
         | 
| 34 | 
            -
                   | 
| 35 | 
            +
                  deprecate
         | 
| 36 | 
            +
                  default_instance.push(path, data)
         | 
| 35 37 | 
             
                end
         | 
| 36 38 |  | 
| 37 | 
            -
                # Deletes the data at path and returs true
         | 
| 38 39 | 
             
                def delete(path)
         | 
| 39 | 
            -
                   | 
| 40 | 
            +
                  deprecate
         | 
| 41 | 
            +
                  default_instance.delete(path)
         | 
| 40 42 | 
             
                end
         | 
| 41 43 |  | 
| 42 | 
            -
                # Write the data at path but does not delete ommited children. Returns the data
         | 
| 43 | 
            -
                #   Firebase.update('users/info', { 'name' => 'Oscar' }) => { 'name' => 'Oscar' }
         | 
| 44 44 | 
             
                def update(path, data)
         | 
| 45 | 
            -
                   | 
| 45 | 
            +
                  deprecate
         | 
| 46 | 
            +
                  default_instance.patch(path, data)
         | 
| 46 47 | 
             
                end
         | 
| 47 48 |  | 
| 49 | 
            +
                def default_instance
         | 
| 50 | 
            +
                  @default_instance ||= Firebase.new(nil, nil)
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                def deprecate
         | 
| 54 | 
            +
                  puts "[FIREBASE] This syntax has been deprecated. Please upgrade to the new Firebase.new(...).method syntax"
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
              end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
              attr_accessor :request
         | 
| 60 | 
            +
             | 
| 61 | 
            +
              def initialize(base_uri, auth=nil)
         | 
| 62 | 
            +
                uri = Firebase.format_uri(base_uri)
         | 
| 63 | 
            +
                @request = Firebase::Request.new(uri, auth)
         | 
| 48 64 | 
             
              end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                # Writes and returns the data
         | 
| 67 | 
            +
                #   Firebase.set('users/info', { 'name' => 'Oscar' }) => { 'name' => 'Oscar' }
         | 
| 68 | 
            +
              def set(path, data)
         | 
| 69 | 
            +
                request.put(path, data)
         | 
| 70 | 
            +
              end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
              # Returns the data at path
         | 
| 73 | 
            +
              def get(path)
         | 
| 74 | 
            +
                request.get(path)
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
              # Writes the data, returns the key name of the data added
         | 
| 78 | 
            +
              #   Firebase.push('users', { 'age' => 18}) => {"name":"-INOQPH-aV_psbk3ZXEX"}
         | 
| 79 | 
            +
              def push(path, data)
         | 
| 80 | 
            +
                request.post(path, data)
         | 
| 81 | 
            +
              end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
              # Deletes the data at path and returs true
         | 
| 84 | 
            +
              def delete(path)
         | 
| 85 | 
            +
                request.delete(path)
         | 
| 86 | 
            +
              end
         | 
| 87 | 
            +
             | 
| 88 | 
            +
              # Write the data at path but does not delete ommited children. Returns the data
         | 
| 89 | 
            +
              #   Firebase.update('users/info', { 'name' => 'Oscar' }) => { 'name' => 'Oscar' }
         | 
| 90 | 
            +
              def update(path, data)
         | 
| 91 | 
            +
                request.patch(path, data)
         | 
| 92 | 
            +
              end
         | 
| 93 | 
            +
             | 
| 49 94 | 
             
            end
         | 
| 95 | 
            +
             | 
    
        data/lib/firebase/request.rb
    CHANGED
    
    | @@ -3,80 +3,55 @@ require 'json' | |
| 3 3 | 
             
            require 'open-uri'
         | 
| 4 4 | 
             
            require 'uri'
         | 
| 5 5 |  | 
| 6 | 
            -
             | 
| 6 | 
            +
            class Firebase
         | 
| 7 7 | 
             
              class Request
         | 
| 8 8 |  | 
| 9 | 
            -
                 | 
| 10 | 
            -
             | 
| 11 | 
            -
                  def get(path)
         | 
| 12 | 
            -
                    process(:get, path)
         | 
| 13 | 
            -
                  end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                  def put(path, value)
         | 
| 16 | 
            -
                    process(:put, path, :body => value.to_json)
         | 
| 17 | 
            -
                  end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
                  def post(path, value)
         | 
| 20 | 
            -
                    process(:post, path, :body => value.to_json)
         | 
| 21 | 
            -
                  end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                  def delete(path)
         | 
| 24 | 
            -
                    process(:delete, path)
         | 
| 25 | 
            -
                  end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                  def patch(path, value)
         | 
| 28 | 
            -
                    process(:patch, path, :body => value.to_json)
         | 
| 29 | 
            -
                  end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                  def build_url(path)
         | 
| 32 | 
            -
                    host = Firebase.base_uri
         | 
| 33 | 
            -
                    path = "#{path}.json"
         | 
| 34 | 
            -
                    query_string = Firebase.auth ? "?auth=#{Firebase.auth}" : ""
         | 
| 35 | 
            -
                    url = URI.join(Firebase.base_uri, path, query_string)
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                    url.to_s
         | 
| 38 | 
            -
                  end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                  private
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                  def process(method, path, options={})
         | 
| 43 | 
            -
                    raise "Please set Firebase.base_uri before making requests" unless Firebase.base_uri
         | 
| 44 | 
            -
             | 
| 45 | 
            -
            	      @@hydra ||= Typhoeus::Hydra.new
         | 
| 46 | 
            -
                    request = Typhoeus::Request.new(build_url(path),
         | 
| 47 | 
            -
                                                    :body => options[:body],
         | 
| 48 | 
            -
                                                    :method => method)
         | 
| 49 | 
            -
                    @@hydra.queue(request)
         | 
| 50 | 
            -
                    @@hydra.run
         | 
| 51 | 
            -
             | 
| 52 | 
            -
                    new request.response
         | 
| 53 | 
            -
                  end
         | 
| 9 | 
            +
                attr_accessor :base_uri, :auth
         | 
| 54 10 |  | 
| 11 | 
            +
                def initialize(base_uri, auth=nil)
         | 
| 12 | 
            +
                  @base_uri = base_uri
         | 
| 13 | 
            +
                  @auth = auth
         | 
| 55 14 | 
             
                end
         | 
| 56 15 |  | 
| 57 | 
            -
                 | 
| 16 | 
            +
                def get(path)
         | 
| 17 | 
            +
                  process(:get, path)
         | 
| 18 | 
            +
                end
         | 
| 58 19 |  | 
| 59 | 
            -
                def  | 
| 60 | 
            -
                   | 
| 20 | 
            +
                def put(path, value)
         | 
| 21 | 
            +
                  process(:put, path, :body => value.to_json)
         | 
| 61 22 | 
             
                end
         | 
| 62 23 |  | 
| 63 | 
            -
                def  | 
| 64 | 
            -
                   | 
| 65 | 
            -
                rescue JSON::ParserError => e
         | 
| 66 | 
            -
                  response.body == 'null' ? nil : raise
         | 
| 24 | 
            +
                def post(path, value)
         | 
| 25 | 
            +
                  process(:post, path, :body => value.to_json)
         | 
| 67 26 | 
             
                end
         | 
| 68 27 |  | 
| 69 | 
            -
                def  | 
| 70 | 
            -
                   | 
| 28 | 
            +
                def delete(path)
         | 
| 29 | 
            +
                  process(:delete, path)
         | 
| 71 30 | 
             
                end
         | 
| 72 31 |  | 
| 73 | 
            -
                def  | 
| 74 | 
            -
                   | 
| 32 | 
            +
                def patch(path, value)
         | 
| 33 | 
            +
                  process(:patch, path, :body => value.to_json)
         | 
| 75 34 | 
             
                end
         | 
| 76 35 |  | 
| 77 | 
            -
                def  | 
| 78 | 
            -
                   | 
| 36 | 
            +
                def build_url(path)
         | 
| 37 | 
            +
                  path = "#{path}.json"
         | 
| 38 | 
            +
                  query_string = auth ? "?auth=#{auth}" : ""
         | 
| 39 | 
            +
                  url = URI.join(base_uri, path, query_string)
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  url.to_s
         | 
| 79 42 | 
             
                end
         | 
| 80 43 |  | 
| 44 | 
            +
                private
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                def process(method, path, options={})
         | 
| 47 | 
            +
                  @@hydra ||= Typhoeus::Hydra.new
         | 
| 48 | 
            +
                  request = Typhoeus::Request.new(build_url(path),
         | 
| 49 | 
            +
                                                  :body => options[:body],
         | 
| 50 | 
            +
                                                  :method => method)
         | 
| 51 | 
            +
                  @@hydra.queue(request)
         | 
| 52 | 
            +
                  @@hydra.run
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  Firebase::Response.new(request.response)
         | 
| 55 | 
            +
                end
         | 
| 81 56 | 
             
              end
         | 
| 82 57 | 
             
            end
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            class Firebase
         | 
| 2 | 
            +
              class Response
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                attr_accessor :response
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                def initialize(response)
         | 
| 7 | 
            +
                  @response = response
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def body
         | 
| 11 | 
            +
                  JSON.parse(response.body, :quirks_mode => true)
         | 
| 12 | 
            +
                rescue JSON::ParserError => e
         | 
| 13 | 
            +
                  response.body == 'null' ? nil : raise
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                def raw_body
         | 
| 17 | 
            +
                  response.body
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def success?
         | 
| 21 | 
            +
                  [200, 204].include? response.code
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def code
         | 
| 25 | 
            +
                  response.code
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
| @@ -2,31 +2,27 @@ require 'spec_helper' | |
| 2 2 |  | 
| 3 3 | 
             
            describe "Firebase Request" do
         | 
| 4 4 |  | 
| 5 | 
            -
              after do
         | 
| 6 | 
            -
                Firebase.base_uri = nil
         | 
| 7 | 
            -
              end
         | 
| 8 | 
            -
             | 
| 9 5 | 
             
              describe "url_builder" do
         | 
| 6 | 
            +
                before do
         | 
| 7 | 
            +
                  @req = req = Firebase::Request.new 'https://test.firebaseio.com'
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 10 | 
             
                it "should build the correct url when passed no path" do
         | 
| 11 | 
            -
                   | 
| 12 | 
            -
                  Firebase::Request.build_url(nil).should == 'https://test.firebaseio.com/.json'
         | 
| 11 | 
            +
                  @req.build_url(nil).should == 'https://test.firebaseio.com/.json'
         | 
| 13 12 | 
             
                end
         | 
| 14 | 
            -
              end
         | 
| 15 13 |  | 
| 16 | 
            -
              describe "url_builder" do
         | 
| 17 14 | 
             
                it "should build the correct url when passed a path" do
         | 
| 18 | 
            -
                  Firebase. | 
| 15 | 
            +
                  req = Firebase::Request.new 'https://test.firebaseio.com'
         | 
| 19 16 |  | 
| 20 | 
            -
                   | 
| 17 | 
            +
                  @req.build_url('users/eugene').should == 'https://test.firebaseio.com/users/eugene.json'
         | 
| 21 18 | 
             
                end
         | 
| 22 19 | 
             
              end
         | 
| 23 20 |  | 
| 24 | 
            -
              describe  | 
| 21 | 
            +
              describe 'auth' do
         | 
| 25 22 | 
             
                it "should include a auth in the query string, if configured" do
         | 
| 26 | 
            -
                   | 
| 27 | 
            -
                  Firebase.auth = 'secretkey'
         | 
| 23 | 
            +
                  req = Firebase::Request.new('https://test.firebaseio.com', 'secretkey')
         | 
| 28 24 |  | 
| 29 | 
            -
                   | 
| 25 | 
            +
                  req.build_url('users/eugene').should == 'https://test.firebaseio.com/users/eugene.json?auth=secretkey'
         | 
| 30 26 | 
             
                end
         | 
| 31 27 | 
             
              end
         | 
| 32 28 | 
             
            end
         | 
    
        data/spec/firebase_spec.rb
    CHANGED
    
    | @@ -2,73 +2,71 @@ require 'spec_helper' | |
| 2 2 |  | 
| 3 3 | 
             
            describe "Firebase" do
         | 
| 4 4 |  | 
| 5 | 
            -
              it 'should have a base_uri attribute' do
         | 
| 6 | 
            -
                Firebase.base_uri.should be_nil
         | 
| 7 | 
            -
                Firebase.base_uri = 'http://example.com/foo'
         | 
| 8 | 
            -
                Firebase.base_uri.should == 'http://example.com/foo/'
         | 
| 9 | 
            -
              end
         | 
| 10 | 
            -
             | 
| 11 5 | 
             
              let (:data) do
         | 
| 12 6 | 
             
                { 'name' => 'Oscar' }
         | 
| 13 7 | 
             
              end
         | 
| 14 8 |  | 
| 9 | 
            +
              before do
         | 
| 10 | 
            +
                @firebase = Firebase.new('https://test.firebaseio.com')
         | 
| 11 | 
            +
                @req = @firebase.request
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 15 14 | 
             
              describe "set" do
         | 
| 16 15 | 
             
                it "writes and returns the data" do
         | 
| 17 | 
            -
                   | 
| 18 | 
            -
                   | 
| 16 | 
            +
                  @req.should_receive(:put).with('users/info', data)
         | 
| 17 | 
            +
                  @firebase.set('users/info', data)
         | 
| 19 18 | 
             
                end
         | 
| 20 19 | 
             
              end
         | 
| 21 20 |  | 
| 22 21 | 
             
              describe "get" do
         | 
| 23 22 | 
             
                it "returns the data" do
         | 
| 24 | 
            -
                   | 
| 25 | 
            -
                   | 
| 23 | 
            +
                  @req.should_receive(:get).with('users/info')
         | 
| 24 | 
            +
                  @firebase.get('users/info')
         | 
| 26 25 | 
             
                end
         | 
| 27 26 |  | 
| 28 27 | 
             
                it "return nil if response body contains 'null'" do
         | 
| 29 | 
            -
                  mock_response =  | 
| 30 | 
            -
                   | 
| 31 | 
            -
                  expect {  | 
| 28 | 
            +
                  mock_response = double(:body => 'null')
         | 
| 29 | 
            +
                  response = Firebase::Response.new(mock_response)
         | 
| 30 | 
            +
                  expect { response.body }.to_not raise_error
         | 
| 32 31 | 
             
                end
         | 
| 33 32 |  | 
| 34 33 | 
             
                it "return true if response body contains 'true'" do
         | 
| 35 | 
            -
                  mock_response =  | 
| 36 | 
            -
                   | 
| 37 | 
            -
                   | 
| 34 | 
            +
                  mock_response = double(:body => 'true')
         | 
| 35 | 
            +
                  response = Firebase::Response.new(mock_response)
         | 
| 36 | 
            +
                  response.body.should eq(true)
         | 
| 38 37 | 
             
                end
         | 
| 39 38 |  | 
| 40 39 | 
             
                it "return false if response body contains 'false'" do
         | 
| 41 | 
            -
                  mock_response =  | 
| 42 | 
            -
                   | 
| 43 | 
            -
                   | 
| 40 | 
            +
                  mock_response = double(:body => 'false')
         | 
| 41 | 
            +
                  response = Firebase::Response.new(mock_response)
         | 
| 42 | 
            +
                  response.body.should eq(false)
         | 
| 44 43 | 
             
                end
         | 
| 45 44 |  | 
| 46 45 | 
             
                it "raises JSON::ParserError if response body contains invalid JSON" do
         | 
| 47 | 
            -
                  mock_response =  | 
| 48 | 
            -
                   | 
| 49 | 
            -
                  expect {  | 
| 46 | 
            +
                  mock_response = double(:body => '{"this is wrong"')
         | 
| 47 | 
            +
                  response = Firebase::Response.new(mock_response)
         | 
| 48 | 
            +
                  expect { response.body }.to raise_error
         | 
| 50 49 | 
             
                end
         | 
| 51 | 
            -
             | 
| 52 50 | 
             
              end
         | 
| 53 51 |  | 
| 54 52 | 
             
              describe "push" do
         | 
| 55 53 | 
             
                it "writes the data" do
         | 
| 56 | 
            -
                   | 
| 57 | 
            -
                   | 
| 54 | 
            +
                  @req.should_receive(:post).with('users', data)
         | 
| 55 | 
            +
                  @firebase.push('users', data)
         | 
| 58 56 | 
             
                end
         | 
| 59 57 | 
             
              end
         | 
| 60 58 |  | 
| 61 59 | 
             
              describe "delete" do
         | 
| 62 60 | 
             
                it "returns true" do
         | 
| 63 | 
            -
                   | 
| 64 | 
            -
                   | 
| 61 | 
            +
                  @req.should_receive(:delete).with('users/info')
         | 
| 62 | 
            +
                  @firebase.delete('users/info')
         | 
| 65 63 | 
             
                end
         | 
| 66 64 | 
             
              end
         | 
| 67 65 |  | 
| 68 66 | 
             
              describe "update" do
         | 
| 69 67 | 
             
                it "updates and returns the data" do
         | 
| 70 | 
            -
                   | 
| 71 | 
            -
                   | 
| 68 | 
            +
                  @req.should_receive(:patch).with('users/info', data)
         | 
| 69 | 
            +
                  @firebase.update('users/info', data)
         | 
| 72 70 | 
             
                end
         | 
| 73 71 | 
             
              end
         | 
| 74 72 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -2,14 +2,14 @@ | |
| 2 2 | 
             
            name: firebase
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 4 | 
             
              prerelease: 
         | 
| 5 | 
            -
              version: 0.1. | 
| 5 | 
            +
              version: 0.1.6
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| 8 8 | 
             
            - Oscar Del Ben
         | 
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013-11- | 
| 12 | 
            +
            date: 2013-11-23 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| @@ -85,6 +85,7 @@ extra_rdoc_files: | |
| 85 85 | 
             
            files:
         | 
| 86 86 | 
             
            - .document
         | 
| 87 87 | 
             
            - .rspec
         | 
| 88 | 
            +
            - CHANGELOG
         | 
| 88 89 | 
             
            - Gemfile
         | 
| 89 90 | 
             
            - Gemfile.lock
         | 
| 90 91 | 
             
            - LICENSE.txt
         | 
| @@ -94,6 +95,7 @@ files: | |
| 94 95 | 
             
            - firebase.gemspec
         | 
| 95 96 | 
             
            - lib/firebase.rb
         | 
| 96 97 | 
             
            - lib/firebase/request.rb
         | 
| 98 | 
            +
            - lib/firebase/response.rb
         | 
| 97 99 | 
             
            - spec/firebase_request_spec.rb
         | 
| 98 100 | 
             
            - spec/firebase_spec.rb
         | 
| 99 101 | 
             
            - spec/spec_helper.rb
         | 
| @@ -110,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 110 112 | 
             
                - !ruby/object:Gem::Version
         | 
| 111 113 | 
             
                  segments:
         | 
| 112 114 | 
             
                  - 0
         | 
| 113 | 
            -
                  hash:  | 
| 115 | 
            +
                  hash: -3647962587689699515
         | 
| 114 116 | 
             
                  version: '0'
         | 
| 115 117 | 
             
              none: false
         | 
| 116 118 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         |