mobily-sms 0.1.0
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/mobily/mobily_account.rb +34 -0
- data/lib/mobily/mobily_api_auth.rb +8 -0
- data/lib/mobily/mobily_api_error.rb +10 -0
- data/lib/mobily/mobily_api_json_request_handler.rb +58 -0
- data/lib/mobily/mobily_api_request.rb +22 -0
- data/lib/mobily/mobily_api_response.rb +25 -0
- data/lib/mobily/mobily_api_unicode_converter.rb +7 -0
- data/lib/mobily/mobily_formatted_sms.rb +56 -0
- data/lib/mobily/mobily_sender.rb +51 -0
- data/lib/mobily/mobily_sms.rb +84 -0
- data/lib/mobily/sms.rb +139 -0
- data/lib/mobily/sms/version.rb +5 -0
- data/lib/mobily/test/tc_api_response_equality.rb +25 -0
- data/lib/mobily/test/tc_convert_to_mobily_unicode.rb +24 -0
- data/lib/mobily/test/tc_gen_msg_key.rb +62 -0
- data/lib/mobily/test/tc_json_request_handler.rb +73 -0
- data/mobily-sms.gemspec +28 -0
- metadata +114 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 8eb008ba2bd84b049e47d2b2085f8cc1bdd1fe88
|
|
4
|
+
data.tar.gz: 5b8ca561ab3eb1f4998ad2da4ebdf2f5644a3641
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3f1085e53ded908978a71f564dab8f97a4a80724d20aa7ba7346a3e2b90fec217c02a92a7c4e94567ccefdb5e8f9bf429f5ed5c36d06406d60149f5c3ee0cc84
|
|
7
|
+
data.tar.gz: 5cf514b3a357d5cd0707a96030c0513fc88487047982d266b1b43dd298a7ab846711fc3bb9ada43c43453f4f40f5ab7b6c0af04bb41ad3ec522dbfdafd5af3a0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at bojanmajed@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
mobily-sms (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
diff-lcs (1.3)
|
|
10
|
+
rake (10.5.0)
|
|
11
|
+
rspec (3.7.0)
|
|
12
|
+
rspec-core (~> 3.7.0)
|
|
13
|
+
rspec-expectations (~> 3.7.0)
|
|
14
|
+
rspec-mocks (~> 3.7.0)
|
|
15
|
+
rspec-core (3.7.1)
|
|
16
|
+
rspec-support (~> 3.7.0)
|
|
17
|
+
rspec-expectations (3.7.0)
|
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
19
|
+
rspec-support (~> 3.7.0)
|
|
20
|
+
rspec-mocks (3.7.0)
|
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
22
|
+
rspec-support (~> 3.7.0)
|
|
23
|
+
rspec-support (3.7.1)
|
|
24
|
+
|
|
25
|
+
PLATFORMS
|
|
26
|
+
ruby
|
|
27
|
+
|
|
28
|
+
DEPENDENCIES
|
|
29
|
+
bundler (~> 1.16)
|
|
30
|
+
mobily-sms!
|
|
31
|
+
rake (~> 10.0)
|
|
32
|
+
rspec (~> 3.0)
|
|
33
|
+
|
|
34
|
+
BUNDLED WITH
|
|
35
|
+
1.16.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 TODO: Write your name
|
|
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,47 @@
|
|
|
1
|
+
# Mobily::Sms
|
|
2
|
+
|
|
3
|
+
mobily-sms gem used to integrate with [Mobilyws](http://mobily.ws/sms/index.php) api's. mobilyws offers a SMS Gateway service "SMS API", that allows you easily connect Send-SMS service with your applications, websites, or any kind of systems that you may have
|
|
4
|
+
|
|
5
|
+
This gem will make your integration with [Mobilyws](http://mobily.ws/sms/index.php) easier, In order to use mobily.ws API, you should have a Mobily.ws account from [Mobilyws](http://mobily.ws/sms/index.php).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'mobily-sms'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
$ bundle
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or install it yourself as:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
$ gem install mobily-sms
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
TODO: Write usage instructions here
|
|
30
|
+
|
|
31
|
+
## Development
|
|
32
|
+
|
|
33
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
34
|
+
|
|
35
|
+
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).
|
|
36
|
+
|
|
37
|
+
## Contributing
|
|
38
|
+
|
|
39
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/[USERNAME]/mobily-sms>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
44
|
+
|
|
45
|
+
## Code of Conduct
|
|
46
|
+
|
|
47
|
+
Everyone interacting in the Mobily::Sms project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/mobily-sms/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "mobily/sms"
|
|
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(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require_relative 'mobily_api_json_request_handler'
|
|
2
|
+
require_relative 'mobily_api_error'
|
|
3
|
+
require_relative 'mobily_api_auth'
|
|
4
|
+
|
|
5
|
+
class MobilyAccount
|
|
6
|
+
def initialize(auth)
|
|
7
|
+
@auth = auth
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def change_password(new_password)
|
|
11
|
+
# changePassword api method wrapper
|
|
12
|
+
request_handler = MobilyApiJsonRequestHandler.new(@auth)
|
|
13
|
+
request_handler.set_api_method('changePassword')
|
|
14
|
+
request_handler.add_parameter('newPassword', new_password)
|
|
15
|
+
request_handler.handle
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def forgot_password(send_to_email=true)
|
|
19
|
+
# forgotPassword api method wrapper
|
|
20
|
+
request_handler = MobilyApiJsonRequestHandler.new(@auth)
|
|
21
|
+
request_type = send_to_email ? 2 : 1
|
|
22
|
+
request_handler.set_api_method('forgetPassword')
|
|
23
|
+
request_handler.add_parameter('type', request_type)
|
|
24
|
+
request_handler.handle
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def check_balance
|
|
28
|
+
# balance api method wrapper
|
|
29
|
+
request_handler = MobilyApiJsonRequestHandler.new(@auth)
|
|
30
|
+
request_handler.set_api_method('balance')
|
|
31
|
+
request_handler.handle.get('balance')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require_relative 'mobily_api_request'
|
|
3
|
+
require_relative 'mobily_api_auth'
|
|
4
|
+
require_relative 'mobily_api_error'
|
|
5
|
+
require_relative 'mobily_api_response'
|
|
6
|
+
|
|
7
|
+
class MobilyApiJsonRequestHandler
|
|
8
|
+
attr_accessor :auth, :request
|
|
9
|
+
|
|
10
|
+
def initialize(auth=nil, request=MobilyApiRequest.new)
|
|
11
|
+
@request = request
|
|
12
|
+
@params = {}
|
|
13
|
+
@content_type = 'json'
|
|
14
|
+
@json_dict = {'Data' => {}}
|
|
15
|
+
@auth = auth
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def add_auth(auth)
|
|
19
|
+
if auth.is_a? MobilyApiAuth
|
|
20
|
+
@json_dict['Data'].merge!({'Auth' => {'mobile' => auth.mobile_number, 'password' => auth.password}})
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def set_api_method(method_name)
|
|
25
|
+
@json_dict['Data'].merge!({'Method' => method_name})
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def add_parameter(key, value)
|
|
29
|
+
if !value.nil?
|
|
30
|
+
@params.merge!({key => value})
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def get_request_data
|
|
35
|
+
if @params.size > 0
|
|
36
|
+
@json_dict['Data'].update({'Params' => @params})
|
|
37
|
+
end
|
|
38
|
+
add_auth(@auth)
|
|
39
|
+
JSON.generate(@json_dict)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def handle
|
|
43
|
+
parse_response(request.send(get_request_data, @content_type))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def parse_response(data)
|
|
49
|
+
json_dict = JSON.parse(data)
|
|
50
|
+
if not json_dict['Error'].nil?
|
|
51
|
+
error = json_dict['Error']
|
|
52
|
+
raise MobilyApiError.new(error['ErrorCode'], error['MessageAr'], error['MessageEn'])
|
|
53
|
+
end
|
|
54
|
+
response = MobilyApiResponse.new(json_dict['status'], json_dict['ResponseStatus'])
|
|
55
|
+
json_dict['Data'].each { |k, v| response.add_data(k, v) }
|
|
56
|
+
response
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'uri'
|
|
4
|
+
|
|
5
|
+
class MobilyApiRequest
|
|
6
|
+
attr_accessor :api_host, :api_end_point
|
|
7
|
+
|
|
8
|
+
def initialize(api_host='mobily.ws', api_end_point='/api/json/')
|
|
9
|
+
@api_host = api_host
|
|
10
|
+
@api_end_point = api_end_point
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def send(request_data, content_type)
|
|
14
|
+
content_type = 'application/'.concat(content_type).concat('; charset=utf-8')
|
|
15
|
+
req = Net::HTTP::Post.new(@api_end_point, initheader={'Content-Type' => content_type})
|
|
16
|
+
req.body = request_data
|
|
17
|
+
res = Net::HTTP.start(@api_host, 80) do |http|
|
|
18
|
+
http.request(req)
|
|
19
|
+
end
|
|
20
|
+
res.body
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class MobilyApiResponse
|
|
2
|
+
attr_accessor :status, :response_status, :data
|
|
3
|
+
|
|
4
|
+
def initialize(status, response_status)
|
|
5
|
+
@status = status
|
|
6
|
+
@response_status = response_status.downcase
|
|
7
|
+
@data = {}
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def add_data(key, value)
|
|
11
|
+
@data.merge!({key => value})
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def get(key)
|
|
15
|
+
@data.has_key?(key) ? @data[key] : nil
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def == other
|
|
19
|
+
eql?(other)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def eql? other
|
|
23
|
+
[@status, @response_status, @data].eql?([other.status, other.response_status, other.data])
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#encoding: utf-8
|
|
2
|
+
require_relative 'mobily_api_json_request_handler'
|
|
3
|
+
require_relative 'mobily_api_error'
|
|
4
|
+
require_relative 'mobily_api_auth'
|
|
5
|
+
require_relative 'mobily_api_unicode_converter'
|
|
6
|
+
require_relative 'mobily_sms'
|
|
7
|
+
|
|
8
|
+
class MobilyFormattedSMS < MobilySMS
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def initialize(auth, numbers=[], sender='', msg='', delete_key=nil, msg_id=nil,
|
|
12
|
+
domain_name=nil, application_type='70')
|
|
13
|
+
super
|
|
14
|
+
@api_method_name = 'msgSendWK'
|
|
15
|
+
@variable_dict = {}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def add_variable_for_number(mobile_number, symbol, value)
|
|
19
|
+
return if not @numbers.include?(mobile_number)
|
|
20
|
+
if @variable_dict.has_key?(mobile_number)
|
|
21
|
+
@variable_dict[mobile_number] << [symbol, value]
|
|
22
|
+
else
|
|
23
|
+
@variable_dict.merge!({mobile_number => [[symbol, value]]})
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def generate_msg_key
|
|
28
|
+
if is_valid_key?
|
|
29
|
+
ordered_number_variables = @numbers.map { |num| @variable_dict[num] }
|
|
30
|
+
ordered_number_variables.map { |x| x.map { |y| y.join(',*,') } }.map { |z| z.join(',@,') }.join('***')
|
|
31
|
+
else
|
|
32
|
+
raise 'Cannot generate msgKey, symbol count is inconsistent'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def prepare_to_send
|
|
39
|
+
super
|
|
40
|
+
@request_handler.add_parameter('msg', MobilyApiUnicodeConverter.convert(@msg))
|
|
41
|
+
@request_handler.add_parameter('msgKey', MobilyApiUnicodeConverter.convert(generate_msg_key))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def is_valid_key?
|
|
45
|
+
is_value_set_count_consistent? and value_set_count_equals_mobile_number_count?
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def is_value_set_count_consistent?
|
|
49
|
+
1 == @variable_dict.values.map { |x| x.size }.uniq.size
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def value_set_count_equals_mobile_number_count?
|
|
53
|
+
@variable_dict.size == @numbers.size
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require_relative 'mobily_api_json_request_handler'
|
|
2
|
+
require_relative 'mobily_api_error'
|
|
3
|
+
require_relative 'mobily_api_auth'
|
|
4
|
+
|
|
5
|
+
class MobilySender
|
|
6
|
+
def initialize(auth)
|
|
7
|
+
@auth = auth
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def request_mobile_number_license(mobile_number)
|
|
11
|
+
request_handler = MobilyApiJsonRequestHandler.new(@auth)
|
|
12
|
+
request_handler.set_api_method('addSender')
|
|
13
|
+
request_handler.add_parameter('sender', mobile_number)
|
|
14
|
+
response = request_handler.handle
|
|
15
|
+
response.get('senderId')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def activate_mobile_number_license(sender_id, activation_code)
|
|
19
|
+
request_handler = MobilyApiJsonRequestHandler.new(@auth)
|
|
20
|
+
request_handler.set_api_method('activeSender')
|
|
21
|
+
request_handler.add_parameter('senderId', sender_id.tr('#', ''))
|
|
22
|
+
request_handler.add_parameter('activeKey', activation_code)
|
|
23
|
+
request_handler.handle
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def is_mobile_number_license_active?(sender_id)
|
|
27
|
+
request_handler = MobilyApiJsonRequestHandler.new(@auth)
|
|
28
|
+
request_handler.set_api_method('checkSender')
|
|
29
|
+
request_handler.add_parameter('senderId', sender_id.tr('#', ''))
|
|
30
|
+
begin
|
|
31
|
+
response = request_handler.handle
|
|
32
|
+
rescue MobilyApiError
|
|
33
|
+
false
|
|
34
|
+
else
|
|
35
|
+
response.get('result') == '1'
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def request_alphabetical_license(sender)
|
|
40
|
+
request_handler = MobilyApiJsonRequestHandler.new(@auth)
|
|
41
|
+
request_handler.set_api_method('addAlphaSender')
|
|
42
|
+
request_handler.add_parameter('sender', sender)
|
|
43
|
+
request_handler.handle
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def get_activation_status_for_all_senders
|
|
47
|
+
request_handler = MobilyApiJsonRequestHandler.new(@auth)
|
|
48
|
+
request_handler.set_api_method('checkAlphasSender')
|
|
49
|
+
request_handler.handle.data
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require_relative 'mobily_api_json_request_handler'
|
|
2
|
+
require_relative 'mobily_api_error'
|
|
3
|
+
require_relative 'mobily_api_auth'
|
|
4
|
+
require_relative 'mobily_api_unicode_converter'
|
|
5
|
+
|
|
6
|
+
class MobilySMS
|
|
7
|
+
attr_reader :date_send, :time_send
|
|
8
|
+
attr_accessor :auth, :sender, :msg, :delete_key, :msg_id, :domain_name, :request_handler
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def initialize(auth, numbers=[], sender='', msg='', delete_key=nil, msg_id=nil,
|
|
12
|
+
domain_name=nil, application_type='70')
|
|
13
|
+
@auth = auth
|
|
14
|
+
@numbers = numbers
|
|
15
|
+
@sender = sender
|
|
16
|
+
@msg = msg
|
|
17
|
+
@date_send = 0
|
|
18
|
+
@time_send = 0
|
|
19
|
+
@delete_key = delete_key
|
|
20
|
+
@msg_id = msg_id
|
|
21
|
+
@domain_name = domain_name
|
|
22
|
+
@application_type = application_type
|
|
23
|
+
@api_method_name = 'msgSend'
|
|
24
|
+
@request_handler = MobilyApiJsonRequestHandler.new(@auth)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def add_number(number)
|
|
28
|
+
@numbers << number
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def get_numbers_as_csv
|
|
32
|
+
@numbers.join(',')
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.can_send?
|
|
36
|
+
|
|
37
|
+
# send status api method wrapper, doesn't need authentication
|
|
38
|
+
request_handler = MobilyApiJsonRequestHandler.new
|
|
39
|
+
request_handler.set_api_method('sendStatus')
|
|
40
|
+
begin
|
|
41
|
+
response = request_handler.handle
|
|
42
|
+
rescue MobilyApiError
|
|
43
|
+
false
|
|
44
|
+
else
|
|
45
|
+
response.get('result') == '1'
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def send
|
|
50
|
+
# send sms api method wrapper
|
|
51
|
+
prepare_to_send
|
|
52
|
+
@request_handler.handle
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def delete
|
|
56
|
+
# send sms api method wrapper
|
|
57
|
+
return if @delete_key.nil?
|
|
58
|
+
request_handler = MobilyApiJsonRequestHandler.new(@auth)
|
|
59
|
+
request_handler.set_api_method('deleteMsg')
|
|
60
|
+
request_handler.add_parameter('deleteKey', @delete_key)
|
|
61
|
+
request_handler.handle
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def schedule_to_send_on(day, month, year, hour=0, min=0, sec=0)
|
|
65
|
+
@time_send = '%02d:%02d:%02d' % [hour, min, sec]
|
|
66
|
+
@date_send = '%02d/%02d/%04d' % [month, day, year]
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def prepare_to_send
|
|
72
|
+
@request_handler.set_api_method(@api_method_name)
|
|
73
|
+
@request_handler.add_parameter('sender', @sender)
|
|
74
|
+
@request_handler.add_parameter('msg', @msg)
|
|
75
|
+
@request_handler.add_parameter('numbers', get_numbers_as_csv)
|
|
76
|
+
@request_handler.add_parameter('dateSend', @date_send)
|
|
77
|
+
@request_handler.add_parameter('timeSend', @time_send)
|
|
78
|
+
@request_handler.add_parameter('deleteKey', @delete_key)
|
|
79
|
+
@request_handler.add_parameter('msgId', @msg_id)
|
|
80
|
+
@request_handler.add_parameter('lang', '3')
|
|
81
|
+
@request_handler.add_parameter('applicationType', @application_type)
|
|
82
|
+
@request_handler.add_parameter('domainName', @domain_name)
|
|
83
|
+
end
|
|
84
|
+
end
|
data/lib/mobily/sms.rb
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
require "mobily/sms/version"
|
|
2
|
+
require_relative 'mobily/mobily_api_auth'
|
|
3
|
+
require_relative 'mobily/mobily_account'
|
|
4
|
+
require_relative 'mobily/mobily_sms'
|
|
5
|
+
require_relative 'mobily/mobily_formatted_sms'
|
|
6
|
+
require_relative 'mobily/mobily_sender'
|
|
7
|
+
require_relative 'mobily/mobily_api_error'
|
|
8
|
+
|
|
9
|
+
class Sms
|
|
10
|
+
|
|
11
|
+
USERNAME = Rails.application.secrets.mobilyws[:username]
|
|
12
|
+
PASSWORD = Rails.application.secrets.mobilyws[:password]
|
|
13
|
+
SMSHOST = Rails.application.secrets.mobilyws[:smshost]
|
|
14
|
+
|
|
15
|
+
def self.send(recipient_mobile, message)
|
|
16
|
+
if check_can_send
|
|
17
|
+
begin
|
|
18
|
+
sms = MobilySMS.new(MobilyApiAuth.new(USERNAME, PASSWORD))
|
|
19
|
+
sms.add_number(recipient_mobile)
|
|
20
|
+
|
|
21
|
+
sms.sender = SMSHOST
|
|
22
|
+
|
|
23
|
+
sms.msg = message
|
|
24
|
+
sms.send
|
|
25
|
+
return 'sms'
|
|
26
|
+
rescue => e
|
|
27
|
+
Rails.logger.debug "ERROR: #{e}"
|
|
28
|
+
Rails.logger.debug "sms sender: #{sms.sender}"
|
|
29
|
+
Rails.logger.debug "sms: #{sms.inspect}"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
return { error_code: '1302' }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.check_can_send
|
|
36
|
+
return true if MobilySMS.can_send?
|
|
37
|
+
false
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.schedule(mobile, password, recipient_mobile)
|
|
41
|
+
sms = MobilySMS.new(MobilyApiAuth.new(mobile, password))
|
|
42
|
+
sms.add_number(recipient_mobile)
|
|
43
|
+
sms.sender = SMSHOST
|
|
44
|
+
sms.msg = 'Testing تجريب ^&**\nFrom Ruby, scheduled'
|
|
45
|
+
sms.schedule_to_send_on(25, 12, 2020, 12, 0, 0)
|
|
46
|
+
sms.delete_key = '666'
|
|
47
|
+
sms.send
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def self.send_formatted(mobile, password, recipient_one, recipient_two)
|
|
51
|
+
auth = MobilyApiAuth.new(mobile, password)
|
|
52
|
+
msg = 'Hi (1), your subscription will end on (2).'
|
|
53
|
+
sms = MobilyFormattedSMS.new(auth, [recipient_one, recipient_two], SMSHOST)
|
|
54
|
+
|
|
55
|
+
sms.add_variable_for_number(recipient_one, '(1)', 'Martin')
|
|
56
|
+
sms.add_variable_for_number(recipient_one, '(2)', '31/12/2017')
|
|
57
|
+
sms.add_variable_for_number(recipient_two, '(1)', 'Tim')
|
|
58
|
+
sms.add_variable_for_number(recipient_two, '(2)', '01/11/2020')
|
|
59
|
+
sms.send
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def self.send_scheduled_formatted(mobile, password, recipient_one, recipient_two)
|
|
63
|
+
auth = MobilyApiAuth.new(mobile, password)
|
|
64
|
+
msg = 'Hi (1), your subscription will end on (2)..'
|
|
65
|
+
|
|
66
|
+
sms = MobilyFormattedSMS.new(auth, [recipient_one, recipient_two], SMSHOST, msg )
|
|
67
|
+
|
|
68
|
+
sms.add_variable_for_number(recipient_one, '(1)', 'Lee')
|
|
69
|
+
sms.add_variable_for_number(recipient_one, '(2)', '31/11/2019')
|
|
70
|
+
sms.add_variable_for_number(recipient_two, '(1)', 'James')
|
|
71
|
+
sms.add_variable_for_number(recipient_two, '(2)', '03/10/2017')
|
|
72
|
+
sms.delete_key = '666'
|
|
73
|
+
sms.schedule_to_send_on(25, 12, 2020, 12, 0, 0)
|
|
74
|
+
sms.send
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# def change_pass(mobile, old_pass, new_pass)
|
|
78
|
+
# account = MobilyAccount.new(MobilyApiAuth.new(mobile, old_pass))
|
|
79
|
+
# account.change_password(new_pass)
|
|
80
|
+
# end
|
|
81
|
+
|
|
82
|
+
# def forgot_pass_email(mobile, password)
|
|
83
|
+
# account = MobilyAccount.new(MobilyApiAuth.new(mobile, password))
|
|
84
|
+
# account.forgot_password
|
|
85
|
+
# end
|
|
86
|
+
|
|
87
|
+
# def forgot_pass_mobile(mobile, password)
|
|
88
|
+
# account = MobilyAccount.new(MobilyApiAuth.new(mobile, password))
|
|
89
|
+
# account.forgot_password(false)
|
|
90
|
+
# end
|
|
91
|
+
|
|
92
|
+
# def check_balance(mobile, password)
|
|
93
|
+
# account = MobilyAccount.new(MobilyApiAuth.new(mobile, password))
|
|
94
|
+
# balance = account.check_balance
|
|
95
|
+
# puts '%s credits available, total %s' % [balance['current'], balance['total']]
|
|
96
|
+
# end
|
|
97
|
+
|
|
98
|
+
# def delete_sms(mobile, password)
|
|
99
|
+
# sms = MobilySMS.new(MobilyApiAuth.new(mobile, password))
|
|
100
|
+
# sms.delete_key = '666'
|
|
101
|
+
# sms.delete
|
|
102
|
+
# end
|
|
103
|
+
|
|
104
|
+
# def add_alpha_sender(mobile, password, alpha_sender)
|
|
105
|
+
# sender = MobilySender.new(MobilyApiAuth.new(mobile, password))
|
|
106
|
+
# sender.request_alphabetical_license(alpha_sender)
|
|
107
|
+
# end
|
|
108
|
+
|
|
109
|
+
# def list_senders(mobile, password)
|
|
110
|
+
# sender = MobilySender.new(MobilyApiAuth.new(mobile, password))
|
|
111
|
+
# senders_by_status = sender.get_activation_status_for_all_senders
|
|
112
|
+
# print 'Active Senders: ', senders_by_status['active'].each { |x| x }
|
|
113
|
+
# print 'Pending Senders: ', senders_by_status['pending'].each { |x| x }
|
|
114
|
+
# print 'Inactive Senders: ', senders_by_status['notActive'].each { |x| x }
|
|
115
|
+
# end
|
|
116
|
+
|
|
117
|
+
# def add_mobile_sender(mobile, password, mobile_sender)
|
|
118
|
+
# sender = MobilySender.new(MobilyApiAuth.new(mobile, password))
|
|
119
|
+
# begin
|
|
120
|
+
# return sender.request_mobile_number_license(mobile_sender)
|
|
121
|
+
# rescue MobilyApiError => e
|
|
122
|
+
# puts e.msg_english, e.msg_arabic
|
|
123
|
+
# end
|
|
124
|
+
# end
|
|
125
|
+
|
|
126
|
+
# def activate_mobile_sender(mobile, password, sender_id, activation_code)
|
|
127
|
+
# sender = MobilySender.new(MobilyApiAuth.new(mobile, password))
|
|
128
|
+
# sender.activate_mobile_number_license(sender_id, activation_code)
|
|
129
|
+
# end
|
|
130
|
+
|
|
131
|
+
# def check_activation_status(mobile, password, sender_id)
|
|
132
|
+
# sender = MobilySender.new(MobilyApiAuth.new(mobile, password))
|
|
133
|
+
# if sender.is_mobile_number_license_active?(sender_id)
|
|
134
|
+
# print 'Activated!'
|
|
135
|
+
# else
|
|
136
|
+
# print 'Not activated!'
|
|
137
|
+
# end
|
|
138
|
+
# end
|
|
139
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/bin/env ruby
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
require_relative '../lib/mobily_api_response'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TestMobilyApiResponseEquality < MiniTest::Unit::TestCase
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_equal
|
|
11
|
+
one = MobilyApiResponse.new('1', 'Success')
|
|
12
|
+
two = MobilyApiResponse.new('1', 'Success')
|
|
13
|
+
assert_equal one, two
|
|
14
|
+
assert_equal true, one.eql?(two)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_not_equal
|
|
18
|
+
one = MobilyApiResponse.new('1', 'Success')
|
|
19
|
+
two = MobilyApiResponse.new('2', 'Success')
|
|
20
|
+
assert_equal false, one == two
|
|
21
|
+
assert_equal false, one.eql?(two)
|
|
22
|
+
assert_equal false, 'string'==one
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/bin/env ruby
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
require_relative '../lib/mobily_api_unicode_converter'
|
|
5
|
+
|
|
6
|
+
class TestMobilyUnicodeConverter < MiniTest::Unit::TestCase
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_arabic_string_from_api_docs
|
|
10
|
+
exp = '06270647064406270020064806330647064406270020062806430020064506390020006D006F00620069006C0079002E00770073'
|
|
11
|
+
assert_equal exp, MobilyApiUnicodeConverter.convert('اهلا وسهلا بك مع mobily.ws')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_single_byte_characters
|
|
15
|
+
assert_equal '000D', MobilyApiUnicodeConverter.convert("\r")
|
|
16
|
+
assert_equal '004D', MobilyApiUnicodeConverter.convert('M')
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_multi_byte_characters
|
|
20
|
+
assert_equal '2022', MobilyApiUnicodeConverter.convert('•')
|
|
21
|
+
assert_equal '03C0', MobilyApiUnicodeConverter.convert('π')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/bin/env ruby
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
require_relative '../lib/mobily_formatted_sms'
|
|
5
|
+
|
|
6
|
+
class TestGenerateMsgKey < MiniTest::Unit::TestCase
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_that_valid_msg_key_is_generated_when_vars_added_in_same_order
|
|
10
|
+
msg = 'Hi (1), your subscription will end on (2).'
|
|
11
|
+
numbers = %w(966505555555 966504444444)
|
|
12
|
+
sms = MobilyFormattedSMS.new(nil, numbers, 'NEW SMS', msg)
|
|
13
|
+
sms.add_variable_for_number('966505555555', '(1)', 'Ahmad')
|
|
14
|
+
sms.add_variable_for_number('966505555555', '(2)', '31/12/2013')
|
|
15
|
+
sms.add_variable_for_number('966504444444', '(1)', 'Mohamed')
|
|
16
|
+
sms.add_variable_for_number('966504444444', '(2)', '01/11/2013')
|
|
17
|
+
exp_msg_key = '(1),*,Ahmad,@,(2),*,31/12/2013***(1),*,Mohamed,@,(2),*,01/11/2013'
|
|
18
|
+
assert_equal exp_msg_key, sms.generate_msg_key
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_that_valid_msg_key_is_generated_when_vars_added_in_diff_order
|
|
22
|
+
msg = 'Hi (1), your subscription will end on (2).'
|
|
23
|
+
numbers = %w(966505555555 966504444444)
|
|
24
|
+
sms = MobilyFormattedSMS.new(nil, numbers, 'NEW SMS', msg)
|
|
25
|
+
sms.add_variable_for_number('966504444444', '(1)', 'Mohamed')
|
|
26
|
+
sms.add_variable_for_number('966505555555', '(1)', 'Ahmad')
|
|
27
|
+
sms.add_variable_for_number('966505555555', '(2)', '31/12/2013')
|
|
28
|
+
sms.add_variable_for_number('966504444444', '(2)', '01/11/2013')
|
|
29
|
+
exp_msg_key = '(1),*,Ahmad,@,(2),*,31/12/2013***(1),*,Mohamed,@,(2),*,01/11/2013'
|
|
30
|
+
assert_equal exp_msg_key, sms.generate_msg_key
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_cannot_insert_var_for_mobile_not_added
|
|
34
|
+
msg = 'Hi (1), your subscription will end on (2).'
|
|
35
|
+
numbers = %w(966505555555 966504444444)
|
|
36
|
+
sms = MobilyFormattedSMS.new(nil, numbers, 'NEW SMS', msg)
|
|
37
|
+
assert_nil sms.add_variable_for_number('1', '(1)', 'Mohamed')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_throws_when_not_enough_value_sets
|
|
41
|
+
msg = 'Hi (1), your subscription will end on (2).'
|
|
42
|
+
numbers = %w(966505555555 966504444444)
|
|
43
|
+
sms = MobilyFormattedSMS.new(nil, numbers, 'NEW SMS', msg)
|
|
44
|
+
sms.add_variable_for_number('966505555555', '(1)', 'Ahmad')
|
|
45
|
+
sms.add_variable_for_number('966505555555', '(2)', '31/12/2013')
|
|
46
|
+
assert_raises RuntimeError do
|
|
47
|
+
sms.generate_msg_key
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_throws_when_value_sets_are_unbalanced
|
|
52
|
+
msg = 'Hi (1), your subscription will end on (2).'
|
|
53
|
+
numbers = %w(966505555555 966504444444)
|
|
54
|
+
sms = MobilyFormattedSMS.new(nil, numbers, 'NEW SMS', msg)
|
|
55
|
+
sms.add_variable_for_number('966505555555', '(1)', 'Ahmad')
|
|
56
|
+
sms.add_variable_for_number('966505555555', '(2)', '31/12/2013')
|
|
57
|
+
sms.add_variable_for_number('966504444444', '(1)', 'Mohamed')
|
|
58
|
+
assert_raises RuntimeError do
|
|
59
|
+
sms.generate_msg_key
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/bin/env ruby
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
require_relative '../lib/mobily_api_json_request_handler'
|
|
5
|
+
require_relative '../lib/mobily_api_response'
|
|
6
|
+
require_relative '../lib/mobily_api_response'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class TestMobilyApiJsonRequestHandler < MiniTest::Unit::TestCase
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_json_building
|
|
13
|
+
expected_json = '{"Data":{"Method":"balance","Auth":{"mobile":"test","password":"test"}}}'
|
|
14
|
+
handler = MobilyApiJsonRequestHandler.new
|
|
15
|
+
handler.auth = MobilyApiAuth.new('test', 'test')
|
|
16
|
+
handler.set_api_method('balance')
|
|
17
|
+
assert_equal expected_json, handler.get_request_data
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_response_parsing_success
|
|
21
|
+
fake_response = '' '{
|
|
22
|
+
"status":1,
|
|
23
|
+
"ResponseStatus":"success",
|
|
24
|
+
"Data":{
|
|
25
|
+
"result":"1",
|
|
26
|
+
"MessageAr":"يمكنك الإرسال الآن",
|
|
27
|
+
"MessageEn":"You can send SMS now"
|
|
28
|
+
},
|
|
29
|
+
"Error":null
|
|
30
|
+
}
|
|
31
|
+
' ''
|
|
32
|
+
expected_response = MobilyApiResponse.new(1, 'success')
|
|
33
|
+
expected_response.add_data('result', '1')
|
|
34
|
+
expected_response.add_data('MessageAr', 'يمكنك الإرسال الآن')
|
|
35
|
+
expected_response.add_data('MessageEn', 'You can send SMS now')
|
|
36
|
+
handler = MobilyApiJsonRequestHandler.new
|
|
37
|
+
handler.request = MobilyApiRequestStub.new(fake_response)
|
|
38
|
+
assert_equal expected_response, handler.handle
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_response_parsing_throws
|
|
42
|
+
fake_response = '' '{
|
|
43
|
+
"status":1,
|
|
44
|
+
"ResponseStatus":"fail",
|
|
45
|
+
"Data":null,
|
|
46
|
+
"Error":{
|
|
47
|
+
"ErrorCode":0,
|
|
48
|
+
"MessageAr":"بوابة غير معرفة لدينا",
|
|
49
|
+
"MessageEn":"API not exist"
|
|
50
|
+
}
|
|
51
|
+
}' ''
|
|
52
|
+
err = assert_raises MobilyApiError do
|
|
53
|
+
handler = MobilyApiJsonRequestHandler.new
|
|
54
|
+
handler.request = MobilyApiRequestStub.new(fake_response)
|
|
55
|
+
handler.handle
|
|
56
|
+
end
|
|
57
|
+
assert_equal 'بوابة غير معرفة لدينا', err.msg_arabic
|
|
58
|
+
assert_equal 'API not exist', err.msg_english
|
|
59
|
+
assert_equal 0, err.code
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class MobilyApiRequestStub
|
|
66
|
+
def initialize(fake_response)
|
|
67
|
+
@fake_response = fake_response
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def send(request_data, content_type)
|
|
71
|
+
@fake_response
|
|
72
|
+
end
|
|
73
|
+
end
|
data/mobily-sms.gemspec
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "mobily/sms/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "mobily-sms"
|
|
8
|
+
spec.version = Mobily::Sms::VERSION
|
|
9
|
+
spec.authors = ["MaJeD BoJaN"]
|
|
10
|
+
spec.email = ["bojanmajed@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = 'integrate with mobilyws'
|
|
13
|
+
spec.description = 'This will help developers to integrate with mobilews service'
|
|
14
|
+
spec.homepage = 'https://github.com/MajedBojan/mobily-sms'
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
spec.bindir = "exe"
|
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
23
|
+
spec.require_paths = ["lib"]
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mobily-sms
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- MaJeD BoJaN
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-04-30 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.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
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: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
description: This will help developers to integrate with mobilews service
|
|
56
|
+
email:
|
|
57
|
+
- bojanmajed@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".gitignore"
|
|
63
|
+
- ".rspec"
|
|
64
|
+
- ".travis.yml"
|
|
65
|
+
- CODE_OF_CONDUCT.md
|
|
66
|
+
- Gemfile
|
|
67
|
+
- Gemfile.lock
|
|
68
|
+
- LICENSE.txt
|
|
69
|
+
- README.md
|
|
70
|
+
- Rakefile
|
|
71
|
+
- bin/console
|
|
72
|
+
- bin/setup
|
|
73
|
+
- lib/mobily/mobily_account.rb
|
|
74
|
+
- lib/mobily/mobily_api_auth.rb
|
|
75
|
+
- lib/mobily/mobily_api_error.rb
|
|
76
|
+
- lib/mobily/mobily_api_json_request_handler.rb
|
|
77
|
+
- lib/mobily/mobily_api_request.rb
|
|
78
|
+
- lib/mobily/mobily_api_response.rb
|
|
79
|
+
- lib/mobily/mobily_api_unicode_converter.rb
|
|
80
|
+
- lib/mobily/mobily_formatted_sms.rb
|
|
81
|
+
- lib/mobily/mobily_sender.rb
|
|
82
|
+
- lib/mobily/mobily_sms.rb
|
|
83
|
+
- lib/mobily/sms.rb
|
|
84
|
+
- lib/mobily/sms/version.rb
|
|
85
|
+
- lib/mobily/test/tc_api_response_equality.rb
|
|
86
|
+
- lib/mobily/test/tc_convert_to_mobily_unicode.rb
|
|
87
|
+
- lib/mobily/test/tc_gen_msg_key.rb
|
|
88
|
+
- lib/mobily/test/tc_json_request_handler.rb
|
|
89
|
+
- mobily-sms.gemspec
|
|
90
|
+
homepage: https://github.com/MajedBojan/mobily-sms
|
|
91
|
+
licenses:
|
|
92
|
+
- MIT
|
|
93
|
+
metadata: {}
|
|
94
|
+
post_install_message:
|
|
95
|
+
rdoc_options: []
|
|
96
|
+
require_paths:
|
|
97
|
+
- lib
|
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - ">="
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '0'
|
|
108
|
+
requirements: []
|
|
109
|
+
rubyforge_project:
|
|
110
|
+
rubygems_version: 2.6.13
|
|
111
|
+
signing_key:
|
|
112
|
+
specification_version: 4
|
|
113
|
+
summary: integrate with mobilyws
|
|
114
|
+
test_files: []
|