class ConnpassToCalendar::Command

Public Class Methods

list_config() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Class Methods

check_env() click to toggle source
# File lib/connpass_to_calendar/command.rb, line 65
def self.check_env
  DB.prepare

  Models::Env::KEYS_LIST.each do |key|
    unless Models::Env.find_by(keyword: key)
      puts "Not enough env. Please use the [config] command to set the env."
      exit
    end
  end
end