Class: Bremen::Soundcloud
- Inherits:
-
Base
- Object
- Base
- Bremen::Soundcloud
show all
- Defined in:
- lib/bremen/soundcloud.rb
Constant Summary
collapse
- BASE_URL =
'http://api.soundcloud.com/'
Class Attribute Summary collapse
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 Attribute Details
.consumer_key ⇒ Object
Returns the value of attribute consumer_key.
15
16
17
|
# File 'lib/bremen/soundcloud.rb', line 15
def consumer_key
@consumer_key
end
|
Class Method Details
.build_query(options = {}) ⇒ Object
17
18
19
20
|
# File 'lib/bremen/soundcloud.rb', line 17
def build_query options = {}
raise %Q{"#{self.name}.consumer_key" must be set} unless consumer_key
super(options.merge(consumer_key: consumer_key))
end
|
.find_url(uid_or_url) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/bremen/soundcloud.rb', line 22
def find_url uid_or_url
if uid_or_url.to_s =~ %r{\A\d+\Z}
"#{BASE_URL}tracks/#{uid_or_url}.json?#{build_query}"
else
"#{BASE_URL}resolve.json?#{build_query({url: uid_or_url})}"
end
end
|
.from_api(hash = {}) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/bremen/soundcloud.rb', line 41
def from_api hash = {}
new({
uid: hash['id'],
url: hash['permalink_url'],
title: hash['title'],
author: Bremen::Author.new({
uid: hash['user']['id'],
url: hash['user']['permalink_url'],
name: hash['user']['username'],
thumbnail_url: hash['user']['avatar_url'].sub(%r{\?.*}, ''),
}),
length: (hash['duration'].to_i / 1000).round,
thumbnail_url: hash['artwork_url'] ? hash['artwork_url'].sub(%r{\?.*}, '') : nil,
created_at: Time.parse(hash['created_at']),
updated_at: Time.parse(hash['created_at']),
})
end
|
.search_url(options = {}) ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/bremen/soundcloud.rb', line 30
def search_url options = {}
options = default_options.merge(options)
query = {
q: options[:keyword],
order: options[:order],
limit: options[:limit],
filter: options[:filter],
}
"#{BASE_URL}tracks.json?#{build_query(query)}"
end
|