import com.google.api.client.googleapis.*
import com.google.api.client.googleapis.auth.clientlogin.*
import com.google.api.data.calendar.v2.*
import com.google.api.data.calendar.v2.atom.*
import com.google.api.client.xml.atom.*
import com.google.api.client.util.*
// 日時
public class When
{
@Key("@startTime")
DateTime startTime
@Key("@endTime")
DateTime endTime
public When()
{
}
public When(GregorianCalendar st, GregorianCalendar et)
{
startTime = new DateTime(st.getTime(), TimeZone.getTimeZone("GMT+9"))
endTime = new DateTime(et.getTime(), TimeZone.getTimeZone("GMT+9"))
}
}
// 場所
public class Where
{
@Key("@valueString")
String valueString
public Where()
{
}
public Where(String vs)
{
valueString = vs
}
}
// カテゴリ
public class Category
{
@Key("@scheme")
String scheme = "http://schemas.google.com/g/2005#kind"
@Key("@term")
String term = "http://schemas.google.com/g/2005#event"
}
// エントリ
public class Entry
{
@Key
Category category
@Key
String title
@Key
String content
@Key("gd:when")
When when
@Key("gd:where")
Where where
public Entry()
{
}
public Entry(String title, String content,
GregorianCalendar st, GregorianCalendar et,
String where)
{
this.category = new Category()
this.title = title
this.content = content
this.when = new When(st, et)
this.where = new Where(where)
}
}
// Parser設定
GoogleTransport transport = new GoogleTransport()
transport.applicationName = "yourcorp-yourapp-1.0"
transport.setVersionHeader(GoogleCalendar.VERSION)
ap = new AtomParser()
ap.namespaceDictionary = GoogleCalendarAtom.NAMESPACE_DICTIONARY
transport.addParser(ap)
username = "youraccount@gmail.com"
password = 'yourpassword'
// 認証
cl = new ClientLogin()
cl.authTokenType = GoogleCalendar.AUTH_TOKEN_TYPE
cl.username = username
cl.password = password
cl.authenticate().setAuthorizationHeader(transport)
entry = new Entry("イベントのテスト",
"イベントのテストのコンテント",
new GregorianCalendar(2010, 6-1, 3, 10, 0, 0),
new GregorianCalendar(2010, 6-1, 3, 12, 0, 0),
"オフィス"
)
// デフォルトカレンダーにイベントを登録
request = transport.buildPostRequest()
request.url = "http://www.google.com/calendar/feeds/default/private/full"
content = new AtomContent()
content.entry = entry
content.namespaceDictionary = GoogleCalendarAtom.NAMESPACE_DICTIONARY
request.content = content;
request.execute().parseAs(Entry.class)
動作環境
groovy 1.7.2, JDK6 Update20, gdata-java-2.2.1-alpha
関連情報
gdata-java-client
http://code.google.com/p/gdata-java-client/
0 件のコメント:
コメントを投稿