Sha256: 08bcb7dbe6fdacaa1b95aa7ad4c111a8795f1474348fdcf5ea23373bfadd646e

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

# encoding: utf-8
require "apb_shuttle_api/version"

require "open-uri"
require "json"

module ApbShuttleApi
  @base_url = "http://apb-shuttle.info/api"

  def self.now
    JSON.load(open("#{@base_url}/now.json"))
  end

  def self.next(next_num = 1)
    JSON.load(open("#{@base_url}/next/#{next_num}.json"))
  end

  def self.all(limit = nil)
    get_all({limit: limit})
  end

  def self.all_apb(limit = nil)
    get_all({kind: 'apb', limit: limit})
  end

  def self.all_orange(limit = nil)
    get_all({kind: 'orange', limit: limit})
  end

  def self.info
    JSON.load(open("#{@base_url}/info.json"))
  end

  private
  def self.get_all(option = {})
    limit = option[:limit]
    limit = nil if limit.to_s.length == 0
    limit = limit.to_s if limit == true || limit == false

    limit = "/#{limit}" if !limit.nil?

    case option[:kind]
    when 'apb'
      JSON.load(open("#{@base_url}/all/apb#{limit}.json"))
    when 'orange'
      JSON.load(open("#{@base_url}/all/orange#{limit}.json"))
    else
      JSON.load(open("#{@base_url}/all#{limit}.json"))
    end
  end

  private_class_method :get_all
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
apb_shuttle_api-0.0.3 lib/apb_shuttle_api.rb
apb_shuttle_api-0.0.2 lib/apb_shuttle_api.rb