Ruby client for Kandypot
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


== Randypot ==
  Randypot is a Ruby client for Kandypot (the sweetest karma service ever deployed)

  This is an introduction about how to use it. You can see specs/lib/randypot_spec.rb for more details.

== Randypot configuration ==

  Configuration can be set through a YAML with a content like this:
      app_key: putyourappkeyhere
      app_token: andhereputthetoken

  Randypot will load it from these files if they are present (settings from each file overrides those loaded from the previous one):
    1.- /etc/randypot/configuration.yml,
    2.- ~/.randypot/configuration.yml
    3.- RAILS_ROOT/config/randypot.yml
    4.- randypot.yml

  Also we can pass to Randypot the location of the configuration file doing something like this:

    Randypot.configure '/my/special/place.yml'

  This will override any setting loaded from previous YAMLs.

  If we don't want to have it in a YAML we can also do the same with:

    Randypot.configure do |config|
      config.service_url = ""
      config.app_key     = "putyourappkeyhere"
      config.app_token   = "andhereputthetoken"

  Again, this settings will be used spite of settings loaded from any YAML file.

== Randypot content creations ==
  Once the configuration is set we can make calls like this to the service (option one: with the class method):

      :content_type => 'photo',
      :content_source => 'ugc',
      :activity_at =>,
      :member => '',
      :content => '')

  But we also can do the same this way:
      :member => '',
      :content => ''

  But also we can get an instance for a member (option two: with the instance method):

    randy ='')
  And do just the same with this even more fancy syntax: ''

== Randypot content reactions ==
  Again we got the two options. With the class method:
      :member  => '',
      :creator => '',
      :content => '')
  Or with the instance method:

    randy ='')
      :creator => '',
      :content => '')

== Randypot relationships ==
  With the class method:

      :member  => '',
      :member_b => '') 

  Or with the instance method:

    randy ='')
    randy.relationships.friend ''

== Randypot members ==

  To get a CSV list with the current Randypot members and their kandypot sizes you can call:

    ranking = Randypot.members

  You'll obtain an raw Randypot::Response instance and the CVS list will be accesible through its "body" method (ranking.body).

  Randypot'll store the results in local cache files to optimize its bandwith needs, avoiding data transfers if Kandypot confirms that no modification has been made since the last request.

  Randypot'll also parse the CVS response storing the result within the #parsed accessor of the response (Randypot.members.parsed).
  The parsed members is an array of Struct objects that responds to #hash, #candies, #updated_at and so on. To list each member with its candies we can do something like this:

    Randypot.members.parsed.each do |member|
      puts User.find_by_hash(member.hash).name + ': ' + member.candies

== Randypot member ==

  To get the current data of a member in JSON format you can call the class method "member" with her or his email as argument. As with Randypot.members, you'll get an Randypot::Responce instance:

    json = Randypot.member("").body

  Randypot'll store the user's data in a local cache file to use it if Kandypot comfirms no modifications on it.

  Randypot'll parse the JSON data for us and it'll be accesible through the #hash, #candies, #updated_at:

    parsed = Randypot.member("").parsed

    puts "Randy's hash: " + parsed.hash
    puts "Randy's candies: " + parsed.candies.to_s
    puts "Randy's last update: " + parsed.updated_at.format('long')

  But here the second option, the instance option, comes again. The cool way to do this is with an instance of Randypot:

    randy ="")

  This instance has the #hash, #candies, #updated_at methods just the same as the object returned by #parsed method of the Randypot's member class method. So we can equally do with "randy" what we've done with "parsed": 

    puts "Randy's hash: " + randy.hash
    puts "Randy's candies: " + randy.candies.to_s
    puts "Randy's last update: " + randy.updated_at.format('long')