Sha256: 4712208cfb5745d92b1ed2fd9a5e24e6e4103f5878232976d11c5bfb227c3191

Contents?: true

Size: 782 Bytes

Versions: 8

Compression:

Stored size: 782 Bytes

Contents

module Dribbble
  module Utils
    module Creatable
      module ClassMethods
        def create(token, attrs)
          @token = token
          res = html_post "/#{api_endpoint}" do |payload|
            available_fields.each { |f| payload[f] = attrs[f] }
          end
          after_create(res)
        end

        # Need to be override if pluralize isn't that naive
        def api_endpoint
          "#{name.split('::').last.downcase}s"
        end

        # Need to be redeclared in the model
        def available_fields
          fail "You need to redeclare this methods in your model"
        end

        def after_create(res)
          new @token, res
        end
      end

      def self.included(base)
        base.extend(ClassMethods)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dribbble-1.2.0 lib/dribbble/utils/creatable.rb
dribbble-1.1.0 lib/dribbble/utils/creatable.rb
dribbble-1.0.4 lib/dribbble/utils/creatable.rb
dribbble-1.0.2 lib/dribbble/utils/creatable.rb
dribbble-1.0.1 lib/dribbble/utils/creatable.rb
dribbble-1.0.0 lib/dribbble/utils/creatable.rb
dribbble-1.0.0.beta2 lib/dribbble/utils/creatable.rb
dribbble-1.0.0.beta1 lib/dribbble/utils/creatable.rb