Class: Bremen::Mixcloud
- Inherits:
-
Base
- Object
- Base
- Bremen::Mixcloud
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
13
14
15
16
17
18
19
|
# File 'lib/bremen/mixcloud.rb', line 13
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/bremen/mixcloud.rb', line 31
def from_api hash = {}
created_at = Time.parse(hash['created_time'])
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
21
22
23
24
25
26
27
28
29
|
# File 'lib/bremen/mixcloud.rb', line 21
def search_url options = {}
options = default_options.merge(options)
query = {
q: options[:keyword],
limit: options[:limit],
type: 'cloudcast',
}
"#{BASE_URL}search/?#{build_query(query)}"
end
|