rubapi 0.0.7 → 0.0.8
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.
- checksums.yaml +4 -4
- data/lib/rubapi/controller.rb +7 -6
- data/lib/rubapi/request.rb +9 -1
- data/lib/rubapi/router.rb +7 -4
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 704f4477b893928e583d280a116813857aa95a57
         | 
| 4 | 
            +
              data.tar.gz: c98bdcc21e38870f23da11e6f8e895992fcec647
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 0bb28b1fd4d41b7335a2ea80b9059ebb3cc2c3574c0d3c46889dedfbb08c4215ed6dfc21da68e733024355908ec7b0a429af56f70754855e52df8b1b5b5c9185
         | 
| 7 | 
            +
              data.tar.gz: 07f330a8c4d8229fe4b3126e1c217cffb0ba43449a97ef488991170d1f5ec17efb66269f9d53a2bffc205b1a1921d4d7c4e22e2f448b7e2de0b1f2ee6e8d19a3
         | 
    
        data/lib/rubapi/controller.rb
    CHANGED
    
    | @@ -60,6 +60,7 @@ module Rubapi | |
| 60 60 | 
             
                  route[:controller] ||= self.class
         | 
| 61 61 | 
             
                  controller = route[:controller].new(self.response)
         | 
| 62 62 | 
             
                  controller.request = self.request
         | 
| 63 | 
            +
                  controller.request.pagination = route[:pagination] unless route[:pagination].nil?
         | 
| 63 64 | 
             
                  controller.send(route[:method])
         | 
| 64 65 | 
             
                end
         | 
| 65 66 |  | 
| @@ -77,12 +78,12 @@ module Rubapi | |
| 77 78 | 
             
                  EM.defer get_conn, callback
         | 
| 78 79 | 
             
                end
         | 
| 79 80 |  | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 81 | 
            +
                # If you try to respond with a reql.expr, it ensures that will return with a Hash(Dict) format
         | 
| 82 | 
            +
                def format_response(response)
         | 
| 83 | 
            +
                  response.map {|re|
         | 
| 84 | 
            +
                    { :"#{re.first}" => re.last }
         | 
| 85 | 
            +
                  }.inject({}) {|sum, re| sum.merge!(re)}
         | 
| 86 | 
            +
                end
         | 
| 86 87 |  | 
| 87 88 | 
             
                def attach_data(data)
         | 
| 88 89 | 
             
                  @content ||= { errors: [] }
         | 
    
        data/lib/rubapi/request.rb
    CHANGED
    
    | @@ -2,14 +2,22 @@ module Rubapi | |
| 2 2 | 
             
              class Request
         | 
| 3 3 | 
             
                attr_accessor :params,
         | 
| 4 4 | 
             
                              :errors,
         | 
| 5 | 
            -
                              :route
         | 
| 5 | 
            +
                              :route,
         | 
| 6 | 
            +
                              :pagination
         | 
| 6 7 |  | 
| 7 8 | 
             
                def initialize
         | 
| 8 9 | 
             
                  self.params = {}
         | 
| 10 | 
            +
                  self.pagination = default_pagination
         | 
| 9 11 | 
             
                end
         | 
| 10 12 |  | 
| 11 13 | 
             
                def parse(param_string)
         | 
| 12 14 | 
             
                  self.params = self.params.merge(Rack::Utils.parse_nested_query(param_string))
         | 
| 13 15 | 
             
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def default_pagination
         | 
| 18 | 
            +
                  {
         | 
| 19 | 
            +
                    per_page: 10
         | 
| 20 | 
            +
                  }
         | 
| 21 | 
            +
                end
         | 
| 14 22 | 
             
              end
         | 
| 15 23 | 
             
            end
         | 
    
        data/lib/rubapi/router.rb
    CHANGED
    
    | @@ -27,11 +27,9 @@ module Rubapi | |
| 27 27 | 
             
                    resources[:actions][verb].each do |re|
         | 
| 28 28 | 
             
                      resource_path = re[:path].split("/")
         | 
| 29 29 | 
             
                      if paths.count == resource_path.count
         | 
| 30 | 
            -
                        params = resource_path.select{|pa| /:([a-z_]+)/.match pa }
         | 
| 31 | 
            -
             | 
| 32 30 | 
             
                        request = re.clone
         | 
| 33 | 
            -
                        request[:params] = extract_params(paths, params)
         | 
| 34 31 | 
             
                        request[:controller] = resources[:controller]
         | 
| 32 | 
            +
                        request[:pagination] = resources[:pagination]
         | 
| 35 33 | 
             
                        return request
         | 
| 36 34 | 
             
                      end
         | 
| 37 35 | 
             
                    end
         | 
| @@ -80,7 +78,8 @@ module Rubapi | |
| 80 78 | 
             
                        delete:[]
         | 
| 81 79 | 
             
                      }, 
         | 
| 82 80 | 
             
                      nested: [],
         | 
| 83 | 
            -
                      controller: nil
         | 
| 81 | 
            +
                      controller: nil,
         | 
| 82 | 
            +
                      pagination: nil
         | 
| 84 83 | 
             
                    }
         | 
| 85 84 | 
             
                  end
         | 
| 86 85 |  | 
| @@ -109,6 +108,10 @@ module Rubapi | |
| 109 108 | 
             
                  def controller(klass)
         | 
| 110 109 | 
             
                    @current_resource[:controller] = klass
         | 
| 111 110 | 
             
                  end
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                  def pagination(options)
         | 
| 113 | 
            +
                    @current_resource[:pagination] = options
         | 
| 114 | 
            +
                  end
         | 
| 112 115 | 
             
                end
         | 
| 113 116 | 
             
              end
         | 
| 114 117 | 
             
            end
         |