Sha256: 5b11abb67d6299b3221f69a2e4a122c8928fcb57a6db7e9e170bc98fbf4cb1b8

Contents?: true

Size: 560 Bytes

Versions: 9

Compression:

Stored size: 560 Bytes

Contents

require 'httparty'
require 'uri'

class AiBangClient
  def initialize(api_base_url, api_key)
    %w(lines transfer stats).each do |category|
      instance_variable_set("@#{category}_api_url", api_base_url + "/#{category}?app_key=#{api_key}&alt=json")
    end
  end
  def bus_lines(city, query)
    encoded_city = URI.encode city
    encoded_query = URI.encode query
    api_url = "#{@lines_api_url}&city=#{encoded_city}&q=#{encoded_query}"
    result = HTTParty.get(api_url).parsed_response["lines"]
    result.has_key?('line') ? result['line'] : []
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
wei-backend-0.1.2 examples/waiting_bus/ai_bang_client.rb
wei-backend-0.1.1 examples/waiting_bus/ai_bang_client.rb
wei-backend-0.1.0 examples/waiting_bus/ai_bang_client.rb
wei-backend-0.0.6 examples/waiting_bus/ai_bang_client.rb
wei-backend-0.0.5 examples/waiting_bus/ai_bang_client.rb
wei-backend-0.0.4 examples/waiting_bus/ai_bang_client.rb
wei-backend-0.0.3 examples/waiting_bus/ai_bang_client.rb
wei-backend-0.0.2 examples/waiting_bus/ai_bang_client.rb
wei-backend-0.0.1 examples/waiting_bus/ai_bang_client.rb