meshx-plugin-sdk 0.0.4 → 0.0.6
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.
- checksums.yaml +4 -4
- data/lib/meshx-plugin-sdk.rb +31 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80180d515a6d2ad6c1b1f378f62c801a04003314a9887b090f205d35ccdf635e
|
4
|
+
data.tar.gz: 29d1fdfb37876a3b4e560461a1cdfb653864449b005ca27ce88afe5fa43f5e10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24e21e7dd3077b1c1113631f813e801b18fc0c3bd8db5ec9f6b5f06eaa118371ef52e50b23b703d66f3668e01197030aed2d42ef06d03efbed0be62531ed6fca
|
7
|
+
data.tar.gz: 63bcad78ae1452647dbb96a1b5c1d3384a61f3318974e453b8d4ad7572edaedfff90c6eae48b01f399ccefd13c119b9cb4e7c69b276bd9549fd668a0ed3d4640
|
data/lib/meshx-plugin-sdk.rb
CHANGED
@@ -9,7 +9,7 @@ require "open3"
|
|
9
9
|
### sdk start
|
10
10
|
module GoApi
|
11
11
|
extend FFI::Library
|
12
|
-
ffi_lib "
|
12
|
+
ffi_lib "foundation-api.so"
|
13
13
|
|
14
14
|
class Example < FFI::Struct
|
15
15
|
# This must be completely in sync with the C struct defined in Go code.
|
@@ -121,6 +121,13 @@ class Controller
|
|
121
121
|
@plugin = Plugin.new(@api, @log, @config)
|
122
122
|
end
|
123
123
|
|
124
|
+
def valid_json?(json)
|
125
|
+
JSON.parse(json)
|
126
|
+
true
|
127
|
+
rescue JSON::ParserError, TypeError => e
|
128
|
+
false
|
129
|
+
end
|
130
|
+
|
124
131
|
def run()
|
125
132
|
keep_reading = true
|
126
133
|
@log.info("starting controller loop")
|
@@ -128,26 +135,30 @@ class Controller
|
|
128
135
|
rtn = @api.get_messages()
|
129
136
|
@log.info("rtn: #{rtn.message} #{rtn.error} #{rtn.exit_code}")
|
130
137
|
# convert message to fileevent
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
138
|
+
if valid_json?(rtn.message)
|
139
|
+
hash = JSON.parse()
|
140
|
+
hash["items"].each do |item|
|
141
|
+
@log.info("message kind: #{item["kind"]}")
|
142
|
+
case item["kind"]
|
143
|
+
when "FileEvent"
|
144
|
+
@log.info("FileEvent")
|
145
|
+
event = FileEvent.new(item)
|
146
|
+
@plugin.on_file_event(event)
|
147
|
+
when "FolderEvent"
|
148
|
+
@log.info("FolderEvent")
|
149
|
+
event = FolderEvent.new(item)
|
150
|
+
@plugin.on_folder_event(event)
|
151
|
+
when "CompleteEvent"
|
152
|
+
@log.info("CompleteEvent")
|
153
|
+
event = CompleteEvent.new(item)
|
154
|
+
@plugin.on_complete_event(event)
|
155
|
+
keep_reading = false
|
156
|
+
else
|
157
|
+
@log.info("unknown event kind: #{item["kind"]}")
|
158
|
+
end
|
150
159
|
end
|
160
|
+
else
|
161
|
+
@log.info("invalid message [#{rtn.message}]")
|
151
162
|
end
|
152
163
|
end
|
153
164
|
@log.info("ending controller loop sending complete event")
|