require 'omniauth-oauth' require 'rexml/document' module OmniAuth module Strategies class Osm < OmniAuth::Strategies::OAuth option :name, "osm" option :client_options, :site => 'http://www.openstreetmap.org' uid { raw_info['id'] } info do raw_info end def raw_info @raw_info ||= parse_info(access_token.get('/api/0.6/user/details').body) rescue ::Errno::ETIMEDOUT raise ::Timeout::Error end # EXAMPLE XML # # # # # # Test description # # # # de-DE # de # # # private def parse_info(xml_data) # extract event information doc = REXML::Document.new(xml_data) user = doc.elements['//user'] home = doc.elements['//home'] languages = doc.get_elements('//lang') image = doc.elements['//img'] description = doc.elements['//description'] basic_attributes = { } basic_attributes['id'] = user.attribute('id').value basic_attributes['display_name'] = user.attribute('display_name').value basic_attributes['languages'] = languages.map(&:text) if languages basic_attributes['image_url'] = image.attribute('href').value if image basic_attributes['lat'] = home.attribute('lat').value.to_f if home basic_attributes['lon'] = home.attribute('lon').value.to_f if home basic_attributes['description'] = description.text if description basic_attributes end end end end