aladtec 0.2.0 → 0.3.2

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.
@@ -1,158 +1,158 @@
1
- require_relative File.join('..','spec_helper')
1
+ # frozen_string_literal: true
2
2
 
3
- describe Aladtec::Client do
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
15
-
16
- it "returns an authentication object" do
17
- expect(auth).to be_success
18
- end
3
+ require_relative File.join('..', 'spec_helper')
19
4
 
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') }
8
+ let(:client_id) { 'foo' }
9
+ let(:client_secret) { 'bar' }
10
+
11
+ before(:each) do
12
+ subject.configure do |config|
13
+ config.client_id = client_id
14
+ config.client_secret = client_secret
15
+ end
16
+ stub_request(:post, 'https://secure.aladtec.com/example/api/oauth/token')
17
+ .to_return(body: { token: 'baz', expires: (Time.now + 3600).to_i }.to_json,
18
+ headers: { 'Content-Type': 'application/json' })
20
19
  end
21
20
 
22
- describe "#members" do
21
+ describe '#members' do
23
22
  let(:members) { subject.members }
24
23
  before(:each) do
25
- stub_request(:post, "https://secure.emsmanager.net/api/index.php").
26
- with(body: hash_including({cmd: "getMembers"})).
27
- to_return(body: fixture('get_members.xml'))
24
+ stub_request(:get, 'https://secure.aladtec.com/example/api/members')
25
+ .with(query: { include_attributes: true })
26
+ .to_return(body: fixture('members.json'),
27
+ headers: { 'Content-Type': 'application/json' })
28
28
  end
29
- it "returns a list of members" do
30
- expect(members.length).to eq(3)
29
+ it 'returns a list of members' do
30
+ expect(members.length).to eq(2)
31
31
  end
32
32
 
33
- let(:john) { members.first }
34
- it "returns members with names" do
35
- expect(john.name).to eq("John Anderson")
33
+ let(:ed) { members.first }
34
+ it 'returns members with names' do
35
+ expect(ed.name).to eq('Ed Mercer')
36
36
  end
37
- it "returns members with ids" do
38
- expect(john.id).to eq(32)
37
+ it 'returns members with ids' do
38
+ expect(ed.id).to eq(42)
39
39
  end
40
40
  end
41
41
 
42
- describe "#events" do
43
- let(:events) { subject.events(begin_date: Date.today)}
42
+ describe '#events' do
43
+ let(:events) { subject.events(begin_time: start_time, end_time: end_time) }
44
44
  before(:each) do
45
- stub_request(:post, "https://secure.emsmanager.net/api/index.php").
46
- with(body: hash_including({cmd: "getEvents"})).
47
- to_return(body: fixture('get_events.xml'))
45
+ stub_request(:get, 'https://secure.aladtec.com/example/api/events')
46
+ .with(query: { range_start: start_time, range_stop: end_time })
47
+ .to_return(body: fixture('events.json'),
48
+ headers: { 'Content-Type': 'application/json' })
48
49
  end
49
- it "returns a list of events" do
50
- expect(events.length).to eq(2)
50
+ it 'returns a list of events' do
51
+ expect(events.length).to eq(3)
51
52
  end
52
53
 
53
54
  let(:event) { events.first }
54
- it "returns events with title" do
55
- expect(event.title).to eq("Game Night")
55
+ it 'returns events with title' do
56
+ expect(event.title).to eq('EMS Monthly Meeting')
56
57
  end
57
58
 
58
- it "returns events with a description" do
59
- expect(event.description).to eq("Play games until the sun comes up!")
59
+ it 'returns events with a description' do
60
+ expect(event.description).to eq('open to the community')
60
61
  end
61
62
 
62
- it "returns events with location" do
63
- expect(event.location).to eq("Public Library")
63
+ it 'returns events with location' do
64
+ expect(event.location).to eq('EMS Station')
64
65
  end
65
66
 
66
- it "returns events with begin date" do
67
- expect(event.begin).to eq(Time.parse("2012-04-20"))
67
+ it 'returns events with begin date' do
68
+ expect(event.starts_at).to eq(Time.parse('2018-01-16T09:00'))
68
69
  end
69
70
 
70
- it "returns events with end date" do
71
- expect(event.end).to eq(Time.parse("2012-04-21 15:30:00 UTC"))
71
+ it 'returns events with end date' do
72
+ expect(event.ends_at).to eq(Time.parse('2018-01-16T11:00'))
72
73
  end
73
74
  end
74
75
 
75
- describe "#schedules" do
76
+ describe '#schedules' do
76
77
  let(:schedules) { subject.schedules }
77
78
  before(:each) do
78
- stub_request(:post, "https://secure.emsmanager.net/api/index.php").
79
- with(body: hash_including({cmd: "getSchedules"})).
80
- to_return(body: fixture('get_schedules.xml'))
79
+ stub_request(:get, 'https://secure.aladtec.com/example/api/schedules')
80
+ .to_return(body: fixture('schedules.json'),
81
+ headers: { 'Content-Type': 'application/json' })
81
82
  end
82
- it "returns a list of schedules" do
83
- expect(schedules.length).to eq(5)
83
+ it 'returns a list of schedules' do
84
+ expect(schedules.length).to eq(2)
84
85
  end
85
86
 
86
87
  let(:schedule) { schedules.first }
87
- it "returns schedules with names" do
88
- expect(schedule.name).to eq("Sample BLS - 24/48")
88
+ it 'returns schedules with names' do
89
+ expect(schedule.name).to eq('Ambulance 1')
89
90
  end
90
91
 
91
- it "returns schedules with ids" do
92
- expect(schedule.id).to eq(5)
92
+ it 'returns schedules with ids' do
93
+ expect(schedule.id).to eq(1)
93
94
  end
94
95
  end
95
96
 
96
- describe "#scheduled_now" do
97
+ describe '#scheduled_now' do
97
98
  let(:schedules) { subject.scheduled_now }
98
99
  before(:each) do
99
- stub_request(:post, "https://secure.emsmanager.net/api/index.php").
100
- with(body: hash_including({cmd: "getScheduledTimeNow"})).
101
- to_return(body: fixture('get_scheduled_time_now.xml'))
100
+ stub_request(:get, 'https://secure.aladtec.com/example/api/scheduled-time/members-scheduled-now')
101
+ .to_return(body: fixture('scheduled_time_now.json'),
102
+ headers: { 'Content-Type': 'application/json' })
102
103
  end
103
- it "returns a list of scheduled time now" do
104
+ it 'returns a list of scheduled time now' do
104
105
  expect(schedules.length).to eq(2)
105
106
  end
106
107
 
107
108
  let(:schedule) { schedules.first }
108
- it "returns schedules with ids" do
109
- expect(schedule.id).to eq(5)
109
+ it 'returns schedules with ids' do
110
+ expect(schedule.id).to eq(1)
110
111
  end
111
112
 
112
- it "returns schedules with positions" do
113
- expect(schedule.positions.length).to eq(2)
113
+ it 'returns schedules with positions' do
114
+ expect(schedule.positions.length).to eq(1)
114
115
  end
115
116
  end
116
117
 
117
- describe "#scheduled_range" do
118
- let(:ranges) { subject.scheduled_range(begin_time: Time.now, end_time: Time.now) }
118
+ describe '#scheduled_range' do
119
+ let(:ranges) do
120
+ subject.scheduled_range(begin_time: start_time,
121
+ end_time: end_time)
122
+ end
119
123
  before(:each) do
120
- stub_request(:post, "https://secure.emsmanager.net/api/index.php").
121
- with(body: hash_including({cmd: "getScheduledTimeRanges"})).
122
- to_return(body: fixture('get_scheduled_time_ranges.xml'))
123
- stub_request(:post, "https://secure.emsmanager.net/api/index.php").
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'))
124
+ stub_request(:get, 'https://secure.aladtec.com/example/api/scheduled-time')
125
+ .with(query: { range_start: start_time, range_stop: end_time })
126
+ .to_return(body: fixture('scheduled_time.json'),
127
+ headers: { 'Content-Type': 'application/json' })
129
128
  end
130
- it "returns a list of scheduled ranges" do
131
- expect(ranges.length).to eq(3)
129
+ it 'returns a list of scheduled ranges' do
130
+ expect(ranges.length).to eq(4)
132
131
  end
133
132
 
134
133
  let(:range) { ranges.first }
135
- it "returns ranges with a begin time" do
136
- expect(range.begin).to eq(Time.parse("2010-03-20T03:30:00Z"))
134
+ it 'returns ranges with a begin time' do
135
+ expect(range.starts_at).to eq(Time.parse('2018-05-18T07:00'))
137
136
  end
138
137
 
139
- it "returns ranges with a end time" do
140
- expect(range.end).to eq(Time.parse("2010-03-20T11:30:00Z"))
138
+ it 'returns ranges with a end time' do
139
+ expect(range.ends_at).to eq(Time.parse('2018-05-19T07:00'))
141
140
  end
142
141
 
143
- it "returns ranges with a member id" do
144
- expect(range.member.id).to eq(42)
142
+ it 'returns ranges with a member id' do
143
+ expect(range.member_id).to eq(3)
145
144
  end
146
145
 
147
- it "returns ranges with a position id" do
148
- expect(range.position.id).to eq(1)
146
+ it 'returns ranges with a position id' do
147
+ expect(range.position_id).to eq(50)
149
148
  end
150
149
 
151
- it "returns ranges with a schedule id" do
152
- expect(range.schedule.id).to eq(5)
150
+ it 'returns ranges with a schedule id' do
151
+ expect(range.schedule_id).to eq(16)
153
152
  end
154
153
  end
155
154
 
155
+ let(:valid_keys) { Aladtec.settings }
156
156
  context 'with module configuration' do
157
157
  before(:each) do
158
158
  Aladtec.configure do |config|
@@ -162,33 +162,32 @@ describe Aladtec::Client do
162
162
  end
163
163
  end
164
164
 
165
- after(:each) do
166
- Aladtec.reset
167
- end
168
-
169
- it "should inherit module configuration" do
165
+ it 'should inherit module configuration' do
170
166
  api = Aladtec::Client.new
171
167
  valid_keys.each do |key|
172
- expect(api.public_send(key)).to eq(key)
168
+ expect(api.config.public_send(key)).to eq(key)
173
169
  end
174
170
  end
171
+
172
+ after(:each) do
173
+ Aladtec.reset_config
174
+ end
175
175
  end
176
176
 
177
177
  context 'with class configuration' do
178
178
  let(:config) do
179
179
  {
180
- :acc_id => 'ai',
181
- :acc_key => 'ak',
182
- :endpoint => 'ep',
183
- :user_agent => 'ua',
184
- :method => 'hm',
180
+ client_id: 'ai',
181
+ client_secret: 'ak',
182
+ endpoint: 'ep',
183
+ user_agent: 'ua'
185
184
  }
186
185
  end
187
186
 
188
187
  it 'should override module configuration' do
189
188
  api = Aladtec::Client.new(config)
190
189
  valid_keys.each do |key|
191
- expect(api.public_send(key)).to eq(config[key])
190
+ expect(api.config.public_send(key)).to eq(config[key])
192
191
  end
193
192
  end
194
193
 
@@ -196,11 +195,11 @@ describe Aladtec::Client do
196
195
  api = Aladtec::Client.new
197
196
 
198
197
  config.each do |key, value|
199
- api.public_send("#{key}=", value)
198
+ api.config.public_send("#{key}=", value)
200
199
  end
201
200
 
202
201
  valid_keys.each do |key|
203
- expect(api.send("#{key}")).to eq(config[key])
202
+ expect(api.config.send(key.to_s)).to eq(config[key])
204
203
  end
205
204
  end
206
205
  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
+ }
@@ -0,0 +1,24 @@
1
+ [
2
+ {
3
+ "schedule_id": 1,
4
+ "positions": [
5
+ {
6
+ "position_id": 1,
7
+ "member_id": 42
8
+ }
9
+ ]
10
+ },
11
+ {
12
+ "schedule_id": 2,
13
+ "positions": [
14
+ {
15
+ "position_id": 3,
16
+ "member_id": 27
17
+ },
18
+ {
19
+ "position_id": 4,
20
+ "member_id": 22
21
+ }
22
+ ]
23
+ }
24
+ ]
@@ -0,0 +1,32 @@
1
+ [
2
+ {
3
+ "schedule_id": 1,
4
+ "name": "Ambulance 1",
5
+ "is_archived": false,
6
+ "positions": [
7
+ {
8
+ "position_id": 1,
9
+ "label": "Driver"
10
+ },
11
+ {
12
+ "position_id": 2,
13
+ "label": "Firefighter"
14
+ }
15
+ ]
16
+ },
17
+ {
18
+ "schedule_id": 2,
19
+ "name": "Fire Crew 1",
20
+ "is_archived": false,
21
+ "positions": [
22
+ {
23
+ "position_id": 3,
24
+ "label": "Slot 1"
25
+ },
26
+ {
27
+ "position_id": 4,
28
+ "label": "Slot 2"
29
+ }
30
+ ]
31
+ }
32
+ ]
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'aladtec'
2
4
  require 'rspec'
3
5
  require 'webmock/rspec'
6
+ require 'dry/configurable/test_interface'
7
+
8
+ module Aladtec
9
+ enable_test_interface
10
+ end
4
11
 
5
12
  begin
6
13
  require 'pry'
@@ -11,10 +18,11 @@ RSpec.configure do |config|
11
18
  config.expect_with :rspec do |c|
12
19
  c.syntax = :expect
13
20
  end
21
+ config.filter_run_when_matching :focus
14
22
  end
15
23
 
16
24
  def fixture_path
17
- File.expand_path("../fixtures", __FILE__)
25
+ File.expand_path('fixtures', __dir__)
18
26
  end
19
27
 
20
28
  def fixture(file)