Class: Nbs
- Inherits:
-
Object
show all
- Extended by:
- Configuration
- Includes:
- HTTParty
- Defined in:
- lib/nbs.rb,
lib/nbs/version.rb
Constant Summary
collapse
- SERVICES =
%w(facebook youtube twitter)
- VERSION =
"0.1.5"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
configuration, define_setting
Constructor Details
#initialize(_nbs_id = 1076707, _options = {}) ⇒ Nbs
define_setting :access_key define_setting :least_favorite_liquid, “seltzer water”
15
16
17
18
|
# File 'lib/nbs.rb', line 15
def initialize(_nbs_id=1076707, _options = {}) @nbs_id = "#{_nbs_id}.json"
@options = {start: (Time.now - 7.day).to_i, end: Time.now.to_i, metric: 'fans'}.merge(_options)
end
|
Instance Attribute Details
#all_metrics_raw ⇒ Object
Returns the value of attribute all_metrics_raw.
9
10
11
|
# File 'lib/nbs.rb', line 9
def all_metrics_raw
@all_metrics_raw
end
|
Class Method Details
.artist_search(_names) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/nbs.rb', line 48
def self.artist_search(_names)
artist_search = []
[_names].flatten.each do |name|
result = get("/artists/search.json", { query: {q: "#{name}"}})
if result.code == 200 && result.parsed_response.present?
result.parsed_response.each do |id, values|
artist_search << {nbs_id: id, name: values["name"], music_brainz_id: values["music_brainz_id"]}
end
end
end
artist_search.uniq
end
|
.metric(_nbs_profile_id = 16209803, _options = {}) ⇒ Object
run the jewels instagram profile
61
62
63
64
65
66
67
68
69
|
# File 'lib/nbs.rb', line 61
def self.metric(_nbs_profile_id=16209803, _options={}) options = {query: {start: (Time.now - 3.day).to_i, end: Time.now.to_i, metric: 'fans'}.merge(_options)}
response = post("/metrics/profile/#{_nbs_profile_id}.json", options)
if response.code == 200
tidy_metrics(response.parsed_response['fans'])
else
[]
end
end
|
.setup(_key) ⇒ Object
71
72
73
|
# File 'lib/nbs.rb', line 71
def self.setup(_key)
base_uri "#{_key}.api3.nextbigsound.com"
end
|
.tidy_metrics(_arry) ⇒ Object
75
76
77
78
79
|
# File 'lib/nbs.rb', line 75
def self.tidy_metrics(_arry)
_arry.map do |day, value|
{time: Time.at(day.to_i.days.to_i).utc, volume: value}
end
end
|
Instance Method Details
#artist_profiles ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/nbs.rb', line 36
def artist_profiles
if @artist_profiles.blank?
@artist_profiles = []
response = self.class.get("/profiles/artist/#{@nbs_id}", @options).parsed_response
response.each do |id, data|
next unless SERVICES.any? { |s| s == data['name'].downcase }
@artist_profiles << {nbs_profile_id: id, url: data['url']}
end
end
@artist_profiles
end
|
#metrics ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/nbs.rb', line 20
def metrics
@all_metrics_raw ||= self.class.post("/metrics/artist/#{@nbs_id}", @options).parsed_response
if @metrics.blank?
@metrics = {}
@all_metrics_raw.each do |am|
service = am["Service"]["name"].downcase
_metrics = am["Metric"]['fans']
if _metrics.present? && SERVICES.any? { |s| s == service }
@metrics[service.to_sym] ||= []
@metrics[service.to_sym] << { url: am['Profile']['url'], data: self.class.tidy_metrics(_metrics)}
end
end
end
@metrics
end
|