Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions services/filter/filter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
13 changes: 13 additions & 0 deletions services/filter/lib/filter/action.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 7 additions & 6 deletions services/filter/lib/filter/filter_server.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# 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'
require "hiyoco/calendar/event_pb"
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

Expand Down
20 changes: 20 additions & 0 deletions services/filter/lib/filter/funnel.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions services/filter/lib/filter/matcher.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions services/filter/lib/filter/outlet.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions services/filter/lib/test/filter_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down