Skip to content

Commit

Permalink
Remove JsonExtractor from the requests package
Browse files Browse the repository at this point in the history
The JsonExtractor is now part of the ponylang/json library.
  • Loading branch information
SeanTAllen committed Jan 22, 2025
1 parent ba429e2 commit f29b712
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 82 deletions.
2 changes: 1 addition & 1 deletion corral.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
{
"locator": "github.com/ponylang/json.git",
"version": "0.1.0"
"version": "0.2.0"
}
],
"info": {
Expand Down
81 changes: 0 additions & 81 deletions github_rest_api/request/json.pony
Original file line number Diff line number Diff line change
Expand Up @@ -4,84 +4,3 @@ use "net"

interface val JsonConverter[A: Any #share]
fun apply(json: JsonType val, creds: Credentials): A ?

class val JsonExtractor
let _json: JsonType val

new val create(json: JsonType val) =>
_json = json

fun val apply(idx_or_key: (String | USize)): JsonExtractor val ? =>
match (_json, idx_or_key)
| (let a: JsonArray val, let idx: USize) =>
JsonExtractor((a.data)(idx)?)
| (let o: JsonObject val, let key: String) =>
JsonExtractor((o.data)(key)?)
else
error
end

fun val size(): USize ? =>
match _json
| let a: JsonArray val =>
a.data.size()
| let o: JsonObject val =>
o.data.size()
else
error
end

fun val values(): Iterator[JsonType val] ? =>
match _json
| let a: JsonArray val =>
a.data.values()
else
error
end

fun val pairs(): Iterator[(String, JsonType val)] ? =>
match _json
| let o: JsonObject val =>
o.data.pairs()
else
error
end

fun val as_array(): Array[JsonType] val ? =>
match _json
| let a: JsonArray val =>
a.data
else
error
end

fun val as_object(): Map[String, JsonType] val ? =>
match _json
| let o: JsonObject val =>
o.data
else
error
end

fun val as_string(): String ? =>
_json as String

fun val as_none(): None ? =>
_json as None

fun val as_f64(): F64 ? =>
_json as F64

fun val as_i64(): I64 ? =>
_json as I64

fun val as_bool(): Bool ? =>
_json as Bool

fun val as_string_or_none(): (String | None) ? =>
match _json
| let s: String => s
| let n: None => n
else
error
end

0 comments on commit f29b712

Please sign in to comment.