퍼즈 드렌더

12053 단어 googleapi
All About Advent Calendar 8일째입니다.

평상시 게임은 전혀 하지 않지만, 어리석은 듯 이 2년 정도 계속하고 있는 게임(앱)이 있습니다.

퍼즈 드라입니다.

요 전날 순위가 200을 넘었습니다.
2년 하고 드디어! ? 라고 생각하는 분이 있을지도 모르지만, 그래도 조금 기쁜 것.

본제와는 전혀 관계가 없지만, 제 리더는 켄시로우입니다.
퍼즈드라내에서는 그다지 강하지도 않고 약도도 없이 미묘한 존재인데, 나 중에서는 앞으로도 부동의 리더로서 군림을 계속할 것이다.



그런데, 드디어 본제에.
올해는 직장에서 Google의 API를 이용하여 사내 서비스를 개발하기도 했습니다.
지금은 사무실 내에서 Excel보다 Google 스프레드시트를 이용하거나, 예정도 Google 캘린더로 관리하거나… 그런 기업도 많아지고 있는 것은 아닐까요.
또 툴의 제공 뿐만이 아니라, 개발자용으로 각종 툴의 API를 공개해 보다 가능성을 넓히고 있는 부분도 멋집니다.

그래서 이번에 좋아하는 퍼즈 드라와 Google의 캘린더 API를 이용하여,
퍼즈드라에서 개최되고 있는 게릴라 던전의 스케줄을 자신의 캘린더에 떨어뜨려 언제 어디서나 (일중에서도) 확인할 수 있도록 하려고 합니다.
※덧붙여서, 게릴라 던전이란 캐릭터를 강하게 할 수 있는 보너스 스테이지 같은 것입니다.

할 일



1. 퍼즈드라의 게릴라 던전의 스케줄을 가져온다
2. Google 캘린더 API를 사용하여 Google 캘린더에 일정을 반영

준비한 것



1. 게릴라 던전 스케줄
API적인 것이 발견되지 않았기 때문에 여기의 웹 페이지 에서 직접 가져오기로 했습니다.
2. GoogleAPI
API는 라이브러리로 제공됩니다.
htps : // 기주 b. 코 m / goo g / goo g-p-pp-c-en t
※API를 이용할 때는 사용하기 위한 리퀘스트나, 인증 키 등 사전에 통과시켜 둘 필요가 있습니다. 이 페이지 가 자세하게 기재되어 있으므로 참고해 주십시오.
3. 환경
언어는 PHP를 사용했습니다.

구현해 보았다.



길어져 버릴 것 같기 때문에 여러가지 생략합니다만,
대략적으로 한 일은 다음과 같습니다.
먼저 Google API 패키지를 composer에서 가져옵니다.

composer.json
    "require": {
        "laravel/framework": "5.0.*",
        "googleads/googleads-php-lib": "dev-master"
    },

억지로 구현되어 있지만, 게릴라 던전의 스케줄을 취득합니다.

PdGetData.php
// サイト読み込み
$dom = file_get_html('http://paznet.net/');
$nodes = $dom->find("table.table caption");
if (array($nodes) && count($nodes) > 0) {
    $date_text = reset($nodes)->text();
    $matches = array();
    if (preg_match('/(?P<month>\d{1,2})[^\d]+?(?P<day>\d{1,2})/', $date_text, $matches) === 1) {
        $date_str = date('Y') . '-' . $matches['month'] . '-' . $matches['day'];
        $this->setDate($date_str);
    }
}
// 以下省略

획득한 일정 정보를 Google 캘린더 API에 전달하여 완료되었습니다.

GoogleCalender.php
/**
 * GoogleCalenderService に認証を通す
 */
public function getServiceCalendar()
{

    $scopes = array('https://www.googleapis.com/auth/calendar');
    $credential = new Google_Auth_AssertionCredentials($this->auth_email, $scopes, $this->key);
    $client = new Google_Client();
    $client->setAssertionCredentials($credential);
    if ($client->getAuth()->isAccessTokenExpired()) {

        $client->getAuth()->refreshTokenWithAssertion($credential);

    }

    return new Google_Service_Calendar($client);

}

/**
 * イベントを追加する
 * 
 * @param string $class          class string(A,B,C,D,E)
 * @param string $subject        event title
 * @param int    $start_timestamp event start timestamp value
 * @param int    $end_timestamp  event end timestamp value
 */
public function addEvent($class, $subject, $start_timestamp, $end_timestamp)
{

    $pd_calendar_id = $this->getPdCalendarId($class);

    $event = new Google_Service_Calendar_Event();
    $event->setSummary($subject);

    // 予定の開始日
    $start_datetime = new Google_Service_Calendar_EventDateTime();
    $start_datetime->setDateTime(date('c', $start_timestamp));
    $event->setStart($start_datetime);

    // 予定の終了日
    $end_datetime = new Google_Service_Calendar_EventDateTime();
    $end_datetime->setDateTime(date('c', $end_timestamp));
    $event->setEnd($end_datetime);

    // リマインダーの設定
    $reminder = new Google_Service_Calendar_EventReminder();
    $reminder->setMethod('popup');
    $reminder->setMinutes(10);
    $reminders = new Google_Service_Calendar_EventReminders();
    $reminders->setUseDefault(false);
    $reminders->setOverrides(array($reminder));
    $event->setReminders($reminders);

    // カレンダーに登録
    $this->getServiceCalendar()->events->insert($pd_calendar_id, $event);

}


결과



결과는 이런 느낌.
의외로 예쁘게 표시할 수 있었습니다.



주의점은, 결코 회사용의 메일 주소에 잘못 등록하지 않는 것.
※높은 확률로 꾸짖음을 받게 됩니다.

그 밖에도 Google 제공의 API는 여러가지 있으므로, 향후 공주목해 가고 싶습니다.

좋은 웹페이지 즐겨찾기