Sha256: e658b074e775e04c86e78302f355a6cc259c892c975cd8a0ddb005516265c9fb

Contents?: true

Size: 921 Bytes

Versions: 1

Compression:

Stored size: 921 Bytes

Contents

require "delegate"

module Ezid
  # A response from the EZID service.
  class Response < SimpleDelegator

    SUCCESS = "success"
    ERROR = "error"

    def self.build(http_response)
      Response.new(http_response)
    end

    def status
      @status ||= status_line.split(/: /)
    end

    def status_line
      content.first
    end

    def content
      @content ||= body.split(/\r?\n/, 2)
    end

    def metadata
      content.last if success? && identifier_uri?
    end

    def identifier
      message.split(/\s/).first if success? && identifier_uri?
    end

    def identifier_uri?
      uri.path =~ /^\/(id|shoulder)\//
    end

    def outcome
      status.first
    end

    def message
      status.last
    end

    def cookie
      self["Set-Cookie"].split(";").first rescue nil
    end

    def error?
      outcome == ERROR
    end

    def success?
      outcome == SUCCESS
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ezid-client-0.1.0 lib/ezid/response.rb