aladtec 0.2.0 → 0.3.0
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 +5 -5
- data/.travis.yml +8 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile +2 -0
- data/README.md +1 -0
- data/Rakefile +4 -2
- data/aladtec.gemspec +20 -16
- data/lib/aladtec.rb +12 -4
- data/lib/aladtec/client.rb +55 -80
- data/lib/aladtec/event.rb +16 -8
- data/lib/aladtec/exceptions.rb +2 -0
- data/lib/aladtec/member.rb +16 -4
- data/lib/aladtec/position.rb +11 -6
- data/lib/aladtec/range.rb +15 -11
- data/lib/aladtec/schedule.rb +12 -13
- data/lib/aladtec/scheduled_now.rb +20 -0
- data/lib/aladtec/version.rb +3 -1
- data/spec/aladtec/aladtec_spec.rb +18 -1
- data/spec/aladtec/client_spec.rb +89 -102
- data/spec/fixtures/events.json +55 -0
- data/spec/fixtures/members.json +39 -0
- data/spec/fixtures/scheduled_time.json +54 -0
- data/spec/fixtures/scheduled_time_now.json +24 -0
- data/spec/fixtures/schedules.json +32 -0
- data/spec/spec_helper.rb +9 -1
- metadata +50 -28
- data/lib/aladtec/authentication.rb +0 -16
- data/lib/aladtec/configuration.rb +0 -37
- data/spec/aladtec/configuration_spec.rb +0 -26
- data/spec/fixtures/authenticate_member.xml +0 -6
- data/spec/fixtures/get_events.xml +0 -1
- data/spec/fixtures/get_members.xml +0 -1
- data/spec/fixtures/get_scheduled_time_now.xml +0 -21
- data/spec/fixtures/get_scheduled_time_ranges.xml +0 -27
- data/spec/fixtures/get_schedules.xml +0 -57
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
4
|
+
|
5
|
+
module Aladtec
|
6
|
+
# ScheduledNow
|
7
|
+
class ScheduledNow
|
8
|
+
extend Dry::Initializer
|
9
|
+
|
10
|
+
option :schedule_id, as: :id
|
11
|
+
option :positions, [] do
|
12
|
+
option :position_id, proc(&:to_i), as: :id
|
13
|
+
option :member_id, proc(&:to_i)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.new(params)
|
17
|
+
super params.transform_keys(&:to_sym)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/aladtec/version.rb
CHANGED
@@ -1,7 +1,24 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative File.join('..', 'spec_helper')
|
2
4
|
|
3
5
|
describe Aladtec do
|
4
6
|
it 'should have a version' do
|
5
7
|
expect(Aladtec::VERSION).not_to be_nil
|
6
8
|
end
|
9
|
+
|
10
|
+
describe '.configure' do
|
11
|
+
Aladtec.settings.each do |key|
|
12
|
+
it "should set the #{key}" do
|
13
|
+
Aladtec.configure do |config|
|
14
|
+
config.public_send("#{key}=", key)
|
15
|
+
end
|
16
|
+
expect(Aladtec.config.public_send(key)).to eq(key)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
after(:each) do
|
21
|
+
Aladtec.reset_config
|
22
|
+
end
|
23
|
+
end
|
7
24
|
end
|
data/spec/aladtec/client_spec.rb
CHANGED
@@ -1,158 +1,146 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
let(:valid_keys) do
|
5
|
-
Aladtec::Configuration::VALID_CONFIG_KEYS
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "#auth" do
|
9
|
-
let(:auth) { subject.auth("user", "pass") }
|
10
|
-
before(:each) do
|
11
|
-
stub_request(:post, "https://secure.emsmanager.net/api/index.php").
|
12
|
-
with(body: hash_including({cmd: "authenticateMember"})).
|
13
|
-
to_return(body: fixture('authenticate_member.xml'))
|
14
|
-
end
|
3
|
+
require_relative File.join('..', 'spec_helper')
|
15
4
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
5
|
+
describe Aladtec::Client do
|
6
|
+
let(:start_time) { Time.now.strftime('%FT%R') }
|
7
|
+
let(:end_time) { (Time.now + 60 * 60 * 24).strftime('%FT%R') }
|
21
8
|
|
22
|
-
describe
|
9
|
+
describe '#members' do
|
23
10
|
let(:members) { subject.members }
|
24
11
|
before(:each) do
|
25
|
-
stub_request(:
|
26
|
-
|
27
|
-
|
12
|
+
stub_request(:get, 'https://secure.aladtec.com/example/api/members')
|
13
|
+
.with(query: { include_attributes: true })
|
14
|
+
.to_return(body: fixture('members.json'),
|
15
|
+
headers: { 'Content-Type': 'application/json' })
|
28
16
|
end
|
29
|
-
it
|
30
|
-
expect(members.length).to eq(
|
17
|
+
it 'returns a list of members' do
|
18
|
+
expect(members.length).to eq(2)
|
31
19
|
end
|
32
20
|
|
33
|
-
let(:
|
34
|
-
it
|
35
|
-
expect(
|
21
|
+
let(:ed) { members.first }
|
22
|
+
it 'returns members with names' do
|
23
|
+
expect(ed.name).to eq('Ed Mercer')
|
36
24
|
end
|
37
|
-
it
|
38
|
-
expect(
|
25
|
+
it 'returns members with ids' do
|
26
|
+
expect(ed.id).to eq(42)
|
39
27
|
end
|
40
28
|
end
|
41
29
|
|
42
|
-
describe
|
43
|
-
let(:events) { subject.events(
|
30
|
+
describe '#events' do
|
31
|
+
let(:events) { subject.events(begin_time: start_time, end_time: end_time) }
|
44
32
|
before(:each) do
|
45
|
-
stub_request(:
|
46
|
-
|
47
|
-
|
33
|
+
stub_request(:get, 'https://secure.aladtec.com/example/api/events')
|
34
|
+
.with(query: { range_start: start_time, range_stop: end_time })
|
35
|
+
.to_return(body: fixture('events.json'),
|
36
|
+
headers: { 'Content-Type': 'application/json' })
|
48
37
|
end
|
49
|
-
it
|
50
|
-
expect(events.length).to eq(
|
38
|
+
it 'returns a list of events' do
|
39
|
+
expect(events.length).to eq(3)
|
51
40
|
end
|
52
41
|
|
53
42
|
let(:event) { events.first }
|
54
|
-
it
|
55
|
-
expect(event.title).to eq(
|
43
|
+
it 'returns events with title' do
|
44
|
+
expect(event.title).to eq('EMS Monthly Meeting')
|
56
45
|
end
|
57
46
|
|
58
|
-
it
|
59
|
-
expect(event.description).to eq(
|
47
|
+
it 'returns events with a description' do
|
48
|
+
expect(event.description).to eq('open to the community')
|
60
49
|
end
|
61
50
|
|
62
|
-
it
|
63
|
-
expect(event.location).to eq(
|
51
|
+
it 'returns events with location' do
|
52
|
+
expect(event.location).to eq('EMS Station')
|
64
53
|
end
|
65
54
|
|
66
|
-
it
|
67
|
-
expect(event.
|
55
|
+
it 'returns events with begin date' do
|
56
|
+
expect(event.starts_at).to eq(Time.parse('2018-01-16T09:00'))
|
68
57
|
end
|
69
58
|
|
70
|
-
it
|
71
|
-
expect(event.
|
59
|
+
it 'returns events with end date' do
|
60
|
+
expect(event.ends_at).to eq(Time.parse('2018-01-16T11:00'))
|
72
61
|
end
|
73
62
|
end
|
74
63
|
|
75
|
-
describe
|
64
|
+
describe '#schedules' do
|
76
65
|
let(:schedules) { subject.schedules }
|
77
66
|
before(:each) do
|
78
|
-
stub_request(:
|
79
|
-
|
80
|
-
|
67
|
+
stub_request(:get, 'https://secure.aladtec.com/example/api/schedules')
|
68
|
+
.to_return(body: fixture('schedules.json'),
|
69
|
+
headers: { 'Content-Type': 'application/json' })
|
81
70
|
end
|
82
|
-
it
|
83
|
-
expect(schedules.length).to eq(
|
71
|
+
it 'returns a list of schedules' do
|
72
|
+
expect(schedules.length).to eq(2)
|
84
73
|
end
|
85
74
|
|
86
75
|
let(:schedule) { schedules.first }
|
87
|
-
it
|
88
|
-
expect(schedule.name).to eq(
|
76
|
+
it 'returns schedules with names' do
|
77
|
+
expect(schedule.name).to eq('Ambulance 1')
|
89
78
|
end
|
90
79
|
|
91
|
-
it
|
92
|
-
expect(schedule.id).to eq(
|
80
|
+
it 'returns schedules with ids' do
|
81
|
+
expect(schedule.id).to eq(1)
|
93
82
|
end
|
94
83
|
end
|
95
84
|
|
96
|
-
describe
|
85
|
+
describe '#scheduled_now' do
|
97
86
|
let(:schedules) { subject.scheduled_now }
|
98
87
|
before(:each) do
|
99
|
-
stub_request(:
|
100
|
-
|
101
|
-
|
88
|
+
stub_request(:get, 'https://secure.aladtec.com/example/api/scheduled-time/members-scheduled-now')
|
89
|
+
.to_return(body: fixture('scheduled_time_now.json'),
|
90
|
+
headers: { 'Content-Type': 'application/json' })
|
102
91
|
end
|
103
|
-
it
|
92
|
+
it 'returns a list of scheduled time now' do
|
104
93
|
expect(schedules.length).to eq(2)
|
105
94
|
end
|
106
95
|
|
107
96
|
let(:schedule) { schedules.first }
|
108
|
-
it
|
109
|
-
expect(schedule.id).to eq(
|
97
|
+
it 'returns schedules with ids' do
|
98
|
+
expect(schedule.id).to eq(1)
|
110
99
|
end
|
111
100
|
|
112
|
-
it
|
113
|
-
expect(schedule.positions.length).to eq(
|
101
|
+
it 'returns schedules with positions' do
|
102
|
+
expect(schedule.positions.length).to eq(1)
|
114
103
|
end
|
115
104
|
end
|
116
105
|
|
117
|
-
describe
|
118
|
-
let(:ranges)
|
106
|
+
describe '#scheduled_range' do
|
107
|
+
let(:ranges) do
|
108
|
+
subject.scheduled_range(begin_time: start_time,
|
109
|
+
end_time: end_time)
|
110
|
+
end
|
119
111
|
before(:each) do
|
120
|
-
stub_request(:
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
with(body: hash_including({cmd: "getMembers"})).
|
125
|
-
to_return(body: fixture('get_members.xml'))
|
126
|
-
stub_request(:post, "https://secure.emsmanager.net/api/index.php").
|
127
|
-
with(body: hash_including({cmd: "getSchedules"})).
|
128
|
-
to_return(body: fixture('get_schedules.xml'))
|
112
|
+
stub_request(:get, 'https://secure.aladtec.com/example/api/scheduled-time')
|
113
|
+
.with(query: { range_start: start_time, range_stop: end_time })
|
114
|
+
.to_return(body: fixture('scheduled_time.json'),
|
115
|
+
headers: { 'Content-Type': 'application/json' })
|
129
116
|
end
|
130
|
-
it
|
131
|
-
expect(ranges.length).to eq(
|
117
|
+
it 'returns a list of scheduled ranges' do
|
118
|
+
expect(ranges.length).to eq(4)
|
132
119
|
end
|
133
120
|
|
134
121
|
let(:range) { ranges.first }
|
135
|
-
it
|
136
|
-
expect(range.
|
122
|
+
it 'returns ranges with a begin time' do
|
123
|
+
expect(range.starts_at).to eq(Time.parse('2018-05-18T07:00'))
|
137
124
|
end
|
138
125
|
|
139
|
-
it
|
140
|
-
expect(range.
|
126
|
+
it 'returns ranges with a end time' do
|
127
|
+
expect(range.ends_at).to eq(Time.parse('2018-05-19T07:00'))
|
141
128
|
end
|
142
129
|
|
143
|
-
it
|
144
|
-
expect(range.
|
130
|
+
it 'returns ranges with a member id' do
|
131
|
+
expect(range.member_id).to eq(3)
|
145
132
|
end
|
146
133
|
|
147
|
-
it
|
148
|
-
expect(range.
|
134
|
+
it 'returns ranges with a position id' do
|
135
|
+
expect(range.position_id).to eq(50)
|
149
136
|
end
|
150
137
|
|
151
|
-
it
|
152
|
-
expect(range.
|
138
|
+
it 'returns ranges with a schedule id' do
|
139
|
+
expect(range.schedule_id).to eq(16)
|
153
140
|
end
|
154
141
|
end
|
155
142
|
|
143
|
+
let(:valid_keys) { Aladtec.settings }
|
156
144
|
context 'with module configuration' do
|
157
145
|
before(:each) do
|
158
146
|
Aladtec.configure do |config|
|
@@ -162,33 +150,32 @@ describe Aladtec::Client do
|
|
162
150
|
end
|
163
151
|
end
|
164
152
|
|
165
|
-
|
166
|
-
Aladtec.reset
|
167
|
-
end
|
168
|
-
|
169
|
-
it "should inherit module configuration" do
|
153
|
+
it 'should inherit module configuration' do
|
170
154
|
api = Aladtec::Client.new
|
171
155
|
valid_keys.each do |key|
|
172
|
-
expect(api.public_send(key)).to eq(key)
|
156
|
+
expect(api.config.public_send(key)).to eq(key)
|
173
157
|
end
|
174
158
|
end
|
159
|
+
|
160
|
+
after(:each) do
|
161
|
+
Aladtec.reset_config
|
162
|
+
end
|
175
163
|
end
|
176
164
|
|
177
165
|
context 'with class configuration' do
|
178
166
|
let(:config) do
|
179
167
|
{
|
180
|
-
:
|
181
|
-
:
|
182
|
-
:
|
183
|
-
:
|
184
|
-
:method => 'hm',
|
168
|
+
client_id: 'ai',
|
169
|
+
client_secret: 'ak',
|
170
|
+
endpoint: 'ep',
|
171
|
+
user_agent: 'ua'
|
185
172
|
}
|
186
173
|
end
|
187
174
|
|
188
175
|
it 'should override module configuration' do
|
189
176
|
api = Aladtec::Client.new(config)
|
190
177
|
valid_keys.each do |key|
|
191
|
-
expect(api.public_send(key)).to eq(config[key])
|
178
|
+
expect(api.config.public_send(key)).to eq(config[key])
|
192
179
|
end
|
193
180
|
end
|
194
181
|
|
@@ -196,11 +183,11 @@ describe Aladtec::Client do
|
|
196
183
|
api = Aladtec::Client.new
|
197
184
|
|
198
185
|
config.each do |key, value|
|
199
|
-
api.public_send("#{key}=", value)
|
186
|
+
api.config.public_send("#{key}=", value)
|
200
187
|
end
|
201
188
|
|
202
189
|
valid_keys.each do |key|
|
203
|
-
expect(api.send(
|
190
|
+
expect(api.config.send(key.to_s)).to eq(config[key])
|
204
191
|
end
|
205
192
|
end
|
206
193
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
{
|
2
|
+
"2018-01-16": [
|
3
|
+
{
|
4
|
+
"event_id": 22,
|
5
|
+
"title": "EMS Monthly Meeting",
|
6
|
+
"description": "open to the community",
|
7
|
+
"location": "EMS Station",
|
8
|
+
"start_datetime": "2018-01-16T09:00",
|
9
|
+
"stop_datetime": "2018-01-16T11:00",
|
10
|
+
"start_timestamp": "1547629200",
|
11
|
+
"stop_timestamp": "1547636400",
|
12
|
+
"extends_before": true,
|
13
|
+
"extends_after": false,
|
14
|
+
"schedules": [
|
15
|
+
1,
|
16
|
+
2
|
17
|
+
],
|
18
|
+
"public": true
|
19
|
+
},
|
20
|
+
{
|
21
|
+
"event_id": 43,
|
22
|
+
"title": "Game Night",
|
23
|
+
"description": "Bring some games and have some fun!",
|
24
|
+
"location": "Event Hall",
|
25
|
+
"start_datetime": "2018-01-16T22:00",
|
26
|
+
"stop_datetime": "2018-01-16T00:00",
|
27
|
+
"start_timestamp": "1526526000",
|
28
|
+
"stop_timestamp": "1526533200",
|
29
|
+
"extends_before": false,
|
30
|
+
"extends_after": false,
|
31
|
+
"schedules": [
|
32
|
+
2
|
33
|
+
],
|
34
|
+
"public": false
|
35
|
+
}
|
36
|
+
],
|
37
|
+
"2018-01-17": [
|
38
|
+
{
|
39
|
+
"event_id": 43,
|
40
|
+
"title": "EMS Coverage for Football Game",
|
41
|
+
"description": "High School Football Game",
|
42
|
+
"location": "Ramer Field",
|
43
|
+
"start_datetime": "2018-01-17T18:00",
|
44
|
+
"stop_datetime": "2018-01-17T04:00",
|
45
|
+
"start_timestamp": "1547748000",
|
46
|
+
"stop_timestamp": "1547758800",
|
47
|
+
"extends_before": false,
|
48
|
+
"extends_after": true,
|
49
|
+
"schedules": [
|
50
|
+
2
|
51
|
+
],
|
52
|
+
"public": false
|
53
|
+
}
|
54
|
+
]
|
55
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"member_id": 42,
|
4
|
+
"is_active": true,
|
5
|
+
"name": "Ed Mercer",
|
6
|
+
"attributes": [
|
7
|
+
{
|
8
|
+
"attribute_id": 1,
|
9
|
+
"value": "Ed"
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"attribute_id": 3,
|
13
|
+
"value": "Mercer"
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"attribute_id": 19,
|
17
|
+
"value": [
|
18
|
+
"Morning",
|
19
|
+
"Evening"
|
20
|
+
]
|
21
|
+
}
|
22
|
+
]
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"member_id": 2,
|
26
|
+
"is_active": false,
|
27
|
+
"name": "Joyner Lucas",
|
28
|
+
"attributes": [
|
29
|
+
{
|
30
|
+
"attribute_id": 1,
|
31
|
+
"value": "Joyner"
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"attribute_id": 3,
|
35
|
+
"value": "Lucas"
|
36
|
+
}
|
37
|
+
]
|
38
|
+
}
|
39
|
+
]
|
@@ -0,0 +1,54 @@
|
|
1
|
+
{
|
2
|
+
"2018-05-18" : [
|
3
|
+
{
|
4
|
+
"member_id" : 3,
|
5
|
+
"schedule_id" : 16,
|
6
|
+
"position_id" : 50,
|
7
|
+
"time_type": "Regular",
|
8
|
+
"start_datetime" : "2018-05-18T07:00",
|
9
|
+
"start_timestamp" : 1526644800,
|
10
|
+
"stop_datetime" : "2018-05-19T07:00",
|
11
|
+
"stop_timestamp" : 1526731200,
|
12
|
+
"extends_before": true,
|
13
|
+
"extends_after": false
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"member_id" : 53,
|
17
|
+
"schedule_id" : 16,
|
18
|
+
"position_id" : 51,
|
19
|
+
"time_type": "Regular",
|
20
|
+
"start_datetime" : "2018-05-18T07:00",
|
21
|
+
"start_timestamp" : 1526644800,
|
22
|
+
"stop_datetime" : "2018-05-19T07:00",
|
23
|
+
"stop_timestamp" : 1526731200,
|
24
|
+
"extends_before": false,
|
25
|
+
"extends_after": false
|
26
|
+
}
|
27
|
+
],
|
28
|
+
"2018-05-19" : [
|
29
|
+
{
|
30
|
+
"member_id" : 52,
|
31
|
+
"schedule_id" : 16,
|
32
|
+
"position_id" : 50,
|
33
|
+
"time_type": "Regular",
|
34
|
+
"start_datetime" : "2018-05-19T09:00",
|
35
|
+
"start_timestamp" : 1526738400,
|
36
|
+
"stop_datetime" : "2018-05-19T17:00",
|
37
|
+
"stop_timestamp" : 1526767200,
|
38
|
+
"extends_before": false,
|
39
|
+
"extends_after": false
|
40
|
+
},
|
41
|
+
{
|
42
|
+
"member_id" : 96,
|
43
|
+
"schedule_id" : 16,
|
44
|
+
"position_id" : 53,
|
45
|
+
"time_type": "Regular",
|
46
|
+
"start_datetime" : "2018-05-19T09:00",
|
47
|
+
"start_timestamp" : 1526738400,
|
48
|
+
"stop_datetime" : "2018-05-19T17:00",
|
49
|
+
"stop_timestamp" : 1526767200,
|
50
|
+
"extends_before": false,
|
51
|
+
"extends_after": false
|
52
|
+
}
|
53
|
+
]
|
54
|
+
}
|