Sha256: 5faadbf84d12dce88c734f88f6e29c94557e3a26ea2a11b56884164a39e90f67

Contents?: true

Size: 1.48 KB

Versions: 5

Compression:

Stored size: 1.48 KB

Contents

require 'json'

module Restfully
  module MediaType
    class Grid5000 < AbstractMediaType

      set :signature, %w{
        grid
        site
        cluster
        node
        nodestatus
        version
        collection
        timeseries
        versions
        user
        metric
        job
        deployment
        networkequipment
        environment
        notification
      }.map{|n|
        "application/vnd.fr.grid5000.api.#{n}+json"
      }.unshift(
        "application/vnd.grid5000.collection+json"
      ).unshift(
        "application/vnd.grid5000.item+json"
      )
      set :parser, ApplicationJson::JSONParser

      def extract_links
        (property.delete("links") || []).map do |link|
          l = Link.new(
            :rel => link['rel'],
            :type => link['type'],
            :href => link['href'],
            :title => link["title"],
            :id => link["title"]
          )
        end
      end

      def collection?
        !!(property("items") && property("total") && property("offset"))
      end

      def meta
        if collection?
          property("items")
        else
          property
        end
      end

      def represents?(id)
        id = id.to_s
        property("uid") == id || property("uid") == id.to_i
      end

      # Only for collections
      def each(*args, &block)
        (property("items") || []).map{|i|
          self.class.new(self.class.serialize(i), @session)
        }.each(*args, &block)
      end

    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
restfully-1.0.8 lib/restfully/media_type/grid5000.rb
restfully-1.0.7 lib/restfully/media_type/grid5000.rb
restfully-1.0.6 lib/restfully/media_type/grid5000.rb
restfully-1.0.5 lib/restfully/media_type/grid5000.rb
restfully-1.0.4 lib/restfully/media_type/grid5000.rb