Sha256: 32ae8a1ac605c0cea262520e201a37e1c95ec087a9747673987f368dc653078a

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

class IdsPlease
  module Grabbers
    class Vkontakte < IdsPlease::Grabbers::Base
      def grab_link
        prepare_link
        agent          = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36'
        @page_source ||= open(link, 'User-Agent' => agent).read.encode('utf-8')
        @network_id    = find_by_regex(/href="\/wall(-\d+)_/)
        @username      = @link.to_s.split('vk.com/').last.gsub('/', '')
        @avatar        = find_by_regex(/page_avatar.+\n.+src="([^"]+)/)
        @avatar        = CGI.unescapeHTML(@avatar) if @avatar
        @display_name  = find_by_regex(/page_name">([^<]+)/)
        @display_name  = CGI.unescapeHTML(@display_name) if @display_name
        @data = {
          description: find_by_regex(/description" content="([^"]+)/)
        }
        @data[:description] = CGI.unescapeHTML(@data[:description]) if @data[:description]
        self
      rescue => e
        record_error __method__, e.message
        return self
      end

      def prepare_link
        id = @link.to_s.split('/').last
        @link = URI("https://new.vk.com/#{id}")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ids_please-2.2.5 lib/ids_please/grabbers/vkontakte.rb