Class: DataMapperRest::Adapter

### Home Classes Methods

### In Files

- lib/dm-rest-adapter/adapter.rb

### Parent

DataMapper::Adapters::AbstractAdapter

### Methods

- ::new
- #create
- #delete
- #read
- #update

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- DataMapperRest
- DataMapperRest::Adapter
- DataMapperRest::BadRequest
- DataMapperRest::ClientError
- DataMapperRest::Connection
- DataMapperRest::ForbiddenAccess
- DataMapperRest::Format
- DataMapperRest::ResourceConflict
- DataMapperRest::ResourceInvalid
- DataMapperRest::ResourceNotFound
- DataMapperRest::ServerError
- DataMapperRest::TimeoutError
- DataMapperRest::UnauthorizedAccess
- DataMapper
- DataMapper::Spec
- DataMapper::Spec::Adapters
- DataMapper::Spec::Adapters::RestAdapter
- Object

No matching classes.

# DataMapperRest::Adapter

All http_"verb" (http_post) method calls use method missing in connection class which uses run_verb

### Public Class Methods

new(*) click to toggle source

    # File lib/dm-rest-adapter/adapter.rb, line 62
    def initialize(*)
      super
      @format = @options.fetch(:format, 'xml')
    end

### Public Instance Methods

create(resources) click to toggle source

    # File lib/dm-rest-adapter/adapter.rb, line 7
    def create(resources)
      resources.each do |resource|
        model = resource.model

        response = connection.http_post("#{resource_name(model)}", resource.to_xml)

        update_with_response(resource, response)
      end
    end

delete(collection) click to toggle source

    # File lib/dm-rest-adapter/adapter.rb, line 49
    def delete(collection)
      collection.select do |resource|
        model = resource.model
        key   = model.key
        id    = key.get(resource).join

        response = connection.http_delete("#{resource_name(model)}/#{id}")
        response.kind_of?(Net::HTTPSuccess)
      end.size
    end

read(query) click to toggle source

    # File lib/dm-rest-adapter/adapter.rb, line 17
    def read(query)
      model = query.model

      records = if id = extract_id_from_query(query)
        response = connection.http_get("#{resource_name(model)}/#{id}")
        [ parse_resource(response.body, model) ]
      else
        query_string = if (params = extract_params_from_query(query)).any?
          params.map { |k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join('&')
        end

        response = connection.http_get("#{resource_name(model)}#{'?' << query_string if query_string}")
        parse_resources(response.body, model)
      end

      query.filter_records(records)
    end

update(dirty_attributes, collection) click to toggle source

    # File lib/dm-rest-adapter/adapter.rb, line 35
    def update(dirty_attributes, collection)
      collection.select do |resource|
        model = resource.model
        key   = model.key
        id    = key.get(resource).join

        dirty_attributes.each { |p, v| p.set!(resource, v) }

        response = connection.http_put("#{resource_name(model)}/#{id}", resource.to_xml)

        update_with_response(resource, response)
      end.size
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.