Class: Bremen::Mixcloud

Inherits:
Base
  • Object
show all
Defined in:
lib/bremen/mixcloud.rb

Constant Summary collapse

BASE_URL =
'http://api.mixcloud.com/'

Instance Attribute Summary

Attributes included from Track

#author, #created_at, #length, #thumbnail_url, #title, #uid, #updated_at, #url

Class Method Summary collapse

Methods inherited from Base

find, search

Methods included from Request

#build_query, #get

Methods included from Track

#initialize

Class Method Details

.find_url(uid_or_url) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/bremen/mixcloud.rb', line 14

def find_url uid_or_url
  if uid_or_url.to_s.include?('www.mixcloud.com')
    uid_or_url.sub('www.mixcloud.com', 'api.mixcloud.com')
  else
    "#{BASE_URL[0..-2]}#{uid_or_url}"
  end
end

.from_api(hash = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bremen/mixcloud.rb', line 33

def from_api hash = {}
  created_at = Time.parse(hash['created_time']).utc
  new({
    uid: hash['key'],
    url: hash['url'],
    title: hash['name'],
    author: Bremen::Author.new({
      uid: hash['user']['key'],
      url: hash['user']['url'],
      name: hash['user']['name'],
      thumbnail_url: hash['user']['pictures']['medium'],
    }),
    length: hash['audio_length'].to_i,
    thumbnail_url: hash['pictures']['medium'],
    created_at: created_at,
    updated_at: created_at,
  })
end

.search_url(options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/bremen/mixcloud.rb', line 22

def search_url options = {}
  options = default_options.merge(options)
  query = {
    q: options[:keyword],
    limit: options[:limit],
    offset: options[:limit] * (options[:page] - 1),
    type: 'cloudcast',
  }
  "#{BASE_URL}search/?#{build_query(query)}"
end