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.5.7 lib/api_client/resource/scope.rb
api_client-0.5.6 lib/api_client/resource/scope.rb
api_client-0.5.5 lib/api_client/resource/scope.rb
api_client-0.5.4 lib/api_client/resource/scope.rb
api_client-0.5.3 lib/api_client/resource/scope.rb
api_client-0.5.2 lib/api_client/resource/scope.rb
api_client-0.5.1 lib/api_client/resource/scope.rb
api_client-0.5.0 lib/api_client/resource/scope.rb
api_client-0.4.3 lib/api_client/resource/scope.rb
api_client-0.4.2 lib/api_client/resource/scope.rb
api_client-0.4.1 lib/api_client/resource/scope.rb
api_client-0.3.3 lib/api_client/resource/scope.rb
api_client-0.4.0 lib/api_client/resource/scope.rb
api_client-0.3.2 lib/api_client/resource/scope.rb
api_client-0.3.1 lib/api_client/resource/scope.rb
api_client-0.3.0 lib/api_client/resource/scope.rb
api_client-0.2.0 lib/api_client/resource/scope.rb
api_client-0.1.9 lib/api_client/resource/scope.rb
api_client-0.1.8 lib/api_client/resource/scope.rb
api_client-0.1.7 lib/api_client/resource/scope.rb