cli_yo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/cli-yo +28 -0
- data/lib/cli_yo/helper.rb +27 -0
- data/lib/cli_yo/yo_arguments.rb +31 -0
- data/lib/cli_yo/yo_error.rb +16 -0
- data/lib/cli_yo.rb +59 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1c3cb81486d2e06715a3de7678b6dbbcdce1ea29
|
4
|
+
data.tar.gz: a183a16fec3d63b6dda3f6d4e48730109285ea6f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d2c5ea920cb0b919e134d33bb77bda6657bf51d55c36b5f3c16b40af6bf2255bd2940a2927ed3a2e1a9a717ebc3a6119906c5e22092205641d26f4a84686004b
|
7
|
+
data.tar.gz: 95e3aaa2bb274bb7154c90138008f37457506b9c0673f2862fdc76fa6e2aa33527eab2e93fca42c424996b3be75587c8cbed032adc650e0c6bc291e19426b679
|
data/bin/cli-yo
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "mercenary"
|
4
|
+
|
5
|
+
Mercenary.program(:cliYo) do |p|
|
6
|
+
p.description 'CliYo is a program which can send Yo!s from the command line, at regular intervals'
|
7
|
+
p.syntax "cli-yo <all your friends you wanna yo!> [options]"
|
8
|
+
p.version "0.0.1"
|
9
|
+
|
10
|
+
p.description "yo your friends from the command line"
|
11
|
+
p.option 'silent', "-s" , '--silent', 'silently yo your friend while you proceed with your work!'
|
12
|
+
p.option "times" , "-t COUNT" , "--times COUNT" , "how many times do you want to yo! your friend, defaults to 1"
|
13
|
+
p.option "interval" , "-i INTERVAL" , "--interval INTERVAL" , "how often do you want to yo! your friend (in minutes) , defaults to 1"
|
14
|
+
p.option "api_token" , "-a TOKEN" , "--api_token TOKEN" , "Write your api_token (or add it inside .bashrc file)"
|
15
|
+
|
16
|
+
p.action do |args , options|
|
17
|
+
require "cli_yo"
|
18
|
+
options = options.inject({}){ |memo , (key , value)| memo[key.to_sym] = value ; memo}
|
19
|
+
options[:usernames] = args
|
20
|
+
|
21
|
+
Cli_Yo.numeric_properties.each do |prop|
|
22
|
+
options[prop] = options[prop].to_i if options[prop]
|
23
|
+
end
|
24
|
+
|
25
|
+
Cli_Yo.yo! options
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Helper
|
2
|
+
def self.consecutive_counter n
|
3
|
+
suffix = "th"
|
4
|
+
unless (n >= 10 && n <= 20) || n.to_s[-2] == '1'
|
5
|
+
if n.to_s[-1] == '1'
|
6
|
+
suffix = "st"
|
7
|
+
elsif n.to_s[-1] == '2'
|
8
|
+
suffix = "nd"
|
9
|
+
elsif n.to_s[-1] == '3'
|
10
|
+
suffix = 'rd'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
"#{n}-#{suffix}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.beautiful_sentence arr
|
17
|
+
return nil if arr.size == 0
|
18
|
+
return arr[0] if arr.size == 1
|
19
|
+
|
20
|
+
str = ""
|
21
|
+
for i in 0...(arr.size - 1) do
|
22
|
+
str += ", " unless i == 0
|
23
|
+
str += "#{arr[i]}"
|
24
|
+
end
|
25
|
+
str = "#{str} and #{arr.last}"
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Yo_Arguments
|
2
|
+
def initialize arguments = Hash.new
|
3
|
+
@arguments = Hash.new
|
4
|
+
|
5
|
+
Cli_Yo.all_properties.each do |prop|
|
6
|
+
@arguments[prop] = arguments[prop]
|
7
|
+
end
|
8
|
+
|
9
|
+
@arguments[:times] ||= 1
|
10
|
+
@arguments[:api_token] ||= `echo $YO_TOKEN`.chomp
|
11
|
+
@arguments[:interval] ||= 1
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing method , *args
|
15
|
+
#check whether the property actuall exists
|
16
|
+
|
17
|
+
is_setter = (method.to_s[-1] == '=')
|
18
|
+
reference_symbol = method.to_s[-1] == '=' ? method.to_s.chop.to_sym : method
|
19
|
+
super unless Cli_Yo.all_properties.include? reference_symbol
|
20
|
+
if is_setter
|
21
|
+
@arguments[reference_symbol] = args[0]
|
22
|
+
else
|
23
|
+
@arguments[reference_symbol]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def property_is_set? property
|
28
|
+
property = property.to_sym if property.class == String
|
29
|
+
@arguments[property] != nil
|
30
|
+
end
|
31
|
+
end
|
data/lib/cli_yo.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "rest_client"
|
2
|
+
require "json"
|
3
|
+
YO_URL = "http://api.justyo.co/yo/"
|
4
|
+
|
5
|
+
module Cli_Yo
|
6
|
+
|
7
|
+
@all_properties = [:silent , :times , :usernames , :api_token , :interval];
|
8
|
+
@numeric_properties = [:times , :interval];
|
9
|
+
@mandatory_properties = [:usernames , :api_token]
|
10
|
+
|
11
|
+
require "cli_yo/yo_arguments.rb"
|
12
|
+
require "cli_yo/yo_error.rb"
|
13
|
+
require "cli_yo/helper.rb"
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_reader :short_cut_mapping , :all_properties , :numeric_properties , :mandatory_properties
|
17
|
+
|
18
|
+
def yo! arguments
|
19
|
+
|
20
|
+
raise Yo_Error.new "invalid arguments class provided!" unless arguments.class == Hash || arguments.class == Yo_Arguments
|
21
|
+
arguments = Yo_Arguments.new arguments if arguments.class == Hash
|
22
|
+
p arguments
|
23
|
+
begin
|
24
|
+
|
25
|
+
raise Yo_Error.new "Noone to yo!" if arguments.usernames.size == 0
|
26
|
+
Cli_Yo.mandatory_properties.each do |prop|
|
27
|
+
raise Yo_Error.new "Missing mandatory argument #{prop}" unless arguments.property_is_set? (prop)
|
28
|
+
end
|
29
|
+
|
30
|
+
puts "Going to start yo-ing #{Helper::beautiful_sentence(arguments.usernames)}"
|
31
|
+
puts "Pid of current Process is #{Process.pid} "
|
32
|
+
|
33
|
+
Process.daemon(true) if arguments.silent
|
34
|
+
counter = arguments.times
|
35
|
+
|
36
|
+
until counter <= 0 do
|
37
|
+
arguments.usernames.each do |username|
|
38
|
+
result = RestClient.post YO_URL , {username: username , api_token: arguments.api_token}
|
39
|
+
result = JSON.parse result , symbolize_names: true
|
40
|
+
raise Yo_Error.new(result[:error] , result[:code]) if result[:code] || result[:error]
|
41
|
+
end
|
42
|
+
puts "Yo-ed #{Helper::beautiful_sentence(arguments.usernames)} ! This is the #{Helper::consecutive_counter (arguments.times - counter + 1)} Yo!!" unless arguments.silent
|
43
|
+
counter -= 1
|
44
|
+
break if counter <= 0
|
45
|
+
sleep arguments.interval * 60 #Yo allows at most 1 minutes once!
|
46
|
+
end
|
47
|
+
|
48
|
+
unless arguments.silent
|
49
|
+
puts "\nCompleted your Yo-es with ultimate awesomeness!"
|
50
|
+
puts "Add the silent option if you don't want these messages to pop up!"
|
51
|
+
end
|
52
|
+
|
53
|
+
rescue Yo_Error => err
|
54
|
+
puts err
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cli_yo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- FY Quah
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.7.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.7.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mercenary
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.3.4
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.3.4
|
55
|
+
description: 'You can Yo anyone, while writing your magnificent code. The best part,
|
56
|
+
you don''t need to do anything! '
|
57
|
+
email: quah.fy95@gmail.com
|
58
|
+
executables:
|
59
|
+
- cli-yo
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- bin/cli-yo
|
64
|
+
- lib/cli_yo.rb
|
65
|
+
- lib/cli_yo/helper.rb
|
66
|
+
- lib/cli_yo/yo_arguments.rb
|
67
|
+
- lib/cli_yo/yo_error.rb
|
68
|
+
homepage: https://github.com/fyquah95/cli-yo/
|
69
|
+
licenses: []
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.2.2
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: A command line interface to send Yo!
|
91
|
+
test_files: []
|