mfms 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/lib/mfms.rb +4 -0
- data/lib/mfms/sms.rb +135 -0
- data/lib/mfms/version.rb +11 -0
- data/mfms.gemspec +18 -0
- metadata +55 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 10fc593c042008f0b6f6d01a6c5dcb6572845946
|
4
|
+
data.tar.gz: 52d84749dd799109b3bb193b08324f2b1ef424de
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e4996ad873444e73b3538468ed65a6f3b807ca4740472e5bce7d581087af6455034cdc58e5269ef449071011d75b7922cf8cc49a5d4c9b3d066ae920a0448860
|
7
|
+
data.tar.gz: 5afb5b4b7a8c929c3f2d9f9fc0e25554c6a3c19b4894c313d8193f7c9dde16740eb3f4bb866849a1e7ff919153b37d805201c5a3a87a85e55d273976b85cc911
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Fokin Eugene
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Mfms
|
2
|
+
|
3
|
+
Library to communicate with Mobile Finance Management Solutions
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
$ gem 'mfms', :git => 'git@github.com:RevoTechnology/mfms.git' # TODO: push to rubygems
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ TODO
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Define settinfs:
|
22
|
+
|
23
|
+
Mfms::SMS.settings = {
|
24
|
+
:login => 'login',
|
25
|
+
:password => 'password',
|
26
|
+
:server => 'server',
|
27
|
+
:port => port,
|
28
|
+
:ssl_port => ssl_port,
|
29
|
+
:cert => 'path/to/cert',
|
30
|
+
}
|
31
|
+
|
32
|
+
Initialize sms:
|
33
|
+
|
34
|
+
sms = Mfms::SMS.new('phone','title','text') # initialize sms
|
35
|
+
|
36
|
+
Send it and get sent sms id and dispatch code
|
37
|
+
|
38
|
+
sms.send # send sms
|
39
|
+
sms.id # get sms id
|
40
|
+
sms.code # get sms dispatch code
|
41
|
+
|
42
|
+
Ex.:
|
43
|
+
|
44
|
+
sms = Mfms::SMS.new('79031111111','MyFavouriteCompany','Testing mfms gem')
|
45
|
+
sms.send
|
46
|
+
sms.id # => 1032
|
47
|
+
sms.code # => ok
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/mfms.rb
ADDED
data/lib/mfms/sms.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'net/http'
|
3
|
+
require 'openssl'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module Mfms
|
7
|
+
class SMS
|
8
|
+
|
9
|
+
attr_accessor :phone, :subject, :message
|
10
|
+
attr_reader :code, :id
|
11
|
+
|
12
|
+
def initialize(phone, subject, message, ssl=true)
|
13
|
+
@port = ssl ? @@ssl_port : @@port
|
14
|
+
@ssl = ssl
|
15
|
+
@phone = phone
|
16
|
+
@subject = subject
|
17
|
+
@message = message
|
18
|
+
|
19
|
+
validate!
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.settings=(settings={})
|
23
|
+
@@login = settings[:login]
|
24
|
+
@@password = settings[:password]
|
25
|
+
@@server = settings[:server]
|
26
|
+
@@port = settings[:port]
|
27
|
+
@@ssl_port = settings[:ssl_port]
|
28
|
+
@@cert_store = OpenSSL::X509::Store.new
|
29
|
+
@@cert_store.add_cert OpenSSL::X509::Certificate.new File.read(settings[:cert])
|
30
|
+
|
31
|
+
validate_settings!
|
32
|
+
end
|
33
|
+
|
34
|
+
def ssl=(flag)
|
35
|
+
@port = flag ? @@ssl_port : @@port
|
36
|
+
@ssl = flag
|
37
|
+
end
|
38
|
+
|
39
|
+
def send
|
40
|
+
return stubbed_send if (defined?(Rails) && !Rails.env.production?)
|
41
|
+
|
42
|
+
establish_connection(@ssl).start do |http|
|
43
|
+
request = Net::HTTP::Get.new(send_url)
|
44
|
+
response = http.request(request)
|
45
|
+
splitted_body = response.body.split(';')
|
46
|
+
@code = splitted_body[0]
|
47
|
+
@id = splitted_body[2]
|
48
|
+
# result = case res_code
|
49
|
+
# when "ok" then "сообщения приняты на отправку"
|
50
|
+
# when "error-system" then "при обработке данного сообщения произошла системная ошибка"
|
51
|
+
# when "error-address-format" then "ошибка формата адреса"
|
52
|
+
# when "error-address-unknown" then "отправка по данному направлению не разрешена"
|
53
|
+
# when "error-subject-format" then "ошибка формата отправителя"
|
54
|
+
# when "error-subject-unknown" then "данный отправителть не разрешен на нашей платформе"
|
55
|
+
# end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Not used atm
|
60
|
+
|
61
|
+
# def self.status msg_id
|
62
|
+
# puts "Сообщение присвоен ID:"
|
63
|
+
# puts msg_id
|
64
|
+
|
65
|
+
# connection = establish_connection(@ssl)
|
66
|
+
# connection.start do |http|
|
67
|
+
# request = Net::HTTP::Get.new(status_url msg_id)
|
68
|
+
# response = http.request(request)
|
69
|
+
# splitted_body = response.body.split(';')
|
70
|
+
# res_code = splitted_body[0]
|
71
|
+
# result = case res_code
|
72
|
+
# when "ok" then "Запрос успешно обработан"
|
73
|
+
# when "error-system" then "Произошла системная ошибка"
|
74
|
+
# when "error-provider-id-unknown" then "Сообщение с таким идентификатором не найдено"
|
75
|
+
# end
|
76
|
+
# stat_code = splitted_body[2]
|
77
|
+
# unless stat_code.nil?
|
78
|
+
# @status = case stat_code
|
79
|
+
# when "enqueued" then "сообщение находится в очереди на отправку"
|
80
|
+
# when "sent" then "сообщение отправлено"
|
81
|
+
# when "delivered" then "сообщение доставлено до абонента"
|
82
|
+
# when "undelivered" then "сообщение недоставлено до абонента"
|
83
|
+
# when "failed" then "сообщение недоставлено из-за ошибки на платформе"
|
84
|
+
# when "delayed" then "было указано отложенное время отправки и сообщение ожидает его"
|
85
|
+
# when "cancelled" then "сообщение было отменено вручную на нашей платформе"
|
86
|
+
# end
|
87
|
+
# end
|
88
|
+
# end
|
89
|
+
|
90
|
+
# if @status
|
91
|
+
# @status
|
92
|
+
# else
|
93
|
+
# "ошибка"
|
94
|
+
# end
|
95
|
+
# end
|
96
|
+
|
97
|
+
# What for?
|
98
|
+
# def to_json
|
99
|
+
# {:url => "#{server}:#{port}#{url}", :sms_message => message}.to_json
|
100
|
+
# end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def stubbed_send
|
105
|
+
end
|
106
|
+
|
107
|
+
def establish_connection(ssl=true)
|
108
|
+
http = Net::HTTP.new(@@server, @port)
|
109
|
+
if ssl
|
110
|
+
http.cert_store = @@cert_store
|
111
|
+
http.use_ssl = true
|
112
|
+
end
|
113
|
+
http
|
114
|
+
end
|
115
|
+
|
116
|
+
def validate!
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.validate_settings!
|
120
|
+
end
|
121
|
+
|
122
|
+
def send_url
|
123
|
+
"/revoup/connector0/send?login=#{@@login}&password=#{@@password}&" +
|
124
|
+
"subject[0]=#{@subject}&address[0]=#{@phone}&text[0]=#{URI.encode(@message)}"
|
125
|
+
end
|
126
|
+
|
127
|
+
# Not used atm
|
128
|
+
|
129
|
+
# def status_url msg_id
|
130
|
+
# "/revoup/connector0/status?login=#{@@login}&password=#{@@password}&" +
|
131
|
+
# "providerId[0]=#{msg_id}"
|
132
|
+
# end
|
133
|
+
|
134
|
+
end
|
135
|
+
end
|
data/lib/mfms/version.rb
ADDED
data/mfms.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mfms/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mfms"
|
8
|
+
spec.version = Mfms::Version.to_s
|
9
|
+
spec.authors = ["Fokin Eugene", "Ilia Stepanov"]
|
10
|
+
spec.email = ["e.fokin@revoup.ru", "i.stepanov"]
|
11
|
+
spec.description = %q{This library helps to send sms via mfms service}
|
12
|
+
spec.summary = %q{Send sms via mfms service}
|
13
|
+
spec.homepage = "https://github.com/RevoTechnology/mfms"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mfms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fokin Eugene
|
8
|
+
- Ilia Stepanov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-27 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: This library helps to send sms via mfms service
|
15
|
+
email:
|
16
|
+
- e.fokin@revoup.ru
|
17
|
+
- i.stepanov
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- lib/mfms.rb
|
28
|
+
- lib/mfms/sms.rb
|
29
|
+
- lib/mfms/version.rb
|
30
|
+
- mfms.gemspec
|
31
|
+
homepage: https://github.com/RevoTechnology/mfms
|
32
|
+
licenses:
|
33
|
+
- MIT
|
34
|
+
metadata: {}
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 2.0.0
|
52
|
+
signing_key:
|
53
|
+
specification_version: 4
|
54
|
+
summary: Send sms via mfms service
|
55
|
+
test_files: []
|