Sha256: ac7ccadb394ae2c66466371242166d19113e5f03553b5c4773690f3c5916b806

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

require 'json'

class IdsPlease
  module Grabbers
    class Mailru < IdsPlease::Grabbers::Base

      def grab_link
        @page_source ||= open(link).read.encode('utf-8')
        uid_url = "http://appsmail.ru/platform/#{link.split('/')[-2..-1].join('/')}"
        @network_id  = JSON.parse(open(uid_url).read)['uid']
        @username, type = get_name_and_type(link)
        @avatar = @page_source.scan(/profile__avatar" src="([^"]+)/).flatten.first
        @display_name = @page_source.scan(/h1.+title="([^"]+)/).flatten.first
        @display_name = CGI.unescapeHTML(@display_name) if @display_name
        @data = {
          type: type,
          description: @page_source.scan(/profile__content_mainInfo" title="([^"]+)/).flatten.first
        }
        @data[:description] = CGI.unescapeHTML(@data[:description]) if @data[:description]
        self
      rescue => e
        p e
        return self
      end

      private

      def get_name_and_type(link)
        ind = -1
        splitted = link.split('/')
        type = 'user'
        splitted.each_with_index do |part, i|
          if part == 'community'
            ind = i + 1
            type = 'group'
          elsif part == 'mail'
            ind = i + 1
          end
        end
        name = splitted[ind].split('?').first.split('#').first
        [name, type]
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ids_please-2.1.2 lib/ids_please/grabbers/mailru.rb
ids_please-2.1.1 lib/ids_please/grabbers/mailru.rb