Class: ConnpassToCalendar::Command

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

Class Method Summary collapse

Class Method Details

.list_configObject



56
57
58
59
60
61
62
63
# File 'lib/connpass_to_calendar/command.rb', line 56

def self.list_config()
  DB.prepare

  envs = Models::Env.order(:keyword)
  envs.each do |env|
    puts "#{env.keyword}=#{env.value}"
  end
end

.put_on_event(params) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/connpass_to_calendar/command.rb', line 3

def self.put_on_event(params)
  check_env

  DB.prepare

  result = Api::Connpass::Event.get(params)
  events = result["events"]
  events.each do |event|
    event_id = event["event_id"]
    summary = event["title"]
    location = "#{event["address"]} #{event["place"]}"
    description = "#{event["catch"]}
イベントURL:#{event["event_url"]}
定員:#{event["limit"]}"
    start_date_time = event["started_at"]
    end_date_time = event["ended_at"]

    puts summary
    puts location
    puts description
    puts start_date_time
    puts end_date_time

    unless Models::Event.find_by(id: event_id)
      Models::Event.create(id: event_id, summary: summary, description: description, start_date_time: start_date_time, end_date_time: end_date_time)

      application_name = Models::Env.find_by(keyword: "application_name").value
      credentials_path = Models::Env.find_by(keyword: "credentials_path").value
      token_path = Models::Env.find_by(keyword: "token_path").value
      user_id = Models::Env.find_by(keyword: "user_id").value
      calendar = Api::GoogleApis::Calendar.new(application_name, credentials_path, token_path, user_id)
      calendar.create_event(summary, location, description, start_date_time, end_date_time)
    end
  end
end

.set_config(key, value) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/connpass_to_calendar/command.rb', line 39

def self.set_config(key, value)
  DB.prepare

  env = Models::Env.find_by(keyword: key)
  if env
    env.update(value: value)
  else
    Models::Env.create(keyword: key, value: value)
  end
end

.show_config(key) ⇒ Object



50
51
52
53
54
# File 'lib/connpass_to_calendar/command.rb', line 50

def self.show_config(key)
  DB.prepare

  puts Models::Env.find_by(keyword: key).value
end