Skip to content

Commit bbe77a9

Browse files
committed
Updated CHANGELOG and README.
1 parent 705a157 commit bbe77a9

File tree

2 files changed

+62
-53
lines changed

2 files changed

+62
-53
lines changed

CHANGELOG.markdown

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
Next Release
2-
============
3-
4-
* [#248](https://github.com/intridea/grape/pull/248): Fix: API `version` returns last version set. - [@narkoz](https://github.com/narkoz).
5-
* [#242](https://github.com/intridea/grape/issues/242): Fix: permanent redirect status. - [@adamgotterer](https://github.com/adamgotterer).
6-
* [#236](https://github.com/intridea/grape/pull/236): Allow validation of nested parameters. - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
7-
* [#221](https://github.com/intridea/grape/pull/221): Added custom exceptions to Grape. Updated validations to use ValidationError that can be rescued. - [@adamgotterer](https://github.com/adamgotterer).
8-
* [#211](https://github.com/intridea/grape/pull/211): Updates to validation and coercion: Fix #211 and force order of operations for presence and coercion - [@adamgotterer](https://github.com/adamgotterer).
1+
0.2.2 (Next Release)
2+
====================
3+
4+
Features
5+
--------
6+
7+
* [#201](https://github.com/intridea/grape/pull/201), [#236](https://github.com/intridea/grape/pull/236), [#221](https://github.com/intridea/grape/pull/221): The `params` DSL now includes support for coercion and validations - [@schmurfy](https://github.com/schmurfy), [@tim-vandecasteele](https://github.com/tim-vandecasteele), [@tim-vandecasteele](https://github.com/tim-vandecasteele).
8+
* [#204](https://github.com/intridea/grape/pull/204): Added ability to declare shared parameters at namespace level - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
9+
* [#234](https://github.com/intridea/grape/pull/234): Added a DSL for creating entities via mixin - [@mbleigh](https://github.com/mbleigh).
10+
* [#240](https://github.com/intridea/grape/pull/240): Define API response format from a query string `format` parameter, if specified - [@neetiraj](https://github.com/neetiraj).
11+
12+
Fixes
13+
-----
14+
15+
* [#248](https://github.com/intridea/grape/pull/248): Fix: API `version` returns last version set - [@narkoz](https://github.com/narkoz).
16+
* [#242](https://github.com/intridea/grape/issues/242): Fix: permanent redirect status should be `301`, was `304` - [@adamgotterer](https://github.com/adamgotterer).
17+
* [#211](https://github.com/intridea/grape/pull/211): Fix: custom validations are no longer triggered when optional and parameter is not present - [@adamgotterer](https://github.com/adamgotterer).
918
* [#210](https://github.com/intridea/grape/pull/210): Fix: `Endpoint#body_params` causing undefined method 'size' - [@adamgotterer](https://github.com/adamgotterer).
10-
* [#201](https://github.com/intridea/grape/pull/201): Rewritten `params` DSL, including support for coercion and validations - [@schmurfy](https://github.com/schmurfy).
1119
* [#205](https://github.com/intridea/grape/pull/205): Fix: Corrected parsing of empty JSON body on POST/PUT - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
1220
* [#181](https://github.com/intridea/grape/pull/181): Fix: Corrected JSON serialization of nested hashes containing `Grape::Entity` instances - [@benrosenblum](https://github.com/benrosenblum).
1321
* [#203](https://github.com/intridea/grape/pull/203): Added a check to `Entity#serializable_hash` that verifies an entity exists on an object - [@adamgotterer](https://github.com/adamgotterer).
14-
* [#204](https://github.com/intridea/grape/pull/204): Added ability to declare shared parameters at namespace level - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
1522
* [#208](https://github.com/intridea/grape/pull/208): `Entity#serializable_hash` must also check if attribute is generated by a user supplied block - [@ppadron](https://github.com/ppadron).
16-
* [#234](https://github.com/intridea/grape/pull/234): Adds a DSL for creating entities via mixin - [@mbleigh](https://github.com/mbleigh).
17-
* [#240](https://github.com/intridea/grape/pull/240): Define API response format from a query string `format` parameter, if specified - [@neetiraj](https://github.com/neetiraj).
1823

1924
0.2.1 (7/11/2012)
2025
=================

README.markdown

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
## What is Grape?
44

5-
Grape is a REST-like API micro-framework for Ruby. It's built to complement
6-
existing web application frameworks such as Rails and Sinatra by providing a
7-
simple DSL to easily develop RESTful APIs. It has built-in support for common
8-
conventions, including multiple formats, subdomain/prefix restriction, content
9-
negotiation, versioning and much more.
5+
Grape is a REST-like API micro-framework for Ruby. It's designed to run on Rack
6+
or complement existing web application frameworks such as Rails and Sinatra by
7+
providing a simple DSL to easily develop RESTful APIs. It has built-in support
8+
for common conventions, including multiple formats, subdomain/prefix restriction,
9+
content negotiation, versioning and much more.
1010

1111
[![Build Status](http://travis-ci.org/intridea/grape.png?branch=master)](http://travis-ci.org/intridea/grape)
1212

@@ -41,6 +41,7 @@ the context of recreating parts of the Twitter API.
4141
``` ruby
4242
class Twitter::API < Grape::API
4343
version 'v1', :using => :header, :vendor => 'twitter'
44+
format :json
4445

4546
helpers do
4647
def current_user
@@ -275,7 +276,8 @@ params do
275276
end
276277
```
277278

278-
You can also create custom classes that take parameters
279+
You can also create custom classes that take parameters.
280+
279281
```ruby
280282
class Length < Grape::Validations::SingleOptionValidator
281283
def validate_param!(attr_name, params)
@@ -293,9 +295,11 @@ end
293295
```
294296

295297
### Validation Errors
298+
296299
When validation and coercion erros occur an exception of type `ValidationError` is raised.
297300
If the exception goes uncaught it will respond with a status of 400 and an error message.
298301
You can rescue a `ValidationError` and respond with a custom response.
302+
299303
```ruby
300304
rescue_from ValidationError do |e|
301305
Rack::Response.new({
@@ -306,8 +310,6 @@ rescue_from ValidationError do |e|
306310
end
307311
```
308312

309-
310-
311313
## Headers
312314

313315
Headers are available through the `header` helper or the `env` hash object.
@@ -340,7 +342,7 @@ end
340342
## Helpers
341343

342344
You can define helper methods that your endpoints can use with the `helpers`
343-
macro by either giving a block or a module:
345+
macro by either giving a block or a module.
344346

345347
``` ruby
346348
module MyHelpers
@@ -369,7 +371,7 @@ end
369371

370372
## Cookies
371373

372-
You can set, get and delete your cookies very simply using `cookies` method:
374+
You can set, get and delete your cookies very simply using `cookies` method.
373375

374376
``` ruby
375377
class API < Grape::API
@@ -385,7 +387,7 @@ class API < Grape::API
385387
end
386388
```
387389

388-
To set more than value use hash-based syntax:
390+
To set more than value use hash-based syntax.
389391

390392
``` ruby
391393
cookies[:counter] = {
@@ -399,7 +401,7 @@ cookies[:counter][:value] +=1
399401

400402
## Redirecting
401403

402-
You can redirect to a new url temporarily or permanently.
404+
You can redirect to a new url temporarily (302) or permanently (301).
403405

404406
``` ruby
405407
redirect "/new_url"
@@ -427,7 +429,7 @@ error!({ "error" => "unexpected error", "detail" => "missing widget" }, 500)
427429
## Exception Handling
428430

429431
Grape can be told to rescue all exceptions and instead return them in
430-
text or json formats.
432+
txt or json formats.
431433

432434
``` ruby
433435
class Twitter::API < Grape::API
@@ -549,7 +551,7 @@ end
549551
You can also set the default format. The order for choosing the format is the following.
550552

551553
* Use the file extension, if specified. If the file is .json, choose the JSON format.
552-
* Use the value of the format parameter in the query string, if specified.
554+
* Use the value of the `format` parameter in the query string, if specified.
553555
* Use the format set by the `format` option, if specified.
554556
* Attempt to find an acceptable format from the `Accept` header.
555557
* Use the default format, if specified by the `default_format` option.
@@ -583,22 +585,22 @@ ever larger responses, using inheritance.
583585

584586
Entities inherit from Grape::Entity, and define a simple DSL. Exposures can use
585587
runtime options to determine which fields should be visible, these options are
586-
available to :if, :unless, and :proc. The option keys :version and :collection
587-
will always be defined. The :version key is defined as api.version. The
588-
:collection key is boolean, and defined as true if the object presented is an
588+
available to `:if`, `:unless`, and `:proc`. The option keys `:version` and `:collection`
589+
will always be defined. The `:version` key is defined as `api.version`. The
590+
`:collection` key is boolean, and defined as `true` if the object presented is an
589591
array.
590592

591593
* `expose SYMBOLS`
592594
* define a list of fields which will always be exposed
593595
* `expose SYMBOLS, HASH`
594-
* HASH keys include :if, :unless, :proc, :as, :using, :format_with, :documentation
595-
* :if and :unless accept hashes (passed during runtime) or procs (arguments are object and options)
596-
* `expose SYMBOL, {:format_with => :formatter}`
596+
* HASH keys include `:if`, `:unless`, `:proc`, `:as`, `:using`, `:format_with`, `:documentation`
597+
* `:if` and `:unless` accept hashes (passed during runtime) or procs (arguments are object and options)
598+
* `expose SYMBOL, { :format_with => :formatter }`
597599
* expose a value, formatting it first
598-
* :format_with can only be applied to one exposure at a time
599-
* `expose SYMBOL, {:as => "alias"}`
600+
* `:format_with` can only be applied to one exposure at a time
601+
* `expose SYMBOL, { :as => "alias" }`
600602
* Expose a value, changing its hash key from SYMBOL to alias
601-
* :as can only be applied to one exposure at a time
603+
* `:as` can only be applied to one exposure at a time
602604
* `expose SYMBOL BLOCK`
603605
* block arguments are object and options
604606
* expose the value returned by the block
@@ -609,10 +611,10 @@ module API
609611
module Entities
610612
class User < Grape::Entity
611613
expose :first_name, :last_name
612-
expose :field, :documentation => {:type => "string", :desc => "words go here"}
613-
expose :email, :if => {:type => :full}
614-
expose :user_type, user_id, :if => lambda{|user,options| user.confirmed?}
615-
expose(:name){|user,options| [user.first_name, user.last_name].join(' ')}
614+
expose :field, :documentation => { :type => "string", :desc => "words go here" }
615+
expose :email, :if => { :type => :full }
616+
expose :user_type, user_id, :if => lambda{ |user,options| user.confirmed? }
617+
expose(:name) { |user,options| [ user.first_name, user.last_name ].join(' ')}
616618
expose :latest_status, :using => API::Status, :as => :status
617619
end
618620
end
@@ -650,9 +652,9 @@ symbols.
650652

651653
### Using Entities
652654

653-
Once an entity is defined, it can be used within endpoints, by calling #present. The #present
655+
Once an entity is defined, it can be used within endpoints, by calling `present`. The `present`
654656
method accepts two arguments, the object to be presented and the options associated with it. The
655-
options hash must always include :with, which defines the entity to expose.
657+
options hash must always include `:with`, which defines the entity to expose.
656658

657659
If the entity includes documentation it can be included in an endpoint's description.
658660

@@ -702,29 +704,29 @@ be overridden by using the `:with` option or an explicit
702704
### Caveats
703705

704706
Entities with duplicate exposure names and conditions will silently overwrite one another.
705-
In the following example, when object#check equals "foo", only afield will be exposed.
706-
However, when object#check equals "bar" both bfield and foo will be exposed.
707+
In the following example, when `object.check` equals "foo", only `field_a` will be exposed.
708+
However, when `object.check` equals "bar" both `field_b` and `foo` will be exposed.
707709

708710
```ruby
709711
module API
710712
module Entities
711713
class User < Grape::Entity
712-
expose :afield, :foo, :if => lambda{|object,options| object.check=="foo"}
713-
expose :bfield, :foo, :if => lambda{|object,options| object.check=="bar"}
714+
expose :field_a, :foo, :if => lambda { |object, options| object.check == "foo" }
715+
expose :field_b, :foo, :if => lambda { |object, options| object.check == "bar" }
714716
end
715717
end
716718
end
717719
```
718720

719-
This can be problematic, when you have mixed collections. Using #respond_to? is safer.
721+
This can be problematic, when you have mixed collections. Using `respond_to?` is safer.
720722

721723
```ruby
722724
module API
723725
module Entities
724726
class User < Grape::Entity
725-
expose :afield, :if => lambda{|object,options| object.check=="foo"}
726-
expose :bfield, :if => lambda{|object,options| object.check=="bar"}
727-
expose :foo, :if => lambda{object,options| object.respond_to?(:foo)}
727+
expose :field_a, :if => lambda { |object, options| object.check == "foo" }
728+
expose :field_b, :if => lambda { |object, options| object.check == "bar" }
729+
expose :foo, :if => lambda { |object, options| object.respond_to?(:foo) }
728730
end
729731
end
730732
end
@@ -863,19 +865,21 @@ RSpec.configure do |config|
863865
end
864866
```
865867

866-
## Note on Patches/Pull Requests
868+
## Contributing to Grape
869+
870+
Grape is work of dozens of contributors. You're encouraged to submit pull requests, propose
871+
features and discuss issues.
867872

868873
* Fork the project
869874
* Write tests for your new feature or a test that reproduces a bug
870875
* Implement your feature or make a bug fix
871876
* Do not mess with Rakefile, version or history
872-
* Commit, push and make a pull request. Bonus points for topical branches.
877+
* Commit, push and make a pull request. Bonus points for topic branches.
873878

874879
## License
875880

876881
MIT License. See LICENSE for details.
877882

878883
## Copyright
879884

880-
Copyright (c) 2010-2012 Michael Bleigh and Intridea, Inc.
881-
885+
Copyright (c) 2010-2012 Michael Bleigh, and Intridea, Inc.

0 commit comments

Comments
 (0)