Last active
December 21, 2015 20:49
-
-
Save ngsw-taro/6363959 to your computer and use it in GitHub Desktop.
Scalaの練習。SlideshareのAPI叩いてみた
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 使用例 | |
import com.taroid.slideshare4s.{SortOrder, SlideShare, Query} | |
object Main { | |
def main(args: Array[String]) { | |
val apiKey = System.getenv("SLIDESHARE_API_KEY") | |
val sharedSecret = System.getenv("SLIDESHARE_SHARED_SECRET") | |
val ss = SlideShare(apiKey, sharedSecret) | |
val query = Query(words = "kotlin", itemsPerPage = 10, language = "ja", sortOrder = SortOrder.LATEST) | |
ss.searchSlideshow(query).foreach(println) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.taroid.slideshare4s | |
import com.taroid.slideshare4s.SortOrder.SortOrder | |
case class Query( | |
words: String, | |
page: Int = 1, | |
itemsPerPage: Int = 12, | |
language: String = "**", | |
sortOrder: SortOrder = SortOrder.RELEVANCE | |
) { | |
require(words != null) | |
require(words.size > 0) | |
require(language != null) | |
require(sortOrder != null) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.taroid.slideshare4s | |
import java.util.Date | |
case class Slideshow( | |
id: Long, | |
title: String, | |
username: String, | |
description: String, | |
url: String, | |
thumbnailUrl: String, | |
created: Date, | |
updated: Date, | |
language: String | |
) { | |
require(title != null) | |
require(username != null) | |
require(description != null) | |
require(url != null) | |
require(thumbnailUrl != null) | |
require(created != null) | |
require(updated != null) | |
require(language != null) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.taroid.slideshare4s | |
object SortOrder extends Enumeration { | |
type SortOrder = Value | |
val RELEVANCE = Value("relevance") | |
val MOSTVIEWED = Value("mostviewd") | |
val MOSTDOWNLOADED = Value("mostdownloaded") | |
val LATEST = Value("latest") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.taroid.slideshare4s | |
import java.security.MessageDigest | |
private object Utils { | |
def toSha1Hex(str: String): String = { | |
require(str != null) | |
val messageDigest = MessageDigest.getInstance("SHA-1") | |
messageDigest.update(str.getBytes) | |
return messageDigest.digest.map("%02x".format(_)).mkString | |
} | |
def createUrlWithParams(url: String, params: (String, Any)*): String = { | |
require(url != null) | |
require(params.forall(_ != null)) | |
val builder = params.foldLeft(new StringBuilder(url).append("?")) { | |
(b, p) => b.append(p._1).append("=").append(p._2.toString).append("&") | |
} | |
return builder.substring(0, builder.size - 1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment