aladtec 0.2.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +8 -1
- data/CHANGELOG.md +8 -0
- data/Gemfile +2 -0
- data/README.md +12 -3
- data/Rakefile +4 -2
- data/aladtec.gemspec +22 -16
- data/lib/aladtec/client.rb +63 -78
- 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/lib/aladtec.rb +12 -4
- data/spec/aladtec/aladtec_spec.rb +18 -1
- data/spec/aladtec/client_spec.rb +100 -101
- 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 +61 -33
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5fe187974f6bb3afdfee9fa734097e8e9aa644e3d8e6d62eb5c3aeca466e3f84
|
4
|
+
data.tar.gz: 31d54f6839c062dba60924565d4d42e65b4521d106dc0bcc614d61889b87cf63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e29cd58cef7d9a02caacc815d6db9fb8b5a4e3279c6b4530d4d7ee6851289b759539881aa2660020c00c9fd0085ba411853cabb442a32a048c52e8ddc084af6
|
7
|
+
data.tar.gz: 6eafb4634d7659680d1b99d305b95ed0e8e9ca46c05885c8a145d837018a88286219b1dc6c5572e97591d1b0d4056a2333648eea69403986cd649c096f662e10
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
|
2
|
+
# 0.3.1
|
3
|
+
- Fix for dry-configurable 0.11 config#update does not return self
|
4
|
+
|
5
|
+
# 0.3.0
|
6
|
+
- Updated to JSON api
|
7
|
+
- Added http dependency
|
8
|
+
|
1
9
|
# 0.2.0
|
2
10
|
- Removed dependencies on happy_mapper and rest_client.
|
3
11
|
- Removed RangeDenormalizer. ScheduledRanges will no longer include member and position attributes.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Aladtec
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/aladtec.svg)](https://badge.fury.io/rb/aladtec)
|
2
3
|
[![Build Status](https://travis-ci.org/travisdahlke/aladtec.svg)](https://travis-ci.org/travisdahlke/aladtec)
|
3
4
|
[![Inline docs](http://inch-ci.org/github/travisdahlke/aladtec.svg?branch=master)](http://inch-ci.org/github/travisdahlke/aladtec)
|
4
5
|
|
@@ -23,8 +24,8 @@ Or install it yourself as:
|
|
23
24
|
Configure the gem with your credentials:
|
24
25
|
|
25
26
|
Aladtec.configure do |config|
|
26
|
-
config.
|
27
|
-
config.
|
27
|
+
config.client_id = ENV['ALADTEC_CLIENT_ID']
|
28
|
+
config.client_secret = ENV['ALADTEC_CLIENT_SECRET']
|
28
29
|
config.endpoint = ENV['ALADTEC_ENDPOINT']
|
29
30
|
end
|
30
31
|
|
@@ -35,12 +36,20 @@ Get members
|
|
35
36
|
|
36
37
|
Get events
|
37
38
|
|
38
|
-
client.events(
|
39
|
+
client.events(begin_time: Time.now, end_time: Time.now + 60 * 60 * 24)
|
39
40
|
|
40
41
|
Get schedules
|
41
42
|
|
42
43
|
client.schedules
|
43
44
|
|
45
|
+
Get scheduled time ranges
|
46
|
+
|
47
|
+
client.scheduled_range(begin_time: Time.new(2019,10,1), end_time: Time.new(2019,10,31))
|
48
|
+
|
49
|
+
Get members scheduled now
|
50
|
+
|
51
|
+
client.scheduled_now
|
52
|
+
|
44
53
|
Refer to the [documentation](http://www.rubydoc.info/github/travisdahlke/aladtec) for more detailed usage.
|
45
54
|
|
46
55
|
## Contributing
|
data/Rakefile
CHANGED
data/aladtec.gemspec
CHANGED
@@ -1,28 +1,34 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'aladtec/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'aladtec'
|
8
9
|
spec.version = Aladtec::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary =
|
12
|
-
spec.description = %
|
13
|
-
|
14
|
-
spec.
|
10
|
+
spec.authors = ['Travis Dahlke']
|
11
|
+
spec.email = ['dahlke.travis@gmail.com']
|
12
|
+
spec.summary = 'Client library for the Aladtec API'
|
13
|
+
spec.description = %(Retrieve schedules and events from the Aladtec API.
|
14
|
+
Works with EMS Manager, Fire Manager, Zanager. )
|
15
|
+
spec.homepage = 'https://github.com/travisdahlke/aladtec'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.required_ruby_version = '> 2.5'
|
15
19
|
|
16
20
|
spec.files = `git ls-files -z`.split("\x0")
|
17
21
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
22
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
23
|
+
spec.require_paths = ['lib']
|
20
24
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
25
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
26
|
+
spec.add_development_dependency 'pry'
|
27
|
+
spec.add_development_dependency 'rake'
|
28
|
+
spec.add_development_dependency 'rspec'
|
29
|
+
spec.add_development_dependency 'webmock'
|
26
30
|
|
27
|
-
spec.add_dependency
|
31
|
+
spec.add_dependency 'dry-configurable', '~> 0.11', '>= 0.11.4'
|
32
|
+
spec.add_dependency 'dry-initializer'
|
33
|
+
spec.add_dependency 'http'
|
28
34
|
end
|
data/lib/aladtec/client.rb
CHANGED
@@ -1,67 +1,75 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'http'
|
3
4
|
require 'aladtec/event'
|
4
5
|
require 'aladtec/member'
|
5
|
-
require 'aladtec/authentication'
|
6
6
|
require 'aladtec/range'
|
7
7
|
require 'aladtec/schedule'
|
8
|
+
require 'aladtec/scheduled_now'
|
8
9
|
require 'aladtec/exceptions'
|
9
10
|
|
10
11
|
module Aladtec
|
12
|
+
# Aladtec API Client
|
11
13
|
class Client
|
14
|
+
attr_reader :config
|
15
|
+
def initialize(args = {})
|
16
|
+
@config = Aladtec.config.dup.tap do |c|
|
17
|
+
c.update(args)
|
18
|
+
end
|
19
|
+
end
|
12
20
|
|
21
|
+
def configure
|
22
|
+
yield config
|
23
|
+
end
|
13
24
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
merged_options = Aladtec.options.merge(options)
|
18
|
-
|
19
|
-
Configuration::VALID_CONFIG_KEYS.each do |key|
|
20
|
-
public_send("#{key}=", merged_options[key])
|
25
|
+
def authenticate
|
26
|
+
if config.client_id.nil? || config.client_secret.nil?
|
27
|
+
raise Aladtec::Error, 'client_id and client_secret are required'
|
21
28
|
end
|
29
|
+
body = { grant_type: 'client_credentials', client_id: config.client_id,
|
30
|
+
client_secret: config.client_secret }
|
31
|
+
response = HTTP.post(URI.join(config.endpoint, 'oauth/token'), json: body)
|
32
|
+
body = response.parse
|
33
|
+
@auth_token = body.fetch('token')
|
34
|
+
@auth_expiration = Time.at body.fetch('expires')
|
35
|
+
response.status.success?
|
22
36
|
end
|
23
37
|
|
24
38
|
# Public: Get a list of events for a date or range of dates
|
25
39
|
#
|
26
40
|
# options - The Hash options used to refine the selection (default: {}):
|
27
|
-
# :
|
28
|
-
# :
|
41
|
+
# :begin_time - The begin date to return events for (required).
|
42
|
+
# :end_time - The end date to return events for (required).
|
29
43
|
def events(options = {})
|
30
|
-
bd = options.fetch(:
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
44
|
+
bd = options.fetch(:begin_time) do
|
45
|
+
raise ArgumentError, 'You must supply a :begin_time option!'
|
46
|
+
end
|
47
|
+
ed = options.fetch(:end_time) do
|
48
|
+
raise ArgumentError, 'You must supply a :end_time option!'
|
35
49
|
end
|
36
|
-
|
37
|
-
|
50
|
+
events = request('events', range_start: format_time(bd),
|
51
|
+
range_stop: format_time(ed))
|
52
|
+
events.values.flatten.map { |event| Event.new(event) }
|
38
53
|
end
|
39
54
|
|
40
55
|
# Public: Get a list of members
|
41
56
|
#
|
42
57
|
def members
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
# Public: Authenticate member
|
48
|
-
#
|
49
|
-
def auth(username, password)
|
50
|
-
body = request(:authenticateMember, memun: username, mempw: password)
|
51
|
-
Authentication.new(body["results"]["authentication"])
|
58
|
+
res = request('members', include_attributes: true)
|
59
|
+
res.map { |member| Member.new(member) }
|
52
60
|
end
|
53
61
|
|
54
62
|
# Public: Get a list of schedules
|
55
63
|
#
|
56
64
|
def schedules
|
57
|
-
|
58
|
-
|
65
|
+
res = request('schedules')
|
66
|
+
res.map { |schedule| Schedule.new(schedule) }
|
59
67
|
end
|
60
68
|
|
61
69
|
# Public: Get list of members scheduled now
|
62
70
|
def scheduled_now(options = {})
|
63
|
-
|
64
|
-
|
71
|
+
res = request('scheduled-time/members-scheduled-now', options)
|
72
|
+
res.map { |schedule| ScheduledNow.new(schedule) }
|
65
73
|
end
|
66
74
|
|
67
75
|
# Public: Get list of members scheduled in a time range
|
@@ -69,61 +77,38 @@ module Aladtec
|
|
69
77
|
# options - The Hash options used to refine the selection (default: {}):
|
70
78
|
# :begin_time - The begin time to return events for (required).
|
71
79
|
# :end_time - The end time to return events for (required).
|
72
|
-
# :sch - Array of schedule ids to fetch
|
73
80
|
def scheduled_range(options = {})
|
74
|
-
bt = options.fetch(:begin_time)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
def fetch_map(body, collection, key, klass)
|
84
|
-
results = body["results"][collection][key] if body["results"][collection]
|
85
|
-
return [] unless results
|
86
|
-
# Array.wrap
|
87
|
-
results = results.respond_to?(:to_ary) ? results.to_ary : [results]
|
88
|
-
results.map{|r| klass.new(r)}
|
89
|
-
end
|
90
|
-
private :fetch_map
|
91
|
-
|
92
|
-
def auth_params
|
93
|
-
{accid: acc_id, acckey: acc_key}
|
81
|
+
bt = options.fetch(:begin_time) do
|
82
|
+
raise ArgumentError, 'You must supply a :begin_time!'
|
83
|
+
end
|
84
|
+
et = options.fetch(:end_time) do
|
85
|
+
raise ArgumentError, 'You must supply an :end_time!'
|
86
|
+
end
|
87
|
+
scheduled_time = request('scheduled-time', range_start: format_time(bt),
|
88
|
+
range_stop: format_time(et))
|
89
|
+
scheduled_time.values.flatten.map { |range| Range.new(range) }
|
94
90
|
end
|
95
|
-
private :auth_params
|
96
91
|
|
97
|
-
|
98
|
-
post_params = options.merge(cmd: cmd)
|
99
|
-
req = Net::HTTP::Post.new(uri)
|
100
|
-
req.set_form_data(auth_params.merge(post_params))
|
101
|
-
req['User-Agent'] = user_agent
|
102
|
-
req['Accept'] = 'application/xml'
|
92
|
+
private
|
103
93
|
|
104
|
-
|
105
|
-
|
106
|
-
|
94
|
+
def request(path, options = {})
|
95
|
+
if auth_expired? && !authenticate
|
96
|
+
raise Aladtec::Error, 'authentication failed'
|
107
97
|
end
|
98
|
+
res = HTTP[user_agent: config.user_agent]
|
99
|
+
.auth("Bearer #{@auth_token}")
|
100
|
+
.get(URI.join(config.endpoint, path), params: options)
|
101
|
+
raise Aladtec::Error, res.status.reason unless res.status.success?
|
108
102
|
|
109
|
-
|
110
|
-
when Net::HTTPSuccess, Net::HTTPRedirection
|
111
|
-
body = MultiXml.parse(res.body)
|
112
|
-
if body["results"]["errors"]
|
113
|
-
raise Aladtec::Error, body["results"]["errors"]["error"]["__content__"]
|
114
|
-
else
|
115
|
-
return body
|
116
|
-
end
|
117
|
-
else
|
118
|
-
raise Aladtec::Error, res.msg
|
119
|
-
end
|
103
|
+
res.parse
|
120
104
|
end
|
121
|
-
private :request
|
122
105
|
|
123
|
-
def
|
124
|
-
|
106
|
+
def format_time(time)
|
107
|
+
(time.is_a?(Time) ? time : Time.parse(time)).strftime('%FT%R')
|
125
108
|
end
|
126
|
-
private :uri
|
127
109
|
|
110
|
+
def auth_expired?
|
111
|
+
!@auth_token || !@auth_expiration || Time.now >= @auth_expiration
|
112
|
+
end
|
128
113
|
end
|
129
114
|
end
|
data/lib/aladtec/event.rb
CHANGED
@@ -1,13 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
4
|
+
|
1
5
|
module Aladtec
|
6
|
+
# Event
|
2
7
|
class Event
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
extend Dry::Initializer
|
9
|
+
|
10
|
+
option :event_id, as: :id
|
11
|
+
option :title
|
12
|
+
option :description
|
13
|
+
option :location
|
14
|
+
option :start_datetime, Time.method(:parse), as: :starts_at
|
15
|
+
option :stop_datetime, Time.method(:parse), as: :ends_at, optional: true
|
16
|
+
|
17
|
+
def self.new(params)
|
18
|
+
super **params.transform_keys(&:to_sym)
|
11
19
|
end
|
12
20
|
end
|
13
21
|
end
|
data/lib/aladtec/exceptions.rb
CHANGED
data/lib/aladtec/member.rb
CHANGED
@@ -1,10 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
4
|
+
|
1
5
|
module Aladtec
|
6
|
+
# Member
|
2
7
|
class Member
|
3
|
-
|
8
|
+
extend Dry::Initializer
|
9
|
+
|
10
|
+
option :member_id, as: :id
|
11
|
+
option :name
|
12
|
+
option :is_active
|
13
|
+
option :attributes, [] do
|
14
|
+
option :attribute_id, as: :id
|
15
|
+
option :value
|
16
|
+
end
|
4
17
|
|
5
|
-
def
|
6
|
-
|
7
|
-
@name = args["name"]
|
18
|
+
def self.new(params)
|
19
|
+
super **params.transform_keys(&:to_sym)
|
8
20
|
end
|
9
21
|
end
|
10
22
|
end
|
data/lib/aladtec/position.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
2
4
|
|
3
5
|
module Aladtec
|
6
|
+
# Position
|
4
7
|
class Position
|
5
|
-
|
8
|
+
extend Dry::Initializer
|
9
|
+
|
10
|
+
option :position_id, as: :id
|
11
|
+
option :label
|
12
|
+
option :member_id, optional: true
|
6
13
|
|
7
|
-
def
|
8
|
-
|
9
|
-
@name = args["name"]
|
10
|
-
@member = Member.new(args["member"]) if args["member"]
|
14
|
+
def self.new(params)
|
15
|
+
super **params.transform_keys(&:to_sym)
|
11
16
|
end
|
12
17
|
end
|
13
18
|
end
|
data/lib/aladtec/range.rb
CHANGED
@@ -1,18 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require '
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
4
4
|
|
5
5
|
module Aladtec
|
6
|
+
# Range
|
6
7
|
class Range
|
7
|
-
|
8
|
+
extend Dry::Initializer
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
option :schedule_id
|
11
|
+
option :position_id
|
12
|
+
option :member_id
|
13
|
+
option :start_datetime, Time.method(:parse), as: :starts_at
|
14
|
+
option :stop_datetime, Time.method(:parse), as: :ends_at
|
15
|
+
option :extends_before
|
16
|
+
option :extends_after
|
16
17
|
|
18
|
+
def self.new(params)
|
19
|
+
super **params.transform_keys(&:to_sym)
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
data/lib/aladtec/schedule.rb
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
2
4
|
|
3
5
|
module Aladtec
|
6
|
+
# Schedule
|
4
7
|
class Schedule
|
5
|
-
|
8
|
+
extend Dry::Initializer
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
option :schedule_id, as: :id
|
11
|
+
option :name
|
12
|
+
option :positions, [] do
|
13
|
+
option :position_id, proc(&:to_i), as: :id
|
14
|
+
option :label
|
11
15
|
end
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
def parse_positions(positions)
|
16
|
-
return [] unless positions
|
17
|
-
return [Position.new(positions)] if positions.include? "id"
|
18
|
-
positions.map{|p| Position.new(p)}
|
17
|
+
def self.new(params)
|
18
|
+
super **params.transform_keys(&:to_sym)
|
19
19
|
end
|
20
|
-
|
21
20
|
end
|
22
21
|
end
|
@@ -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
data/lib/aladtec.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
|
-
|
2
|
-
require "aladtec/configuration"
|
3
|
-
require "aladtec/client"
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
3
|
+
require 'dry/configurable'
|
4
|
+
require 'aladtec/version'
|
5
|
+
require 'aladtec/client'
|
6
|
+
|
7
|
+
# Aladtec API Wrapper
|
5
8
|
module Aladtec
|
6
|
-
extend
|
9
|
+
extend Dry::Configurable
|
10
|
+
|
11
|
+
setting :endpoint, default: 'https://secure.aladtec.com/example/api/'
|
12
|
+
setting :user_agent, default: "Aladtec API Ruby Gem #{Aladtec::VERSION}"
|
13
|
+
setting :client_id
|
14
|
+
setting :client_secret
|
7
15
|
end
|
@@ -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
|