Module: Cli_Yo

Defined in:
lib/cli_yo.rb,
lib/cli_yo/helper.rb,
lib/cli_yo/yo_error.rb,
lib/cli_yo/yo_arguments.rb

Defined Under Namespace

Modules: Helper Classes: Yo_Arguments, Yo_Error

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.all_propertiesObject (readonly)

Returns the value of attribute all_properties.



16
17
18
# File 'lib/cli_yo.rb', line 16

def all_properties
  @all_properties
end

.mandatory_propertiesObject (readonly)

Returns the value of attribute mandatory_properties.



16
17
18
# File 'lib/cli_yo.rb', line 16

def mandatory_properties
  @mandatory_properties
end

.numeric_propertiesObject (readonly)

Returns the value of attribute numeric_properties.



16
17
18
# File 'lib/cli_yo.rb', line 16

def numeric_properties
  @numeric_properties
end

.short_cut_mappingObject (readonly)

Returns the value of attribute short_cut_mapping.



16
17
18
# File 'lib/cli_yo.rb', line 16

def short_cut_mapping
  @short_cut_mapping
end

Class Method Details

.yo!(arguments) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cli_yo.rb', line 18

def yo! arguments

  raise Yo_Error.new "invalid arguments class provided!" unless arguments.class == Hash || arguments.class == Yo_Arguments
  arguments = Yo_Arguments.new arguments if arguments.class == Hash
  begin

    raise Yo_Error.new "Noone to yo!" if arguments.usernames.size == 0
    Cli_Yo.mandatory_properties.each do |prop|
      raise Yo_Error.new "Missing mandatory argument #{prop}" unless arguments.property_is_set? (prop)
    end

    puts "Going to start yo-ing #{Helper.beautiful_sentence(arguments.usernames)}"

    Process.daemon(true) if arguments.silent
    counter = arguments.times

    until counter <= 0 do
      arguments.usernames.each do |username|
        result = RestClient.post YO_URL , {username: username , api_token: arguments.api_token}
        result = JSON.parse result , symbolize_names: true
        raise Yo_Error.new(result[:error] , result[:code]) if result[:code] || result[:error]
      end
      puts "Yo-ed #{Helper::beautiful_sentence(arguments.usernames)} ! This is the #{Helper::consecutive_counter (arguments.times - counter + 1)} Yo!!" unless arguments.silent
      counter -= 1
      break if counter <= 0
      sleep arguments.interval * 60  #Yo allows at most 1 minutes once!
    end

    unless arguments.silent
      puts "\nCompleted your Yo-es with ultimate awesomeness!"
      puts "Add the silent option if you don't want these messages to pop up!"
    end

  rescue Yo_Error => err
    puts err
  end
end