Skip to content

Commit

Permalink
Fix location null bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yukihirai0505 committed Oct 2, 2017
1 parent f12433d commit 14f14d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
Expand Up @@ -3,21 +3,16 @@ package com.yukihirai0505.sInstagram.responses.common
/**
* Created by yukihirai on 2016/11/10.
*/
import play.api.libs.json.{JsValue, _}
import play.api.libs.functional.syntax._

import play.api.libs.json._

case class MediaLocation(
id: JsValue,
latitude: Double,
longitude: Double,
name: String
)
id: Option[Int],
latitude: Option[Double],
longitude: Option[Double],
name: Option[String]
)

object MediaLocation {
implicit val mediaLocationReader: Reads[MediaLocation] = (
(__ \ 'id).read[JsValue] ~
(__ \ 'latitude).read[Double] ~
(__ \ 'longitude).read[Double] ~
(__ \ 'name).read[String]
)(MediaLocation.apply _)
implicit val mediaLocationFormat = Json.format[MediaLocation]
}
Expand Up @@ -15,6 +15,7 @@ import com.yukihirai0505.sInstagram.responses.users.basicinfo.UserInfo
import com.yukihirai0505.sInstagram.responses.users.feed.UserFeed
import org.scalatest.matchers.{BePropertyMatchResult, BePropertyMatcher}
import org.scalatest.{FlatSpec, Matchers}
import org.slf4j.Logger

import scala.concurrent.Await
import scala.concurrent.duration._
Expand Down Expand Up @@ -76,7 +77,7 @@ class InstagramSpec extends FlatSpec with Matchers {
"getRecentMediaFeed" should "return a Some[MediaFeed]" in {
val request = Await.result(instagram.getRecentMediaFeed(), 10 seconds)
mediaId = request.data.flatMap(_.data.lastOption.flatMap(x => Some(x.id)))
locationId = request.data.flatMap(_.data.lastOption.flatMap(_.location.flatMap(x => Some(x.id.toString()))))
locationId = request.data.flatMap(_.data.lastOption.flatMap(_.location.flatMap(x => Some(x.id.getOrElse("").toString))))
request should be(anInstanceOf[Response[MediaFeed]])
}

Expand Down

0 comments on commit 14f14d9

Please sign in to comment.