tele42 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/lib/tele42.rb +44 -0
- data/lib/tele42/base.rb +57 -0
- data/lib/tele42/errors.rb +11 -0
- data/lib/tele42/sms.rb +86 -0
- data/lib/tele42/version.rb +3 -0
- data/spec/lib/tele42/base_spec.rb +36 -0
- data/spec/lib/tele42/sms_spec.rb +81 -0
- data/spec/lib/tele42_spec.rb +88 -0
- data/spec/spec_helper.rb +23 -0
- data/tele42.gemspec +26 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f27f25b71cb66cfe35ff51b709ef66ea03e8e27c
|
4
|
+
data.tar.gz: 0bbb7f4f2c13b785c45c62da0cd2271e858d5d45
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 64ab427a195bf19fe99c3963b557ab3b206c2348ea96e1d9638a10387920d8dec3c230a0a71c6fe016f9a712287314371a45a76465e2062b212d7871825ae546
|
7
|
+
data.tar.gz: 70afc1617c91653019d3e0a5d89702f941706dfdf07e3b92db0bd2e608bd0b9f5eee8a8d7e21a0ec8893baf4e347a1a7f97b331eead3608654709afb3a858a9d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Alexander Simonov
|
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,44 @@
|
|
1
|
+
# Tele42 [![Build Status](https://travis-ci.org/dotpromo/tele42.png?branch=master)](https://travis-ci.org/dotpromo/tele42) [![Coverage Status](https://coveralls.io/repos/dotpromo/tele42/badge.png)](https://coveralls.io/r/dotpromo/tele42) [![Code Climate](https://codeclimate.com/github/dotpromo/tele42.png)](https://codeclimate.com/github/dotpromo/tele42)
|
2
|
+
|
3
|
+
42 Telecom HTTP SMS-MT API wrapper
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tele42'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tele42
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
|
22
|
+
### Send text message
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# 42 Telecom specific client
|
26
|
+
client = ::Tele42::SMS.new({username: 'username', password: 'password', server: 'https://server1.msgtoolbox.com'})
|
27
|
+
# get result from 42 Telecom
|
28
|
+
id_of_sms_message = client.send_text(from: '1234567890', to: '1234567890', text: 'Hello world!')
|
29
|
+
```
|
30
|
+
|
31
|
+
## Ruby versions supporting
|
32
|
+
|
33
|
+
* 1.9.3
|
34
|
+
* 2.0.0
|
35
|
+
* Rubinius in 1.9 mode
|
36
|
+
* jRuby in 1.9 mode
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/tele42.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'faraday'
|
3
|
+
require 'kconv'
|
4
|
+
require 'tele42/version'
|
5
|
+
require 'tele42/errors'
|
6
|
+
require 'tele42/base'
|
7
|
+
require 'tele42/sms'
|
8
|
+
|
9
|
+
module Tele42
|
10
|
+
|
11
|
+
extend self
|
12
|
+
attr_accessor :debug, :username, :password, :server, :route, :callback_url
|
13
|
+
attr_writer :user_agent, :logger
|
14
|
+
|
15
|
+
# ensures the setup only gets run once
|
16
|
+
@_ran_once = false
|
17
|
+
|
18
|
+
def reset!
|
19
|
+
@_ran_once = false
|
20
|
+
@username = nil
|
21
|
+
@password = nil
|
22
|
+
@server = nil
|
23
|
+
@route = nil
|
24
|
+
@callback_url = nil
|
25
|
+
@user_agent = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def user_agent
|
29
|
+
@user_agent ||= "Tele42 v#{::Tele42::VERSION}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def setup
|
33
|
+
yield self unless @_ran_once
|
34
|
+
@_ran_once = true
|
35
|
+
end
|
36
|
+
|
37
|
+
def logger
|
38
|
+
@logger ||= Logger.new(STDOUT)
|
39
|
+
end
|
40
|
+
|
41
|
+
reset!
|
42
|
+
end
|
43
|
+
|
44
|
+
#require 'nexmos/railties' if defined?(::Rails)
|
data/lib/tele42/base.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Tele42
|
2
|
+
class Base
|
3
|
+
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
parse_options(options)
|
7
|
+
check_options
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse_options(args)
|
11
|
+
%w(username password server route).each do |k|
|
12
|
+
ks = k.to_sym
|
13
|
+
self.instance_variable_set("@#{k}".to_sym, args[ks] || ::Tele42.__send__(ks))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def default_params
|
18
|
+
@default_params ||= {
|
19
|
+
'username' => @username,
|
20
|
+
'password' => @password
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def check_options
|
25
|
+
raise ::Tele42::InvalidUserName, 'username should be set' if @username.nil? || @username.empty?
|
26
|
+
raise ::Tele42::InvalidPassword, 'password should be set' if @password.nil? || @password.empty?
|
27
|
+
raise ::Tele42::InvalidServer, 'server should be set' if @server.nil? || @server.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
def server_url
|
31
|
+
@server_url ||= begin
|
32
|
+
if @server =~ /http/
|
33
|
+
@server
|
34
|
+
else
|
35
|
+
"https://#{@server}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def faraday_options
|
41
|
+
{
|
42
|
+
:url => server_url,
|
43
|
+
:headers => {
|
44
|
+
:accept => 'text/html',
|
45
|
+
:user_agent => ::Tele42.user_agent
|
46
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def connection
|
51
|
+
@connection ||= Faraday::Connection.new(faraday_options) do |conn|
|
52
|
+
conn.request :url_encoded
|
53
|
+
conn.adapter Faraday.default_adapter
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end # Base
|
57
|
+
end # Tele42
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Tele42
|
2
|
+
class InvalidUserName < StandardError; end
|
3
|
+
class InvalidPassword < StandardError; end
|
4
|
+
class InvalidServer < StandardError; end
|
5
|
+
class InvalidFrom < StandardError; end
|
6
|
+
class InvalidRoute < StandardError; end
|
7
|
+
class BadLoginDetails < StandardError; end
|
8
|
+
class BadMessage < StandardError; end
|
9
|
+
class BadNumber < StandardError; end
|
10
|
+
class NotEnoughCredits < StandardError; end
|
11
|
+
end
|
data/lib/tele42/sms.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
module Tele42
|
2
|
+
class SMS < ::Tele42::Base
|
3
|
+
|
4
|
+
def initialize(options)
|
5
|
+
super(options)
|
6
|
+
check_route
|
7
|
+
end
|
8
|
+
|
9
|
+
def check_route
|
10
|
+
raise ::Tele42::InvalidRoute, 'route should be set' if @route.nil? || @route.empty?
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_params
|
14
|
+
@default_params ||= super.merge('route' => @route)
|
15
|
+
end
|
16
|
+
|
17
|
+
def unicode!
|
18
|
+
@unicode = true
|
19
|
+
end
|
20
|
+
|
21
|
+
def send_text(options = {})
|
22
|
+
from = options[:from]
|
23
|
+
to = options[:to]
|
24
|
+
message = options[:text]
|
25
|
+
check_from(from)
|
26
|
+
params = default_params.merge(
|
27
|
+
'to' => to,
|
28
|
+
'from' => from,
|
29
|
+
'message' => generate_message_for(:text, message)
|
30
|
+
)
|
31
|
+
if @unicode
|
32
|
+
params['coding'] = 'unicode'
|
33
|
+
end
|
34
|
+
res = connection.get('/api/current/send/message.php', params)
|
35
|
+
parse_result(res)
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse_result(res)
|
39
|
+
data = res.body.split(',')
|
40
|
+
if data[0].to_i == 1
|
41
|
+
data[1]
|
42
|
+
else
|
43
|
+
parse_error(data)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_error(data)
|
48
|
+
case data[1].to_i
|
49
|
+
when 1
|
50
|
+
raise ::Tele42::BadLoginDetails
|
51
|
+
when 2
|
52
|
+
raise ::Tele42::BadMessage
|
53
|
+
when 3
|
54
|
+
raise ::Tele42::BadNumber, "Bad to number #{data[2]}"
|
55
|
+
when 4
|
56
|
+
raise ::Tele42::NotEnoughCredits
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def generate_message_for(type, message)
|
61
|
+
case type
|
62
|
+
when :text
|
63
|
+
generate_text_message(message)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def generate_text_message(message)
|
68
|
+
if @unicode
|
69
|
+
if defined?(JRUBY_VERSION)
|
70
|
+
message.each_byte.map { |b| sprintf('00%02X', b) }.join
|
71
|
+
else
|
72
|
+
::Kconv.kconv(message, ::NKF::UTF16, ::NKF::UTF8).unpack('H*').first.upcase
|
73
|
+
end
|
74
|
+
else
|
75
|
+
message.force_encoding('iso-8859-1')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def check_from(from)
|
80
|
+
unless from =~ /\A\d{1,15}\z/ || from =~ /\A[[:alnum:]]{1,11}\z/
|
81
|
+
raise ::Tele42::InvalidFrom, 'invalid from format'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe ::Tele42::Base do
|
3
|
+
before(:each) do
|
4
|
+
::Tele42.reset!
|
5
|
+
end
|
6
|
+
let(:options) { {username: 'a', password: 'b', server: 'c'} }
|
7
|
+
subject { ::Tele42::Base.new(options) }
|
8
|
+
context '#new' do
|
9
|
+
it 'should call #parse_options and #check_options' do
|
10
|
+
options = {'a' => 'b'}
|
11
|
+
::Tele42::Base.any_instance.should_receive(:parse_options).with(options)
|
12
|
+
::Tele42::Base.any_instance.should_receive(:check_options)
|
13
|
+
::Tele42::Base.new(options)
|
14
|
+
end
|
15
|
+
it 'should raise with invalid user name error' do
|
16
|
+
expect { ::Tele42::Base.new({'a' => 'b'}) }.to raise_error(::Tele42::InvalidUserName)
|
17
|
+
end
|
18
|
+
it 'should raise with invalid password error' do
|
19
|
+
expect { ::Tele42::Base.new(username: 'a') }.to raise_error(::Tele42::InvalidPassword)
|
20
|
+
end
|
21
|
+
it 'should raise with invalid server error' do
|
22
|
+
expect { ::Tele42::Base.new(username: 'a', password: 'b') }.to raise_error(::Tele42::InvalidServer)
|
23
|
+
end
|
24
|
+
it 'should ser proper instance variables' do
|
25
|
+
subject.instance_variable_get(:@username).should == 'a'
|
26
|
+
subject.instance_variable_get(:@password).should == 'b'
|
27
|
+
subject.instance_variable_get(:@server).should == 'c'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
its(:default_params) { should == {'username' => 'a', 'password' => 'b'} }
|
31
|
+
its(:server_url) { should == 'https://c' }
|
32
|
+
its(:faraday_options) { should == {url: 'https://c', headers: { accept: 'text/html', user_agent: "Tele42 v#{::Tele42::VERSION}" }} }
|
33
|
+
its(:connection) { should be_a(::Faraday::Connection) }
|
34
|
+
context '#connection' do
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe ::Tele42::SMS do
|
3
|
+
before(:each) do
|
4
|
+
::Tele42.reset!
|
5
|
+
end
|
6
|
+
let(:options) { {username: 'a', password: 'b', server: 'c', route: 'd'} }
|
7
|
+
subject { ::Tele42::SMS.new(options) }
|
8
|
+
context '#new' do
|
9
|
+
it 'should call #check_route' do
|
10
|
+
options = {'a' => 'b'}
|
11
|
+
::Tele42::SMS.any_instance.should_receive(:parse_options).with(options)
|
12
|
+
::Tele42::SMS.any_instance.should_receive(:check_options)
|
13
|
+
::Tele42::SMS.any_instance.should_receive(:check_route)
|
14
|
+
::Tele42::SMS.new(options)
|
15
|
+
end
|
16
|
+
it 'should raise with invalid route error' do
|
17
|
+
expect { ::Tele42::SMS.new(username: 'a', password: 'b', server: 'c') }.to raise_error(::Tele42::InvalidRoute)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
its(:default_params) { should == {'username' => 'a', 'password' => 'b', 'route' => 'd'} }
|
21
|
+
context '#send_text' do
|
22
|
+
it 'should call #check_from' do
|
23
|
+
stub_request(:get, "https://c/api/current/send/message.php?from=12345678&message=foobar&password=b&route=d&to=1234567&username=a").
|
24
|
+
with(:headers => {'Accept'=>'text/html', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Tele42 v0.0.1'}).
|
25
|
+
to_return(:status => 200, :body => "1,2,1", :headers => {})
|
26
|
+
subject.should_receive(:check_from).with('12345678')
|
27
|
+
subject.send_text(to: '1234567', from: '12345678', text: 'foobar')
|
28
|
+
end
|
29
|
+
it 'should call #generate_message_for' do
|
30
|
+
stub_request(:get, "https://c/api/current/send/message.php?from=12345678&message=foobar&password=b&route=d&to=1234567&username=a").
|
31
|
+
with(:headers => {'Accept'=>'text/html', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Tele42 v0.0.1'}).
|
32
|
+
to_return(:status => 200, :body => "1,2,1", :headers => {})
|
33
|
+
subject.should_receive(:generate_message_for).with(:text, 'foobar').and_call_original
|
34
|
+
subject.send_text(to: '1234567', from: '12345678', text: 'foobar')
|
35
|
+
end
|
36
|
+
it 'should call #parse_result' do
|
37
|
+
stub_request(:get, "https://c/api/current/send/message.php?from=12345678&message=foobar&password=b&route=d&to=1234567&username=a").
|
38
|
+
with(:headers => {'Accept'=>'text/html', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Tele42 v0.0.1'}).
|
39
|
+
to_return(:status => 200, :body => "1,2,1", :headers => {})
|
40
|
+
subject.should_receive(:parse_result).and_call_original
|
41
|
+
subject.send_text(to: '1234567', from: '12345678', text: 'foobar')
|
42
|
+
end
|
43
|
+
it 'should return proper sms message id' do
|
44
|
+
stub_request(:get, "https://c/api/current/send/message.php?from=12345678&message=foobar&password=b&route=d&to=1234567&username=a").
|
45
|
+
with(:headers => {'Accept'=>'text/html', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Tele42 v0.0.1'}).
|
46
|
+
to_return(:status => 200, :body => "1,message_id,1", :headers => {})
|
47
|
+
subject.send_text(to: '1234567', from: '12345678', text: 'foobar').should == 'message_id'
|
48
|
+
end
|
49
|
+
it 'should raise error BadLoginDetails' do
|
50
|
+
stub_request(:get, "https://c/api/current/send/message.php?from=12345678&message=foobar&password=b&route=d&to=1234567&username=a").
|
51
|
+
with(:headers => {'Accept'=>'text/html', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Tele42 v0.0.1'}).
|
52
|
+
to_return(:status => 200, :body => "0,1", :headers => {})
|
53
|
+
expect { subject.send_text(to: '1234567', from: '12345678', text: 'foobar') }.to raise_error(::Tele42::BadLoginDetails)
|
54
|
+
end
|
55
|
+
it 'should raise error BadMessage' do
|
56
|
+
stub_request(:get, "https://c/api/current/send/message.php?from=12345678&message=foobar&password=b&route=d&to=1234567&username=a").
|
57
|
+
with(:headers => {'Accept'=>'text/html', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Tele42 v0.0.1'}).
|
58
|
+
to_return(:status => 200, :body => "0,2", :headers => {})
|
59
|
+
expect { subject.send_text(to: '1234567', from: '12345678', text: 'foobar') }.to raise_error(::Tele42::BadMessage)
|
60
|
+
end
|
61
|
+
it 'should raise error BadNumber' do
|
62
|
+
stub_request(:get, "https://c/api/current/send/message.php?from=12345678&message=foobar&password=b&route=d&to=1234567&username=a").
|
63
|
+
with(:headers => {'Accept'=>'text/html', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Tele42 v0.0.1'}).
|
64
|
+
to_return(:status => 200, :body => "0,3,12345678", :headers => {})
|
65
|
+
expect { subject.send_text(to: '1234567', from: '12345678', text: 'foobar') }.to raise_error(::Tele42::BadNumber, 'Bad to number 12345678')
|
66
|
+
end
|
67
|
+
it 'should raise error NotEnoughCredits' do
|
68
|
+
stub_request(:get, "https://c/api/current/send/message.php?from=12345678&message=foobar&password=b&route=d&to=1234567&username=a").
|
69
|
+
with(:headers => {'Accept'=>'text/html', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Tele42 v0.0.1'}).
|
70
|
+
to_return(:status => 200, :body => "0,4", :headers => {})
|
71
|
+
expect { subject.send_text(to: '1234567', from: '12345678', text: 'foobar') }.to raise_error(::Tele42::NotEnoughCredits)
|
72
|
+
end
|
73
|
+
it 'should send sms in unicode variant' do
|
74
|
+
stub_request(:get, "https://c/api/current/send/message.php?coding=unicode&from=12345678&message=00480065006C006C006F00200057006F0072006C0064&password=b&route=d&to=1234567&username=a").
|
75
|
+
with(:headers => {'Accept'=>'text/html', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Tele42 v0.0.1'}).
|
76
|
+
to_return(:status => 200, :body => "1,nessage_id,1", :headers => {})
|
77
|
+
subject.unicode!
|
78
|
+
subject.send_text(to: '1234567', from: '12345678', text: 'Hello World')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe ::Tele42 do
|
3
|
+
|
4
|
+
subject { ::Tele42 }
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
subject.reset!
|
8
|
+
end
|
9
|
+
|
10
|
+
context '#reset!' do
|
11
|
+
its(:user_agent) { should == "Tele42 v#{::Tele42::VERSION}" }
|
12
|
+
its(:username) { should be_nil }
|
13
|
+
its(:password) { should be_nil }
|
14
|
+
its(:server) { should be_nil }
|
15
|
+
its(:route) { should be_nil }
|
16
|
+
its(:callback_url) { should be_nil }
|
17
|
+
its(:logger) { should be_kind_of(::Logger) }
|
18
|
+
end
|
19
|
+
|
20
|
+
context '#setup' do
|
21
|
+
|
22
|
+
context 'single call' do
|
23
|
+
it 'should set user_agent' do
|
24
|
+
subject.setup do |c|
|
25
|
+
c.user_agent = 'Test1245'
|
26
|
+
end
|
27
|
+
subject.user_agent.should == 'Test1245'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should set logger' do
|
31
|
+
newlogger = ::Logger.new(STDERR)
|
32
|
+
subject.setup do |c|
|
33
|
+
c.logger = newlogger
|
34
|
+
end
|
35
|
+
subject.logger.should == newlogger
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should set username' do
|
39
|
+
subject.setup do |c|
|
40
|
+
c.username = 'username'
|
41
|
+
end
|
42
|
+
subject.username.should == 'username'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should set password' do
|
46
|
+
subject.setup do |c|
|
47
|
+
c.password = 'password'
|
48
|
+
end
|
49
|
+
subject.password.should == 'password'
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should set server' do
|
53
|
+
subject.setup do |c|
|
54
|
+
c.server = 'server'
|
55
|
+
end
|
56
|
+
subject.server.should == 'server'
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should set route' do
|
60
|
+
subject.setup do |c|
|
61
|
+
c.route = 'route1'
|
62
|
+
end
|
63
|
+
subject.route.should == 'route1'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should set callback_url' do
|
67
|
+
subject.setup do |c|
|
68
|
+
c.callback_url = 'http://example.com/'
|
69
|
+
end
|
70
|
+
subject.callback_url.should == 'http://example.com/'
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'double call' do
|
76
|
+
it 'should not accept running setup more then once' do
|
77
|
+
subject.setup do |c|
|
78
|
+
c.username = 'user1'
|
79
|
+
end
|
80
|
+
subject.setup do |c|
|
81
|
+
c.username = 'user2'
|
82
|
+
end
|
83
|
+
subject.username.should == 'user1'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require 'coveralls'
|
8
|
+
Coveralls.wear!
|
9
|
+
require 'webmock'
|
10
|
+
require 'webmock/rspec'
|
11
|
+
require 'tele42'
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
15
|
+
config.run_all_when_everything_filtered = true
|
16
|
+
config.filter_run :focus
|
17
|
+
|
18
|
+
# Run specs in random order to surface order dependencies. If you find an
|
19
|
+
# order dependency and want to debug it, you can fix the order by providing
|
20
|
+
# the seed, which is printed after each run.
|
21
|
+
# --seed 1234
|
22
|
+
config.order = 'random'
|
23
|
+
end
|
data/tele42.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tele42/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tele42"
|
8
|
+
spec.version = Tele42::VERSION
|
9
|
+
spec.authors = ["Alexander Simonov"]
|
10
|
+
spec.email = ["alex@simonov.me"]
|
11
|
+
spec.description = %q{42 Telecom SMS-MT API wrapper}
|
12
|
+
spec.summary = %q{42 Telecom SMS-MT API wrapper}
|
13
|
+
spec.homepage = "https://github.com/dotpromo/tele42"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'webmock'
|
25
|
+
spec.add_dependency('faraday')
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tele42
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Simonov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-07 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
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: rspec
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: 42 Telecom SMS-MT API wrapper
|
84
|
+
email:
|
85
|
+
- alex@simonov.me
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- .travis.yml
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- lib/tele42.rb
|
98
|
+
- lib/tele42/base.rb
|
99
|
+
- lib/tele42/errors.rb
|
100
|
+
- lib/tele42/sms.rb
|
101
|
+
- lib/tele42/version.rb
|
102
|
+
- spec/lib/tele42/base_spec.rb
|
103
|
+
- spec/lib/tele42/sms_spec.rb
|
104
|
+
- spec/lib/tele42_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- tele42.gemspec
|
107
|
+
homepage: https://github.com/dotpromo/tele42
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.0.6
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: 42 Telecom SMS-MT API wrapper
|
131
|
+
test_files:
|
132
|
+
- spec/lib/tele42/base_spec.rb
|
133
|
+
- spec/lib/tele42/sms_spec.rb
|
134
|
+
- spec/lib/tele42_spec.rb
|
135
|
+
- spec/spec_helper.rb
|