mtm 1.0.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,28 +1,17 @@
1
1
  # Mtm
2
2
 
3
- TODO: Write a gem description
3
+ Timecard solution for a day's work information
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'mtm'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install mtm
7
+ the default environment is tuby 1.9.3
8
+ Opens your teminal and input:
9
+
10
+ $gem install mtm
18
11
 
19
12
  ## Usage
20
13
 
21
- How to use this script?
22
-
23
- 1. Opens your teminal and input:$: gem install mtm
24
-
25
- 2. Opens your teminal and input: tm -p 'Project name' -c 'Change name' -h 8 -d 'Tested some pages' -u bruce.yue:password
14
+ Opens your teminal and input: tm -p 'Project name' -c 'Change name' -h 8 -d 'Tested some pages' -u bruce.yue:password
26
15
  The default hours is 8 and default description is "Tested some pages and fixed some bugs."
27
16
  If step 2 have been done, '-u' is not required in the step 3.
28
17
  For example:
@@ -37,10 +26,13 @@ How to use this script?
37
26
  $: at 9pm today tm -p 'Peak Development' -h 6 -d 'Added exception process logic.'
38
27
 
39
28
 
40
- ## Contributing
29
+ ## Config
41
30
 
42
- 1. Fork it
43
- 2. Create your feature branch (`git checkout -b my-new-feature`)
44
- 3. Commit your changes (`git commit -am 'Add some feature'`)
45
- 4. Push to the branch (`git push origin my-new-feature`)
46
- 5. Create new Pull Request
31
+ 1. run
32
+ $ which ruby
33
+ The result will be '/Users/Jack/.rvm/gems/ruby-1.9.3-p327/bin/mtm'
34
+ 2. go to
35
+ '/Users/Jack/.rvm/gems/ruby-1.9.3-p327/gems/mtm-1.0.4/lib/mtm'
36
+ 3. config
37
+ config.rb
38
+ 4. mtm -h for details
data/lib/mtm/config.rb CHANGED
@@ -3,9 +3,9 @@
3
3
  ####################################################################################
4
4
  # please fill these fields: ###
5
5
  SF_USERNAME = '' # Salesforce user name ###
6
- SF_PASSWORD = '' # Salesforce password ###
6
+ SF_PASSWORD = '' # Salesforce password ###
7
7
  SF_SECURITY_TOKEN = '' # Salesforce password security token(option) ###
8
-
8
+ MOBILE_NUMBER = '' # 18988888888 you need to send the mobile to me and verify it.
9
9
 
10
10
 
11
11
  ############ option ################
data/lib/mtm/mtm.rb CHANGED
@@ -3,6 +3,7 @@ require 'rubygems'
3
3
  require 'restforce' # gem install restforce
4
4
  require 'optparse/date'
5
5
  require 'ruby-progressbar'
6
+ require 'twilio-ruby'
6
7
  require 'utils'
7
8
  require 'config'
8
9
 
@@ -28,6 +29,9 @@ options[:tm_description] = SF_TIMECARD_DESCRIPTION
28
29
  sf_client_id = '3MVG9Y6d_Btp4xp6SWO6yPlUURnycVbOfuH7I_NH2bjaw0yeoguRatNzKRpEVaIvmX7TcQbVVjuQUCZ006pwN'
29
30
  sf_client_secret = '5339957415407001741' # salesforce remote app client secret
30
31
  user_name_suffix = '@pm.meginfo.com'
32
+ # twilio
33
+ account_sid = 'ACe81d15486c1f4568a9c981053bce307b'
34
+ auth_token = 'a502db99e86340c4967cb89f0714c4ce'
31
35
 
32
36
  op = OptionParser.new do |opts|
33
37
  opts.banner = <<-BANNER
@@ -133,18 +137,6 @@ if options[:tm_list]
133
137
  abort
134
138
  end
135
139
 
136
- # Creates time card
137
- def create_timecard(*args, client)
138
- @tm = client.create!('TimeCard__c', Project__c: args[0],
139
- Change__c: args[1],
140
- Date__c: args[2],
141
- Hours__c: args[3],
142
- TeamMember__c: args[4],
143
- Description__c: args[5])
144
- puts
145
- puts "Timecrad created successfully. Hour: '#{args[3]}', Project: '#{args[6]}'"
146
- end
147
-
148
140
  msg = 'Project not found'
149
141
  begin
150
142
  if options[:tm_project] != ''
@@ -174,15 +166,16 @@ if projects.first == nil
174
166
  abort msg
175
167
  end
176
168
 
177
- begin
178
- if projects.size == 1
169
+ is_success = true
170
+ if projects.size == 1
171
+ begin
179
172
  team_member = client.query("select Id from TeamMember__c where Project__c = '#{projects.first.Id}' and User__c = '#{@sf_user_id}'");
180
173
  if(options[:tm_change] == '' && options[:tm_c_number] == nil)
181
- create_timecard(projects.first.Id, nil, options[:tm_date], options[:tm_hour],
174
+ Mtm.create_timecard(projects.first.Id, nil, options[:tm_date], options[:tm_hour],
182
175
  team_member.first.Id, options[:tm_description], projects.first.Name, client)
183
176
  else
184
177
  if (projects.first.Changes__r != nil && projects.first.Changes__r.size == 1)
185
- create_timecard(projects.first.Id, projects.first.Changes__r.first.Id,
178
+ Mtm.create_timecard(projects.first.Id, projects.first.Changes__r.first.Id,
186
179
  options[:tm_date], options[:tm_hour], team_member.first.Id,
187
180
  options[:tm_description], projects.first.Name, client)
188
181
  elsif projects.first.Changes__r == nil
@@ -194,15 +187,20 @@ begin
194
187
  projects.first.Changes__r.each { |c| puts c.Name }
195
188
  end
196
189
  end
197
- else
190
+ rescue Exception => e
191
+ is_success = false
198
192
  puts
199
- puts 'Please select a project to continue:'
200
- projects.each { |p| puts p.Name }
193
+ puts e.message
194
+ abort 'Failed to create timecard.'
201
195
  end
202
- rescue Exception => e
196
+ else
197
+ is_success = false
203
198
  puts
204
- puts e.message
205
- abort 'Failed to create timecard.'
199
+ puts 'Please select a project to continue:'
200
+ projects.each { |p| puts p.Name }
201
+ end
202
+ if is_success
203
+ Mtm.send_sms(projects.first.Name, options[:tm_hour], options[:tm_description], MOBILE_NUMBER, account_sid, auth_token)
206
204
  end
207
205
 
208
206
  @pb.finish
data/lib/mtm/utils.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'twilio-ruby'
2
+
1
3
  module Mtm
2
4
  extend self
3
5
 
@@ -9,5 +11,35 @@ module Mtm
9
11
  Date.parse(d)
10
12
  end
11
13
  end
14
+
15
+ # Creates time card
16
+ def create_timecard(*args, client)
17
+ client.create!('TimeCard__c', Project__c: args[0],
18
+ Change__c: args[1],
19
+ Date__c: args[2],
20
+ Hours__c: args[3],
21
+ TeamMember__c: args[4],
22
+ Description__c: args[5])
23
+ puts
24
+ puts "Timecrad created successfully. Hour: '#{args[3]}', Project: '#{args[6]}'"
25
+ end
26
+
27
+ def send_sms(*args, mobile, account_sid, auth_token)
28
+ if !mobile.empty?
29
+ begin
30
+ # set up a client to talk to the Twilio REST API
31
+ @t_client = Twilio::REST::Client.new account_sid, auth_token
32
+ @t_client.account.sms.messages.create(
33
+ :from => '+13852158355',
34
+ :to => '+86'+mobile,
35
+ :body => "Project: #{args[0]}, Hours: #{args[1]}, Description: #{args[2]}"
36
+ )
37
+ rescue Exception => e
38
+ puts
39
+ puts e.message
40
+ abort 'Failed to send SMS to your mobile, please contact BruceYue to verify it!'
41
+ end
42
+ end
43
+ end
12
44
 
13
45
  end
data/lib/mtm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mtm
2
- VERSION = "1.0.3"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir:
11
11
  - bin
12
12
  cert_chain: []
13
- date: 2013-03-27 00:00:00.000000000 Z
13
+ date: 2013-03-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: restforce
@@ -44,6 +44,22 @@ dependencies:
44
44
  - - ! '>='
45
45
  - !ruby/object:Gem::Version
46
46
  version: 1.0.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: twilio-ruby
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.9.0
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 3.9.0
47
63
  description: Timecard solution
48
64
  email:
49
65
  - bruce.yue@outlook.com