Sha256: 24b085278f1913082f535da19c2fc3c806db1b511a207764b0f093210368c173

Contents?: true

Size: 971 Bytes

Versions: 1

Compression:

Stored size: 971 Bytes

Contents

module TophatterMerchant
  class ApiKey < Resource

    attr_accessor :id, :access_token, :created_at

    class << self

      # ap TophatterMerchant::ApiKey.schema
      def schema
        get(url: "#{path}/schema.json")
      end

      # ap TophatterMerchant::ApiKey.all.map(&:to_h)
      def all
        get(url: "#{path}.json").map do |hash|
          ApiKey.new(hash)
        end
      end

      # ap TophatterMerchant::ApiKey.retrieve(1).to_h
      def retrieve(id)
        ApiKey.new get(url: "#{path}/#{id}.json")
      end

      # ap TophatterMerchant::ApiKey.create.to_h
      def create
        ApiKey.new post(url: "#{path}.json")
      end

      # ap TophatterMerchant::ApiKey.destroy(TophatterMerchant::ApiKey.all.last.id).map(&:to_h)
      def destroy(id)
        delete(url: "#{path}/#{id}.json").map do |hash|
          ApiKey.new(hash)
        end
      end

      protected

      def path
        super + '/api_keys'
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tophatter-merchant-1.0 lib/tophatter_merchant/api_key.rb