Sha256: 6876f78032783ed039b08a8538f3640c4b16a10cc98ae592def39b31fc351914

Contents?: true

Size: 1.58 KB

Versions: 44

Compression:

Stored size: 1.58 KB

Contents

# This class includes methods for calling restful APIs
module ApiClient

  module Resource

    class Scope < ApiClient::Scope

      dsl_accessor :path, :return_self => true

      def format
        @scopeable.format
      end

      def append_format(path)
        format ? [path, format].join('.') : path
      end

      def find(id)
        path     = [@path, id].join('/')
        path     = append_format(path)
        response = get(path)
        scoped(self) do
          raw? ? response : @scopeable.build(response)
        end
      end

      def find_all(params = {})
        path     = append_format(@path)
        response = get(path, params)
        scoped(self) do
          raw? ? response : @scopeable.build(response)
        end
      end

      def create(params = {})
        path = append_format(@path)
        hash = if @scopeable.namespace
          { @scopeable.namespace => params }
        else
          params
        end
        response = post(path, hash)
        scoped(self) do
          raw? ? response : @scopeable.build(response)
        end
      end

      def update(id, params = {})
        path = [@path, id].join('/')
        path = append_format(path)
        hash = if @scopeable.namespace
          { @scopeable.namespace => params }
        else
          params
        end
        response = put(path, hash)
        scoped(self) do
          raw? ? response : @scopeable.build(response)
        end
      end

      def destroy(id)
        path = [@path, id].join('/')
        path = append_format(path)
        delete(path)
        true
      end

    end

  end

end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
api_client-0.6.0-java lib/api_client/resource/scope.rb
api_client-0.6.0 lib/api_client/resource/scope.rb
api_client-0.5.26-java lib/api_client/resource/scope.rb
api_client-0.5.26 lib/api_client/resource/scope.rb
api_client-0.5.25-java lib/api_client/resource/scope.rb
api_client-0.5.25 lib/api_client/resource/scope.rb
api_client-0.5.24 lib/api_client/resource/scope.rb
api_client-0.5.22 lib/api_client/resource/scope.rb
api_client-0.5.21 lib/api_client/resource/scope.rb
api_client-0.5.20 lib/api_client/resource/scope.rb
api_client-0.5.19 lib/api_client/resource/scope.rb
api_client-0.5.18 lib/api_client/resource/scope.rb
api_client-0.5.17 lib/api_client/resource/scope.rb
api_client-0.5.16 lib/api_client/resource/scope.rb
api_client-0.5.15 lib/api_client/resource/scope.rb
api_client-0.5.14 lib/api_client/resource/scope.rb
api_client-0.5.13 lib/api_client/resource/scope.rb
api_client-0.5.12 lib/api_client/resource/scope.rb
api_client-0.5.11 lib/api_client/resource/scope.rb
api_client-0.5.9 lib/api_client/resource/scope.rb