elk 0.0.3p0 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.MD +1 -1
- data/lib/elk.rb +13 -1
- data/lib/elk/number.rb +1 -0
- data/lib/elk/sms.rb +7 -6
- data/spec/elk_spec.rb +34 -4
- data/spec/fixtures/invalid_to_number.txt +8 -0
- data/spec/fixtures/no_parameters.txt +8 -0
- metadata +48 -8
data/README.MD
CHANGED
data/lib/elk.rb
CHANGED
@@ -10,11 +10,13 @@ require 'elk/sms'
|
|
10
10
|
module Elk
|
11
11
|
BASE_DOMAIN = 'api.46elks.com'
|
12
12
|
API_VERSION = 'a1'
|
13
|
-
VERSION = '0.0.
|
13
|
+
VERSION = '0.0.4'
|
14
14
|
|
15
15
|
class AuthError < RuntimeError; end
|
16
16
|
class ServerError < RuntimeError; end
|
17
17
|
class BadResponse < RuntimeError; end
|
18
|
+
class BadRequest < RuntimeError; end
|
19
|
+
class MissingParameter < RuntimeError; end
|
18
20
|
|
19
21
|
class << self
|
20
22
|
attr_accessor :username
|
@@ -45,6 +47,8 @@ module Elk
|
|
45
47
|
raise AuthError, "Authentication failed"
|
46
48
|
rescue RestClient::InternalServerError
|
47
49
|
raise ServerError, "Server error"
|
50
|
+
rescue RestClient::Forbidden => e
|
51
|
+
raise BadRequest, e.http_body
|
48
52
|
end
|
49
53
|
|
50
54
|
def parse_json(body)
|
@@ -53,4 +57,12 @@ module Elk
|
|
53
57
|
raise BadResponse, "Can't parse JSON"
|
54
58
|
end
|
55
59
|
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Hash
|
63
|
+
def require_keys!(required_keys)
|
64
|
+
unless (missing_parameters = required_keys - self.keys).empty?
|
65
|
+
raise Elk::MissingParameter, "Requires #{missing_parameters.collect {|s| ":#{s}"}.join(', ')} parameters"
|
66
|
+
end
|
67
|
+
end
|
56
68
|
end
|
data/lib/elk/number.rb
CHANGED
data/lib/elk/sms.rb
CHANGED
@@ -22,15 +22,16 @@ module Elk
|
|
22
22
|
end
|
23
23
|
|
24
24
|
class << self
|
25
|
-
def send(
|
26
|
-
parameters
|
27
|
-
|
28
|
-
self.new(Elk.parse_json(response.body))
|
29
|
-
ensure
|
25
|
+
def send(parameters)
|
26
|
+
parameters.require_keys!([:from, :message, :to])
|
27
|
+
|
30
28
|
# Warn if the from string will be capped by the sms gateway
|
31
|
-
if parameters[:from].match(/^(\w{11,})$/)
|
29
|
+
if parameters[:from] && parameters[:from].match(/^(\w{11,})$/)
|
32
30
|
warn "SMS 'from' value #{parameters[:from]} will be capped at 11 chars"
|
33
31
|
end
|
32
|
+
|
33
|
+
response = Elk.post('/SMS', parameters)
|
34
|
+
self.new(Elk.parse_json(response.body))
|
34
35
|
end
|
35
36
|
|
36
37
|
def all
|
data/spec/elk_spec.rb
CHANGED
@@ -2,6 +2,14 @@ require 'spec_helper'
|
|
2
2
|
require 'elk'
|
3
3
|
|
4
4
|
describe Elk do
|
5
|
+
it 'should handle garbage json' do
|
6
|
+
bad_response_body = fixture('bad_response_body.txt').read
|
7
|
+
|
8
|
+
expect {
|
9
|
+
Elk.parse_json(bad_response_body)
|
10
|
+
}.to raise_error(Elk::BadResponse)
|
11
|
+
end
|
12
|
+
|
5
13
|
describe Elk::Number do
|
6
14
|
it 'allocates a number' do
|
7
15
|
stub_request(:post, "https://USERNAME:PASSWORD@api.46elks.com/a1/Numbers").
|
@@ -120,12 +128,12 @@ describe Elk do
|
|
120
128
|
}.to raise_error(Elk::ServerError)
|
121
129
|
end
|
122
130
|
|
123
|
-
it '
|
124
|
-
|
131
|
+
it 'should handle no parameters' do
|
132
|
+
configure_elk
|
125
133
|
|
126
134
|
expect {
|
127
|
-
Elk.
|
128
|
-
}.to raise_error(Elk::
|
135
|
+
sms = Elk::Number.allocate({})
|
136
|
+
}.to raise_error(Elk::MissingParameter)
|
129
137
|
end
|
130
138
|
end
|
131
139
|
|
@@ -221,5 +229,27 @@ describe Elk do
|
|
221
229
|
sms.message.should == 'Your order #171 has now been sent!'
|
222
230
|
end
|
223
231
|
|
232
|
+
it 'should handle invalid to number' do
|
233
|
+
stub_request(:post, "https://USERNAME:PASSWORD@api.46elks.com/a1/SMS").
|
234
|
+
with(:body => {"from" => "+46761042247", :message => "Your order #171 has now been sent!", :to => "monkey"},
|
235
|
+
:headers => {'Accept'=>'application/json', 'Content-Type'=>'application/x-www-form-urlencoded'}).
|
236
|
+
to_return(fixture('invalid_to_number.txt'))
|
237
|
+
|
238
|
+
configure_elk
|
239
|
+
|
240
|
+
expect {
|
241
|
+
sms = Elk::SMS.send(:from => '+46761042247',
|
242
|
+
:to => 'monkey',
|
243
|
+
:message => 'Your order #171 has now been sent!')
|
244
|
+
}.to raise_error(Elk::BadRequest, 'Invalid to number')
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'should handle no parameters' do
|
248
|
+
configure_elk
|
249
|
+
|
250
|
+
expect {
|
251
|
+
sms = Elk::SMS.send({})
|
252
|
+
}.to raise_error(Elk::MissingParameter)
|
253
|
+
end
|
224
254
|
end
|
225
255
|
end
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Johan Eckerstroem
|
@@ -10,7 +15,8 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-18 00:00:00 +02:00
|
19
|
+
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: json_pure
|
@@ -20,6 +26,11 @@ dependencies:
|
|
20
26
|
requirements:
|
21
27
|
- - ~>
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 5
|
33
|
+
- 2
|
23
34
|
version: 1.5.2
|
24
35
|
type: :runtime
|
25
36
|
version_requirements: *id001
|
@@ -31,6 +42,11 @@ dependencies:
|
|
31
42
|
requirements:
|
32
43
|
- - ~>
|
33
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 9
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 6
|
49
|
+
- 3
|
34
50
|
version: 1.6.3
|
35
51
|
type: :runtime
|
36
52
|
version_requirements: *id002
|
@@ -42,6 +58,11 @@ dependencies:
|
|
42
58
|
requirements:
|
43
59
|
- - ~>
|
44
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 63
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
- 9
|
65
|
+
- 2
|
45
66
|
version: 0.9.2
|
46
67
|
type: :development
|
47
68
|
version_requirements: *id003
|
@@ -53,6 +74,11 @@ dependencies:
|
|
53
74
|
requirements:
|
54
75
|
- - ~>
|
55
76
|
- !ruby/object:Gem::Version
|
77
|
+
hash: 23
|
78
|
+
segments:
|
79
|
+
- 2
|
80
|
+
- 6
|
81
|
+
- 0
|
56
82
|
version: 2.6.0
|
57
83
|
type: :development
|
58
84
|
version_requirements: *id004
|
@@ -64,10 +90,15 @@ dependencies:
|
|
64
90
|
requirements:
|
65
91
|
- - ~>
|
66
92
|
- !ruby/object:Gem::Version
|
93
|
+
hash: 7
|
94
|
+
segments:
|
95
|
+
- 1
|
96
|
+
- 6
|
97
|
+
- 4
|
67
98
|
version: 1.6.4
|
68
99
|
type: :development
|
69
100
|
version_requirements: *id005
|
70
|
-
description:
|
101
|
+
description: Used to configure numbers, send/reciev SMS/MMS/Voice messages at 46elks
|
71
102
|
email: johan@duh.se
|
72
103
|
executables: []
|
73
104
|
|
@@ -85,6 +116,8 @@ files:
|
|
85
116
|
- spec/fixtures/bad_response_body.txt
|
86
117
|
- spec/fixtures/deallocates_a_number.txt
|
87
118
|
- spec/fixtures/gets_allocated_numbers.txt
|
119
|
+
- spec/fixtures/invalid_to_number.txt
|
120
|
+
- spec/fixtures/no_parameters.txt
|
88
121
|
- spec/fixtures/reloads_a_number.txt
|
89
122
|
- spec/fixtures/reloads_a_sms.txt
|
90
123
|
- spec/fixtures/sends_a_sms.txt
|
@@ -94,7 +127,8 @@ files:
|
|
94
127
|
- spec/fixtures/updates_a_number.txt
|
95
128
|
- spec/spec_helper.rb
|
96
129
|
- README.MD
|
97
|
-
|
130
|
+
has_rdoc: true
|
131
|
+
homepage:
|
98
132
|
licenses: []
|
99
133
|
|
100
134
|
post_install_message:
|
@@ -107,17 +141,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
141
|
requirements:
|
108
142
|
- - ">="
|
109
143
|
- !ruby/object:Gem::Version
|
144
|
+
hash: 3
|
145
|
+
segments:
|
146
|
+
- 0
|
110
147
|
version: "0"
|
111
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
149
|
none: false
|
113
150
|
requirements:
|
114
|
-
- - "
|
151
|
+
- - ">="
|
115
152
|
- !ruby/object:Gem::Version
|
116
|
-
|
153
|
+
hash: 3
|
154
|
+
segments:
|
155
|
+
- 0
|
156
|
+
version: "0"
|
117
157
|
requirements: []
|
118
158
|
|
119
159
|
rubyforge_project:
|
120
|
-
rubygems_version: 1.
|
160
|
+
rubygems_version: 1.3.7
|
121
161
|
signing_key:
|
122
162
|
specification_version: 3
|
123
163
|
summary: Client library for 46elks SMS/MMS/Voice service.
|