💾 Archived View for alltext.umaneti.net › ruby-net-text.gmi captured on 2022-04-29 at 11:18:18. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2022-03-01)
-=-=-=-=-=-=-
Net::Gemini provides a rich library which can be used to build Gemini user-agents. Net::Gemini is designed to work closely with URI.
the same documentation on Rubydoc (HTTPS)
ruby-net-text git repository (HTTPS)
ruby-net-text on Rubygems (HTTPS)
All examples assume you have loaded Net::Gemini with:
require 'net/gemini'
This will also require 'uri' so you don't need to require it separately.
The Net::Gemini methods in the following sections do not persist connections.
uri = URI('gemini://example.com/index.html?count=10') Net::Gemini.get(uri) # => String
uri = URI('gemini://example.com/index.html') params = { :limit => 10, :page => 3 } uri.query = URI.encode_www_form(params) res = Net::Gemini.get_response(uri) puts res.body if res.body_permitted?
res = Net::Gemini.get_response(URI('gemini://exemple.com/home')) # Status puts res.status # => '20' puts res.meta # => 'text/gemini; charset=UTF-8; lang=en' # Headers puts res.header.inspect # => { status: '20', meta: 'text/gemini; charset=UTF-8', mimetype: 'text/gemini', lang: 'en', charset: 'utf-8', format: nil }
The lang, charset and format headers will only be provided in case of `text/*` mimetype, and only if body for 2* status codes.
# Body puts res.body if res.body_permitted? puts res.body(flowed: 85)
The #fetch method, contrary to the #request one will try to automatically resolves redirection, leading you to the final destination.
u = URI('gemini://exemple.com/redirect') res = Net::Gemini.start(u.host, u.port) do |g| g.request(u) end puts "#{res.status} - #{res.meta}" # => '30 final/dest' puts res.uri.to_s # => 'gemini://exemple.com/redirect' u = URI('gemini://exemple.com/redirect') res = Net::Gemini.start(u.host, u.port) do |g| g.fetch(u) end puts "#{res.status} - #{res.meta}" # => '20 - text/gemini;' puts res.uri.to_s # => 'gemini://exemple.com/final/dest'
--
📅 dernière modification le mercredi 2 décembre 2020 à 20:56
📝 Écrit par Étienne Deparis avec GNU/Emacs 27.2 (Org mode 9.4.6) et publié avec Fronde 0.3.2