Sha256: 5fa2c707117a66cb87464e2498be30576d4c7a2a8319ce585ef7deddbba5b796

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

require 'dribbble/utils/findable'
require 'dribbble/utils/creatable'
require 'dribbble/utils/updatable'
require 'dribbble/utils/deletable'
require 'dribbble/attachment'
require 'dribbble/comment'
require 'dribbble/like'

module Dribbble
  class Shot < Dribbble::Base
    include Dribbble::Utils::Findable
    include Dribbble::Utils::Creatable
    include Dribbble::Utils::Updatable
    include Dribbble::Utils::Deletable

    has_many :attachments, :buckets, :comments, :likes, :projects
    has_many :rebounds, as: Dribbble::Shot

    def self.all(token, attrs = {})
      @token = token
      batch_new token, html_get('/shots', attrs)
    end

    def self.available_fields
      %i(title image description tags team_id rebound_source_id)
    end

    def self.after_create(res)
      res.code == 202 ? res.headers[:location].split('/').last : false
    end

    def like?
      html_get "/shots/#{id}/like"
      true
    rescue RestClient::ResourceNotFound
      false
    end

    def like!
      res = html_post "/shots/#{id}/like"
      res.code == 201 ? true : false
    end

    def unlike!
      res = html_delete "/shots/#{id}/like"
      res.code == 204 ? true : false
    end

    def rebounds(attrs = {})
      Dribbble::Shot.batch_new token, html_get("/shots/#{id}/rebounds", attrs)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dribbble-1.0.4 lib/dribbble/shot.rb
dribbble-1.0.2 lib/dribbble/shot.rb
dribbble-1.0.1 lib/dribbble/shot.rb
dribbble-1.0.0 lib/dribbble/shot.rb
dribbble-1.0.0.beta2 lib/dribbble/shot.rb