chagol 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'chagol'
4
+ require 'optparse'
5
+
6
+ # Load the user settings
7
+ # Initialize the same if they don't exist
8
+ # Create a .chagol directory in the users home directory
9
+ # Initialize an empty configuration and a users sqlite db
10
+ # TODO all of the above
11
+
12
+ # Parse the command line options with the awesome optionparser
13
+ options = Hash.new
14
+
15
+ OptionParser.new do |opts|
16
+ opts.banner = "Usage: chagol --to name|phoneno --message 'Your Message'"
17
+ opts.on("-h", "--help") { puts opts; exit }
18
+ opts.on("-v", "--version") do
19
+ puts "Chagol is currently at version #{Chagol::VERSION}"
20
+ exit
21
+ end
22
+ # The list of usernames can be separated by commas
23
+ opts.on("-t user1,user2,userN", "--to", Array) do |users|
24
+ options[:users] = users
25
+ end
26
+ opts.on("-m msg", "--message", String) do |msg|
27
+ options[:message] = msg
28
+ end
29
+ # Like users, there can be one or more lists specified
30
+ opts.on("-l l1,l2,lN", "--list", Array) do |lists|
31
+ options[:lists] = lists
32
+ end
33
+ end.parse!
34
+
35
+ # Now we respond to the parameters passed to us
36
+ # A message is necessary for all actions except quering
37
+ # for the version of the gem
38
+ if options[:message] && (options[:users] || options[:lists])
39
+ # Send messages to individual users
40
+ if options[:users] && options[:users].length > 0
41
+ #TODO : Replace these stubs with the actual code to send messages
42
+ puts "Your Message will be sent to the following users"
43
+ options[:users].each { |user| puts user }
44
+ end
45
+ # Send messages to user created lists
46
+ if options[:lists] && options[:lists].length > 0
47
+ puts "Your Message will be sent to the following lists"
48
+ options[:lists].each { |list| puts list }
49
+ end
50
+ else
51
+ puts "The great chagol isn't a mind reader!
52
+ Please specify a recipient or a list of recipients
53
+ to whom you want the message delivered."
54
+ end
@@ -1,4 +1,6 @@
1
1
  require "chagol/version"
2
+ require "chagol/cli"
3
+ require "chagol/contact"
2
4
  require "net/http"
3
5
 
4
6
  module Chagol
@@ -0,0 +1,15 @@
1
+ # This file handles the tasks that are to be performed when chagol is installed
2
+ # It involves creating the .chagol directory in the users home and also
3
+ # initializing the json files that store the contents
4
+
5
+ module Chagol
6
+ def self.install_chagol
7
+ chagol_path = Dir.home + "/.chagol"
8
+ Dir.mkdir(chagol_path)
9
+ # Create the sample json files for the contacts
10
+ File.open(chagol_path + "/contacts.json", "w") do |f|
11
+ f.write('{"json_class":"Contact","data":{"id":1,"name":"Nikhil","phone":"9900000018"}}')
12
+ end
13
+ # Create the json for the lists
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ require "json"
2
+
3
+ module Chagol
4
+ class Contact
5
+ def initialize(id, name, phone)
6
+ @id = id
7
+ @name = name
8
+ @phone = phone
9
+ end
10
+
11
+ def to_json(*a)
12
+ {
13
+ json_class: self.class.name,
14
+ data: { id: @id, name: @name, phone: @phone }
15
+ }.to_json(*a)
16
+ end
17
+
18
+ def self.json_create(o)
19
+ new( o[:data][:id], o[:data][:name], o[:data][:phone] )
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Chagol
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chagol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,13 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-26 00:00:00.000000000 Z
12
+ date: 2012-06-27 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Chagol can send messages to any Indian mobile no
15
15
  email:
16
16
  - root@NikhilBhardwaj.in
17
- executables: []
17
+ executables:
18
+ - chagol
18
19
  extensions: []
19
20
  extra_rdoc_files: []
20
21
  files:
@@ -23,8 +24,11 @@ files:
23
24
  - LICENSE
24
25
  - README.md
25
26
  - Rakefile
27
+ - bin/chagol
26
28
  - chagol.gemspec
27
29
  - lib/chagol.rb
30
+ - lib/chagol/cli.rb
31
+ - lib/chagol/contact.rb
28
32
  - lib/chagol/version.rb
29
33
  homepage: https://github.com/nikhilbhardwaj/chagol
30
34
  licenses: []