elk 0.0.13 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.MD +38 -12
- data/lib/elk.rb +31 -75
- data/lib/elk/client.rb +77 -0
- data/lib/elk/error.rb +16 -0
- data/lib/elk/number.rb +42 -18
- data/lib/elk/sms.rb +49 -24
- data/lib/elk/util.rb +13 -3
- data/lib/elk/version.rb +1 -1
- data/spec/fixtures/sends_a_sms_to_multiple_recipients.txt +1 -1
- data/spec/fixtures/sends_a_sms_with_long_sender.txt +2 -2
- data/spec/integration/number_spec.rb +191 -0
- data/spec/integration/sms_spec.rb +241 -0
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +9 -3
- data/spec/unit/client_spec.rb +69 -0
- data/spec/unit/elk_spec.rb +70 -0
- data/spec/unit/number_spec.rb +93 -0
- data/spec/unit/sms_spec.rb +66 -0
- data/spec/unit/utils_spec.rb +50 -0
- metadata +27 -35
- data/spec/elk/number_spec.rb +0 -117
- data/spec/elk/sms_spec.rb +0 -168
- data/spec/elk_spec.rb +0 -58
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
1
|
require 'rspec'
|
4
2
|
require 'webmock/rspec'
|
5
3
|
|
@@ -16,4 +14,12 @@ def configure_elk
|
|
16
14
|
config.username = 'USERNAME'
|
17
15
|
config.password = 'PASSWORD'
|
18
16
|
end
|
19
|
-
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_headers
|
20
|
+
{ "Accept" => "application/json" }
|
21
|
+
end
|
22
|
+
|
23
|
+
def post_headers
|
24
|
+
{ "Accept" => "application/json", "Content-Type" => "application/x-www-form-urlencoded" }
|
25
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "elk"
|
3
|
+
|
4
|
+
describe Elk::Client do
|
5
|
+
it { is_expected.to respond_to(:configure) }
|
6
|
+
it { is_expected.to respond_to(:base_url) }
|
7
|
+
it { is_expected.to respond_to(:base_domain) }
|
8
|
+
it { is_expected.to respond_to(:username) }
|
9
|
+
it { is_expected.to respond_to(:username=) }
|
10
|
+
it { is_expected.to respond_to(:password) }
|
11
|
+
it { is_expected.to respond_to(:password=) }
|
12
|
+
|
13
|
+
let(:username) { "username" }
|
14
|
+
let(:password) { "password" }
|
15
|
+
|
16
|
+
it "should accept username and password" do
|
17
|
+
client = Elk::Client.new(username: username, password: password)
|
18
|
+
expect(client.username).to eq(username)
|
19
|
+
expect(client.password).to eq(password)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ".base_url" do
|
23
|
+
context "detect missing username and/or password" do
|
24
|
+
context "when nothing is configured" do
|
25
|
+
specify do
|
26
|
+
subject.configure do |config|
|
27
|
+
config.username = nil
|
28
|
+
config.password = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
expect { subject.base_url }.to raise_error(Elk::AuthError)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when username is missing" do
|
36
|
+
specify do
|
37
|
+
subject.configure do |config|
|
38
|
+
config.username = nil
|
39
|
+
config.password = "PASSWORD"
|
40
|
+
end
|
41
|
+
|
42
|
+
expect { subject.base_url }.to raise_error(Elk::AuthError)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when password is missing" do
|
47
|
+
specify do
|
48
|
+
subject.configure do |config|
|
49
|
+
config.username = "USERNAME"
|
50
|
+
config.password = nil
|
51
|
+
end
|
52
|
+
|
53
|
+
expect { subject.base_url }.to raise_error(Elk::AuthError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when all is configured" do
|
58
|
+
specify do
|
59
|
+
subject.configure do |config|
|
60
|
+
config.username = "USERNAME"
|
61
|
+
config.password = "PASSWORD"
|
62
|
+
end
|
63
|
+
|
64
|
+
expect { subject.base_url }.not_to raise_error
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "elk"
|
3
|
+
|
4
|
+
describe Elk do
|
5
|
+
|
6
|
+
subject { Elk }
|
7
|
+
|
8
|
+
it { is_expected.to respond_to(:client) }
|
9
|
+
it { is_expected.to respond_to(:configure) }
|
10
|
+
it { is_expected.to respond_to(:base_url) }
|
11
|
+
it { is_expected.to respond_to(:base_domain) }
|
12
|
+
it { is_expected.to respond_to(:username) }
|
13
|
+
it { is_expected.to respond_to(:username=) }
|
14
|
+
it { is_expected.to respond_to(:password) }
|
15
|
+
it { is_expected.to respond_to(:password=) }
|
16
|
+
|
17
|
+
describe ".client" do
|
18
|
+
it "should reuse the same client object" do
|
19
|
+
expect(Elk.client.object_id).to eq(Elk.client.object_id)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe ".base_url" do
|
24
|
+
context "detect missing username and/or password" do
|
25
|
+
context "when nothing is configured" do
|
26
|
+
specify do
|
27
|
+
subject.configure do |config|
|
28
|
+
config.username = nil
|
29
|
+
config.password = nil
|
30
|
+
end
|
31
|
+
|
32
|
+
expect { subject.base_url }.to raise_error(Elk::AuthError)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when username is missing" do
|
37
|
+
specify do
|
38
|
+
subject.configure do |config|
|
39
|
+
config.username = nil
|
40
|
+
config.password = "PASSWORD"
|
41
|
+
end
|
42
|
+
|
43
|
+
expect { subject.base_url }.to raise_error(Elk::AuthError)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when password is missing" do
|
48
|
+
specify do
|
49
|
+
subject.configure do |config|
|
50
|
+
config.username = "USERNAME"
|
51
|
+
config.password = nil
|
52
|
+
end
|
53
|
+
|
54
|
+
expect { subject.base_url }.to raise_error(Elk::AuthError)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when all is configured" do
|
59
|
+
specify do
|
60
|
+
subject.configure do |config|
|
61
|
+
config.username = "USERNAME"
|
62
|
+
config.password = "PASSWORD"
|
63
|
+
end
|
64
|
+
|
65
|
+
expect { subject.base_url }.not_to raise_error
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "elk"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
describe Elk::Number do
|
6
|
+
subject(:number) { described_class.new({}) }
|
7
|
+
|
8
|
+
let(:client) { instance_double(Elk::Client) }
|
9
|
+
|
10
|
+
describe "#new" do
|
11
|
+
context "when passing a client" do
|
12
|
+
subject(:number) { described_class.new(client: client) }
|
13
|
+
|
14
|
+
it "should use the passed in client" do
|
15
|
+
expect(number.client).to eq(client)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "without passing a client" do
|
20
|
+
it "should instantiate a client" do
|
21
|
+
expect(number.client).to be_an(Elk::Client)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#status" do
|
27
|
+
subject(:status) { described_class.new(active: active).status }
|
28
|
+
|
29
|
+
context "with an active number" do
|
30
|
+
let(:active) { "yes" }
|
31
|
+
|
32
|
+
it { is_expected.to eq(:active) }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with an deallocated number" do
|
36
|
+
let(:active) { "no" }
|
37
|
+
|
38
|
+
it { is_expected.to eq(:deallocated) }
|
39
|
+
end
|
40
|
+
|
41
|
+
context "without any status" do
|
42
|
+
let(:active) { }
|
43
|
+
|
44
|
+
it { is_expected.to eq(nil) }
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with an unknown status" do
|
48
|
+
let(:active) { "bananas" }
|
49
|
+
|
50
|
+
it { is_expected.to eq(nil) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe ".allocate" do
|
55
|
+
let(:allocate_response) { double("Response", body: JSON.dump({}) ) }
|
56
|
+
|
57
|
+
context "when passing a client" do
|
58
|
+
it "should use the passed in client" do
|
59
|
+
expect(client).to receive(:post)
|
60
|
+
.with("/Numbers", country: "no") { allocate_response }
|
61
|
+
described_class.allocate(client: client, country: "no")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "without passing a client" do
|
66
|
+
it "should instantiate a client" do
|
67
|
+
expect_any_instance_of(Elk::Client).to receive(:post)
|
68
|
+
.with("/Numbers", country: "no") { allocate_response }
|
69
|
+
described_class.allocate(country: "no")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe ".all" do
|
75
|
+
let(:all_response) { double("Response", body: JSON.dump(data: []) ) }
|
76
|
+
|
77
|
+
context "when passing a client" do
|
78
|
+
it "should use the passed in client" do
|
79
|
+
expect(client).to receive(:get)
|
80
|
+
.with("/Numbers") { all_response }
|
81
|
+
described_class.all(client: client)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "without passing a client" do
|
86
|
+
it "should instantiate a client" do
|
87
|
+
expect_any_instance_of(Elk::Client).to receive(:get)
|
88
|
+
.with("/Numbers") { all_response }
|
89
|
+
described_class.all
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "elk"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
describe Elk::SMS do
|
6
|
+
subject(:sms) { described_class.new({}) }
|
7
|
+
|
8
|
+
let(:client) { instance_double(Elk::Client) }
|
9
|
+
|
10
|
+
describe "#new" do
|
11
|
+
context "when passing a client" do
|
12
|
+
subject(:sms) { described_class.new(client: client) }
|
13
|
+
|
14
|
+
it "should use the passed in client" do
|
15
|
+
expect(sms.client).to eq(client)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "without passing a client" do
|
20
|
+
it "should instantiate a client" do
|
21
|
+
expect(sms.client).to be_an(Elk::Client)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe ".send" do
|
27
|
+
let(:sms_response) { double("Response", body: JSON.dump({}) ) }
|
28
|
+
|
29
|
+
context "when passing a client" do
|
30
|
+
it "should use the passed in client" do
|
31
|
+
expect(client).to receive(:post)
|
32
|
+
.with("/SMS", from: "", to: "", message: "") { sms_response }
|
33
|
+
described_class.send(client: client, from: "", to: "", message: "")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "without passing a client" do
|
38
|
+
it "should instantiate a client" do
|
39
|
+
expect_any_instance_of(Elk::Client).to receive(:post)
|
40
|
+
.with("/SMS", from: "", to: "", message: "") { sms_response }
|
41
|
+
described_class.send(from: "", to: "", message: "")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".all" do
|
48
|
+
let(:all_response) { double("Response", body: JSON.dump(data: []) ) }
|
49
|
+
|
50
|
+
context "when passing a client" do
|
51
|
+
it "should use the passed in client" do
|
52
|
+
expect(client).to receive(:get)
|
53
|
+
.with("/SMS") { all_response }
|
54
|
+
described_class.all(client: client)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "without passing a client" do
|
59
|
+
it "should instantiate a client" do
|
60
|
+
expect_any_instance_of(Elk::Client).to receive(:get)
|
61
|
+
.with("/SMS") { all_response }
|
62
|
+
described_class.all
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "elk"
|
3
|
+
|
4
|
+
describe Elk::Util do
|
5
|
+
describe "#verify_parameters" do
|
6
|
+
let(:parameters) { { from: "mom", to: "god" } }
|
7
|
+
|
8
|
+
context "with all required parameters" do
|
9
|
+
let(:required_parameters) { [:from, :to] }
|
10
|
+
|
11
|
+
it "should not raise any exceptions" do
|
12
|
+
extend Elk::Util
|
13
|
+
expect {
|
14
|
+
verify_parameters(parameters, required_parameters)
|
15
|
+
}.to_not raise_error
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with a missing required parameter" do
|
20
|
+
let(:required_parameters) { [:from, :to, :message] }
|
21
|
+
|
22
|
+
it "should raise missing parameter exception" do
|
23
|
+
extend Elk::Util
|
24
|
+
expect {
|
25
|
+
verify_parameters(parameters, required_parameters)
|
26
|
+
}.to raise_error(Elk::MissingParameter)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".parse_json" do
|
32
|
+
subject { Elk::Util }
|
33
|
+
|
34
|
+
context "with empty object body" do
|
35
|
+
let(:body) { "{}" }
|
36
|
+
|
37
|
+
it "should return empty hash" do
|
38
|
+
expect(subject.parse_json(body)).to eq({})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with garbage json" do
|
43
|
+
let(:body) { fixture("bad_response_body.txt").read }
|
44
|
+
|
45
|
+
it "should raise bad response exception" do
|
46
|
+
expect { subject.parse_json(body) }.to raise_error(Elk::BadResponse)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,83 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Johan
|
7
|
+
- Johan Eckerström
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: multi_json
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rest-client
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
|
-
- - ~>
|
17
|
+
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
19
|
version: '1.6'
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
|
-
- - ~>
|
24
|
+
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
26
|
version: '1.6'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rake
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
|
-
- - ~>
|
31
|
+
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
33
|
version: '10.0'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- - ~>
|
38
|
+
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '10.0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rspec
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- - ~>
|
45
|
+
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
47
|
+
version: '3.0'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- - ~>
|
52
|
+
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
54
|
+
version: '3.0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: webmock
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- - ~>
|
59
|
+
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
61
|
version: '1.0'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- - ~>
|
66
|
+
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '1.0'
|
83
69
|
description: Elk can be used to allocate a phone numbers, manage the numbers and send
|
@@ -89,16 +75,15 @@ extra_rdoc_files:
|
|
89
75
|
- README.MD
|
90
76
|
- MIT-LICENSE
|
91
77
|
files:
|
92
|
-
- README.MD
|
93
78
|
- MIT-LICENSE
|
79
|
+
- README.MD
|
80
|
+
- lib/elk.rb
|
81
|
+
- lib/elk/client.rb
|
82
|
+
- lib/elk/error.rb
|
94
83
|
- lib/elk/number.rb
|
95
84
|
- lib/elk/sms.rb
|
96
85
|
- lib/elk/util.rb
|
97
86
|
- lib/elk/version.rb
|
98
|
-
- lib/elk.rb
|
99
|
-
- spec/elk/number_spec.rb
|
100
|
-
- spec/elk/sms_spec.rb
|
101
|
-
- spec/elk_spec.rb
|
102
87
|
- spec/fixtures/allocates_a_number.txt
|
103
88
|
- spec/fixtures/auth_error.txt
|
104
89
|
- spec/fixtures/bad_response_body.txt
|
@@ -114,8 +99,15 @@ files:
|
|
114
99
|
- spec/fixtures/server_error.txt
|
115
100
|
- spec/fixtures/sms_history.txt
|
116
101
|
- spec/fixtures/updates_a_number.txt
|
102
|
+
- spec/integration/number_spec.rb
|
103
|
+
- spec/integration/sms_spec.rb
|
117
104
|
- spec/spec.opts
|
118
105
|
- spec/spec_helper.rb
|
106
|
+
- spec/unit/client_spec.rb
|
107
|
+
- spec/unit/elk_spec.rb
|
108
|
+
- spec/unit/number_spec.rb
|
109
|
+
- spec/unit/sms_spec.rb
|
110
|
+
- spec/unit/utils_spec.rb
|
119
111
|
homepage: https://github.com/jage/elk
|
120
112
|
licenses:
|
121
113
|
- MIT
|
@@ -126,18 +118,18 @@ require_paths:
|
|
126
118
|
- lib
|
127
119
|
required_ruby_version: !ruby/object:Gem::Requirement
|
128
120
|
requirements:
|
129
|
-
- -
|
121
|
+
- - ">="
|
130
122
|
- !ruby/object:Gem::Version
|
131
123
|
version: 1.9.3
|
132
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
125
|
requirements:
|
134
|
-
- -
|
126
|
+
- - ">="
|
135
127
|
- !ruby/object:Gem::Version
|
136
128
|
version: '0'
|
137
129
|
requirements:
|
138
130
|
- API account at 46elks.com
|
139
131
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.
|
132
|
+
rubygems_version: 2.4.5.1
|
141
133
|
signing_key:
|
142
134
|
specification_version: 4
|
143
135
|
summary: Client library for 46elks SMS/MMS/Voice service.
|