Class: SocialProfile::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/social_profile/person.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uid, access_token, options = {}) ⇒ Person

Returns a new instance of Person.



7
8
9
10
11
# File 'lib/social_profile/person.rb', line 7

def initialize(uid, access_token, options = {})
  @uid = uid
  @access_token = access_token
  @options = options
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



5
6
7
# File 'lib/social_profile/person.rb', line 5

def access_token
  @access_token
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/social_profile/person.rb', line 5

def options
  @options
end

#uidObject (readonly)

Returns the value of attribute uid.



5
6
7
# File 'lib/social_profile/person.rb', line 5

def uid
  @uid
end

Class Method Details

.get(provider, uid, access_token, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/social_profile/person.rb', line 13

def self.get(provider, uid, access_token, options = {})
  return if provider.nil?

  klass = case provider.to_s
    when "facebook" then People::Facebook
    when "vkontakte" then People::Vkontakte
    when "twitter" then People::Twitter
    else Person
  end

  klass.new(uid, access_token, options)
end

Instance Method Details

#album!(options = {}) ⇒ Object

Create new album id



32
33
34
# File 'lib/social_profile/person.rb', line 32

def album!(options = {})
  raise NotImplementedError("Subclasses should implement this!")
end

#fetch_album(album_id) ⇒ Object

Find album by id



27
28
29
# File 'lib/social_profile/person.rb', line 27

def fetch_album(album_id)
  raise NotImplementedError("Subclasses should implement this!")
end

#find_album(album_id) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/social_profile/person.rb', line 36

def find_album(album_id)
  return if album_id.nil?

  begin
    fetch_album(album_id) 
  rescue Exception => e
    return nil
  end
end

#find_or_create_album(album_id, options = {}) ⇒ Object



46
47
48
49
50
# File 'lib/social_profile/person.rb', line 46

def find_or_create_album(album_id, options = {})
  record = find_album(album_id)
  record ||= album!(options)  
  record
end

#followers_count(options = {}) ⇒ Object

Get followers count



76
77
78
# File 'lib/social_profile/person.rb', line 76

def followers_count(options = {})
  nil
end

#friends_count(options = {}) ⇒ Object

Get friends count



71
72
73
# File 'lib/social_profile/person.rb', line 71

def friends_count(options = {})
  nil
end

#share_photo!(album_id, filepath, options = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/social_profile/person.rb', line 52

def share_photo!(album_id, filepath, options = {})
  album = find_or_create_album(album_id, options[:album])

  data = {
    :source => File.new(filepath)
  }.merge(options[:photo] || {})

  album.photo!(data)
end

#tag_object!(object, tags) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/social_profile/person.rb', line 62

def tag_object!(object, tags)
  tags = Array.wrap(tags)

  return if tags.empty? || object.nil?

  object.tag!(:tags => tags)
end