messagebird 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +13 -0
- data/VERSION +1 -1
- data/lib/messagebird.rb +1 -0
- data/lib/messagebird/config.rb +2 -1
- data/lib/messagebird/http/local_connection.rb +15 -0
- data/lib/messagebird/http/sender.rb +22 -2
- data/messagebird.gemspec +5 -3
- data/test/messagebird/http/local_connection_test.rb +29 -0
- data/test/messagebird/http/sender_test.rb +40 -22
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdf8c0f25e17948ac7a654fec62921c47b53a113
|
4
|
+
data.tar.gz: c524dba34f1ca0b23e94f756c6855167d15889d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7ea06262d1e743ffd96b5bc47ef35b337d1bac02a7799748d3c59e1719f5190f5111e64ea249a9c3444e59c84998df0cb2e3e8e9a166b71a1104477e6a7c865
|
7
|
+
data.tar.gz: 20201d522b0c8249fd80521eeb2842af4d84b95889e6570ecea74502321e523e5f9579a30464b1e0390aab2e141cdc3a21505a2155b318e43568a791dad9d9d0
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
0.1.4
|
2
|
+
-----------
|
3
|
+
- Introduces a new config option :enabled, which is set to false by default.
|
4
|
+
This was added to prevent test and development enviroments from establishing actual connections
|
5
|
+
to the MessageBird servers. Connections may be enabled by setting:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
MessageBird.configure do
|
9
|
+
enabled true
|
10
|
+
end
|
11
|
+
```
|
12
|
+
|
13
|
+
|
1
14
|
0.1.3
|
2
15
|
-----------
|
3
16
|
- Sender_ID is now validated. Valid formats are:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/messagebird.rb
CHANGED
@@ -8,6 +8,7 @@ require 'messagebird/config'
|
|
8
8
|
require 'messagebird/deliverable'
|
9
9
|
require 'messagebird/helpers'
|
10
10
|
require 'messagebird/sms'
|
11
|
+
require 'messagebird/http/local_connection'
|
11
12
|
require 'messagebird/http/sender'
|
12
13
|
require 'messagebird/http/sms'
|
13
14
|
require 'messagebird/http/response_code'
|
data/lib/messagebird/config.rb
CHANGED
@@ -3,6 +3,7 @@ module MessageBird::HTTP
|
|
3
3
|
class << self
|
4
4
|
|
5
5
|
attr_writer :response_factory
|
6
|
+
attr_writer :enabled
|
6
7
|
|
7
8
|
def deliver(sms, &block)
|
8
9
|
ensure_valid_sms!(sms)
|
@@ -27,7 +28,7 @@ module MessageBird::HTTP
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def create_connection(uri)
|
30
|
-
|
31
|
+
connection_factory.call(uri.host, uri.port).tap do |http|
|
31
32
|
http.use_ssl = true
|
32
33
|
# http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
33
34
|
end
|
@@ -41,8 +42,27 @@ module MessageBird::HTTP
|
|
41
42
|
raise ArgumentError unless obj.is_a? MessageBird::HTTP::SMS
|
42
43
|
end
|
43
44
|
|
45
|
+
def connection_factory
|
46
|
+
@connection_factory ||= connection_class.method(:new)
|
47
|
+
end
|
48
|
+
|
44
49
|
def response_factory
|
45
|
-
@response_factory ||= Response.
|
50
|
+
@response_factory ||= Response.method(:new)
|
51
|
+
end
|
52
|
+
|
53
|
+
def enabled
|
54
|
+
if @enabled.nil?
|
55
|
+
@enabled = MessageBird::Config.enabled
|
56
|
+
end
|
57
|
+
@enabled
|
58
|
+
end
|
59
|
+
|
60
|
+
def connection_class
|
61
|
+
if enabled
|
62
|
+
Net::HTTP
|
63
|
+
else
|
64
|
+
LocalConnection
|
65
|
+
end
|
46
66
|
end
|
47
67
|
|
48
68
|
end
|
data/messagebird.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: messagebird 0.1.
|
5
|
+
# stub: messagebird 0.1.4 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "messagebird"
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.4"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Bram de Vries"]
|
14
|
-
s.date = "2014-
|
14
|
+
s.date = "2014-02-11"
|
15
15
|
s.description = "Implementation of the MessageBird SMS API for Ruby"
|
16
16
|
s.email = "dev@blaet.net"
|
17
17
|
s.executables = ["messagebird_test_connection"]
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/messagebird/config.rb",
|
33
33
|
"lib/messagebird/deliverable.rb",
|
34
34
|
"lib/messagebird/helpers.rb",
|
35
|
+
"lib/messagebird/http/local_connection.rb",
|
35
36
|
"lib/messagebird/http/response.rb",
|
36
37
|
"lib/messagebird/http/response_code.rb",
|
37
38
|
"lib/messagebird/http/sender.rb",
|
@@ -42,6 +43,7 @@ Gem::Specification.new do |s|
|
|
42
43
|
"test/messagebird/config_test.rb",
|
43
44
|
"test/messagebird/deliverable_test.rb",
|
44
45
|
"test/messagebird/helpers_test.rb",
|
46
|
+
"test/messagebird/http/local_connection_test.rb",
|
45
47
|
"test/messagebird/http/response_code_test.rb",
|
46
48
|
"test/messagebird/http/response_test.rb",
|
47
49
|
"test/messagebird/http/sender_test.rb",
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe MessageBird::HTTP::LocalConnection do
|
4
|
+
|
5
|
+
let(:klass){ MessageBird::HTTP::LocalConnection }
|
6
|
+
|
7
|
+
subject{ klass.new("host", "port") }
|
8
|
+
|
9
|
+
describe '#initialize' do
|
10
|
+
it 'takes two arguments' do
|
11
|
+
klass.new("host", "port")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#request' do
|
16
|
+
it 'responds to #request' do
|
17
|
+
assert subject.respond_to?(:request)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'takes one argument' do
|
21
|
+
subject.request("")
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'always returns an object that responds with the :success response body' do
|
25
|
+
subject.request("").body.must_equal "01"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -15,39 +15,32 @@ describe MessageBird::HTTP::Sender do
|
|
15
15
|
stub(mock_connection).request{:bar}
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
mock(subject).send_sms(:foo)
|
22
|
-
subject.deliver(:foo)
|
23
|
-
end
|
18
|
+
after do
|
19
|
+
subject.enabled = false
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
stub(subject).send_request.with_any_args{'FooBat'}
|
30
|
-
subject.send(:send_sms, sms) do |response|
|
31
|
-
response.must_equal 'FooBat'
|
32
|
-
end
|
22
|
+
describe '#connection_class' do
|
23
|
+
it 'returns a Net::HTTP class' do
|
24
|
+
subject.enabled = true
|
25
|
+
subject.send(:connection_class).must_equal Net::HTTP
|
33
26
|
end
|
34
27
|
|
35
|
-
|
36
|
-
|
37
|
-
subject.
|
38
|
-
|
28
|
+
describe 'local_loop variable set to true' do
|
29
|
+
it 'returns a LocalConnection class' do
|
30
|
+
subject.send(:connection_class).must_equal MessageBird::HTTP::LocalConnection
|
31
|
+
end
|
39
32
|
end
|
40
33
|
end
|
41
34
|
|
42
35
|
describe '#create_connection' do
|
43
36
|
it 'creates a new connection' do
|
44
|
-
mock(
|
37
|
+
mock(MessageBird::HTTP::LocalConnection).new.with_any_args{mock_connection}
|
45
38
|
subject.send :create_connection, uri
|
46
39
|
end
|
47
40
|
|
48
41
|
it 'sets the connection to SSL' do
|
49
42
|
mock(mock_connection).use_ssl=(true)
|
50
|
-
stub(
|
43
|
+
stub(MessageBird::HTTP::LocalConnection).new.with_any_args{mock_connection}
|
51
44
|
subject.send :create_connection, uri
|
52
45
|
end
|
53
46
|
end
|
@@ -59,9 +52,33 @@ describe MessageBird::HTTP::Sender do
|
|
59
52
|
end
|
60
53
|
end
|
61
54
|
|
55
|
+
describe '#deliver' do
|
56
|
+
it 'sends the given sms' do
|
57
|
+
stub(subject).ensure_valid_sms!
|
58
|
+
mock(subject).send_sms(:foo)
|
59
|
+
subject.deliver(:foo)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'takes an optional block' do
|
63
|
+
stub(subject).ensure_valid_sms!
|
64
|
+
stub(subject).create_connection.with_any_args
|
65
|
+
stub(subject).create_request.with_any_args
|
66
|
+
stub(subject).send_request.with_any_args{'FooBat'}
|
67
|
+
subject.send(:send_sms, sms) do |response|
|
68
|
+
response.must_equal 'FooBat'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'raises an ArgumentError when given object is not a valid SMS' do
|
73
|
+
assert_raises(ArgumentError){
|
74
|
+
subject.deliver('string')
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
62
79
|
describe '#response_factory' do
|
63
80
|
it 'works' do
|
64
|
-
|
81
|
+
subject.send(:response_factory).is_a?(Method)
|
65
82
|
end
|
66
83
|
end
|
67
84
|
|
@@ -87,11 +104,12 @@ describe MessageBird::HTTP::Sender do
|
|
87
104
|
subject.send :send_sms, sms
|
88
105
|
end
|
89
106
|
|
90
|
-
it '
|
107
|
+
it 'sends the request over the connection' do
|
91
108
|
stub(subject).create_connection.with_any_args{:foo}
|
92
109
|
stub(subject).create_request.with_any_args{:bar}
|
93
110
|
mock(subject).send_request(:foo, :bar){:bat}
|
94
111
|
subject.send :send_sms, sms
|
95
112
|
end
|
96
113
|
end
|
114
|
+
|
97
115
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: messagebird
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bram de Vries
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jeweler
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- lib/messagebird/config.rb
|
46
46
|
- lib/messagebird/deliverable.rb
|
47
47
|
- lib/messagebird/helpers.rb
|
48
|
+
- lib/messagebird/http/local_connection.rb
|
48
49
|
- lib/messagebird/http/response.rb
|
49
50
|
- lib/messagebird/http/response_code.rb
|
50
51
|
- lib/messagebird/http/sender.rb
|
@@ -55,6 +56,7 @@ files:
|
|
55
56
|
- test/messagebird/config_test.rb
|
56
57
|
- test/messagebird/deliverable_test.rb
|
57
58
|
- test/messagebird/helpers_test.rb
|
59
|
+
- test/messagebird/http/local_connection_test.rb
|
58
60
|
- test/messagebird/http/response_code_test.rb
|
59
61
|
- test/messagebird/http/response_test.rb
|
60
62
|
- test/messagebird/http/sender_test.rb
|