aladtec 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +11 -3
- data/aladtec.gemspec +2 -0
- data/lib/aladtec/client.rb +13 -3
- data/lib/aladtec/version.rb +1 -1
- data/spec/aladtec/client_spec.rb +12 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58c7d99e528d980f7de92a4ba20e6e795d4a6d0fa0e5a2fde093136118844325
|
4
|
+
data.tar.gz: 1cef98df4ff014b2d317e11dacddf121f5b8c87165ab9d63c92944ffdda10eaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfa179a7edf38f090f83c7c37921eaa127e0e29987cc4f06ee535852dfa16da0201e8e8a87be93ff7fc09c0777d5a33d04556053031721ebf91574a2ba1edea7
|
7
|
+
data.tar.gz: cc20798aee7902d02ea43ab81e717d0f946a4a0328eb811049d681c30f440c7c49b419adc3f403bee9317234a2a55b17d2cc4ce8e9442c78f993aa9208f4f145
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -24,8 +24,8 @@ Or install it yourself as:
|
|
24
24
|
Configure the gem with your credentials:
|
25
25
|
|
26
26
|
Aladtec.configure do |config|
|
27
|
-
config.
|
28
|
-
config.
|
27
|
+
config.client_id = ENV['ALADTEC_CLIENT_ID']
|
28
|
+
config.client_secret = ENV['ALADTEC_CLIENT_SECRET']
|
29
29
|
config.endpoint = ENV['ALADTEC_ENDPOINT']
|
30
30
|
end
|
31
31
|
|
@@ -36,12 +36,20 @@ Get members
|
|
36
36
|
|
37
37
|
Get events
|
38
38
|
|
39
|
-
client.events(
|
39
|
+
client.events(begin_time: Time.now, end_time: Time.now + 60 * 60 * 24)
|
40
40
|
|
41
41
|
Get schedules
|
42
42
|
|
43
43
|
client.schedules
|
44
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
|
+
|
45
53
|
Refer to the [documentation](http://www.rubydoc.info/github/travisdahlke/aladtec) for more detailed usage.
|
46
54
|
|
47
55
|
## Contributing
|
data/aladtec.gemspec
CHANGED
@@ -15,6 +15,8 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.homepage = 'https://github.com/travisdahlke/aladtec'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
|
18
|
+
spec.required_ruby_version = '> 2.5'
|
19
|
+
|
18
20
|
spec.files = `git ls-files -z`.split("\x0")
|
19
21
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
22
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
data/lib/aladtec/client.rb
CHANGED
@@ -13,7 +13,9 @@ module Aladtec
|
|
13
13
|
class Client
|
14
14
|
attr_reader :config
|
15
15
|
def initialize(args = {})
|
16
|
-
@config = Aladtec.config.dup.
|
16
|
+
@config = Aladtec.config.dup.tap do |c|
|
17
|
+
c.update(args)
|
18
|
+
end
|
17
19
|
end
|
18
20
|
|
19
21
|
def configure
|
@@ -21,6 +23,9 @@ module Aladtec
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def authenticate
|
26
|
+
if config.client_id.nil? || config.client_secret.nil?
|
27
|
+
raise Aladtec::Error, 'client_id and client_secret are required'
|
28
|
+
end
|
24
29
|
body = { grant_type: 'client_credentials', client_id: config.client_id,
|
25
30
|
client_secret: config.client_secret }
|
26
31
|
response = HTTP.post(URI.join(config.endpoint, 'oauth/token'), json: body)
|
@@ -72,7 +77,6 @@ module Aladtec
|
|
72
77
|
# options - The Hash options used to refine the selection (default: {}):
|
73
78
|
# :begin_time - The begin time to return events for (required).
|
74
79
|
# :end_time - The end time to return events for (required).
|
75
|
-
# :sch - Array of schedule ids to fetch
|
76
80
|
def scheduled_range(options = {})
|
77
81
|
bt = options.fetch(:begin_time) do
|
78
82
|
raise ArgumentError, 'You must supply a :begin_time!'
|
@@ -80,7 +84,6 @@ module Aladtec
|
|
80
84
|
et = options.fetch(:end_time) do
|
81
85
|
raise ArgumentError, 'You must supply an :end_time!'
|
82
86
|
end
|
83
|
-
# sch = Array(options.fetch(:sch, "all")).join(",")
|
84
87
|
scheduled_time = request('scheduled-time', range_start: format_time(bt),
|
85
88
|
range_stop: format_time(et))
|
86
89
|
scheduled_time.values.flatten.map { |range| Range.new(range) }
|
@@ -89,6 +92,9 @@ module Aladtec
|
|
89
92
|
private
|
90
93
|
|
91
94
|
def request(path, options = {})
|
95
|
+
if auth_expired? && !authenticate
|
96
|
+
raise Aladtec::Error, 'authentication failed'
|
97
|
+
end
|
92
98
|
res = HTTP[user_agent: config.user_agent]
|
93
99
|
.auth("Bearer #{@auth_token}")
|
94
100
|
.get(URI.join(config.endpoint, path), params: options)
|
@@ -100,5 +106,9 @@ module Aladtec
|
|
100
106
|
def format_time(time)
|
101
107
|
(time.is_a?(Time) ? time : Time.parse(time)).strftime('%FT%R')
|
102
108
|
end
|
109
|
+
|
110
|
+
def auth_expired?
|
111
|
+
!@auth_token || !@auth_expiration || Time.now >= @auth_expiration
|
112
|
+
end
|
103
113
|
end
|
104
114
|
end
|
data/lib/aladtec/version.rb
CHANGED
data/spec/aladtec/client_spec.rb
CHANGED
@@ -5,6 +5,18 @@ require_relative File.join('..', 'spec_helper')
|
|
5
5
|
describe Aladtec::Client do
|
6
6
|
let(:start_time) { Time.now.strftime('%FT%R') }
|
7
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' })
|
19
|
+
end
|
8
20
|
|
9
21
|
describe '#members' do
|
10
22
|
let(:members) { subject.members }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aladtec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Dahlke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -166,16 +166,16 @@ require_paths:
|
|
166
166
|
- lib
|
167
167
|
required_ruby_version: !ruby/object:Gem::Requirement
|
168
168
|
requirements:
|
169
|
-
- - "
|
169
|
+
- - ">"
|
170
170
|
- !ruby/object:Gem::Version
|
171
|
-
version: '
|
171
|
+
version: '2.5'
|
172
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
173
|
requirements:
|
174
174
|
- - ">="
|
175
175
|
- !ruby/object:Gem::Version
|
176
176
|
version: '0'
|
177
177
|
requirements: []
|
178
|
-
rubygems_version: 3.
|
178
|
+
rubygems_version: 3.1.2
|
179
179
|
signing_key:
|
180
180
|
specification_version: 4
|
181
181
|
summary: Client library for the Aladtec API
|