aladtec 0.2.0 → 0.3.0
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 +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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1e687432d0c3fdf944414f149f28dbddd226255191cf192240a6f5ba244f9077
|
4
|
+
data.tar.gz: a8bd333f2c39f0ed0d88fcabe7127488f80b09f5d349a4118412936c145bdfac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '011149c9cf0f94c581135fbb1c2f0e1aa2e4ea05fcb97c03e4eb7008c9ffe68b7f80750618a71b7503599e9543483ff6ffc431e19a0360a5e21b93f7ee6305fa'
|
7
|
+
data.tar.gz: '0293445a0e145bbd54ca1db4a138feafb3d68ebf2e19559de880988f2afc7fded9a7ca66284090c79795ad3fb0d17f7894a9897e6f9f05cb8b6ad610c8f46730'
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
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
|
|
data/Rakefile
CHANGED
data/aladtec.gemspec
CHANGED
@@ -1,28 +1,32 @@
|
|
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'
|
15
17
|
|
16
18
|
spec.files = `git ls-files -z`.split("\x0")
|
17
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
21
|
+
spec.require_paths = ['lib']
|
20
22
|
|
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
|
23
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
24
|
+
spec.add_development_dependency 'pry'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
spec.add_development_dependency 'webmock'
|
26
28
|
|
27
|
-
spec.add_dependency
|
29
|
+
spec.add_dependency 'dry-configurable'
|
30
|
+
spec.add_dependency 'dry-initializer'
|
31
|
+
spec.add_dependency 'http'
|
28
32
|
end
|
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, 'https://secure.aladtec.com/example/api/'
|
12
|
+
setting :user_agent, "Aladtec API Ruby Gem #{Aladtec::VERSION}"
|
13
|
+
setting :client_id
|
14
|
+
setting :client_secret
|
7
15
|
end
|
data/lib/aladtec/client.rb
CHANGED
@@ -1,67 +1,70 @@
|
|
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.update(args)
|
17
|
+
end
|
12
18
|
|
19
|
+
def configure
|
20
|
+
yield config
|
21
|
+
end
|
13
22
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
23
|
+
def authenticate
|
24
|
+
body = { grant_type: 'client_credentials', client_id: config.client_id,
|
25
|
+
client_secret: config.client_secret }
|
26
|
+
response = HTTP.post(URI.join(config.endpoint, 'oauth/token'), json: body)
|
27
|
+
body = response.parse
|
28
|
+
@auth_token = body.fetch('token')
|
29
|
+
@auth_expiration = Time.at body.fetch('expires')
|
30
|
+
response.status.success?
|
22
31
|
end
|
23
32
|
|
24
33
|
# Public: Get a list of events for a date or range of dates
|
25
34
|
#
|
26
35
|
# options - The Hash options used to refine the selection (default: {}):
|
27
|
-
# :
|
28
|
-
# :
|
36
|
+
# :begin_time - The begin date to return events for (required).
|
37
|
+
# :end_time - The end date to return events for (required).
|
29
38
|
def events(options = {})
|
30
|
-
bd = options.fetch(:
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
39
|
+
bd = options.fetch(:begin_time) do
|
40
|
+
raise ArgumentError, 'You must supply a :begin_time option!'
|
41
|
+
end
|
42
|
+
ed = options.fetch(:end_time) do
|
43
|
+
raise ArgumentError, 'You must supply a :end_time option!'
|
35
44
|
end
|
36
|
-
|
37
|
-
|
45
|
+
events = request('events', range_start: format_time(bd),
|
46
|
+
range_stop: format_time(ed))
|
47
|
+
events.values.flatten.map { |event| Event.new(event) }
|
38
48
|
end
|
39
49
|
|
40
50
|
# Public: Get a list of members
|
41
51
|
#
|
42
52
|
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"])
|
53
|
+
res = request('members', include_attributes: true)
|
54
|
+
res.map { |member| Member.new(member) }
|
52
55
|
end
|
53
56
|
|
54
57
|
# Public: Get a list of schedules
|
55
58
|
#
|
56
59
|
def schedules
|
57
|
-
|
58
|
-
|
60
|
+
res = request('schedules')
|
61
|
+
res.map { |schedule| Schedule.new(schedule) }
|
59
62
|
end
|
60
63
|
|
61
64
|
# Public: Get list of members scheduled now
|
62
65
|
def scheduled_now(options = {})
|
63
|
-
|
64
|
-
|
66
|
+
res = request('scheduled-time/members-scheduled-now', options)
|
67
|
+
res.map { |schedule| ScheduledNow.new(schedule) }
|
65
68
|
end
|
66
69
|
|
67
70
|
# Public: Get list of members scheduled in a time range
|
@@ -71,59 +74,31 @@ module Aladtec
|
|
71
74
|
# :end_time - The end time to return events for (required).
|
72
75
|
# :sch - Array of schedule ids to fetch
|
73
76
|
def scheduled_range(options = {})
|
74
|
-
bt = options.fetch(:begin_time)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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}
|
77
|
+
bt = options.fetch(:begin_time) do
|
78
|
+
raise ArgumentError, 'You must supply a :begin_time!'
|
79
|
+
end
|
80
|
+
et = options.fetch(:end_time) do
|
81
|
+
raise ArgumentError, 'You must supply an :end_time!'
|
82
|
+
end
|
83
|
+
# sch = Array(options.fetch(:sch, "all")).join(",")
|
84
|
+
scheduled_time = request('scheduled-time', range_start: format_time(bt),
|
85
|
+
range_stop: format_time(et))
|
86
|
+
scheduled_time.values.flatten.map { |range| Range.new(range) }
|
94
87
|
end
|
95
|
-
private :auth_params
|
96
88
|
|
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'
|
89
|
+
private
|
103
90
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
91
|
+
def request(path, options = {})
|
92
|
+
res = HTTP[user_agent: config.user_agent]
|
93
|
+
.auth("Bearer #{@auth_token}")
|
94
|
+
.get(URI.join(config.endpoint, path), params: options)
|
95
|
+
raise Aladtec::Error, res.status.reason unless res.status.success?
|
108
96
|
|
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
|
97
|
+
res.parse
|
120
98
|
end
|
121
|
-
private :request
|
122
99
|
|
123
|
-
def
|
124
|
-
|
100
|
+
def format_time(time)
|
101
|
+
(time.is_a?(Time) ? time : Time.parse(time)).strftime('%FT%R')
|
125
102
|
end
|
126
|
-
private :uri
|
127
|
-
|
128
103
|
end
|
129
104
|
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
|