class Sc20XX::Client

responsible for the very basic information of the app

Constants

DEFAULT_LIMIT

Attributes

client_id[R]
current_user[RW]

Public Class Methods

new(client_id) click to toggle source
# File lib/sc20XX/client.rb, line 12
def initialize(client_id)
  @client_id = client_id
  @current_user = nil
end

Public Instance Methods

get(path, params = {}) click to toggle source
# File lib/sc20XX/client.rb, line 41
def get(path, params = {})
  JSON.parse(request(Net::HTTP::Get, path, params).body)
end
location(url) click to toggle source
# File lib/sc20XX/client.rb, line 45
def location(url)
  uri = URI.parse(url)
  res = request(Net::HTTP::Get, uri.path)
  res.header['Location'] if res.code == '302'
end
request(type, path, params = {}) click to toggle source
# File lib/sc20XX/client.rb, line 32
def request(type, path, params = {})
  params[:client_id] = client_id
  params[:format] = 'json'

  Net::HTTP.start('api.soundcloud.com', 443, use_ssl: true) do |http|
    http.request(type.new("#{path}?#{uri_escape params}"))
  end
end
resolve(permalink) click to toggle source
# File lib/sc20XX/client.rb, line 21
def resolve(permalink)
  res = get('/resolve', url: "http://soundcloud.com/#{permalink}")
  if res['location']
    get URI.parse(res['location']).path
  end
end
tracks(page = 1, limit = DEFAULT_LIMIT) click to toggle source
# File lib/sc20XX/client.rb, line 17
def tracks(page = 1, limit = DEFAULT_LIMIT)
  get('/tracks', offset: (page - 1) * limit, limit: limit)
end
uri_escape(params) click to toggle source
# File lib/sc20XX/client.rb, line 28
def uri_escape(params)
  URI.escape(params.collect { |k, v| "#{k}=#{v}" }.join('&'))
end