Sha256: fb2275527396c6a6db642d1b75b30952bb1bcf73278a8e649bbc01b0defbf751

Contents?: true

Size: 727 Bytes

Versions: 27

Compression:

Stored size: 727 Bytes

Contents

require "yajl"

module Harpy
  class EntryPoint
    attr_accessor :url

    def initialize(url)
      self.url = url
    end

    def resource_url(resource_type)
      response = Harpy.client.get url
      case response.code
      when 200
        body = Yajl::Parser.parse response.body
        link = (body["link"] || []).detect{|link| link["rel"] == resource_type}
        link["href"] if link
      else
        Harpy.client.invalid_code response
      end
    end

    def urn(urn)
      response = Harpy.client.get "#{url}/#{urn}"
      case response.code
      when 301
        response.headers_hash["Location"]
      when 404
        nil
      else
        Harpy.client.invalid_code response
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
harpy-0.5.2 lib/harpy/entry_point.rb
harpy-0.5.1 lib/harpy/entry_point.rb
harpy-0.5.0 lib/harpy/entry_point.rb
harpy-0.4.5 lib/harpy/entry_point.rb
harpy-0.4.4 lib/harpy/entry_point.rb
harpy-0.4.3 lib/harpy/entry_point.rb
harpy-0.4.2 lib/harpy/entry_point.rb
harpy-0.4.1 lib/harpy/entry_point.rb
harpy-0.4.0 lib/harpy/entry_point.rb
harpy-0.3.0 lib/harpy/entry_point.rb
harpy-0.2.1 lib/harpy/entry_point.rb
harpy-0.2.0 lib/harpy/entry_point.rb
harpy-0.1.14 lib/harpy/entry_point.rb
harpy-0.1.13 lib/harpy/entry_point.rb
harpy-0.1.12 lib/harpy/entry_point.rb
harpy-0.1.11 lib/harpy/entry_point.rb
harpy-0.1.10 lib/harpy/entry_point.rb
harpy-0.1.9 lib/harpy/entry_point.rb
harpy-0.1.8 lib/harpy/entry_point.rb
harpy-0.1.7 lib/harpy/entry_point.rb