This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main(){ | |
dyn, err := MakeJSONContainer(rawData) | |
if err != nil { | |
fmt.Println("error:", err) | |
} else { | |
for _, v := range dyn.All() { | |
if val ,err := v.Get("payload.deeper_nesting.return_value");err == nil { | |
println(val) | |
} else { | |
fmt.Println("error:", err) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type JSONContainer struct { | |
data []interface{} | |
} | |
func (j *JSONContainer) All() (objects []JSONObject) { | |
for _, v := range j.data { | |
objects = append(objects, JSONObject{data: v}) | |
} | |
return | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val, _ := v.Get("payload.deeper_nesting.return_value") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Document Container | |
type JSONContainer struct { | |
data []interface{} | |
} | |
//Return all objects | |
func (j *JSONContainer) All() (objects []JSONObject) { | |
for _, v := range j.data { | |
newJSONObject := JSONObject{data: v} | |
objects = append(objects, newJSONObject) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type" : "CreateEvent", | |
"actor" : { | |
"avatar_url" : "https://secure.gravatar.com/avatar/05abda697c2654a02391248bed3a5f3e?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", | |
"url" : "https://api.github.com/users/mbeale", | |
"id" : 1507647, | |
"gravatar_id" : "05abda697c2654a02391248bed3a5f3e", | |
"login" : "mbeale" | |
}, | |
"repo" : { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jsondata []interface{} | |
err := json.Unmarshal(rawData, &jsondata) | |
if err == nil{ | |
m := v.(map[string]interface{}) | |
//the following prints out the type | |
fmt.Printf("%s \n",m["type"]) | |
} else { | |
fmt.Println("error:", err) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ { | |
"type" : "WatchEvent", | |
"actor" : { | |
"avatar_url" : "https://secure.gravatar.com/avatar/f873c249ce2812e897cdd3eb8cc697ea?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", | |
"url" : "https://api.github.com/users/pkorotkov", | |
"id" : 532567, | |
"gravatar_id" : "f873c249ce2812e897cdd3eb8cc697ea", | |
"login" : "pkorotkov" | |
}, | |
"repo" : { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try{ | |
$subscription = new Recurly_Subscription(); | |
$account = Recurly_Account::get('1'); //this will throw a not found exception if the account_code does not exist | |
$subscription->account = $account; | |
$subscription->create(); //this will throw a validation error exception as there are missing fields | |
} | |
catch (Exception $e) { | |
//for a list of possible exception types go to | |
//https://github.com/recurly/recurly-client-php/blob/master/lib/recurly/errors.php | |
//you could use send these messages to a log for later analysis |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Generic Reader | |
type nopCloser struct { | |
io.Reader | |
} | |
//update function | |
func (a *Account) Update() error { | |
if xmlstring, err := xml.MarshalIndent(a, "", " "); err == nil { | |
xmlstring = []byte(xml.Header + string(xmlstring)) | |
client := &http.Client{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
account Account | |
//resp is http.Response from http.Client | |
if body, readerr := ioutil.ReadAll(resp.Body); readerr == nil { | |
//load object xml | |
if xmlerr := xml.Unmarshal(body, &account); xmlerr != nil { | |
return xmlerr | |
} | |
} else { | |
//return read error | |
return readerr |