Sha256: 92b9da4a9f1105f021f8de33b213b8c6874d397782e523a6170335db654594b7

Contents?: true

Size: 1.74 KB

Versions: 4

Compression:

Stored size: 1.74 KB

Contents

# encoding: utf-8

module SocialProfile
  module Providers
    class Odnoklassniki < Base
      
      def picture_url
        @picture_url ||= begin
          url = info('image').gsub("photoType=4", "photoType=3")
          check_url(url)
        end
      end
      
      def profile_url
        @profile_url ||= begin
          urls = info('urls')
          urls.nil? ? nil : urls['Odnoklassniki']
        end
      end
      
      # 0 - unknown
      # 1 - female
      # 2 - male
      # Возвращаемые значения: 1 - женский, 2 - мужской, 0 - без указания пола. 
      def gender
        @gender ||= case extra('raw_info')['gender']
          when 'male' then 2
          when 'female' then 1
          else 0
        end
      end

      def birthday
        @birthday ||= begin
          Date.strptime(extra('raw_info')['birthday'],'%m/%d/%Y')
        rescue Exception => e
          nil
        end
      end

      def city_name
        @city_name ||= begin
          location('city')
        end
      end

      def location?
        raw_info? && extra('raw_info')['location'] && extra('raw_info')['location'].is_a?(Hash)
      end

      def location(key)
        if location? && Utils.exists?(extra('raw_info')['location'][key])
          extra('raw_info')['location'][key]
        end
      end
      
      protected
      
        def check_url(url)
          response = Utils.head(url, :follow_redirects => false)

          if response.code == 302 && response.headers['location']
            [response.headers['location']].flatten.first
          else
            url
          end
        end
      
        def raw_info?
          extra('raw_info') && extra('raw_info').is_a?(Hash)
        end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
social_profile-0.3.2 lib/social_profile/providers/odnoklassniki.rb
social_profile-0.3.1 lib/social_profile/providers/odnoklassniki.rb
social_profile-0.3.0 lib/social_profile/providers/odnoklassniki.rb
social_profile-0.2.2 lib/social_profile/providers/odnoklassniki.rb