chagol 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/chagol +24 -5
- data/lib/chagol/contact.rb +3 -2
- data/lib/chagol/version.rb +1 -1
- metadata +1 -1
data/bin/chagol
CHANGED
@@ -3,11 +3,14 @@
|
|
3
3
|
require 'chagol'
|
4
4
|
require 'optparse'
|
5
5
|
|
6
|
-
# Load the user settings
|
7
|
-
# Initialize the same if they don't exist
|
8
6
|
# Create a .chagol directory in the users home directory
|
9
|
-
# Initialize an empty configuration and
|
10
|
-
|
7
|
+
# Initialize an empty configuration and contacts in json format
|
8
|
+
if !Dir.exists?(Dir.home + "/.chagol")
|
9
|
+
Chagol.install_chagol
|
10
|
+
puts "Please enter your contacts in ~/.chagol/contacts.json\n
|
11
|
+
Modify the one that already exists and add as many more as \n
|
12
|
+
you want in the same format"
|
13
|
+
end
|
11
14
|
|
12
15
|
# Parse the command line options with the awesome optionparser
|
13
16
|
options = Hash.new
|
@@ -36,14 +39,30 @@ end.parse!
|
|
36
39
|
# A message is necessary for all actions except quering
|
37
40
|
# for the version of the gem
|
38
41
|
if options[:message] && (options[:users] || options[:lists])
|
42
|
+
# Load the contacts in from the json also TODO load lists too
|
43
|
+
contacts = Array.new
|
44
|
+
File.open(File.expand_path("~/.chagol/contacts.json","r")).each_line do |line|
|
45
|
+
contacts << JSON.parse(line)
|
46
|
+
end
|
47
|
+
# Load the username, password and provider from the config file
|
48
|
+
require File.expand_path("~/.chagol/config")
|
49
|
+
messenger = Chagol::SmsSender.new($user[:phone_no], $user[:password], $user[:provider])
|
39
50
|
# Send messages to individual users
|
40
51
|
if options[:users] && options[:users].length > 0
|
41
52
|
#TODO : Replace these stubs with the actual code to send messages
|
42
53
|
puts "Your Message will be sent to the following users"
|
43
|
-
options[:users].each
|
54
|
+
options[:users].each do |target|
|
55
|
+
contacts.each do |contact|
|
56
|
+
if target.casecmp(contact.name) == 0
|
57
|
+
puts "#{target}, #{contact.phone} => #{options[:message]}"
|
58
|
+
messenger.send(contact.phone,options[:message])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
44
62
|
end
|
45
63
|
# Send messages to user created lists
|
46
64
|
if options[:lists] && options[:lists].length > 0
|
65
|
+
# TODO: implement lists
|
47
66
|
puts "Your Message will be sent to the following lists"
|
48
67
|
options[:lists].each { |list| puts list }
|
49
68
|
end
|
data/lib/chagol/contact.rb
CHANGED
@@ -2,6 +2,7 @@ require "json"
|
|
2
2
|
|
3
3
|
module Chagol
|
4
4
|
class Contact
|
5
|
+
attr_reader :id, :name, :phone
|
5
6
|
def initialize(id, name, phone)
|
6
7
|
@id = id
|
7
8
|
@name = name
|
@@ -10,13 +11,13 @@ module Chagol
|
|
10
11
|
|
11
12
|
def to_json(*a)
|
12
13
|
{
|
13
|
-
json_class: self.class.name,
|
14
|
+
json_class: "Chagol::" + self.class.name,
|
14
15
|
data: { id: @id, name: @name, phone: @phone }
|
15
16
|
}.to_json(*a)
|
16
17
|
end
|
17
18
|
|
18
19
|
def self.json_create(o)
|
19
|
-
new( o[
|
20
|
+
new( o["data"]["id"], o["data"]["name"], o["data"]["phone"] )
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
data/lib/chagol/version.rb
CHANGED