sms_aero 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.codeclimate.yml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +17 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +126 -0
- data/Rakefile +6 -0
- data/lib/sms_aero.rb +55 -0
- data/lib/sms_aero/models/answer.rb +8 -0
- data/lib/sms_aero/models/sms.rb +15 -0
- data/lib/sms_aero/models/tariff.rb +8 -0
- data/lib/sms_aero/operations/add_blacklist.rb +11 -0
- data/lib/sms_aero/operations/add_group.rb +11 -0
- data/lib/sms_aero/operations/add_phone.rb +17 -0
- data/lib/sms_aero/operations/check_balance.rb +11 -0
- data/lib/sms_aero/operations/check_groups.rb +12 -0
- data/lib/sms_aero/operations/check_senders.rb +15 -0
- data/lib/sms_aero/operations/check_sending.rb +11 -0
- data/lib/sms_aero/operations/check_sign.rb +15 -0
- data/lib/sms_aero/operations/check_status.rb +11 -0
- data/lib/sms_aero/operations/check_tariff.rb +12 -0
- data/lib/sms_aero/operations/delete_group.rb +11 -0
- data/lib/sms_aero/operations/delete_phone.rb +12 -0
- data/lib/sms_aero/operations/send_sms.rb +17 -0
- data/lib/sms_aero/operations/send_to_group.rb +15 -0
- data/lib/sms_aero/types/birthday.rb +20 -0
- data/lib/sms_aero/types/channel.rb +4 -0
- data/lib/sms_aero/types/digital.rb +8 -0
- data/lib/sms_aero/types/filled_string.rb +3 -0
- data/lib/sms_aero/types/future.rb +16 -0
- data/lib/sms_aero/types/phone.rb +12 -0
- data/lib/sms_aero/types/sign_status.rb +9 -0
- data/sms_aero.gemspec +23 -0
- data/spec/sms_aero/operations/add_blacklist_spec.rb +88 -0
- data/spec/sms_aero/operations/add_group_spec.rb +88 -0
- data/spec/sms_aero/operations/add_phone_spec.rb +221 -0
- data/spec/sms_aero/operations/check_balance_spec.rb +85 -0
- data/spec/sms_aero/operations/check_groups_spec.rb +72 -0
- data/spec/sms_aero/operations/check_senders_spec.rb +98 -0
- data/spec/sms_aero/operations/check_sending_spec.rb +88 -0
- data/spec/sms_aero/operations/check_sign_spec.rb +87 -0
- data/spec/sms_aero/operations/check_status_spec.rb +88 -0
- data/spec/sms_aero/operations/check_tariff_spec.rb +72 -0
- data/spec/sms_aero/operations/delete_group_spec.rb +88 -0
- data/spec/sms_aero/operations/delete_phone_spec.rb +118 -0
- data/spec/sms_aero/operations/send_sms_spec.rb +179 -0
- data/spec/sms_aero/operations/send_to_group_spec.rb +171 -0
- data/spec/sms_aero/types/birthday_spec.rb +33 -0
- data/spec/sms_aero/types/channel_spec.rb +19 -0
- data/spec/sms_aero/types/digital_spec.rb +15 -0
- data/spec/sms_aero/types/future_spec.rb +38 -0
- data/spec/sms_aero/types/phone_spec.rb +21 -0
- data/spec/sms_aero/types/sign_status_spec.rb +19 -0
- data/spec/spec_helper.rb +20 -0
- metadata +205 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
RSpec.describe SmsAero, "#check_tariff" do
|
2
|
+
let(:settings) { { user: "LOGIN", password: "PASSWORD" } }
|
3
|
+
let(:client) { described_class.new(settings) }
|
4
|
+
let(:params) { {} }
|
5
|
+
let(:answer) { { result: "accepted", reason: { "Direct channel": "1.75" } } }
|
6
|
+
|
7
|
+
before { stub_request(:any, //).to_return(body: answer.to_json) }
|
8
|
+
subject { client.check_tariff(params) }
|
9
|
+
|
10
|
+
context "using ssl via POST:" do
|
11
|
+
let(:host) { "https://gate.smsaero.ru/checktarif" }
|
12
|
+
let(:query) { "answer=json&password=PASSWORD&user=LOGIN" }
|
13
|
+
|
14
|
+
it "sends a request" do
|
15
|
+
subject
|
16
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns statuses" do
|
20
|
+
expect(subject.result).to eq "accepted"
|
21
|
+
expect(subject.tariff).to eq direct: 1.75
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "via GET:" do
|
26
|
+
let(:host) { "https://gate.smsaero.ru/checktarif" }
|
27
|
+
let(:query) { "answer=json&password=PASSWORD&user=LOGIN" }
|
28
|
+
|
29
|
+
before { settings[:use_post] = false }
|
30
|
+
|
31
|
+
it "sends a request" do
|
32
|
+
subject
|
33
|
+
expect(a_request(:get, "#{host}?#{query}")).to have_been_made
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "not using ssl:" do
|
38
|
+
let(:host) { "http://gate.smsaero.ru/checktarif" }
|
39
|
+
let(:query) { "answer=json&password=PASSWORD&user=LOGIN" }
|
40
|
+
|
41
|
+
before { settings[:use_ssl] = false }
|
42
|
+
|
43
|
+
it "sends a request" do
|
44
|
+
subject
|
45
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "with custom user:" do
|
50
|
+
let(:host) { "https://gate.smsaero.ru/checktarif" }
|
51
|
+
let(:query) { "answer=json&password=PASSWORD&user=USER" }
|
52
|
+
|
53
|
+
before { params[:user] = "USER" }
|
54
|
+
|
55
|
+
it "sends a request" do
|
56
|
+
subject
|
57
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with custom password:" do
|
62
|
+
let(:host) { "https://gate.smsaero.ru/checktarif" }
|
63
|
+
let(:query) { "answer=json&password=PSWD&user=LOGIN" }
|
64
|
+
|
65
|
+
before { params[:password] = "PSWD" }
|
66
|
+
|
67
|
+
it "sends a request" do
|
68
|
+
subject
|
69
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
RSpec.describe SmsAero, "#delete_group" do
|
2
|
+
let(:settings) { { user: "LOGIN", password: "PASSWORD" } }
|
3
|
+
let(:client) { described_class.new(settings) }
|
4
|
+
let(:params) { { group: "foobar" } }
|
5
|
+
let(:answer) { { result: "accepted" } }
|
6
|
+
|
7
|
+
before { stub_request(:any, //).to_return(body: answer.to_json) }
|
8
|
+
subject { client.delete_group(params) }
|
9
|
+
|
10
|
+
context "using ssl via POST:" do
|
11
|
+
let(:host) { "https://gate.smsaero.ru/delgroup" }
|
12
|
+
let(:query) { "answer=json&group=foobar&password=PASSWORD&user=LOGIN" }
|
13
|
+
|
14
|
+
it "sends a request" do
|
15
|
+
subject
|
16
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns success" do
|
20
|
+
expect(subject).to be_kind_of SmsAero::Answer
|
21
|
+
expect(subject.result).to eq "accepted"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "via GET:" do
|
26
|
+
let(:host) { "https://gate.smsaero.ru/delgroup" }
|
27
|
+
let(:query) { "answer=json&group=foobar&password=PASSWORD&user=LOGIN" }
|
28
|
+
|
29
|
+
before { settings[:use_post] = false }
|
30
|
+
|
31
|
+
it "sends a request" do
|
32
|
+
subject
|
33
|
+
expect(a_request(:get, "#{host}?#{query}")).to have_been_made
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "not using ssl:" do
|
38
|
+
let(:host) { "http://gate.smsaero.ru/delgroup" }
|
39
|
+
let(:query) { "answer=json&group=foobar&password=PASSWORD&user=LOGIN" }
|
40
|
+
|
41
|
+
before { settings[:use_ssl] = false }
|
42
|
+
|
43
|
+
it "sends a request" do
|
44
|
+
subject
|
45
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "with custom user:" do
|
50
|
+
let(:host) { "https://gate.smsaero.ru/delgroup" }
|
51
|
+
let(:query) { "answer=json&group=foobar&password=PASSWORD&user=USER" }
|
52
|
+
|
53
|
+
before { params[:user] = "USER" }
|
54
|
+
|
55
|
+
it "sends a request" do
|
56
|
+
subject
|
57
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with custom password:" do
|
62
|
+
let(:host) { "https://gate.smsaero.ru/delgroup" }
|
63
|
+
let(:query) { "answer=json&group=foobar&password=PSWD&user=LOGIN" }
|
64
|
+
|
65
|
+
before { params[:password] = "PSWD" }
|
66
|
+
|
67
|
+
it "sends a request" do
|
68
|
+
subject
|
69
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "with invalid group:" do
|
74
|
+
before { params[:group] = "" }
|
75
|
+
|
76
|
+
it "raises an exception" do
|
77
|
+
expect { subject }.to raise_error(TypeError)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "without a group:" do
|
82
|
+
before { params.delete :group }
|
83
|
+
|
84
|
+
it "raises an exception" do
|
85
|
+
expect { subject }.to raise_error(KeyError)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
RSpec.describe SmsAero, "#delete_phone" do
|
2
|
+
let(:settings) { { user: "LOGIN", password: "PASSWORD" } }
|
3
|
+
let(:client) { described_class.new(settings) }
|
4
|
+
let(:params) { { group: "foo", phone: "+7(002)034-5678" } }
|
5
|
+
let(:answer) { { result: "accepted" } }
|
6
|
+
|
7
|
+
before { stub_request(:any, //).to_return(body: answer.to_json) }
|
8
|
+
subject { client.delete_phone(params) }
|
9
|
+
|
10
|
+
context "using ssl via POST:" do
|
11
|
+
let(:host) { "https://gate.smsaero.ru/delphone" }
|
12
|
+
let(:query) do
|
13
|
+
"answer=json&group=foo&password=PASSWORD&phone=70020345678&user=LOGIN"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "sends a request" do
|
17
|
+
subject
|
18
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns success" do
|
22
|
+
expect(subject).to be_kind_of SmsAero::Answer
|
23
|
+
expect(subject.result).to eq "accepted"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "via GET:" do
|
28
|
+
let(:host) { "https://gate.smsaero.ru/delphone" }
|
29
|
+
let(:query) do
|
30
|
+
"answer=json&group=foo&password=PASSWORD&phone=70020345678&user=LOGIN"
|
31
|
+
end
|
32
|
+
|
33
|
+
before { settings[:use_post] = false }
|
34
|
+
|
35
|
+
it "sends a request" do
|
36
|
+
subject
|
37
|
+
expect(a_request(:get, "#{host}?#{query}")).to have_been_made
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "not using ssl:" do
|
42
|
+
let(:host) { "http://gate.smsaero.ru/delphone" }
|
43
|
+
let(:query) do
|
44
|
+
"answer=json&group=foo&password=PASSWORD&phone=70020345678&user=LOGIN"
|
45
|
+
end
|
46
|
+
|
47
|
+
before { settings[:use_ssl] = false }
|
48
|
+
|
49
|
+
it "sends a request" do
|
50
|
+
subject
|
51
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with custom user:" do
|
56
|
+
let(:host) { "https://gate.smsaero.ru/delphone" }
|
57
|
+
let(:query) do
|
58
|
+
"answer=json&group=foo&password=PASSWORD&phone=70020345678&user=USER"
|
59
|
+
end
|
60
|
+
|
61
|
+
before { params[:user] = "USER" }
|
62
|
+
|
63
|
+
it "sends a request" do
|
64
|
+
subject
|
65
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with custom password:" do
|
70
|
+
let(:host) { "https://gate.smsaero.ru/delphone" }
|
71
|
+
let(:query) do
|
72
|
+
"answer=json&group=foo&password=PSWD&phone=70020345678&user=LOGIN"
|
73
|
+
end
|
74
|
+
|
75
|
+
before { params[:password] = "PSWD" }
|
76
|
+
|
77
|
+
it "sends a request" do
|
78
|
+
subject
|
79
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "without a group:" do
|
84
|
+
let(:host) { "https://gate.smsaero.ru/delphone" }
|
85
|
+
let(:query) { "answer=json&password=PASSWORD&phone=70020345678&user=LOGIN" }
|
86
|
+
|
87
|
+
before { params.delete :group }
|
88
|
+
|
89
|
+
it "sends a request" do
|
90
|
+
subject
|
91
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "with invalid group:" do
|
96
|
+
before { params[:group] = "" }
|
97
|
+
|
98
|
+
it "raises an exception" do
|
99
|
+
expect { subject }.to raise_error(TypeError)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "with invalid phone:" do
|
104
|
+
before { params[:phone] = "234" }
|
105
|
+
|
106
|
+
it "raises an exception" do
|
107
|
+
expect { subject }.to raise_error(TypeError, /234/)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "without a phone:" do
|
112
|
+
before { params.delete :phone }
|
113
|
+
|
114
|
+
it "raises an exception" do
|
115
|
+
expect { subject }.to raise_error(KeyError)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
RSpec.describe SmsAero, "#send_sms" do
|
2
|
+
let(:settings) { { user: "BAZ", password: "QUX" } }
|
3
|
+
let(:client) { described_class.new(settings) }
|
4
|
+
let(:params) { { text: "Hi", to: "+7 (909) 382-84-45" } }
|
5
|
+
let(:answer) { { id: 3898, result: "accepted" } }
|
6
|
+
|
7
|
+
before { stub_request(:any, //).to_return(body: answer.to_json) }
|
8
|
+
subject { client.send_sms(params) }
|
9
|
+
|
10
|
+
context "using ssl via POST:" do
|
11
|
+
let(:host) { "https://gate.smsaero.ru/send" }
|
12
|
+
let(:query) do
|
13
|
+
"answer=json&password=QUX&text=Hi&to=79093828445&type=2&user=BAZ"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "sends a request" do
|
17
|
+
subject
|
18
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns success" do
|
22
|
+
expect(subject).to be_kind_of SmsAero::Answer
|
23
|
+
expect(subject.result).to eq "accepted"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "via GET:" do
|
28
|
+
let(:host) { "https://gate.smsaero.ru/send" }
|
29
|
+
let(:query) do
|
30
|
+
"answer=json&password=QUX&text=Hi&to=79093828445&type=2&user=BAZ"
|
31
|
+
end
|
32
|
+
|
33
|
+
before { settings[:use_post] = false }
|
34
|
+
|
35
|
+
it "sends a request" do
|
36
|
+
subject
|
37
|
+
expect(a_request(:get, "#{host}?#{query}")).to have_been_made
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "not using ssl:" do
|
42
|
+
let(:host) { "http://gate.smsaero.ru/send" }
|
43
|
+
let(:query) do
|
44
|
+
"answer=json&password=QUX&text=Hi&to=79093828445&type=2&user=BAZ"
|
45
|
+
end
|
46
|
+
|
47
|
+
before { settings[:use_ssl] = false }
|
48
|
+
|
49
|
+
it "sends a request" do
|
50
|
+
subject
|
51
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with custom user:" do
|
56
|
+
let(:host) { "https://gate.smsaero.ru/send" }
|
57
|
+
let(:query) do
|
58
|
+
"answer=json&password=QUX&text=Hi&to=79093828445&type=2&user=USER"
|
59
|
+
end
|
60
|
+
|
61
|
+
before { params[:user] = "USER" }
|
62
|
+
|
63
|
+
it "sends a request" do
|
64
|
+
subject
|
65
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with custom password:" do
|
70
|
+
let(:host) { "https://gate.smsaero.ru/send" }
|
71
|
+
let(:query) do
|
72
|
+
"answer=json&password=PSWD&text=Hi&to=79093828445&type=2&user=BAZ"
|
73
|
+
end
|
74
|
+
|
75
|
+
before { params[:password] = "PSWD" }
|
76
|
+
|
77
|
+
it "sends a request" do
|
78
|
+
subject
|
79
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "with invalid phone:" do
|
84
|
+
before { params[:to] = "1324" }
|
85
|
+
|
86
|
+
it "raises an exception" do
|
87
|
+
expect { subject }.to raise_error(TypeError, /1324/)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "without a phone:" do
|
92
|
+
before { params.delete :to }
|
93
|
+
|
94
|
+
it "raises an exception" do
|
95
|
+
expect { subject }.to raise_error(KeyError)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "with valid date:" do
|
100
|
+
let(:host) { "https://gate.smsaero.ru/send" }
|
101
|
+
let(:query) do
|
102
|
+
"answer=json&date=4122144000&password=QUX&text=Hi&" \
|
103
|
+
"to=79093828445&type=2&user=BAZ"
|
104
|
+
end
|
105
|
+
|
106
|
+
before { params[:date] = DateTime.parse("2100-08-17 00:00:00 UTC") }
|
107
|
+
|
108
|
+
it "sends a request" do
|
109
|
+
subject
|
110
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "with old date:" do
|
115
|
+
before { params[:date] = (Date.today - 1) }
|
116
|
+
|
117
|
+
it "raises an exception" do
|
118
|
+
expect { subject }.to raise_error(TypeError)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "with invalid date:" do
|
123
|
+
before { params[:date] = "foo" }
|
124
|
+
|
125
|
+
it "raises an exception" do
|
126
|
+
expect { subject }.to raise_error(TypeError, /foo/)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "with digital channel:" do
|
131
|
+
let(:host) { "https://gate.smsaero.ru/send" }
|
132
|
+
let(:query) do
|
133
|
+
"answer=json&digital=1&password=QUX&text=Hi&to=79093828445&user=BAZ"
|
134
|
+
end
|
135
|
+
|
136
|
+
before { params[:digital] = true }
|
137
|
+
|
138
|
+
it "sends a request" do
|
139
|
+
subject
|
140
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "with valid type:" do
|
145
|
+
let(:host) { "https://gate.smsaero.ru/send" }
|
146
|
+
let(:query) do
|
147
|
+
"answer=json&password=QUX&text=Hi&to=79093828445&type=3&user=BAZ"
|
148
|
+
end
|
149
|
+
|
150
|
+
before { params[:type] = 3 }
|
151
|
+
|
152
|
+
it "sends a request" do
|
153
|
+
subject
|
154
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context "with invalid type:" do
|
159
|
+
before { params[:type] = 11 }
|
160
|
+
|
161
|
+
it "raises an exception" do
|
162
|
+
expect { subject }.to raise_error(TypeError, /11/)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "with test:" do
|
167
|
+
let(:host) { "https://gate.smsaero.ru/testsend" }
|
168
|
+
let(:query) do
|
169
|
+
"answer=json&password=QUX&text=Hi&to=79093828445&type=2&user=BAZ"
|
170
|
+
end
|
171
|
+
|
172
|
+
before { params[:test] = true }
|
173
|
+
|
174
|
+
it "sends a request" do
|
175
|
+
subject
|
176
|
+
expect(a_request(:post, "#{host}?#{query}")).to have_been_made
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|