Skip to content

Instantly share code, notes, and snippets.

@mbeale
mbeale / gist:2361290
Created April 11, 2012 18:41
recurly sub sample
subscription = Recurly::Subscription.create(
:plan_code => 'standard',
:currency => 'USD',
:add_ons => [{
:add_on => {
:add_on_code => 'extraip',
:quantity => 1
}
}],
:account => {
@mbeale
mbeale / gist:2473165
Created April 23, 2012 19:11
PHP v2 recurly upgrade subscription add_on
$subscription = Recurly_Subscription::get('17caaca1716f33572edc8146e0aaefde');
$add_on = new Recurly_SubscriptionAddOn();
$add_on->quantity = 2;
$add_on->add_on_code = 'extraip';
$subscription->subscription_add_ons[] = $add_on;
$subscription->updateImmediately();
@mbeale
mbeale / gist:2731904
Created May 19, 2012 18:42
GO and XML sample1
//Account struct
type Account struct{
account_code, username,email, state, first_name string
last_name, company_name, accept_language string
hosted_login_token, created_at string
}
@mbeale
mbeale / gist:2731920
Created May 19, 2012 18:46
GO and XML sample2
//Account struct
type Account struct{
XMLName xml.Name `xml:"account"`
AccountCode string `xml:"account_code"`
Username string `xml:"username"`
Email string `xml:"email"`
State string `xml:"state,omitempty"`
FirstName string `xml:"first_name"`
LastName string `xml:"last_name"`
CompanyName string `xml:"company_name"`
@mbeale
mbeale / gist:2731955
Created May 19, 2012 18:55
GO and XML sample3
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
@mbeale
mbeale / gist:2732090
Created May 19, 2012 19:28
GO and XML sample4
//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{}
@mbeale
mbeale / gist:4113026
Created November 19, 2012 19:19
Recurly Error Handling PHP Best practices
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
@mbeale
mbeale / gist:4241133
Created December 8, 2012 17:40
Sample Data set for Dynamic JSON
[ {
"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" : {
@mbeale
mbeale / gist:4241157
Created December 8, 2012 17:47
Dynamic JSON sample1
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)
}
@mbeale
mbeale / gist:4241224
Created December 8, 2012 18:17
Sample JSON record for Dynamic JSON
{
"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" : {