sms24x7 0.1.0 → 0.2.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: ef9489a23b505f0b5d55145e6fbd9f1a3e18f89b
4
+ data.tar.gz: ddfa04b66da1a6632d4316756e1c544f6ef2ca3a
5
+ SHA512:
6
+ metadata.gz: 0d5f0920931f6a9e4f44c7abbc53d11d9cd895a77f8149ca3a0c01666524bd5190c8f44cdc7dae697651a8f79e860590e7b74c7031a4e82e7e3e27a14f6f6ca7
7
+ data.tar.gz: 605442ff1b11b9d89720056a81ab2a28a45b003aa4b47008c091475bdc72bc27555b59c58052a8a5f3be0c89fac97e16b0913971639046d012c03bc90e94456d
data/LICENSE CHANGED
@@ -1,22 +1,8 @@
1
- Copyright (c) 2012 Gleb Averchuk
1
+ Copyright (c) 2012, Gleb Averchuk
2
+ All rights reserved.
2
3
 
3
- MIT License
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
5
 
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.
6
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/sms24x7.png)](http://badge.fury.io/rb/sms24x7)
2
+
1
3
  # Sms24x7
2
4
 
3
5
  Sending SMS via sms24x7 API. For more details see http://sms24x7.ru/api/
@@ -20,12 +22,21 @@ Or install it yourself as:
20
22
 
21
23
  In the begining, you need to [register](http://outbox.sms24x7.ru/registration.php?pattern_id=2) for sending SMS through sms24x7 gateway.
22
24
 
25
+ Before sending SMS, you need to configure SmsApi with login credentials:
26
+
27
+ ```
28
+ SmsApi.setup do |config|
29
+ config.email = 'your@email.com'
30
+ config.password = 'your_password'
31
+ end
32
+ ```
33
+
23
34
  There are two ways for sending your SMS.
24
35
 
25
36
  The first - it's sending a SMS to one recipient. To do this, use:
26
37
 
27
38
  ```
28
- SmsApi.push_msg_nologin('your@email.com', 'your_password', 'recipient_phone', 'sms_text', params)
39
+ SmsApi.push_msg_nologin('recipient_phone', 'sms_text', params)
29
40
  ```
30
41
 
31
42
  here `recipient_phone` - is a phone number in format '7xxxyyyzzzz' and `params` - additional params that you can see in [documentation](http://sms24x7.ru/wp-content/uploads/2011/04/api_manual.pdf).
@@ -33,18 +44,12 @@ here `recipient_phone` - is a phone number in format '7xxxyyyzzzz' and `params`
33
44
  The second way - it's sending multiple SMS to multiple recipients.
34
45
 
35
46
  ```
36
- SmsApi.login('your@email.com', 'your_password')
37
- recipient_phones_str_arr.each do |recipient_phone|
38
- SmsApi.push_msg(recipient_phone, 'sms_text', params)
47
+ SmsApi.login do
48
+ recipient_phones_str_arr.each do |recipient_phone|
49
+ SmsApi.push_msg(recipient_phone, 'sms_text', params)
50
+ end
39
51
  end
40
52
  ```
41
53
 
42
54
  here `recipient_phones_str_arr` - it's array that consist phone numbers as strings in format that represented above.
43
55
 
44
- ## Contributing
45
-
46
- 1. Fork it
47
- 2. Create your feature branch (`git checkout -b my-new-feature`)
48
- 3. Commit your changes (`git commit -am 'Added some feature'`)
49
- 4. Push to the branch (`git push origin my-new-feature`)
50
- 5. Create new Pull Request
@@ -1,5 +1,6 @@
1
1
  require 'curb-fu'
2
2
  require 'json/pure'
3
+ require 'active_support/core_ext/module/attribute_accessors'
3
4
 
4
5
  module SmsApi
5
6
  SMS_HOST = 'api.sms24x7.ru'
@@ -14,8 +15,19 @@ module SmsApi
14
15
  class NoGateError < BaseError; end
15
16
  class OtherError < BaseError; end
16
17
 
18
+ # Login info
19
+ mattr_accessor :email
20
+ mattr_accessor :password
21
+
22
+ # Session cookie
23
+ mattr_reader :cookie
24
+
17
25
  module_function
18
26
 
27
+ def setup
28
+ yield self
29
+ end
30
+
19
31
  # Public: Sends request to API
20
32
  #
21
33
  # request - Associative array to pass to API, :format key will be overridden
@@ -59,7 +71,6 @@ module SmsApi
59
71
 
60
72
  # Public: Sends a message via sms24x7 API, combining authenticating and sending message in one request.
61
73
  #
62
- # email, passwrod - Login info
63
74
  # phone - Recipient phone number in international format (like 7xxxyyyzzzz)
64
75
  # text - Message text, ASCII or UTF-8.
65
76
  # params - Additional parameters as key => value array, see API doc.
@@ -70,11 +81,11 @@ module SmsApi
70
81
  # :credits => credits - Price for a single part
71
82
  # }
72
83
  #
73
- def push_msg_nologin(email, password, phone, text, params = {})
84
+ def push_msg_nologin(phone, text, params = {})
74
85
  request = {
75
86
  :method => 'push_msg',
76
- :email => email,
77
- :password => password,
87
+ :email => @@email,
88
+ :password => @@password,
78
89
  :phone => phone,
79
90
  :text => text
80
91
  }.merge(params)
@@ -84,27 +95,30 @@ module SmsApi
84
95
 
85
96
  # Public: Logs in API, producing a session ID to be sent back in session cookie.
86
97
  #
87
- # email - User's email
88
- # password - User's password
89
- #
90
98
  # Returns:
91
- # cookie - Is a string "sid=#{session_id}" to be passed to cURL
99
+ # cookie - Is a string "sid=#{session_id}" to be passed to cURL if no block given
92
100
  #
93
- def login(email, password)
101
+ def login
94
102
  request = {
95
103
  :method => 'login',
96
- :email => email,
97
- :password => password
104
+ :email => @@email,
105
+ :password => @@password
98
106
  }
99
107
  responce = _communicate(request)
100
108
  raise InterfaceError, "Login request OK, but no 'sid' set" unless (sid = responce[:data]['sid'])
101
- @_cookie = "sid=#{CGI::escape(sid)}"
109
+ @@cookie = "sid=#{CGI::escape(sid)}"
110
+
111
+ if block_given?
112
+ yield
113
+ @@cookie = nil
114
+ end
115
+
116
+ @@cookie
102
117
  end
103
118
 
104
119
  # Public: Sends message via API, using previously obtained cookie to authenticate.
105
120
  # That is, must first call the login method.
106
121
  #
107
- # cookie - String, returned by smsapi_login, "sid=#{session_id}"
108
122
  # phone - Target phone
109
123
  # text - Message text, ASCII or UTF-8
110
124
  # params - Dictionary of optional parameters, see API documentation of push_msg method
@@ -116,13 +130,13 @@ module SmsApi
116
130
  # }
117
131
  #
118
132
  def push_msg(phone, text, params = {})
119
- raise NoLoginError, 'Must first call the login method' unless @_cookie
133
+ raise NoLoginError, 'Must first call the login method' unless @@cookie
120
134
  request = {
121
135
  :method => 'push_msg',
122
136
  :phone => phone,
123
137
  :text => text
124
138
  }.merge(params)
125
- responce = _communicate(request, @_cookie)
139
+ responce = _communicate(request, @@cookie)
126
140
  check_and_result_push_msg(responce)
127
141
  end
128
142
 
@@ -141,7 +155,6 @@ module SmsApi
141
155
  unless (n_raw_sms = data['n_raw_sms']) && (credits = data['credits'])
142
156
  raise InterfaceError, "Could not find 'n_raw_sms' or 'credits' in successful push_msg response"
143
157
  end
144
- #{ :n_raw_sms => n_raw_sms.to_i, :credits => credits.to_f }
145
158
  data
146
159
  end
147
160
  end
@@ -1,3 +1,3 @@
1
1
  module SmsApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/sms24x7.gemspec CHANGED
@@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency 'curb-fu'
19
19
  gem.add_dependency 'json'
20
+ gem.add_dependency 'activesupport', '>= 3.2.1'
20
21
  end
@@ -2,16 +2,27 @@ require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe SmsApi do
4
4
  describe 'Testing sms24x7 api calls' do
5
+ def error_message(variable, filename, line_number = nil)
6
+ msg = "Please setup your #{variable} in spec/#{filename}"
7
+ msg << " at line ##{line_number}" if line_number
8
+ msg
9
+ end
10
+
11
+ def check_email_and_password
12
+ SmsApi.email.should_not be_nil, error_message('email', 'spec_helper.rb')
13
+ SmsApi.email.should match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/), error_message('email', 'spec_helper.rb')
14
+
15
+ SmsApi.password.should_not be_nil, error_message('password', 'spec_helper.rb')
16
+ SmsApi.password.should_not eq(''), error_message('password', 'spec_helper.rb')
17
+ end
18
+
5
19
  it 'sending SMS' do
6
- email = 'your@email.com'
7
- password = 'your_password'
8
- phone = '79991234567' # your phone
20
+ check_email_and_password
9
21
 
10
- email.should match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/), 'We need your email'
11
- password.should_not eq(''), 'We need your password'
12
- phone.should_not eq(''), 'We need your phone number'
22
+ phone = '' # <- enter here your phone number
23
+ phone.should_not eq(''), error_message('phone number', 'functional_spec.rb', __LINE__ - 1)
13
24
 
14
- sending_result = SmsApi.push_msg_nologin(email, password, phone, 'test passed',
25
+ sending_result = SmsApi.push_msg_nologin(phone, 'test passed',
15
26
  :sender_name => 'RSpec',
16
27
  :api => '1.1',
17
28
  :satellite_adv => 'IF_EXISTS')
@@ -20,10 +31,32 @@ describe SmsApi do
20
31
  sending_result.should have_key('credits')
21
32
  end
22
33
 
34
+ it 'sending multiple SMS' do
35
+ check_email_and_password
36
+
37
+ phones = %w() # <- enter here a few of your phone numbers
38
+ phones.should_not be_empty, error_message('phone numbers', 'functional_spec.rb', __LINE__ - 1)
39
+
40
+ SmsApi.login do
41
+ phones.each do |phone|
42
+ sending_result = SmsApi.push_msg_nologin(phone, 'multiple SMS test passed')
43
+ sending_result.should have_key('n_raw_sms')
44
+ sending_result.should have_key('credits')
45
+ end
46
+ end
47
+
48
+ SmsApi.cookie.should be_nil
49
+ end
50
+
23
51
  it 'incorrect email and password' do
24
- lambda {
25
- SmsApi.push_msg_nologin('test@test.tt', 'T_T', '79991234567', 'wrong')
26
- }.should raise_error(SmsApi::AuthError)
52
+ SmsApi.setup do |config|
53
+ config.email = 'test@test.tt'
54
+ config.password = 'T_T'
55
+ end
56
+
57
+ expect {
58
+ SmsApi.push_msg_nologin('79991234567', 'wrong')
59
+ }.to raise_error(SmsApi::AuthError)
27
60
  end
28
61
  end
29
62
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,8 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'sms24x7'
3
3
  require 'rspec'
4
+
5
+ SmsApi.setup do |config|
6
+ config.email = '' # <- enter your email here
7
+ config.password = '' # <- enter your password here
8
+ end
metadata CHANGED
@@ -1,38 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sms24x7
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gleb Averchuk
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-04-05 00:00:00.000000000 Z
11
+ date: 2013-11-05 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: curb-fu
16
- requirement: &11599700 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *11599700
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: json
27
- requirement: &11598620 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *11598620
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.1
36
55
  description: Sending SMS via sms24x7 API
37
56
  email:
38
57
  - altermn@gmail.com
@@ -53,27 +72,26 @@ files:
53
72
  - spec/spec_helper.rb
54
73
  homepage: https://github.com/newmen/sms24x7
55
74
  licenses: []
75
+ metadata: {}
56
76
  post_install_message:
57
77
  rdoc_options: []
58
78
  require_paths:
59
79
  - lib
60
80
  required_ruby_version: !ruby/object:Gem::Requirement
61
- none: false
62
81
  requirements:
63
- - - ! '>='
82
+ - - '>='
64
83
  - !ruby/object:Gem::Version
65
84
  version: '0'
66
85
  required_rubygems_version: !ruby/object:Gem::Requirement
67
- none: false
68
86
  requirements:
69
- - - ! '>='
87
+ - - '>='
70
88
  - !ruby/object:Gem::Version
71
89
  version: '0'
72
90
  requirements: []
73
91
  rubyforge_project:
74
- rubygems_version: 1.8.17
92
+ rubygems_version: 2.0.3
75
93
  signing_key:
76
- specification_version: 3
94
+ specification_version: 4
77
95
  summary: Uses sms24x7 gateway for sending SMS
78
96
  test_files:
79
97
  - spec/functional_spec.rb