Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove JsonExtractor from the requests package #38

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .release-notes/38.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Remove `JsonExtractor` from the requests package #38

Previously, the `request` package included a `JsonExtractor` class that was used to extract JSON data from a response. This class has been removed from the package. If you were using this class, you will need to update your code to use the `JsonExtractor` from the [`ponylang/json`](https://github.com/ponylang/json) library instead instead.

`JsonExtractor` is available in all versions of `ponylang/json` starting with 0.2.0.
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
Loading