Sha256: f62d2a310d90a221717a8de7958cad98e18065f941b24c3cd280312b80048b03

Contents?: true

Size: 907 Bytes

Versions: 16

Compression:

Stored size: 907 Bytes

Contents

module ApipieBindings

  class Resource

    attr_reader :name

    def initialize(name, api)
      raise NameError.new("Resource '#{name}' does not exist in the API") unless api.apidoc[:docs][:resources].key?(name)
      @name = name
      @api = api
    end

    def call(action, params={}, headers={}, options={})
      @api.call(@name, action, params, headers, options)
    end

    def apidoc
      @api.apidoc[:docs][:resources][@name]
    end

    def actions
      apidoc[:methods].map { |a| action(a[:name].to_sym) }
    end

    def has_action?(name)
      apidoc[:methods].any? { |action| action[:name].to_sym == name }
    end

    def action(name)
      ApipieBindings::Action.new(@name, name, @api)
    end

    def singular_name
      ApipieBindings::Inflector.singularize(@name.to_s)
    end

    def to_s
      "<Resource :#{@name}>"
    end

    def inspect
      to_s
    end

  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
apipie-bindings-0.0.17 lib/apipie_bindings/resource.rb
apipie-bindings-0.0.16 lib/apipie_bindings/resource.rb
apipie-bindings-0.0.15 lib/apipie_bindings/resource.rb
apipie-bindings-0.0.14 lib/apipie_bindings/resource.rb
apipie-bindings-0.0.13 lib/apipie_bindings/resource.rb
apipie-bindings-0.0.12 lib/apipie_bindings/resource.rb
apipie-bindings-0.0.11 lib/apipie_bindings/resource.rb
apipie-bindings-0.0.10 lib/apipie_bindings/resource.rb
apipie-bindings-0.0.9 lib/apipie_bindings/resource.rb
apipie-bindings-0.0.8 lib/apipie_bindings/resource.rb
apipie-bindings-0.0.7 lib/apipie_bindings/resource.rb
apipie-bindings-0.0.6 lib/apipie_bindings/resource.rb
apipie-bindings-0.0.5 lib/apipie_bindings/resource.rb
apipie-bindings-0.0.4 lib/apipie_bindings/resource.rb
apipie-bindings-0.0.3 lib/apipie_bindings/resource.rb
apipie-bindings-0.0.2 lib/apipie_bindings/resource.rb