Sha256: 20bc1e99d0d12163b03e895b46f01f5554c4ddc054c32102375aa4e3b367c209

Contents?: true

Size: 2 KB

Versions: 5

Compression:

Stored size: 2 KB

Contents

module Nearmiss
  class Client

    # Methods for the Projects API
    #
    module Projects

      # List projects
      #
      # @note Shows a list of projects for the users organization aka account
      #
      # @return [Array<Sawyer::Resource>] List of projects
      def projects(options = {})
        paginate "projects", options
      end
      alias :list_projects :projects

      # Get a single project
      #
      # @param project [String] UUID of project to fetch
      # @return [Sawyer::Resource] Project information
      #
      def project(project, options = {})
        get "#{project_path(project)}", options
      end

      # Create a project
      #
      # @param options [Hash] Project information.
      # @option options [String] :name e.g. Berkeley Art Museum
      # @option options [String] :project_id e.g. 10611.70
      # @return [Sawyer::Resource] Newly created project info
      def create_project(options = {})
        post 'projects', options
      end

      # Edit a project
      #
      # @param options [Hash] Project information.
      # @option options [String] :name e.g. Berkeley Art Museum
      # @option options [String] :project_id e.g. 10611.70
      #
      # @return
      #   [Sawyer::Resource] Newly created project info
      # @example Update a project
      #   @client.edit_project('some_id', {
      #     name: "New name of project",
      #     project_id: "1043.32"
      #   })
      #
      def edit_project(project, options = {})
        patch "#{project_path(project)}", options
      end

      # Delete a project
      #
      # @param project [String] Project ID
      # @return [Boolean] Indicating success of deletion
      #
      def delete_project(project, options = {})
        boolean_from_response :delete, "projects/#{project}", options
      end
      alias :remove_project :delete_project

      private

      def project_path(id)
        if uuid?(id)
          "projects/#{id}"
        else
          "project/#{id}"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nearmiss-ruby-1.0.4 lib/nearmiss-ruby/client/projects.rb
nearmiss-ruby-1.0.3 lib/nearmiss-ruby/client/projects.rb
nearmiss-ruby-1.0.2 lib/nearmiss-ruby/client/projects.rb
nearmiss-ruby-1.0.1 lib/nearmiss-ruby/client/projects.rb
nearmiss-ruby-1.0.0 lib/nearmiss-ruby/client/projects.rb