Skip to content

Instantly share code, notes, and snippets.

@derekwyatt
Last active December 14, 2015 00:19
Show Gist options
  • Select an option

  • Save derekwyatt/4997985 to your computer and use it in GitHub Desktop.

Select an option

Save derekwyatt/4997985 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Load in the PrimalAccess class
require './PrimalAccess.rb'
require 'rubygems'
# We require this particular gem
#
# To install it:
# gem install json
#
require 'json'
# Prints things out nicely
require 'pp'
# Constructs the PrimalAccess object so we can talk to Primal
primal = PrimalAccess.new("<your appId>", "<your appKey>",
"<your username>", "<your password>")
#
# Call the convenience method that POSTs our topic to Primal and
# then filters the content against the resulting interest network.
#
code, body = primal.postThenFilter("mobiledemo", "@Everything",
"/computing/mobile")
#
# We've made this a separate function because it's going to be
# what we're going to be modifying most often. The data service
# will return to us, a JSON payload as a regular order of
# business. What's going to change is how we manipulate that
# result. For now, we're starting small
#
def processJSON(json)
# "Pretty Print" the JSON response
pp json
end
# If successful
if code == 200
# Convert the payload to JSON
json = JSON.parse(body)
# Process the result
processJSON(json)
else
puts "Something went wrong #{code} -- #{body}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment