Sha256: 7eb926287a08e6b823f982c56b31e7db6e3426649b6195009747495ebc6208a7

Contents?: true

Size: 898 Bytes

Versions: 1

Compression:

Stored size: 898 Bytes

Contents

require 'hashie'

module TicketingHub
  class Resource < ::Hashie::Mash
    attr_accessor :client, :path, :id

    def initialize(client, values, path, id)
      self.client = client; self.path = path; self.id = id
      super(values)
    end

    def update
      update! attributes
      return true
    rescue TicketingHub::UnprocessableEntity
      return false
    end

    def destroy
      destroy! attributes
      return true
    rescue TicketingHub::UnprocessableEntity
      return false
    end

    def update! attributes
      merge! client.patch("#{path}/#{id}", attributes)
      return self
    rescue TicketingHub::UnprocessableEntity => e
      merge! e.response_body
      raise e
    end

    def destroy!
      merge! client.delete "#{path}/#{id}"
      return self
    rescue TicketingHub::UnprocessableEntity => e
      merge! e.response_body
      raise e
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ticketinghub-1.1.1 lib/ticketing_hub/resource.rb