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
25
26
27
# 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
    when "instagram" then People::Instagram
    when "instagram_parser" then People::InstagramParser
    when "google" then People::Google
    else Person
  end

  klass.new(uid, access_token, options)
end

Instance Method Details

#album!(options = {}) ⇒ Object

Create new album id



35
36
37
# File 'lib/social_profile/person.rb', line 35

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

#fetch_album(album_id) ⇒ Object

Find album by id



30
31
32
# File 'lib/social_profile/person.rb', line 30

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

#find_album(album_id) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/social_profile/person.rb', line 39

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



49
50
51
52
53
# File 'lib/social_profile/person.rb', line 49

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



79
80
81
# File 'lib/social_profile/person.rb', line 79

def followers_count(options = {})
  nil
end

#friends_count(options = {}) ⇒ Object

Get friends count



74
75
76
# File 'lib/social_profile/person.rb', line 74

def friends_count(options = {})
  nil
end

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



55
56
57
58
59
60
61
62
63
# File 'lib/social_profile/person.rb', line 55

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



65
66
67
68
69
70
71
# File 'lib/social_profile/person.rb', line 65

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

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

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