Sha256: c782034c8a81b338fdecd98fe358638178038e21a03fa967dff4fee34f97edf8

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

# encoding: utf-8
module SocialProfile
  module Providers
    class Facebook < Base
      # http://developers.facebook.com/docs/reference/api/#pictures
      #    
      def picture_url
        @picture_url ||= begin
          url = info('image').split('?').shift()
          check_url([url, "type=large"].join('?'))
        end
      end
      
      def profile_url
        @profile_url ||= begin
          urls = info('urls')
          urls.nil? ? nil : urls['Facebook']
        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
      
      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
      
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
social_profile-0.1.3 lib/social_profile/providers/facebook.rb
social_profile-0.1.2 lib/social_profile/providers/facebook.rb
social_profile-0.1.1 lib/social_profile/providers/facebook.rb