Sha256: 74d8c6468f70f1562ff09a0cd1d022342cf6188325c25169306fcf481d9ff922

Contents?: true

Size: 802 Bytes

Versions: 1

Compression:

Stored size: 802 Bytes

Contents

require "net/http"
require "addressable/template"

module MediaArtsDb
  class HttpBase
    class << self
      def get(uri, query = nil)
        uri_obj = if query.nil?
                    Addressable::URI.parse(uri)
                  else
                    template = Addressable::Template.new("#{uri}{?query*}")
                    template.expand(query)
                  end
        request(uri_obj)
      end

      private

      def request(uri_obj)
        begin
          response = Net::HTTP.get_response(uri_obj)
        rescue => e
          raise RuntimeError, "#{e.message}\n\n#{e.backtrace}"
        end
        response.code == '200' ? response.body : response_error(response)
      end

      def response_error(response)
        # 未実装
        false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
media_arts_db-1.0.0 lib/media_arts_db/http_base.rb