Phish.net API Wrappers

Phish.net API Wrappers: Ruby 1.x

The following Ruby wrapper can communicate with the Phish.net API. It was submitted by Stephen Blackstone. You can download the phish.net API ruby wrapper for use.

# Phish.net Ruby API Wrapper, Stephen Blackstone 

require 'net/http'
require 'net/https'
require 'json'
require 'openssl'
require 'pp'

class PNet
  BASE_URL =  "https://api.phish.net/api.js"

  def initialize(api_key)
    @options = {
      'api'    => "2.0",
      'apikey' => api_key,
      'format' => "json"
    }
    @url = URI.parse(BASE_URL)
  end

  def perform_action(opts)
    url = URI.parse(BASE_URL)
    request = Net::HTTP::Post.new(url.path)
    request.set_form_data(@options.merge(opts))
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE # Comodo certs still need extra cert chain?
    res = http.start {|http| http.request(request) }
    case res
    when Net::HTTPSuccess
      begin
        return JSON::Parser.new(res.body).parse
      rescue
        raise "Server or Parse Error"
      end
    else
      raise "Server Error"
    end
  end

  public
  # Will cause the Authkey to be used from this point forward.
  def api_authorize(opts = {})
    opts['method'] = "pnet.api.authorize"
    auth = perform_action(opts)
    if auth["success"] == 1
      @options["authkey"] = auth["authkey"]
      return true
    else
      raise "Authentication Failure"
    end
  end

  # Forget the auth key.
  def deauthorize
    @options.delete("authkey")
  end


  # Call any method with pnet.remote_method_name(:option1 => val1, :option2 => val2)
  def method_missing(m, *args, &block)
    action =  "pnet_#{m}".tr('_', '.')
    opts = args.first || {}
    opts.merge!({'method' => action})
    perform_action(opts)
  end

end'

Usage is as follows:

pnet = PNet.new("API_KEY")

# Setlists
setlist = pnet.shows_setlists_get('showdate' => "2009-03-06")
pp setlist

# News
news = pnet.news_get
pp news

# Random Setlist
random_setlist = pnet.shows_setlists_random
pp random_setlist

# Upcoming Shows
shows = pnet.shows_upcoming
pp shows

# Authorize
auth = pnet.api_authorize("username" => "steveb3210", "passwd" => "MY_PASSWORD")
user = pnet.user_get("username" => "steveb3210")
pp user

# Cause Fail
pnet.deauthorize
user = pnet.user_get("username" => "steveb3210")
pp user

This should provide you the infrastructure to communicate with the phish.net API using any method.

Phish.net Login

Register | Forgot Password
Support Phish.net & MBIRD


Phish.net

Phish.net is a non-commercial project run by Phish fans and for Phish fans under the auspices of the all-volunteer, non-profit Mockingbird Foundation.

This project serves to compile, preserve, and protect encyclopedic information about Phish and their music.

Credits | Terms Of Use | Legal

© 1990-2017  The Mockingbird Foundation, Inc. | Hosted by End Point Corporation