Move sample JSON into SampleResponse.json

This commit is contained in:
Richard Feldman
2016-09-07 04:19:22 -05:00
parent 7d806e8bb2
commit 527a02428f
2 changed files with 2688 additions and 49 deletions

View File

@@ -6,6 +6,7 @@ import Html.Attributes exposing (class, target, href, property, defaultValue)
import Html.Events exposing (..) import Html.Events exposing (..)
import Json.Decode exposing (..) import Json.Decode exposing (..)
import Json.Decode.Pipeline exposing (..) import Json.Decode.Pipeline exposing (..)
import SampleResponse
main : Program Never main : Program Never
@@ -17,58 +18,13 @@ main =
} }
-- see http://package.elm-lang.org/packages/elm-lang/core/latest/Json-Decode#decodeString
sampleJson : String
sampleJson =
"""
{
"total_count": 40,
"incomplete_results": false,
"items": [
{
"id": 3081286,
"name": "Tetris",
"full_name": "dtrupenn/Tetris",
"owner": {
"login": "dtrupenn",
"id": 872147,
"avatar_url": "https://secure.gravatar.com/avatar/e7956084e75f239de85d3a31bc172ace?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
"gravatar_id": "",
"url": "https://api.github.com/users/dtrupenn",
"received_events_url": "https://api.github.com/users/dtrupenn/received_events",
"type": "User"
},
"private": false,
"html_url": "https://github.com/dtrupenn/Tetris",
"description": "A C implementation of Tetris using Pennsim through LC4",
"fork": false,
"url": "https://api.github.com/repos/dtrupenn/Tetris",
"created_at": "2012-01-01T00:31:50Z",
"updated_at": "2013-01-05T17:58:47Z",
"pushed_at": "2012-01-01T00:37:02Z",
"homepage": "",
"size": 524,
"stargazers_count": 1,
"watchers_count": 1,
"language": "Assembly",
"forks_count": 0,
"open_issues_count": 0,
"master_branch": "master",
"default_branch": "master",
"score": 10.309712
}
]
}
"""
searchResultDecoder : Decoder SearchResult searchResultDecoder : Decoder SearchResult
searchResultDecoder = searchResultDecoder =
-- See https://developer.github.com/v3/search/#example -- See https://developer.github.com/v3/search/#example
-- and http://package.elm-lang.org/packages/NoRedInk/elm-decode-pipeline/latest -- and http://package.elm-lang.org/packages/NoRedInk/elm-decode-pipeline/latest
--
-- Look in SampleResponse.elm to see the exact JSON we'll be decoding!
--
-- TODO replace these calls to `hardcoded` with calls to `required` -- TODO replace these calls to `hardcoded` with calls to `required`
decode SearchResult decode SearchResult
|> hardcoded 0 |> hardcoded 0
@@ -92,7 +48,7 @@ type alias SearchResult =
initialModel : Model initialModel : Model
initialModel = initialModel =
{ query = "tutorial" { query = "tutorial"
, results = decodeResults sampleJson , results = decodeResults SampleResponse.json
} }

2683
part6/SampleResponse.elm Normal file

File diff suppressed because it is too large Load Diff