You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just wanted to make you aware of quicktype, which can generate code from cli.fyi data for using the data in many programming languages.
Generate Swift for BTC data
~ curl cli.fyi/BTC | quicktype -l swift
// To parse the JSON, add this file to your project and do:
//
// let topLevel = try TopLevel(json)
import Foundation
struct TopLevel: Codable {
let type: String
let data: [String: Double]
}
// MARK: Convenience initializers
extension TopLevel {
init(data: Data) throws {
self = try JSONDecoder().decode(TopLevel.self, from: data)
}
init(_ json: String, using encoding: String.Encoding = .utf8) throws {
guard let data = json.data(using: encoding) else {
throw NSError(domain: "JSONDecoding", code: 0, userInfo: nil)
}
try self.init(data: data)
}
init(fromURL url: URL) throws {
try self.init(data: try Data(contentsOf: url))
}
func jsonData() throws -> Data {
return try JSONEncoder().encode(self)
}
func jsonString(encoding: String.Encoding = .utf8) throws -> String? {
return String(data: try self.jsonData(), encoding: encoding)
}
}
Generate Go for domain info
~ curl cli.fyi/github.com | quicktype -l go --top-level DomainInfo
// To parse and unparse this JSON data, add this code to your project and do:
//
// domainInfo, err := UnmarshalDomainInfo(bytes)
// bytes, err = domainInfo.Marshal()
package main
import "encoding/json"
func UnmarshalDomainInfo(data []byte) (DomainInfo, error) {
var r DomainInfo
err := json.Unmarshal(data, &r)
return r, err
}
func (r *DomainInfo) Marshal() ([]byte, error) {
return json.Marshal(r)
}
type DomainInfo struct {
Type string `json:"type"`
Data Data `json:"data"`
}
type Data struct {
DNS []string `json:"dns"`
Whois []string `json:"whois"`
}
Generate C# classes for client info
~ curl cli.fyi/me | \
quicktype -l csharp --features attributes-only --top-level ClientInfo --density dense \
--namespace CLI.FYI
namespace CLI.FYI
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using J = Newtonsoft.Json.JsonPropertyAttribute;
using R = Newtonsoft.Json.Required;
using N = Newtonsoft.Json.NullValueHandling;
public partial class ClientInfo
{
[J("type")] public string Type { get;set; }
[J("data")] public Data Data { get;set; }
}
public partial class Data
{
[J("iPAddress")] public string IPAddress { get;set; }
[J("userAgent")] public string UserAgent { get;set; }
[J("browser")] public string Browser { get;set; }
[J("iPAddressInfo")] public IPAddressInfo IPAddressInfo { get;set; }
}
public partial class IPAddressInfo
{
[J("organisation")] public string Organisation { get;set; }
[J("country")] public string Country { get;set; }
[J("countryCode")] public string CountryCode { get;set; }
[J("city")] public string City { get;set; }
[J("continent")] public string Continent { get;set; }
[J("latitude")] public string Latitude { get;set; }
[J("longitude")] public string Longitude { get;set; }
}
}
The text was updated successfully, but these errors were encountered:
Just wanted to make you aware of quicktype, which can generate code from cli.fyi data for using the data in many programming languages.
Generate Swift for BTC data
Generate Go for domain info
Generate C# classes for client info
The text was updated successfully, but these errors were encountered: