Sha256: e075e23bf73918328345ad6053a8bc68781ac9444d2847493ff21fa73b493724

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 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

1 entries across 1 versions & 1 rubygems

Version Path
ids_please-2.2.0 lib/ids_please/grabbers/mailru.rb