Class: ChatWorkToSlack::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/chatwork_to_slack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
# File 'lib/chatwork_to_slack.rb', line 11

def initialize(args)
  @room_id = args[:room_id]
  @channel = args[:channel]
  @workdir = args[:workdir]
  @users = args[:users]
  @chatwork_csv_path = args[:chatwork_csv_path]
  @chatwork_api_key = args[:chatwork_api_key]
end

Instance Attribute Details

#chatwork_api_keyObject (readonly)

Returns the value of attribute chatwork_api_key.



9
10
11
# File 'lib/chatwork_to_slack.rb', line 9

def chatwork_api_key
  @chatwork_api_key
end

#chatwork_csv_pathObject (readonly)

Returns the value of attribute chatwork_csv_path.



9
10
11
# File 'lib/chatwork_to_slack.rb', line 9

def chatwork_csv_path
  @chatwork_csv_path
end

#room_idObject (readonly)

Returns the value of attribute room_id.



9
10
11
# File 'lib/chatwork_to_slack.rb', line 9

def room_id
  @room_id
end

#usersObject (readonly)

Returns the value of attribute users.



9
10
11
# File 'lib/chatwork_to_slack.rb', line 9

def users
  @users
end

#workdirObject (readonly)

Returns the value of attribute workdir.



9
10
11
# File 'lib/chatwork_to_slack.rb', line 9

def workdir
  @workdir
end

Instance Method Details

#generate_templateObject



32
33
34
35
36
37
38
39
# File 'lib/chatwork_to_slack.rb', line 32

def generate_template
  CSV.generate do |csv|
    csv << ['chatwork_account_id', 'chatwork_name', 'slack_name']
    chatwork_users.each do |u|
      csv << [u['account_id'], u['name'], u['chatwork_id']]
    end
  end
end

#to_csvObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/chatwork_to_slack.rb', line 20

def to_csv
  invalid_users.each do |name|
    puts "[WARN] #{name} is not valid slack username"
  end

  CSV.generate do |csv|
    slack_messages.each do |slack_message|
      csv << slack_message
    end
  end
end