mfms 0.1.1 → 0.2.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -6
  3. data/lib/mfms/sms.rb +69 -80
  4. data/lib/mfms/version.rb +2 -2
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90548a57b075fcd5f84cd9e0b3491bd988d5f3b0
4
- data.tar.gz: bfab3bc9ad2ec73d9173ca590e483d13cc735a48
3
+ metadata.gz: 6275368229d65373594802e1ea72a218dfde252b
4
+ data.tar.gz: 6f8c06258ad905b2904ca677a3b6b0d3628e0524
5
5
  SHA512:
6
- metadata.gz: b402976de6632c51cf29beff6dee03cb05f6556cce7c8b3357f34aa53867b4258b883f48ca7ae1f535bc99d090d2702b4ed836773fd2fe6e86e886d43a6eb42f
7
- data.tar.gz: 7d3e369a6eab28b6d65ca2aefe6ff83ce713ebbe27c1ff5b44e57755735b999b719375001a9cd3dd00d2643eecaef110ee3197f4dbd16fb60531afff25a68999
6
+ metadata.gz: a90c7ac25217b7810c0646db83bd8eb9aaed73f5c3518c9634c99313ac145e29ae5cdc8c878b7d19fa72fed1496aec83e365d07ca5a226f546bac61a707cca07
7
+ data.tar.gz: 9c90c71176091a054a52db407a36b6c1f040c5b1064e84cbbcd03142a972a97897589306ddabdf2330e4226de89cc12049d68cc1a9f6122770bfd76b493499f9
data/README.md CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- Define settinfs:
21
+ Define settings:
22
22
 
23
23
  Mfms::SMS.settings = {
24
24
  :login => 'login',
@@ -27,24 +27,32 @@ Define settinfs:
27
27
  :port => port,
28
28
  :ssl_port => ssl_port,
29
29
  :cert => 'path/to/cert',
30
+ :ssl => true # default is true
30
31
  }
31
32
 
32
33
  Initialize sms:
33
34
 
34
35
  sms = Mfms::SMS.new('phone','title','text') # initialize sms
35
36
 
36
- Send it and get sent sms id and dispatch code
37
+ Send it and get sent sms id and dispatch code:
37
38
 
38
- sms.send # send sms
39
+ sms.send # send sms. returns sms id or dispatch code if something went wrong
39
40
  sms.id # get sms id
40
- sms.code # get sms dispatch code
41
+
42
+ Get current sms status and update it:
43
+
44
+ sms.status # get sms delivery status
45
+ sms.update_status # updates sms delivery status. returns status or status check response code on error
46
+
47
+ Get any sms status:
48
+
49
+ code, status = Mfms::SMS.status(sms_id) # code - response code can contain error description, status - sms delivery status if code is 'ok'
41
50
 
42
51
  Ex.:
43
52
 
44
53
  sms = Mfms::SMS.new('79031111111','MyFavouriteCompany','Testing mfms gem')
45
- sms.send
54
+ sms.send # => 1032
46
55
  sms.id # => 1032
47
- sms.code # => ok
48
56
 
49
57
  ## Contributing
50
58
 
data/lib/mfms/sms.rb CHANGED
@@ -7,14 +7,13 @@ module Mfms
7
7
  class SMS
8
8
 
9
9
  attr_accessor :phone, :subject, :message
10
- attr_reader :code, :id
10
+ attr_reader :id, :status
11
11
 
12
- def initialize(phone, subject, message, ssl=true)
13
- @port = ssl ? @@ssl_port : @@port
14
- @ssl = ssl
12
+ def initialize(phone, subject, message)
15
13
  @phone = phone
16
14
  @subject = subject
17
15
  @message = message
16
+ @status = 'not-sent'
18
17
 
19
18
  validate!
20
19
  end
@@ -27,72 +26,68 @@ module Mfms
27
26
  @@ssl_port = settings[:ssl_port]
28
27
  @@cert_store = OpenSSL::X509::Store.new
29
28
  @@cert_store.add_cert OpenSSL::X509::Certificate.new File.read(settings[:cert])
29
+ @@ssl = settings[:ssl] & true # connect using ssl by default
30
30
 
31
31
  validate_settings!
32
32
  end
33
33
 
34
- def ssl=(flag)
35
- @port = flag ? @@ssl_port : @@port
36
- @ssl = flag
34
+ def self.ssl=(flag)
35
+ @@ssl = flag
37
36
  end
38
37
 
38
+ def self.ssl
39
+ @@ssl
40
+ end
41
+
42
+ # => SMS send status codes:
43
+ # "ok" "Сообщения приняты на отправку"
44
+ # "error-system" "При обработке данного сообщения произошла системная ошибка"
45
+ # "error-address-format" "Ошибка формата адреса"
46
+ # "error-address-unknown" "Отправка по данному направлению не разрешена"
47
+ # "error-subject-format" "Ошибка формата отправителя"
48
+ # "error-subject-unknown" "Данный отправителть не разрешен на нашей платформе"
49
+
39
50
  def send
40
51
  #return stubbed_send if (defined?(Rails) && !Rails.env.production?)
41
-
42
- establish_connection(@ssl).start do |http|
52
+ self.class.establish_connection.start do |http|
43
53
  request = Net::HTTP::Get.new(send_url)
44
54
  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
55
+ body = response.body.split(';')
56
+ return body[0] unless body[0] == 'ok'
57
+ @status = 'sent'
58
+ @id = body[2]
59
+ end
60
+ end
61
+
62
+ # => SMS delivery status codes:
63
+ # "enqueued" "Сообщение находится в очереди на отправку"
64
+ # "sent" "Сообщение отправлено"
65
+ # "delivered" "Сообщение доставлено до абонента"
66
+ # "undelivered" "Сообщение недоставлено до абонента"
67
+ # "failed" "Сообщение недоставлено из-за ошибки на платформе"
68
+ # "delayed" "Было указано отложенное время отправки и сообщение ожидает его"
69
+ # "cancelled" "Сообщение было отменено вручную на нашей платформе"
70
+
71
+ # => SMS status check response codes:
72
+ # "ok" "Запрос успешно обработан"
73
+ # "error-system" "Произошла системная ошибка"
74
+ # "error-provider-id-unknown" "Сообщение с таким идентификатором не найдено"
75
+
76
+ def self.status(id)
77
+ establish_connection.start do |http|
78
+ request = Net::HTTP::Get.new(status_url id)
79
+ response = http.request(request)
80
+ body = response.body.split(';')
81
+ return body[0], body[2] # code, status
56
82
  end
57
83
  end
58
84
 
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
85
+ def update_status
86
+ return @status if @id.nil?
87
+ code, status = self.class.status(@id)
88
+ return code unless code == 'ok'
89
+ @status = status
90
+ end
96
91
 
97
92
  # What for?
98
93
  # def to_json
@@ -101,35 +96,29 @@ module Mfms
101
96
 
102
97
  private
103
98
 
104
- #def stubbed_send
105
- #end
106
-
107
- def establish_connection(ssl=true)
108
- http = Net::HTTP.new(@@server, @port)
109
- if ssl
99
+ def self.establish_connection
100
+ port = @@ssl ? @@ssl_port : @@port
101
+ http = Net::HTTP.new(@@server, port)
102
+ http.use_ssl = @@ssl
110
103
  http.cert_store = @@cert_store
111
- http.use_ssl = true
104
+ http
112
105
  end
113
- http
114
- end
115
106
 
116
- def validate!
117
- end
118
-
119
- def self.validate_settings!
120
- end
107
+ def validate!
108
+ end
121
109
 
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
110
+ def self.validate_settings!
111
+ end
126
112
 
127
- # Not used atm
113
+ def send_url
114
+ "/revoup/connector0/send?login=#{@@login}&password=#{@@password}&" +
115
+ "subject[0]=#{@subject}&address[0]=#{@phone}&text[0]=#{URI.encode(@message)}"
116
+ end
128
117
 
129
- # def status_url msg_id
130
- # "/revoup/connector0/status?login=#{@@login}&password=#{@@password}&" +
131
- # "providerId[0]=#{msg_id}"
132
- # end
118
+ def self.status_url msg_id
119
+ "/revoup/connector0/status?login=#{@@login}&password=#{@@password}&" +
120
+ "providerId[0]=#{msg_id}"
121
+ end
133
122
 
134
123
  end
135
124
  end
data/lib/mfms/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Mfms
2
2
  class Version
3
3
  MAJOR = 0
4
- MINOR = 1
5
- PATCH = 1
4
+ MINOR = 2
5
+ PATCH = 0
6
6
 
7
7
  def self.to_s
8
8
  "#{MAJOR}.#{MINOR}.#{PATCH}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mfms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fokin Eugene
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-01 00:00:00.000000000 Z
12
+ date: 2013-03-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: This library helps to send sms via mfms service
15
15
  email: