opal/vienna — pull request #6 by svoboda-jan (2013-04-27 11:58:26+00:00)
Title: Add Vienna::Ajax module

### Example usage

```ruby
class Contact < Vienna::Model
include Vienna::Ajax
url '/api/v1/contacts'

attributes *%w{ id first_name last_name number }

end

Contact.on :refresh do |contacts|
# ... read array of contacts
end

# GET to /api/v1/contacts, fires the :refresh event when ready
Contact.fetch

Contact.on :create do |contact|
# ... contact is the created model returned by server
end

Contact.on :change do |contacts|
# ... read array of contacts
end

c = Contact.new(first_name: 'Jan', last_name: 'Svoboda')

# POST to /api/v1/contacts, fires :create and :change event when ready
c.save

# PUT to /api/v1/contacts/1, fires :change event when ready
# the 1 at the end of the url is the id returned by previous POST
c.number = 123
c.save

# DELETE to /api/v1/contacts/1, fires :change event when ready
c.destroy
```