xcal-parktronic 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +7 -0
- data/README.md +73 -7
- data/lib/xcal/parktronic.rb +11 -0
- data/lib/xcal/parktronic/api_client.rb +8 -5
- data/lib/xcal/parktronic/generic_response.rb +18 -2
- data/lib/xcal/parktronic/routes.rb +9 -2
- data/lib/xcal/parktronic/routes/alarms.rb +115 -34
- data/lib/xcal/parktronic/routes/command_notifications.rb +56 -0
- data/lib/xcal/parktronic/routes/custom_queries.rb +80 -0
- data/lib/xcal/parktronic/routes/event_history_items.rb +36 -0
- data/lib/xcal/parktronic/routes/events.rb +67 -0
- data/lib/xcal/parktronic/routes/metrics.rb +120 -0
- data/lib/xcal/parktronic/routes/nested/alarm_actions.rb +84 -0
- data/lib/xcal/parktronic/routes/nested/device_errors.rb +35 -0
- data/lib/xcal/parktronic/routes/nested/events.rb +57 -0
- data/lib/xcal/parktronic/routes/nested/metric_values.rb +35 -0
- data/lib/xcal/parktronic/routes/outages.rb +34 -0
- data/lib/xcal/parktronic/routes/stack_changes.rb +53 -0
- data/lib/xcal/parktronic/version.rb +1 -1
- data/spec/lib/xcal/parktronic/api_client_spec.rb +12 -2
- data/spec/lib/xcal/parktronic/routes/alarms_route_spec.rb +16 -1
- data/spec/lib/xcal/parktronic/routes/command_notifications_routes_spec.rb +32 -0
- data/spec/lib/xcal/parktronic/routes/event_history_items_routes_spec.rb +28 -0
- data/spec/lib/xcal/parktronic/routes/events_route_spec.rb +33 -0
- data/spec/lib/xcal/parktronic/routes/metrics_routes_spec.rb +92 -49
- data/spec/lib/xcal/parktronic/routes/nested/alarm_actions_spec.rb +58 -0
- data/spec/lib/xcal/parktronic/routes/nested/events_spec.rb +24 -0
- data/spec/lib/xcal/parktronic/routes/outages_routes_spec.rb +25 -0
- data/spec/lib/xcal/parktronic/routes/stack_changes_routes_spec.rb +38 -0
- data/spec/support/api_mock.rb +147 -2
- data/spec/support/fixtures/responses/alarm_action.json +19 -0
- data/spec/support/fixtures/responses/alarm_actions.json +40 -0
- data/spec/support/fixtures/responses/alarm_events.json +180 -0
- data/spec/support/fixtures/responses/alarm_post.json +12 -0
- data/spec/support/fixtures/responses/alarm_tags.json +1 -0
- data/spec/support/fixtures/responses/command_notification.json +7 -0
- data/spec/support/fixtures/responses/command_notifications.json +45 -0
- data/spec/support/fixtures/responses/event.json +22 -0
- data/spec/support/fixtures/responses/event_tags.json +1 -0
- data/spec/support/fixtures/responses/events.json +42 -0
- data/spec/support/fixtures/responses/events_history_page_1.json +55 -0
- data/spec/support/fixtures/responses/events_history_page_2.json +55 -0
- data/spec/support/fixtures/responses/metric.json +8 -0
- data/spec/support/fixtures/responses/metric_device_errors.json +610 -0
- data/spec/support/fixtures/responses/metric_metric_values.json +586 -0
- data/spec/support/fixtures/responses/metric_post.json +12 -0
- data/spec/support/fixtures/responses/metrics_page_1.json +90 -0
- data/spec/support/fixtures/responses/metrics_page_2.json +90 -0
- data/spec/support/fixtures/responses/outages_page_1.json +55 -0
- data/spec/support/fixtures/responses/outages_page_2.json +55 -0
- data/spec/support/fixtures/responses/stack_changes_page_1.json +80 -0
- data/spec/support/fixtures/responses/stack_changes_page_2.json +80 -0
- data/spec/support/fixtures/responses/stack_changes_post.json +12 -0
- data/xcal-parktronic.gemspec +1 -1
- metadata +76 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGJhY2FjMDA3YzIwYWY2ZGVjN2IwNTliNmJjMWNjZTZjYmU3NGU0Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmE2MzU3Mzk2NWJiZjk2ZTkxOWRhYzk4ZWE4OWM0NmM4MWVlNTE0Zg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDAxMzYyMTk1ZDM0MTg3MzkwNDVjNjg4YjMwYTA0M2UzNzhkZWJkM2Q1MTVj
|
10
|
+
ZWExNWZmNmZkYWU0YzJiNmYyZTI3ODk5ZjViOTE1YzI3OTFlNDkxY2RlOWM0
|
11
|
+
Mzg0YmJlZGRkYWE5YjkyMzZmNmRjNzE1YzBlYWZmMDY1YjJlZGU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjU4MTI5YTliN2RiM2QzZGQxZTVmMDg0MzE3M2JmNDc1NDFlMWRkMDkyNDk5
|
14
|
+
NTIxYzdhMDVlZmMyMWYyNTJiOWVkOTE1NDM2Y2U5YmY4ZGI2MjA3YzkwYTU0
|
15
|
+
YjFkZjY2ODFkZWVjYjE4MDViNDc4ODQyYjMzMzBmZDlkNzg5ODU=
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
|
2
|
+
[![Build Status](https://api.travis-ci.org/Ser1aL/xcal-parktronic.png?branch=master)](http://travis-ci.org/Ser1aL/xcal-parktronic)
|
3
|
+
|
1
4
|
# Xcal::Parktronic
|
2
5
|
|
3
6
|
TODO: Write a gem description
|
@@ -16,14 +19,77 @@ Or install it yourself as:
|
|
16
19
|
|
17
20
|
$ gem install xcal-parktronic
|
18
21
|
|
22
|
+
## RDocs
|
23
|
+
|
24
|
+
You can view documentation in RDoc format here:
|
25
|
+
|
26
|
+
http://rubydoc.info/gems/xcal-parktronic/frames
|
27
|
+
|
19
28
|
## Usage
|
20
29
|
|
21
|
-
|
30
|
+
# Initialization:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
api = Xcal::Parktronic::ApiClient.new(access_token: 'your_access_token', endpoint: 'http://api_host')
|
34
|
+
```
|
35
|
+
|
36
|
+
# Alarms:
|
37
|
+
```ruby
|
38
|
+
api.alarms
|
39
|
+
api.alarm_tags(1)
|
40
|
+
api.search_alarm(name: 'test', tagged_with: 'test', time_range: 24, originating_system: 'Splunk', page: 1, per_page: 20)
|
41
|
+
```
|
42
|
+
|
43
|
+
# Outages:
|
44
|
+
```ruby
|
45
|
+
api.outages
|
46
|
+
api.outages(page: 2, per_page: 5)
|
47
|
+
```
|
48
|
+
|
49
|
+
# Stack changes
|
50
|
+
```ruby
|
51
|
+
api.stack_changes
|
52
|
+
api.stack_changes(page: 2, per_page: 5)
|
53
|
+
api.stack_changes(page: 2, per_page: 5, element: 'XBO')
|
54
|
+
api.stack_changes(time_range: {time_offset: -1, start_date: 0, start_time: 1440, end_time: 0}, element: 'XBO')
|
55
|
+
```
|
56
|
+
|
57
|
+
# Events history
|
58
|
+
```ruby
|
59
|
+
api.events_history
|
60
|
+
api.events_history(page: 2, per_page: 5)
|
61
|
+
api.events_history(host_impacted: 'xre-host-1', service_impacted: 'xre')
|
62
|
+
```
|
63
|
+
|
64
|
+
# Command notifications (remote commands)
|
65
|
+
```ruby
|
66
|
+
api.command_notifications
|
67
|
+
api.command_notifications(page: 1, per_page: 2)
|
68
|
+
api.update_command_notification(10)
|
69
|
+
```
|
70
|
+
|
71
|
+
# Events
|
72
|
+
```ruby
|
73
|
+
api.add_event
|
74
|
+
api.update_event
|
75
|
+
api.event_tags(1)
|
76
|
+
api.alarm(3).get_all_events
|
77
|
+
api.alarm(3).post_event(data)
|
78
|
+
```
|
22
79
|
|
23
|
-
|
80
|
+
# Alarm Actions
|
81
|
+
```ruby
|
82
|
+
api.alarm(3).get_alarm_actions
|
83
|
+
api.alarm(3).get_alarm_action(alarm_action_id)
|
84
|
+
api.alarm(3).post_alarm_action
|
85
|
+
api.alarm(3).update_alarm_action
|
86
|
+
api.alarm(3).set_position
|
87
|
+
```
|
24
88
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
89
|
+
# Custom Queries
|
90
|
+
```ruby
|
91
|
+
api.get_custom_queries
|
92
|
+
api.post_custom_query
|
93
|
+
api.update_custom_query
|
94
|
+
api.find_custom_query
|
95
|
+
```
|
data/lib/xcal/parktronic.rb
CHANGED
@@ -11,6 +11,17 @@ require 'hashie'
|
|
11
11
|
|
12
12
|
# each route then common Routes module
|
13
13
|
require 'xcal/parktronic/routes/alarms'
|
14
|
+
require 'xcal/parktronic/routes/events'
|
15
|
+
require 'xcal/parktronic/routes/nested/events'
|
16
|
+
require 'xcal/parktronic/routes/metrics'
|
17
|
+
require 'xcal/parktronic/routes/custom_queries'
|
18
|
+
require 'xcal/parktronic/routes/nested/alarm_actions'
|
19
|
+
require 'xcal/parktronic/routes/nested/metric_values'
|
20
|
+
require 'xcal/parktronic/routes/nested/device_errors'
|
21
|
+
require 'xcal/parktronic/routes/outages'
|
22
|
+
require 'xcal/parktronic/routes/stack_changes'
|
23
|
+
require 'xcal/parktronic/routes/event_history_items'
|
24
|
+
require 'xcal/parktronic/routes/command_notifications'
|
14
25
|
require 'xcal/parktronic/routes'
|
15
26
|
|
16
27
|
# exceptions
|
@@ -7,13 +7,16 @@ module Xcal
|
|
7
7
|
|
8
8
|
# API Client initialization.
|
9
9
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
10
|
+
# ==== Parameters
|
11
|
+
# * +endpoint+ - OIV endpoint
|
12
|
+
# * +proxy+ - enables proxy if proxy url is passed
|
13
|
+
# * +access_token+ - access key to application
|
14
|
+
# * +version+ - api version. defaults to v1
|
15
|
+
# ==== Examples
|
16
|
+
# api = Xcal::Parktronic::ApiClient.new(access_token: 'your_access_token', endpoint: 'http://api-host.com')
|
15
17
|
def initialize(args)
|
16
18
|
@args = args
|
19
|
+
@args.default_proc = proc{|h, k| h.key?(k.to_s) ? h[k.to_s] : nil}
|
17
20
|
end
|
18
21
|
|
19
22
|
def host
|
@@ -4,11 +4,19 @@ module Xcal
|
|
4
4
|
class GenericResponse
|
5
5
|
include Exceptions
|
6
6
|
|
7
|
+
# define all nested routes here
|
8
|
+
include Routes::Nested::Events
|
9
|
+
include Routes::Nested::DeviceErrors
|
10
|
+
include Routes::Nested::MetricValues
|
11
|
+
include Routes::Nested::AlarmActions
|
12
|
+
|
13
|
+
attr_reader :client
|
14
|
+
|
7
15
|
# Generic Response initializations
|
8
16
|
#
|
9
17
|
# Accepted attributes are:
|
10
18
|
# +raw_response+ should be a hash or a valid raw JSON string
|
11
|
-
def initialize(raw_response = nil)
|
19
|
+
def initialize(raw_response = nil, client = nil)
|
12
20
|
# nil input
|
13
21
|
raise InvalidResponseArgument.new('Cannot create response object without raw response') if raw_response.nil?
|
14
22
|
|
@@ -28,12 +36,20 @@ module Xcal
|
|
28
36
|
end
|
29
37
|
|
30
38
|
@source = Hashie::Mash.new(@source)
|
39
|
+
@client = client
|
40
|
+
end
|
41
|
+
|
42
|
+
def has_key?(key)
|
43
|
+
@source.has_key?(key)
|
31
44
|
end
|
32
45
|
|
33
46
|
def method_missing(*args)
|
34
|
-
#
|
47
|
+
# verify key in hashed self first
|
35
48
|
if @source.has_key?(args.first)
|
36
49
|
@source[args.first]
|
50
|
+
# verify key in nested routes
|
51
|
+
elsif respond_to?(args.first)
|
52
|
+
send args.first
|
37
53
|
else
|
38
54
|
raise NoMethodError, "undefined method `#{args.first}' for #{self.class}"
|
39
55
|
end
|
@@ -2,8 +2,15 @@ module Xcal
|
|
2
2
|
module Parktronic
|
3
3
|
|
4
4
|
module Routes
|
5
|
-
# include
|
5
|
+
# include top-level routes here
|
6
6
|
include Alarms
|
7
|
+
include Metrics
|
8
|
+
include Events
|
9
|
+
include Outages
|
10
|
+
include StackChanges
|
11
|
+
include EventHistoryItems
|
12
|
+
include CommandNotifications
|
13
|
+
include CustomQueries
|
7
14
|
end
|
8
15
|
end
|
9
|
-
end
|
16
|
+
end
|
@@ -6,72 +6,153 @@ module Xcal
|
|
6
6
|
|
7
7
|
# Fetches latest alarms
|
8
8
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
9
|
+
# ==== Parameters
|
10
|
+
# * +page+ page number, defaults to 1
|
11
|
+
# * +per_page+ per page value, defaults to 100
|
12
|
+
#
|
13
|
+
# ==== Examples
|
14
|
+
# api.get_paged_alarms
|
15
|
+
# api.get_paged_alarms(page: 2, per_page: 5)
|
16
|
+
# api.alarms
|
17
|
+
# api.alarms(page: 2, per_page: 5)
|
12
18
|
def get_paged_alarms(args = {})
|
13
19
|
args.merge!(:access_token => access_token)
|
14
20
|
response = http.get("/#{api_version}/alarms?#{URI.encode_www_form(args)}")
|
15
21
|
|
16
22
|
generic_response = Xcal::Parktronic::GenericResponse.new(response.body)
|
17
|
-
response.code == '200'
|
23
|
+
if response.code == '200'
|
24
|
+
generic_response.alarms.map { |alarm| Xcal::Parktronic::GenericResponse.new(alarm.alarm, self) }
|
25
|
+
else
|
26
|
+
generic_response
|
27
|
+
end
|
18
28
|
|
19
29
|
# TODO Add caching
|
20
30
|
end
|
21
31
|
alias :alarms :get_paged_alarms
|
22
32
|
|
23
|
-
|
24
33
|
# Fetches alarm with specific ID
|
25
34
|
#
|
26
|
-
#
|
27
|
-
# +id+ alarm ID
|
35
|
+
# ==== Parameters
|
36
|
+
# * +id+ alarm ID
|
37
|
+
#
|
38
|
+
# ==== Examples
|
39
|
+
# api.get_alarm(2)
|
28
40
|
def get_alarm(id)
|
29
41
|
response = http.get("/#{api_version}/alarms/#{id}?access_token=#{access_token}")
|
30
42
|
|
31
43
|
generic_response = Xcal::Parktronic::GenericResponse.new(response.body)
|
32
|
-
response.code == '200' ? generic_response.alarm : generic_response
|
44
|
+
response.code == '200' ? Xcal::Parktronic::GenericResponse.new(generic_response.alarm, self) : generic_response
|
33
45
|
|
34
46
|
# TODO Add caching
|
35
47
|
end
|
36
48
|
alias :alarm :get_alarm
|
37
49
|
|
50
|
+
|
38
51
|
# Posts new alarm
|
39
52
|
#
|
40
|
-
#
|
53
|
+
# ==== Parameters
|
54
|
+
# * +alarm+ hash of Alarm data.
|
55
|
+
# * +events+ array of Events or leave blank for creating alarm without events.
|
41
56
|
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
|
50
|
-
|
57
|
+
# ==== Examples
|
58
|
+
# # Creates only Alarm, without Events
|
59
|
+
# api.post_alarm(alarm: {name: 'alarm name', originating_system: 'Source System', impact_level: 'low'})
|
60
|
+
# # Creates Alarm with Events
|
61
|
+
# alarm_params = {name: 'alarm name', originating_system: 'Source System', impact_level: 'low'}
|
62
|
+
# event_1_params = {subject: 'EventSubj', description: 'EventDesc', host_impacted: 'host', initiated_at: '2013-11-22T01:00:24Z', service_impacted: 'EventSvc', incident_status: 'CRITICAL'}
|
63
|
+
# api.post_alarm( alarm: alarm_params, events: [event_1_params, event_2_params, ...] )
|
64
|
+
def post_alarm(args = {})
|
65
|
+
url_path = args[:events].nil? ? 'alarms/create_without_events' : 'alarms'
|
66
|
+
request = Net::HTTP::Post.new("/#{api_version}/#{url_path}", 'Content-Type' => 'application/json')
|
67
|
+
|
68
|
+
params = { access_token: access_token, alarm: args[:alarm] }
|
69
|
+
params.merge!(events: args[:events]) unless args[:events].nil?
|
70
|
+
|
71
|
+
request.body = params.to_json
|
72
|
+
response = http.start { |net| net.request(request) }
|
73
|
+
|
74
|
+
Xcal::Parktronic::GenericResponse.new(response.body)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Update alarm with specific ID
|
51
78
|
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
# {
|
56
|
-
# :subject => 'EventSubj',
|
57
|
-
# :description => 'EventDesc',
|
58
|
-
# :host_impacted => 'host',
|
59
|
-
# :initiated_at => '2013-11-22T01:00:24Z',
|
60
|
-
# :service_impacted => 'EventSvc',
|
61
|
-
# :incident_status => 'CRITICAL'
|
62
|
-
# }
|
63
|
-
# ]
|
79
|
+
# ==== Parameters
|
80
|
+
# * +id+ alarm ID
|
81
|
+
# * +params+ alarm params
|
64
82
|
#
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
83
|
+
# ==== Examples
|
84
|
+
# api.update_alarm(2, name: 'new name')
|
85
|
+
# api.update_alarm(5, name: 'new name', originating_system: 'new system', description: 'test')
|
86
|
+
def update_alarm(id, params)
|
87
|
+
request = Net::HTTP::Patch.new("/#{api_version}/alarms/#{id}", 'Content-Type' => 'application/json')
|
88
|
+
request.body = { access_token: access_token, alarm: params }.to_json
|
69
89
|
|
90
|
+
response = http.start { |net| net.request(request) }
|
70
91
|
Xcal::Parktronic::GenericResponse.new(response.body)
|
71
92
|
end
|
72
93
|
|
73
94
|
end
|
74
95
|
|
96
|
+
# Find all Alarm Tags
|
97
|
+
#
|
98
|
+
# ==== Parameters
|
99
|
+
# * +id+ alarm ID
|
100
|
+
#
|
101
|
+
# ==== Examples
|
102
|
+
# api.get_alarm_tags(2)
|
103
|
+
# api.alarm_tags(2)
|
104
|
+
def get_alarm_tags(id)
|
105
|
+
response = http.get("/#{api_version}/alarms/#{id}/tags?#{URI.encode_www_form(access_token: access_token)}")
|
106
|
+
|
107
|
+
generic_response = Xcal::Parktronic::GenericResponse.new(response.body, self)
|
108
|
+
response.code == '200' && generic_response.has_key?(:tags) ? generic_response.tags.map(&:tag) : generic_response
|
109
|
+
end
|
110
|
+
alias :alarm_tags :get_alarm_tags
|
111
|
+
|
112
|
+
# Search unclosed alarm by name or tag or originating system with time range
|
113
|
+
#
|
114
|
+
# ==== Parameters
|
115
|
+
# * +name+ string, alarm name
|
116
|
+
# * +tagged_with+ string or array, tag list
|
117
|
+
# * +time_range+ integer, time range in hours, defaults to 24 hours
|
118
|
+
# * +originating_system+ string or array, originating system name(s), blank by default (example: 'Op5_Nagios' or 'Op5_Nagios Splunk' or ['Op5_Nagios', 'Splunk'])
|
119
|
+
# * +page+ integer, page number, defaults to 1
|
120
|
+
# * +per_page+ integer, per page value, defaults to 100
|
121
|
+
#
|
122
|
+
# ==== Examples
|
123
|
+
# api.search_alarm(name: 'test alarm')
|
124
|
+
# api.search_alarm(tagged_with: 'test alarm', time_range: 120)
|
125
|
+
|
126
|
+
def search_alarm(args = {})
|
127
|
+
custom_extends = [ 'latest_event', 'latest_unclosed_event' ]
|
128
|
+
custom_scopes = { with_most_recent_events: [] }
|
129
|
+
|
130
|
+
#Filter
|
131
|
+
filter = { alarms: '' }
|
132
|
+
custom_filter = args[:originating_system]
|
133
|
+
custom_filter = custom_filter.split(' ') if custom_filter.is_a?(String)
|
134
|
+
filter = { alarms: custom_filter.map{|os| "originating_system = '#{os}'"}.join(' OR ') } unless custom_filter.nil?
|
135
|
+
|
136
|
+
#Scopes (time range)
|
137
|
+
custom_scopes[:within_event_date_range] = [(Time.now - (60 * (60 * args.fetch(:time_range, 24)))).strftime('%Y-%m-%d %H:%M:%S'), Time.now.strftime('%Y-%m-%d %H:%M:%S')]
|
138
|
+
|
139
|
+
#Tags
|
140
|
+
custom_scopes[:tagged_with] = args[:tagged_with] unless args[:tagged_with].nil?
|
141
|
+
|
142
|
+
# Params for request
|
143
|
+
scopes = URI.escape(custom_scopes.to_json)
|
144
|
+
search = URI.escape({name: args.fetch(:name, '')}.to_json)
|
145
|
+
extends = URI.escape(args.fetch(:extends, custom_extends).to_json)
|
146
|
+
filter = URI.escape(args.fetch(:filter, filter).to_json)
|
147
|
+
page = args.fetch(:page, 1)
|
148
|
+
per_page = args.fetch(:per_page, 100)
|
149
|
+
|
150
|
+
response = http.get("/#{api_version}/alarms/search?page=#{page}&per_page=#{per_page}&scopes=#{scopes}&search=#{search}&extends=#{extends}&filter=#{filter}&access_token=#{access_token}")
|
151
|
+
|
152
|
+
generic_response = Xcal::Parktronic::GenericResponse.new(response.body)
|
153
|
+
response.code == '200' && generic_response.has_key?(:alarms) ? generic_response.alarms.map(&:alarm) : generic_response
|
154
|
+
end
|
155
|
+
|
75
156
|
end
|
76
157
|
end
|
77
158
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Xcal
|
2
|
+
module Parktronic
|
3
|
+
module Routes
|
4
|
+
|
5
|
+
module CommandNotifications
|
6
|
+
|
7
|
+
# Fetches remote commands
|
8
|
+
#
|
9
|
+
# ==== Parameters
|
10
|
+
# * +page+ page number, defaults to 1
|
11
|
+
# * +per_page+ per page value, defaults to 100
|
12
|
+
#
|
13
|
+
# ==== Examples
|
14
|
+
# api.get_paged_command_notifications
|
15
|
+
# api.command_notifications
|
16
|
+
def get_paged_command_notifications(args = {})
|
17
|
+
args.merge!(access_token: access_token)
|
18
|
+
response = http.get("/#{api_version}/command_notifications?#{URI.encode_www_form(args)}")
|
19
|
+
|
20
|
+
generic_response = Xcal::Parktronic::GenericResponse.new(response.body)
|
21
|
+
if response.code == '200' && generic_response.has_key?(:remote_commands)
|
22
|
+
generic_response.remote_commands.map { |command| Xcal::Parktronic::GenericResponse.new(command.remote_command, self) }
|
23
|
+
else
|
24
|
+
generic_response
|
25
|
+
end
|
26
|
+
|
27
|
+
# TODO Add caching
|
28
|
+
end
|
29
|
+
alias :command_notifications :get_paged_command_notifications
|
30
|
+
|
31
|
+
|
32
|
+
# Set inactive remote command
|
33
|
+
#
|
34
|
+
# ==== Parameters
|
35
|
+
# * +id+ remote command ID
|
36
|
+
#
|
37
|
+
# ==== Examples
|
38
|
+
# api.update_command_notification(1)
|
39
|
+
# api.set_inactive_command_notification(1)
|
40
|
+
def update_command_notification(id)
|
41
|
+
begin
|
42
|
+
request = Net::HTTP::Patch.new("/#{api_version}/command_notifications/#{id}", 'Content-Type' => 'application/json')
|
43
|
+
rescue # ruby 1.9.2
|
44
|
+
request = Net::HTTP::Put.new("/#{api_version}/command_notifications/#{id}", 'Content-Type' => 'application/json')
|
45
|
+
end
|
46
|
+
request.body = { access_token: access_token }.to_json
|
47
|
+
|
48
|
+
response = http.start { |net| net.request(request) }
|
49
|
+
Xcal::Parktronic::GenericResponse.new(response.body)
|
50
|
+
end
|
51
|
+
alias :set_inactive_command_notification :update_command_notification
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|