mobilywscli 0.0.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9fd7c7d0b073e5c7a198b38be0468b84f94a4073
4
+ data.tar.gz: 3bcdb736cdcc97ebb5058ff3a174f7605b58d095
5
+ SHA512:
6
+ metadata.gz: e1181daa76d703809790317e11a1e633a60140ed30f0164ce01e166342b21afb131a0d3b0eb46916fbe34ce7abc3747b008560baef3a32da9abb55bbf950df7a
7
+ data.tar.gz: aed403cb63fcb1e2282cf817c055031f68239928fabef56141c056559d625f5ef3a359f027ead4ce0a690f5eb66de8ab72dfd4df31c0d7631aad83019fb3f6b2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mobilywscli.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # [![Application icon](https://mobily.ws/images/logo.png)][icon]
2
+ [icon]: https://mobily.ws/images/logo.png
3
+
4
+ # Mobilyws CLI
5
+
6
+ A command-line tool for Mobilyws. http://mobily.ws/
7
+
8
+ ## Installation
9
+
10
+ First, make sure you have Ruby installed.
11
+
12
+ **On a Mac**, open `/Applications/Utilities/Terminal.app` and type:
13
+
14
+ ruby -v
15
+
16
+ If the output looks something like this, you're in good shape:
17
+
18
+ ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin12.1.0]
19
+
20
+ If the output looks more like this, you need to [install Ruby][ruby]:
21
+ [ruby]: http://www.ruby-lang.org/en/downloads/
22
+
23
+ ruby: command not found
24
+
25
+ **On Linux**, for Debian-based systems, open a terminal and type:
26
+
27
+ sudo apt-get install ruby-dev
28
+
29
+ or for Red Hat-based distros like Fedora and CentOS, type:
30
+
31
+ sudo yum install ruby-devel
32
+
33
+ (if necessary, adapt for your package manager)
34
+
35
+ **On Windows**, you can install Ruby with [RubyInstaller][].
36
+ [rubyinstaller]: http://rubyinstaller.org/
37
+
38
+
39
+ After that you can install mobilyws:
40
+
41
+ $ gem install mobilywscli
42
+
43
+ And then execute:
44
+
45
+ $ bundle
46
+
47
+ ## Usage
48
+
49
+ First You will need to register for account at Mobily https://mobily.ws/sms/index.php?id=2
50
+
51
+ ### Setup
52
+
53
+ Add Mobilyws credentials (username - password - sender)
54
+
55
+ $ mobilywscli setup
56
+
57
+ ### Balance
58
+
59
+ Print current balance:
60
+
61
+ $ mobilywscli balance
62
+
63
+ ### Send SMS
64
+
65
+ Send a new sms message:
66
+
67
+ $ mobilywscli sendsms
68
+
69
+ ### Service status
70
+
71
+ Check mobilyws status:
72
+
73
+ $ mobilywscli status
74
+
75
+ ## Contributing
76
+
77
+ 1. Fork it
78
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
79
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
80
+ 4. Push to the branch (`git push origin my-new-feature`)
81
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/mobilywscli ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'commander/import'
5
+ require 'mobilywscli'
6
+
7
+ program :version, '0.0.1'
8
+ program :description, 'CLI FOR MOBILY SMS'
9
+ default_command :welcome
10
+
11
+ command :welcome do |c|
12
+ c.syntax = 'status'
13
+ c.description = 'Displays welcome message'
14
+ c.action do |args, options|
15
+ print_header
16
+ print_footer
17
+ end
18
+ end
19
+
20
+ command :setup do |c|
21
+ c.syntax = 'type setup and press enter key and follow the prompt'
22
+ c.description = 'Add mobilyws login information >> username - password - sender << '
23
+ c.action do |args, options|
24
+ print_header
25
+ say Mobilywscli.setup( ask("USERNAME: "), ask("PASSWORD: "), ask("SENDER: "))
26
+ print_footer
27
+ end
28
+ end
29
+
30
+ command :status do |c|
31
+ c.syntax = 'status'
32
+ c.description = 'Displays mobilyws gateway status'
33
+ c.action do |args, options|
34
+ print_header
35
+ say Mobilywscli.send_status
36
+ print_footer
37
+ end
38
+ end
39
+
40
+ command :balance do |c|
41
+ c.syntax = 'balance'
42
+ c.description = 'Displays current balance'
43
+ c.action do |args, options|
44
+ print_header
45
+ say Mobilywscli.get_balance
46
+ print_footer
47
+ end
48
+ end
49
+
50
+ command :sendsms do |c|
51
+ c.syntax = 'type sendsms and press enter key and follow the prompt'
52
+ c.description = 'Send a new sms message'
53
+ c.action do |args, options|
54
+ print_header
55
+ numbers = ask("Numbers: ")
56
+ message = ask("Message: ")
57
+ say Mobilywscli.send(numbers,message)
58
+ print_footer
59
+ end
60
+ end
61
+
62
+ def print_header
63
+ puts "\n\n\n|||||||||||||||||| Welcome to Mobily SMS Gateway! ||||||||||||||||||\n\n\n"
64
+ end
65
+
66
+ def print_footer
67
+ puts "\n\n\n"
68
+ end
69
+
70
+
71
+ __END__
@@ -0,0 +1,324 @@
1
+ # coding: utf-8
2
+
3
+ require "mobilywscli/version"
4
+
5
+ require 'net/https'
6
+ require 'net/http'
7
+ require 'open-uri'
8
+ require 'yaml'
9
+ require 'mobilywscli'
10
+
11
+ module Mobilywscli
12
+
13
+ API_BASE_URI = "http://mobily.ws/api/"
14
+ SETTING_FILE_PATH = File.join(File.dirname(__FILE__),"settings.yaml")
15
+
16
+ class << self
17
+
18
+ attr_accessor :current_result_message
19
+
20
+ #============================================
21
+ # Check for mobilyws gateway status
22
+ def send_status
23
+ url = URI.parse("#{API_BASE_URI}sendStatus.php")
24
+ current_result_message = result_messages(Net::HTTP.get(url), 0)
25
+ end
26
+
27
+ #============================================
28
+ # Add & modify mobily credentials
29
+ def setup(muname, mpassword, msender)
30
+ mobily_credential_yaml = YAML.load_file(SETTING_FILE_PATH)
31
+
32
+ mobily_credential_yaml['mobily_username'] = muname.to_s
33
+ mobily_credential_yaml['mobily_password'] = mpassword.to_s
34
+ mobily_credential_yaml['mobily_sender'] = msender.to_s
35
+
36
+ begin
37
+ File.open(SETTING_FILE_PATH,'w') do |h|
38
+ h.write mobily_credential_yaml.to_yaml
39
+ end
40
+ rescue SystemCallError
41
+ raise StandardError
42
+ end
43
+
44
+ end
45
+
46
+ #============================================
47
+ # Get current mobily setting
48
+ def get_mobily_credential(credential_type)
49
+ mobily_credential_yaml = YAML.load_file(SETTING_FILE_PATH)
50
+
51
+ case credential_type
52
+ when :username then return mobily_credential_yaml['mobily_username']
53
+ when :password then return mobily_credential_yaml['mobily_password']
54
+ when :sender then return mobily_credential_yaml['mobily_sender']
55
+ else return "unknown request"
56
+ end
57
+
58
+ end
59
+
60
+ #============================================
61
+ # Check for balance
62
+ def get_balance
63
+ url = URI.parse("#{API_BASE_URI}balance.php?mobile=#{get_mobily_credential(:username)}&password=#{get_mobily_credential(:password)}")
64
+ current_result_message = result_messages(Net::HTTP.get(url), 1)
65
+ end
66
+
67
+ #============================================
68
+ # Send message
69
+ def send(numbers, message)
70
+ message = convert_to_unicode(message)
71
+ url = URI.parse(URI.encode("#{API_BASE_URI}msgSend.php?mobile=#{get_mobily_credential(:username)}&password=#{get_mobily_credential(:password)}&numbers=#{numbers}&msg=#{message}&sender=#{get_mobily_credential(:sender)}&applicationType=24"))
72
+ current_result_message = result_messages(Net::HTTP.get(url), 2)
73
+ end
74
+
75
+ #============================================
76
+ # Result messages handler
77
+ def result_messages(q, op_type)
78
+
79
+ # Get current sttaus of mobily gateway
80
+ if op_type == 0
81
+
82
+ if q == '1'
83
+ result = "Service is available"
84
+ else
85
+ result = "Service is not available"
86
+ end
87
+
88
+ # Get current balance
89
+ elsif op_type == 1
90
+
91
+ case q
92
+ when '1'
93
+ result = "username is incorrect, please make sure that the username is the same name that you use to access mobily.ws"
94
+ when '2'
95
+ result = "password is incorrect, please make sure that the password is the same passowrd that you use to access mobily.ws"
96
+ when '-1'
97
+ result = "Communication with Server Failed."
98
+ when '-2'
99
+ result = "Communication with Database Failed."
100
+ else
101
+ current_balance = q.split('/')
102
+ result = "Mobily current balance: #{current_balance[1]} of #{current_balance[0]}"
103
+ end
104
+
105
+ # Send message
106
+ elsif op_type == 2
107
+
108
+ case q
109
+ when '1'
110
+ result = "Message has been sent successfully."
111
+ when '2'
112
+ result = "Balance = 0"
113
+ when '3'
114
+ result = "insufficient balance"
115
+ when '4'
116
+ result = "Mobile Number Not Available"
117
+ when '5'
118
+ result = "Password is incorrect"
119
+ when '6'
120
+ result = "Web page ineffective, try sending again"
121
+ when '13'
122
+ result = "The sender name is not acceptable"
123
+ when '14'
124
+ result = "The sender name is not active"
125
+ when '15'
126
+ result = "Invalid or empty numbers"
127
+ when '16'
128
+ result = "Sender name is empty"
129
+ when '17'
130
+ result = "The text of the message is not encrypted properly"
131
+ when '-1'
132
+ result = "Communication with Database Failed."
133
+ when '-2'
134
+ result = "Communication with Server Failed."
135
+ else
136
+ result = q
137
+ end
138
+
139
+ end
140
+
141
+
142
+ end
143
+
144
+ #============================================
145
+
146
+ def convert_to_unicode(message)
147
+
148
+ chrarray = {
149
+
150
+ "،" => "060D" ,
151
+ "؛"=> "061B",
152
+ "؟"=> "061F",
153
+ "ء"=> "0621",
154
+ "آ"=> "0622",
155
+ "أ"=> "0623",
156
+ "ؤ"=> "0624",
157
+ "إ"=> "0625",
158
+ "ئ"=> "0626",
159
+ "ا"=> "0627",
160
+ "ب"=> "0628",
161
+ "ة"=> "0629",
162
+ "ت"=> "062A",
163
+ "ث"=> "062B",
164
+ "ج"=> "062C",
165
+ "ح"=> "062D",
166
+ "خ"=> "062E",
167
+ "د"=> "062F",
168
+ "ذ" => "0630",
169
+ "ر"=> "0631",
170
+ "ز"=> "0632",
171
+ "س"=> "0633",
172
+ "ش"=> "0634",
173
+ "ص"=> "0635",
174
+ "ض"=> "0636",
175
+ "ط"=> "0637",
176
+ "ظ"=> "0638",
177
+ "ع"=> "0639",
178
+ "غ"=> "063A",
179
+ "ف"=> "0641",
180
+ "ق"=> "0642",
181
+ "ك"=> "0643",
182
+ "ل"=> "0644",
183
+ "م"=> "0645",
184
+ "ن"=> "0646",
185
+ "ه"=> "0647",
186
+ "و"=> "0648",
187
+ "ى"=> "0649",
188
+ "ي"=> "064A",
189
+ "ـ" => "0640",
190
+ "ً" => "064B",
191
+ "ٌ"=> "064C",
192
+ "ٍ"=> "064D",
193
+ "َ"=> "064E",
194
+ "ُ"=> "064F",
195
+ "ِ"=> "0650",
196
+ "ّ"=> "0651",
197
+ "ْ"=> "0652",
198
+ "!"=> "0021",
199
+ '""'=> "0022",
200
+ "#"=> "0023",
201
+ "$"=> "0024",
202
+ "%"=> "0025",
203
+ "&"=> "0026",
204
+ "'"=> "0027",
205
+ "("=> "0028",
206
+ ")"=> "0029",
207
+ "*"=> "002A",
208
+ "+"=> "002B",
209
+ ","=> "002C",
210
+ "-"=> "002D",
211
+ "."=> "002E",
212
+ "/"=> "002F",
213
+ "0"=> "0030",
214
+ "1"=> "0031",
215
+ "2"=> "0032",
216
+ "3"=> "0033",
217
+ "4"=> "0034",
218
+ "5"=> "0035",
219
+ "6"=> "0036",
220
+ "7"=> "0037",
221
+ "8"=> "0038",
222
+ "9"=> "0039",
223
+ ":"=> "003A",
224
+ ""=> "003B",
225
+ "<"=> "003C",
226
+ "="=> "003D",
227
+ ">"=> "003E",
228
+ "?"=> "003F",
229
+ "@"=> "0040",
230
+ "A"=> "0041",
231
+ "B"=> "0042",
232
+ "C"=> "0043",
233
+ "D"=> "0044",
234
+ "E"=> "0045",
235
+ "F"=> "0046",
236
+ "G"=> "0047",
237
+ "H"=> "0048",
238
+ "I"=> "0049",
239
+ "J"=> "004A",
240
+ "K"=> "004B",
241
+ "L"=> "004C",
242
+ "M"=> "004D",
243
+ "N"=> "004E",
244
+ "O"=> "004F",
245
+ "P"=> "0050",
246
+ "Q"=> "0051",
247
+ "R"=> "0052",
248
+ "S"=> "0053",
249
+ "T"=> "0054",
250
+ "U"=> "0055",
251
+ "V"=> "0056",
252
+ "W"=> "0057",
253
+ "X"=> "0058",
254
+ "Y"=> "0059",
255
+ "Z"=> "005A",
256
+ '[" "('=> "005B",
257
+ "\\"=> "005C",
258
+ ']" ")'=> "005D",
259
+ "^"=> "005E",
260
+ "_"=> "005F",
261
+ "`"=> "0060",
262
+ "a"=> "0061",
263
+ "b"=> "0062",
264
+ "c"=> "0063",
265
+ "d"=> "0064",
266
+ "e"=> "0065",
267
+ "f"=> "0066",
268
+ "g"=> "0067",
269
+ "h"=> "0068",
270
+ "i"=> "0069",
271
+ "j"=> "006A",
272
+ "k"=> "006B",
273
+ "l"=> "006C",
274
+ "m"=> "006D",
275
+ "n"=> "006E",
276
+ "o"=> "006F",
277
+ "p"=> "0070",
278
+ "q"=> "0071",
279
+ "r"=> "0072",
280
+ "s"=> "0073",
281
+ "t"=> "0074",
282
+ "u"=> "0075",
283
+ "v"=> "0076",
284
+ "w"=> "0077",
285
+ "x"=> "0078",
286
+ "y"=> "0079",
287
+ "z"=> "007A",
288
+ "{"=> "007B",
289
+ "|"=> "007C",
290
+ "}"=> "007D",
291
+ "~"=> "007E",
292
+ "©"=> "00A9",
293
+ "®"=> "00AE",
294
+ "÷"=> "00F7",
295
+ "×"=> "00F7",
296
+ "§"=> "00A7",
297
+ "\r"=> "000A",
298
+ " " => "0020"
299
+
300
+ }
301
+
302
+ result = ''
303
+
304
+ message.chars.to_a.map { |x|
305
+ if chrarray.has_key?(x)
306
+ result += chrarray[x]
307
+ else
308
+ x
309
+ end
310
+
311
+ }.join
312
+
313
+ result
314
+
315
+ end
316
+
317
+ #============================================
318
+
319
+ end
320
+
321
+ end
322
+
323
+ __END__
324
+
@@ -0,0 +1,3 @@
1
+ module Mobilywscli
2
+ VERSION = "0.0.2"
3
+ end
data/lib/settings.yaml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ mobily_username: '966566666666'
3
+ mobily_password: '8888888'
4
+ mobily_sender: Mohammed
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mobilywscli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mobilywscli"
8
+ spec.version = Mobilywscli::VERSION
9
+ spec.authors = ["Mohammed AlSheikh"]
10
+ spec.email = ["msheikh2009@yahoo.com"]
11
+ spec.description = "A command-line tool for Mobilyws. http://mobily.ws"
12
+ spec.summary = "CLI for Mobilyws"
13
+ spec.homepage = "https://github.com/moh-alsheikh/mobilywscli"
14
+ spec.license = "MIT"
15
+ spec.bindir = 'bin'
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.files = Dir["README.md","Gemfile","Rakefile", "mobilywscli.gemspec","lib/**/*"]
18
+ spec.files += Dir.glob('lib/**/*.rb')
19
+ spec.files += Dir.glob('bin/**/*')
20
+ spec.files += Dir.glob('spec/**/*')
21
+ spec.executables = ["mobilywscli"]
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ["lib"]
24
+ spec.add_dependency 'commander', '~> 4.2'
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency 'rake', '~> 0'
27
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mobilywscli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Mohammed AlSheikh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: commander
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A command-line tool for Mobilyws. http://mobily.ws
56
+ email:
57
+ - msheikh2009@yahoo.com
58
+ executables:
59
+ - mobilywscli
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - bin/mobilywscli
67
+ - lib/mobilywscli.rb
68
+ - lib/mobilywscli/version.rb
69
+ - lib/settings.yaml
70
+ - mobilywscli.gemspec
71
+ homepage: https://github.com/moh-alsheikh/mobilywscli
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: CLI for Mobilyws
95
+ test_files: []