Class: Ayadn::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/ayadn/profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Profile

Returns a new instance of Profile.



7
8
9
10
# File 'lib/ayadn/profile.rb', line 7

def initialize options
  abort(Status.profile_options) if options.empty?
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/ayadn/profile.rb', line 5

def options
  @options
end

#payloadObject (readonly)

Returns the value of attribute payload.



5
6
7
# File 'lib/ayadn/profile.rb', line 5

def payload
  @payload
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/ayadn/profile.rb', line 5

def text
  @text
end

Instance Method Details

#get_text_from_userObject



22
23
24
25
26
27
28
29
# File 'lib/ayadn/profile.rb', line 22

def get_text_from_user
  unless @options[:delete] || @options[:avatar] || @options[:cover]
    writer = Post.new
    input = writer.compose()
    writer.check_post_length(input)
    @text = input.join("\n")
  end
end

#prepare_payloadObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ayadn/profile.rb', line 31

def prepare_payload
  @payload = \
  if @options[:bio]
    if @options[:delete]
      {'description' => {'text' => ''}}
    else
      {'description' => {'text' => @text}}
    end
  elsif @options[:name]
    if @options[:delete]
      abort("'Delete' isn't available for 'name'.\n".color(:red))
    else
      {'name' => @text}
    end
  elsif @options[:twitter]
    if @options[:delete]
      {'annotations' => [{'type' => 'net.app.core.directory.twitter'}]}
    else
      {'annotations' => [{
        'type' => 'net.app.core.directory.twitter',
        'value' => {'username' => @text}}]}
    end
  elsif @options[:blog]
    if @options[:delete]
      {'annotations' => [{'type' => 'net.app.core.directory.blog'}]}
    else
      {'annotations' => [{
        'type' => 'net.app.core.directory.blog',
        'value' => {'url' => @text}}]}
    end
  elsif @options[:web]
    if @options[:delete]
      {'annotations' => [{'type' => 'net.app.core.directory.homepage'}]}
    else
      {'annotations' => [{
        'type' => 'net.app.core.directory.homepage',
        'value' => {'url' => @text}}]}
    end
  end
end

#updateObject



12
13
14
15
16
17
18
19
20
# File 'lib/ayadn/profile.rb', line 12

def update
  if @options[:avatar]
    FileOps.upload_avatar(@options[:avatar].join)
  elsif @options[:cover]
    FileOps.upload_cover(@options[:cover].join)
  else
    CNX.patch(Endpoints.new.user('me'), @payload)
  end
end