Sha256: 28eab3941ee2110dba22a138910fee90f84409a48f1cc6b854beed6e1a2065bc

Contents?: true

Size: 820 Bytes

Versions: 2

Compression:

Stored size: 820 Bytes

Contents

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

module MediaArtsDb
  class HttpBase
    class << self
      def http_get(uri, query = nil)
        uri_obj = if query
                    template = Addressable::Template.new("#{uri}{?query*}")
                    template.expand(query)
                  else
                    Addressable::URI.parse(uri)
                  end
        # p uri_obj
        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)
        # 未実装
        nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
media_arts_db-0.1.1 lib/media_arts_db/http_base.rb
media_arts_db-0.1.0 lib/media_arts_db/http_base.rb