mobilyws 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7d8ba73588c52f1f870f8a7441bab832c4573368
4
+ data.tar.gz: 7cca5705f55692b60ee845028bf3a299201df32a
5
+ SHA512:
6
+ metadata.gz: e5d577050a5e79e9f8f3888a8be25273fdcb118736d79d75ecc70f449efe108b32d8dcfd8847daea84a8a0473e832c188b7c7892a62df0ce470f49d692cde0f3
7
+ data.tar.gz: c52fbdaa0c1e4d79406c518b5198ea34e2302b44293ecaeb59598f36761e9e3e1992e923c80f6a915b4af28ba44c1a9a1eae4590aa8a9684b7ba994182f8725f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mobilyws.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Abdulaziz AlShetwi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Mobilyws
2
+
3
+ Ruby Library for Mobily.ws SMS Gateway API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'mobilyws'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mobilyws
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## TODO
26
+
27
+ - [x] Send messeage.
28
+ - [ ] Get status.
29
+ - [ ] Check balance.
30
+ - [ ] Send template message.
31
+ - [ ] Delete messeage.
32
+ - [ ] forget Messeage.
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mobilyws. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
43
+
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
48
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mobilyws"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,44 @@
1
+ require 'open-uri'
2
+ require 'net/http'
3
+ require 'net/https'
4
+
5
+ module Mobilyws
6
+
7
+ class API
8
+ attr_reader :username, :password, :sender_name
9
+
10
+ def initialize(username, password, sender_name)
11
+ # setup Request object
12
+ uri = URI.parse("https://mobily.ws/")
13
+ @http = Net::HTTP.new(uri.host, uri.port)
14
+ @http.use_ssl = true
15
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
16
+
17
+ @username = username
18
+ @password = password
19
+ @sender_name = sender_name
20
+ end
21
+
22
+ def send(message:, numbers:[], **optional_params)
23
+ receivers = numbers.join ","
24
+ unicode_message = Mobilyws::encode(message)
25
+ data = default_parameters(msg:unicode_message, numbers:receivers)
26
+
27
+ request = Net::HTTP::Post.new("/api/msgSend.php")
28
+ request.set_form_data(data)
29
+ response = @http.request(request)
30
+ SEND_MSG_RESPONSES[response.body]
31
+ end
32
+
33
+ def default_parameters(**others)
34
+ {
35
+ mobile: @username,
36
+ password: @password,
37
+ sender: @sender_name,
38
+ applicationType: 24
39
+ }.merge(others)
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,3 @@
1
+ module Mobilyws
2
+ VERSION = "0.1.0"
3
+ end
data/lib/mobilyws.rb ADDED
@@ -0,0 +1,187 @@
1
+ require 'mobilyws/version'
2
+ require 'mobilyws/api'
3
+
4
+ module Mobilyws
5
+
6
+ class APIError < StandardError; end
7
+
8
+ SEND_MSG_RESPONSES = {
9
+ "1" => "SMS sent successfully",
10
+ "2" => APIError.new("Your balance is 0"),
11
+ "3" => APIError.new("Your balance is not enough"),
12
+ "4" => APIError.new("Invalid mobile number (or invalid username)"),
13
+ "5" => APIError.new("Invalid password."),
14
+ "6" => APIError.new("SMS-API not responding, please try again"),
15
+ "7" => APIError.new("Sender name is not accepted"),
16
+ "8" => APIError.new("Sender name is not active from Mobily.ws and mobile telecommunications companies"),
17
+ "9" => APIError.new("Mobile(s) number(s) is not specified or incorrect"),
18
+ "13" => APIError.new("Sender name is unaccepted"),
19
+ "14" => APIError.new("Sender name is unkonwn"),
20
+ "15" => APIError.new("received numbers are invalid or empty"),
21
+ "16" => APIError.new("Sender name is empty"),
22
+ "17" => APIError.new("Message text is not specified or not encoded properly with Mobily.ws Unicode"),
23
+ "18" => APIError.new("Sending SMS stopped from support"),
24
+ "19" => APIError.new("ApplicationType is not specified or invalid"),
25
+ }
26
+
27
+
28
+ # I stole this nice hash from https://github.com/moh-alsheikh/mobilywscli
29
+ UTF8_CHAR_ENCODE = {
30
+ "،" => "060D" ,
31
+ "؛"=> "061B",
32
+ "؟"=> "061F",
33
+ "ء"=> "0621",
34
+ "آ"=> "0622",
35
+ "أ"=> "0623",
36
+ "ؤ"=> "0624",
37
+ "إ"=> "0625",
38
+ "ئ"=> "0626",
39
+ "ا"=> "0627",
40
+ "ب"=> "0628",
41
+ "ة"=> "0629",
42
+ "ت"=> "062A",
43
+ "ث"=> "062B",
44
+ "ج"=> "062C",
45
+ "ح"=> "062D",
46
+ "خ"=> "062E",
47
+ "د"=> "062F",
48
+ "ذ" => "0630",
49
+ "ر"=> "0631",
50
+ "ز"=> "0632",
51
+ "س"=> "0633",
52
+ "ش"=> "0634",
53
+ "ص"=> "0635",
54
+ "ض"=> "0636",
55
+ "ط"=> "0637",
56
+ "ظ"=> "0638",
57
+ "ع"=> "0639",
58
+ "غ"=> "063A",
59
+ "ف"=> "0641",
60
+ "ق"=> "0642",
61
+ "ك"=> "0643",
62
+ "ل"=> "0644",
63
+ "م"=> "0645",
64
+ "ن"=> "0646",
65
+ "ه"=> "0647",
66
+ "و"=> "0648",
67
+ "ى"=> "0649",
68
+ "ي"=> "064A",
69
+ "ـ" => "0640",
70
+ "ً" => "064B",
71
+ "ٌ"=> "064C",
72
+ "ٍ"=> "064D",
73
+ "َ"=> "064E",
74
+ "ُ"=> "064F",
75
+ "ِ"=> "0650",
76
+ "ّ"=> "0651",
77
+ "ْ"=> "0652",
78
+ "!"=> "0021",
79
+ '""'=> "0022",
80
+ "#"=> "0023",
81
+ "$"=> "0024",
82
+ "%"=> "0025",
83
+ "&"=> "0026",
84
+ "'"=> "0027",
85
+ "("=> "0028",
86
+ ")"=> "0029",
87
+ "*"=> "002A",
88
+ "+"=> "002B",
89
+ ","=> "002C",
90
+ "-"=> "002D",
91
+ "."=> "002E",
92
+ "/"=> "002F",
93
+ "0"=> "0030",
94
+ "1"=> "0031",
95
+ "2"=> "0032",
96
+ "3"=> "0033",
97
+ "4"=> "0034",
98
+ "5"=> "0035",
99
+ "6"=> "0036",
100
+ "7"=> "0037",
101
+ "8"=> "0038",
102
+ "9"=> "0039",
103
+ ":"=> "003A",
104
+ ""=> "003B",
105
+ "<"=> "003C",
106
+ "="=> "003D",
107
+ ">"=> "003E",
108
+ "?"=> "003F",
109
+ "@"=> "0040",
110
+ "A"=> "0041",
111
+ "B"=> "0042",
112
+ "C"=> "0043",
113
+ "D"=> "0044",
114
+ "E"=> "0045",
115
+ "F"=> "0046",
116
+ "G"=> "0047",
117
+ "H"=> "0048",
118
+ "I"=> "0049",
119
+ "J"=> "004A",
120
+ "K"=> "004B",
121
+ "L"=> "004C",
122
+ "M"=> "004D",
123
+ "N"=> "004E",
124
+ "O"=> "004F",
125
+ "P"=> "0050",
126
+ "Q"=> "0051",
127
+ "R"=> "0052",
128
+ "S"=> "0053",
129
+ "T"=> "0054",
130
+ "U"=> "0055",
131
+ "V"=> "0056",
132
+ "W"=> "0057",
133
+ "X"=> "0058",
134
+ "Y"=> "0059",
135
+ "Z"=> "005A",
136
+ '[" "('=> "005B",
137
+ "\\"=> "005C",
138
+ ']" ")'=> "005D",
139
+ "^"=> "005E",
140
+ "_"=> "005F",
141
+ "`"=> "0060",
142
+ "a"=> "0061",
143
+ "b"=> "0062",
144
+ "c"=> "0063",
145
+ "d"=> "0064",
146
+ "e"=> "0065",
147
+ "f"=> "0066",
148
+ "g"=> "0067",
149
+ "h"=> "0068",
150
+ "i"=> "0069",
151
+ "j"=> "006A",
152
+ "k"=> "006B",
153
+ "l"=> "006C",
154
+ "m"=> "006D",
155
+ "n"=> "006E",
156
+ "o"=> "006F",
157
+ "p"=> "0070",
158
+ "q"=> "0071",
159
+ "r"=> "0072",
160
+ "s"=> "0073",
161
+ "t"=> "0074",
162
+ "u"=> "0075",
163
+ "v"=> "0076",
164
+ "w"=> "0077",
165
+ "x"=> "0078",
166
+ "y"=> "0079",
167
+ "z"=> "007A",
168
+ "{"=> "007B",
169
+ "|"=> "007C",
170
+ "}"=> "007D",
171
+ "~"=> "007E",
172
+ "©"=> "00A9",
173
+ "®"=> "00AE",
174
+ "÷"=> "00F7",
175
+ "×"=> "00F7",
176
+ "§"=> "00A7",
177
+ "\r"=> "000A",
178
+ " " => "0020"
179
+ }
180
+ # TODO Freeze keys and values
181
+
182
+ def self.encode(message)
183
+ encoded_message = ""
184
+ message.each_char {|c| encoded_message << UTF8_CHAR_ENCODE.fetch(c, c) }
185
+ encoded_message
186
+ end
187
+ end
data/mobilyws.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mobilyws/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mobilyws"
8
+ spec.version = Mobilyws::VERSION
9
+ spec.authors = ["Abdulaziz AlShetwi"]
10
+ spec.email = ["ecleeld@gmail.com"]
11
+
12
+ spec.summary = 'Ruby bindings for Mobily.ws SMS API'
13
+ spec.description = 'Ruby bindings for Mobily.ws API. for more details visit http://mobily.ws'
14
+ spec.homepage = "http://github.com/ecleel/mobilyws"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "minitest"
33
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mobilyws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Abdulaziz AlShetwi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
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: Ruby bindings for Mobily.ws API. for more details visit http://mobily.ws
56
+ email:
57
+ - ecleeld@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/mobilyws.rb
72
+ - lib/mobilyws/api.rb
73
+ - lib/mobilyws/version.rb
74
+ - mobilyws.gemspec
75
+ homepage: http://github.com/ecleel/mobilyws
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.5
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Ruby bindings for Mobily.ws SMS API
99
+ test_files: []