Snafu

Snafu is a Ruby gem that provides an interface to the API for Glitch, a browser-based MMO created by Tiny Speck.

API Support

Currently Supported

  • In-Game Time & Date (See the GlitchTime class for more info)
  • Giants
    • giants.list (Snafu::Giants#get_giants)
  • Locations
    • locations.getHubs (Snafu::Locations#get_hubs)
    • locations.getStreets (Snafu::Locations#get_hub)
    • locations.streetInfo (Snafu::Locations#get_street)

Not Yet Supported

  • Achievements
  • Auctions
  • Avatar
  • Players
  • Skills

Usage

To get started, instantiate the client with either no options or with the OAuth token of an authenticated user if ‘identity’ scope or higher is required.


    snafu = Snafu.new(:oauth_token => "your-oauth-token")

Snafu currently does not support Glitch’s OAuth authentication. There are other gems that support authenticating with Glitch such as OmniAuth.

In-Game Time & Date

Note that the hour, minute, day of week, day of year, and day of month are all zero-based.

To get the current in-game date and time:


    current_time = snafu.glitch_time
    current_time.year
    => 20
    current_time.month
    => "Spork"
    current_time.day
    => "Hairday"

Giants


    # giants.list
    giants = snafu.get_giants
    giants.first.name
    => "Alph"

Locations

All locations.* methods are supported. Each method returns a Ruby object representing the returned data.


    # locations.*
    hubs = snafu.get_hubs # "locations.getHubs"
    hub = snafu.get_hub(hub_id) # "locations.getStreets"
    street = snafu.get_street(street_tsid) # "locations.streetInfo"

Achievements


    achievements = snafu.get_achievements # "achievements.listAll"
    achievements.first.name
    => "1-Star Cuisinartist"
    achievements.first.desc
    => "Whipped up 11 meals with an Awesome Pot"

Manual Method Calls

You can also receive raw data from the Glitch API by passing any method name into #call and supplying any required parameters via an options hash. This returns a Hash representation of the JSON returned by Glitch.

For example, to manually call the Glitch calendar.getholidays method:


    snafu.call("calendar.getHolidays")
    => {
    =>   "ok"=>1,
    =>   "days"=>
    =>   [{"month"=>1, "day"=>5, "name"=>"AlphCon"},
    =>    {"month"=>2, "day"=>2, "name"=>"Lemadan"},
    =>    {"month"=>3, "day"=>3, "name"=>"Pot Twoday"},
    =>    {"month"=>4, "day"=>2, "name"=>"Root"},
    =>    {"month"=>4, "day"=>3, "name"=>"Root"},
    =>    {"month"=>4, "day"=>4, "name"=>"Root"},
    =>    {"month"=>4, "day"=>11, "name"=>"Sprinkling"},
    =>    {"month"=>6, "day"=>17, "name"=>"Croppaday"},
    =>    {"month"=>7, "day"=>1, "name"=>"Belabor Day"},
    =>    {"month"=>8, "day"=>37, "name"=>"Zilloween"},
    =>    {"month"=>11, "day"=>11, "name"=>"Recurse Eve"}]
    => }

    snafu.call("locations.getStreets", :hub_id => 27)
    => {
    =>   "ok"=>1,
    =>   "hub_id"=>"27",
    =>   "name"=>"Ix",
    =>   "streets"=>
    =>   {
    =>     "LM416LNIKVLM1"=>{"name"=>"Baby Steppes"},
    =>     "LM413SQ6LRN58"=>{"name"=>"East Spice"},
    =>     "LM410QQ0CHARO"=>{"name"=>"Flipside"},
    =>     "LM4115NJ46G8M"=>{"name"=>"Groddle Ladder"},
    =>     "LM4109NI2R640"=>{"name"=>"Guillermo Gamera Way"},
    =>     "LM410TMR0S2S1"=>{"name"=>"Ruta Asuncion"},
    =>     "LM413RQ6LRG9N"=>{"name"=>"West Spice"}
    =>   }
    => }

Credits

Jeff Browning – Original author Lee Jensen – Contributions to GlitchTime