datamapper / dm-more

Extras for DataMapper, including bridges to DataObjects::Migrations and Merb::DataMapper

Dan Kubb (author)
Fri Nov 06 00:41:05 -0800 2009
commit  c0e0b46c6a1f1c4a7e9a6f760508d85668535e90
tree    9cc9cf6dc63cbba071ce20252bbe635a7dda7d22
parent  7110cbbde1a6e339e5988aa209361421508d34ea parent  a539a7407c2525fc8dd3575a61d17c98adfd423c
dm-more / adapters / dm-rest-adapter
name age message
..
file History.rdoc Wed Sep 30 14:25:02 -0700 2009 Updated History [Dan Kubb]
file LICENSE Sat Jul 12 10:01:44 -0700 2008 Added rest adapter files from elight/dm-more [djwonk]
file Manifest.txt Loading commit data...
file README.rdoc Sun Mar 08 16:02:07 -0700 2009 [dm-rest-adapter] Stripped whitespace [Dan Kubb]
file Rakefile
file TODO Sat Dec 06 19:51:12 -0800 2008 [dm-more] Reorganized Rakefile and rake tasks ... [Dan Kubb]
directory lib/
directory spec/
directory tasks/ Tue Nov 03 23:20:20 -0800 2009 [all] Remove unecessary flag in install task S... [myabc]
adapters/dm-rest-adapter/README.rdoc

dm-rest-adapter

A DataMapper adapter for REST Web Services

Usage

DM Rest Adapter requires the use of a model which is the same name as the resource you are using. For example, if you have a resource named "posts" you will create a standard datamapper object called post.rb in app/models. The only difference in this model is you will need to define the rest adapter for the model. The following is an example of a post model, where the host settings point to the app you are running the resource on. In addition I have included a basic auth login which will be used if your resource requires auth:

DataMapper.setup(:default, {

 :adapter  => 'rest',
 :format   => 'xml',
 :host     => 'localhost',
 :port     => 4000,
 :login    => 'user',
 :password => 'verys3crit'

})

class Post

  include DataMapper::Resource

  property :id, Serial
  property :title, String
  property :body,  Text

end

If you notice this looks exactly like a normal datmapper model. Every property you define will map itself with the xml returned or posted from/to the resource.

Code

Now for some code examples. DM Rest Adapter uses the same methods as datamapper including during creation.

Post.first => returns the object from the resouce Post.get(1) => returns the object from the resource p = Post.new(:title => "My awesome blog post", :body => "I really have nothing to say…") p.save => saves the resource on the remote

Caveat

Posts do not honor RESTful HTTP status codes. I might fix this…

TODO:

Nested resources Put verb actions