diff --git a/services/filter/filter.gemspec b/services/filter/filter.gemspec index c0c4e29..af65326 100644 --- a/services/filter/filter.gemspec +++ b/services/filter/filter.gemspec @@ -9,15 +9,15 @@ Gem::Specification.new do |spec| spec.authors = ["Nomura Laboratory, Eiji Yamamoto, Yoshinari Nonura"] spec.email = ["nomura.laboratory@gmail.com"] - spec.summary = %q{TODO: Edit event received with gRPC, and send event by gRPC.} - spec.description = %q{TODO: Edit event received with gRPC, and send event by gRPC.} + spec.summary = %q{Edit event received with gRPC, and send event by gRPC.} + spec.description = %q{Edit event received with gRPC, and send event by gRPC.} spec.homepage = "https://github.com/nomlab/hiyoco" spec.license = "MIT" # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' # to allow pushing to a single host or delete this section to allow pushing to any host. if spec.respond_to?(:metadata) - spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" + spec.metadata["allowed_push_host"] = "Set to 'http://mygemserver.com'" else raise "RubyGems 2.0 or newer is required to protect against " \ "public gem pushes." diff --git a/services/filter/lib/filter/action.rb b/services/filter/lib/filter/action.rb new file mode 100644 index 0000000..68fc604 --- /dev/null +++ b/services/filter/lib/filter/action.rb @@ -0,0 +1,13 @@ +class Action + def initialize(query) + query_array = query.split(":") + @type = query_array[0] + @event_item = query_array[1] + end + + def apply(e) + eval("e.#{event_item} = ''") if @type == "hide" + end + + attr_accessor :type, :event_item +end diff --git a/services/filter/lib/filter/filter_server.rb b/services/filter/lib/filter/filter_server.rb index 8ebe0ed..ab49e76 100644 --- a/services/filter/lib/filter/filter_server.rb +++ b/services/filter/lib/filter/filter_server.rb @@ -1,5 +1,7 @@ +# coding: utf-8 this_dir = File.expand_path(File.dirname(__FILE__)) lib_dir = File.join(this_dir, '../proto') +$LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir) $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir) require 'grpc' @@ -7,15 +9,14 @@ require "hiyoco/filter/service_pb" require "hiyoco/filter/service_services_pb" require "hiyoco/informant/service_services_pb" +require "funnel" class FilterServer < Hiyoco::Filter::Filter::Service def say_event(e, _unused_call) - stub = Hiyoco::Informant::Informant::Stub.new('0.0.0.0:50051', :this_channel_is_insecure) - start_time = Time.at(e.start.date.date.seconds) - end_time = Time.at(e.end.date.date.seconds) - str = "Summary:#{e.summary}\nDescription:#{e.description}\nStart at #{start_time.strftime("%Y-%m-%d %H:%M")}\nEnd at #{end_time.strftime("%Y-%m-%d %H:%M")}\n" - message = stub.say_event(Hiyoco::Calendar::Text.new(body: str )).result - puts message + query = ["summary:打合せ", "hide:description", "slack"] + funnel = Funnel.new(query) + #funnel.outlet.apply(e) # for confirm raw event + funnel.apply(e) end end diff --git a/services/filter/lib/filter/funnel.rb b/services/filter/lib/filter/funnel.rb new file mode 100644 index 0000000..3987949 --- /dev/null +++ b/services/filter/lib/filter/funnel.rb @@ -0,0 +1,20 @@ +require "matcher" +require "action" +require "outlet" + +class Funnel + def initialize(query) + @matcher = Matcher.new(query[0]) + @action = Action.new(query[1]) + @outlet = Outlet.new(query[2]) + end + + def apply(e) + if @matcher.apply(e) then + @action.apply(e) + end + @outlet.apply(e) + end + + attr_accessor :matcher, :action, :outlet +end diff --git a/services/filter/lib/filter/matcher.rb b/services/filter/lib/filter/matcher.rb new file mode 100644 index 0000000..addbf45 --- /dev/null +++ b/services/filter/lib/filter/matcher.rb @@ -0,0 +1,13 @@ +class Matcher + def initialize(query) + query_array = query.split(":") + @event_item = query_array[0] + @arg = query_array[1] + end + + def apply(e) + return true if eval("e.#{event_item}.include?(\"#{arg}\")") + end + + attr_accessor :event_item, :arg +end diff --git a/services/filter/lib/filter/outlet.rb b/services/filter/lib/filter/outlet.rb new file mode 100644 index 0000000..0825e44 --- /dev/null +++ b/services/filter/lib/filter/outlet.rb @@ -0,0 +1,20 @@ +class Outlet + def initialize(query) + query_array = query.split(":") + @type = query_array[0] + @dest = query_array[1] + end + + def apply(e) + if @type == "slack" then + start_time = Time.at(e.start.date.date.seconds) + end_time = Time.at(e.end.date.date.seconds) + stub = Hiyoco::Informant::Informant::Stub.new('0.0.0.0:50051', :this_channel_is_insecure) + str = "Summary:#{e.summary}\nDescription:#{e.description}\nStart at #{start_time.strftime("%Y-%m-%d %H:%M")}\nEnd at #{end_time.strftime("%Y-%m-%d %H:%M")}\n" + message = stub.say_event(Hiyoco::Calendar::Text.new(body: str )).result + puts message + end + end + + attr_accessor :type, :dest +end diff --git a/services/filter/lib/test/filter_client.rb b/services/filter/lib/test/filter_client.rb index 2edac21..ae4a678 100644 --- a/services/filter/lib/test/filter_client.rb +++ b/services/filter/lib/test/filter_client.rb @@ -21,8 +21,8 @@ def create_date(time) def main start_time = Time.new(2018, 8, 6, 13, 30, 0, "+09:00") end_time = Time.new(2018, 8, 6, 15, 30, 0, "+09:00") - summary = "第160回GN談話会" - description = "" + summary = "第160回GN検討打合せ" + description = "test event" stub = Hiyoco::Filter::Filter::Stub.new('0.0.0.0:50050', :this_channel_is_insecure) ev = Hiyoco::Calendar::Event.new(start: create_date(start_time), end: create_date(end_time), summary: summary, description: description)