nbs 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +50 -1
- data/lib/nbs/version.rb +1 -1
- data/lib/nbs.rb +43 -26
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ea55a957b2a59467dab8a568e576cb39e0800d8
|
4
|
+
data.tar.gz: f8d837eb05a9a80a7037cd6653c6e35342073cae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42496492938c9f415693e45ff7cca1c741d9c9e7ec89e53e78757c3e463c788cdbaf7ecdc0b17504ac7868a80b995701835f3cca86e8eb32f2a90d5ed296e513
|
7
|
+
data.tar.gz: 12be612e9c9e7f964cbb57d0921e10b5db28af77c4dc0db4169c1fd817555ea837d0f22aececd699e06bc34887864f83d63a7734d89f7f9c6f544246d995e1ca
|
data/README.md
CHANGED
@@ -55,7 +55,7 @@ results in
|
|
55
55
|
]
|
56
56
|
```
|
57
57
|
|
58
|
-
### Metrics
|
58
|
+
### Metrics and Profiles
|
59
59
|
instance based on nbs id
|
60
60
|
```
|
61
61
|
default_options = {
|
@@ -106,6 +106,55 @@ available metrics via gem (more available through api)
|
|
106
106
|
|
107
107
|
Typically results go as far back as 3 months
|
108
108
|
|
109
|
+
`nbs.artist_profiles` returns
|
110
|
+
|
111
|
+
```
|
112
|
+
[
|
113
|
+
[0] {
|
114
|
+
:nbs_profle_id => "9946716",
|
115
|
+
:url => "http://www.facebook.com/therealrunthejewels"
|
116
|
+
},
|
117
|
+
[1] {
|
118
|
+
:nbs_profle_id => "9946718",
|
119
|
+
:url => "http://twitter.com/runjewels"
|
120
|
+
},
|
121
|
+
[2] {
|
122
|
+
:nbs_profle_id => "9946719",
|
123
|
+
:url => "http://www.youtube.com/channel/UCeveumRTn2o--9j1Xz2KUCQ"
|
124
|
+
},
|
125
|
+
[3] {
|
126
|
+
:nbs_profle_id => "16209803",
|
127
|
+
:url => "http://instagram.com/runthejewels"
|
128
|
+
}
|
129
|
+
]
|
130
|
+
```
|
131
|
+
|
132
|
+
### Metric
|
133
|
+
```
|
134
|
+
Nbs.metric('9946716', {})
|
135
|
+
default_options = { start: (Time.now - 3.day).to_i,
|
136
|
+
end: Time.now.to_i,
|
137
|
+
metric: 'fans' }
|
138
|
+
```
|
139
|
+
returns metrics for a single profile. eg:
|
140
|
+
```
|
141
|
+
[
|
142
|
+
[0] {
|
143
|
+
:time => 2017-07-09 00:00:00 UTC,
|
144
|
+
:volume => 64608
|
145
|
+
},
|
146
|
+
[1] {
|
147
|
+
:time => 2017-07-10 00:00:00 UTC,
|
148
|
+
:volume => 64737
|
149
|
+
},
|
150
|
+
[2] {
|
151
|
+
:time => 2017-07-11 00:00:00 UTC,
|
152
|
+
:volume => 64903
|
153
|
+
}
|
154
|
+
]
|
155
|
+
```
|
156
|
+
|
157
|
+
|
109
158
|
## Development
|
110
159
|
|
111
160
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/nbs/version.rb
CHANGED
data/lib/nbs.rb
CHANGED
@@ -6,56 +6,73 @@ require 'active_support/all'
|
|
6
6
|
class Nbs
|
7
7
|
include HTTParty
|
8
8
|
extend Configuration
|
9
|
+
attr_accessor :all_metrics_raw
|
9
10
|
|
11
|
+
SERVICES = %w(facebook youtube twitter instagram)
|
10
12
|
# define_setting :access_key
|
11
13
|
# define_setting :least_favorite_liquid, "seltzer water"
|
12
14
|
|
13
|
-
def initialize(_nbs_id=
|
15
|
+
def initialize(_nbs_id=1076707, _options = {}) # run the jewels
|
14
16
|
@nbs_id = "#{_nbs_id}.json"
|
15
|
-
@options = {
|
17
|
+
@options = {start: (Time.now - 7.day).to_i, end: Time.now.to_i, metric: 'fans'}.merge(_options)
|
16
18
|
end
|
17
19
|
|
18
|
-
def
|
20
|
+
def metrics
|
19
21
|
@all_metrics_raw ||= self.class.post("/metrics/artist/#{@nbs_id}", @options).parsed_response
|
20
|
-
if @
|
21
|
-
@
|
22
|
+
if @metrics.blank?
|
23
|
+
@metrics = {}
|
22
24
|
@all_metrics_raw.each do |am|
|
23
|
-
|
25
|
+
service = am["Service"]["name"].downcase
|
26
|
+
_metrics = am["Metric"]['fans']
|
27
|
+
if _metrics.present? && SERVICES.any? { |s| s == service }
|
28
|
+
@metrics[service.to_sym] ||= []
|
29
|
+
@metrics[service.to_sym] << { url: am['Profile']['url'], data: self.class.tidy_metrics(_metrics)}
|
30
|
+
end
|
24
31
|
end
|
25
32
|
end
|
26
|
-
@
|
33
|
+
@metrics
|
27
34
|
end
|
28
35
|
|
29
|
-
def
|
30
|
-
if @
|
31
|
-
@
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
+
def artist_profiles
|
37
|
+
if @artist_profiles.blank?
|
38
|
+
@artist_profiles = []
|
39
|
+
response = self.class.get("/profiles/artist/#{@nbs_id}", @options).parsed_response
|
40
|
+
response.each do |id, data|
|
41
|
+
next unless SERVICES.any? { |s| s == data['name'].downcase }
|
42
|
+
@artist_profiles << {nbs_profle_id: id, url: data['url']}
|
43
|
+
end
|
36
44
|
end
|
37
|
-
@
|
45
|
+
@artist_profiles
|
38
46
|
end
|
39
47
|
|
40
|
-
def self.artist_search(
|
41
|
-
|
42
|
-
|
43
|
-
result = get("/artists/search.json", { query: {q: "#{
|
44
|
-
|
45
|
-
|
46
|
-
|
48
|
+
def self.artist_search(_names)
|
49
|
+
artist_search = []
|
50
|
+
[_names].flatten.each do |name|
|
51
|
+
result = get("/artists/search.json", { query: {q: "#{name}"}})
|
52
|
+
if result.code == 200
|
53
|
+
result.parsed_response.each do |id, values|
|
54
|
+
artist_search << {nbs_id: id, name: values["name"], music_brainz_id: values["music_brainz_id"]}
|
55
|
+
end
|
47
56
|
end
|
48
57
|
end
|
49
|
-
|
58
|
+
artist_search.uniq
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.metric(_nbs_profile_id=16209803, _options={}) #run the jewels instagram profile
|
62
|
+
options = {query: {start: (Time.now - 3.day).to_i, end: Time.now.to_i, metric: 'fans'}.merge(_options)}
|
63
|
+
response = post("/metrics/profile/#{_nbs_profile_id}.json", options)
|
64
|
+
if response.code == 200
|
65
|
+
tidy_metrics(response.parsed_response['fans'])
|
66
|
+
else
|
67
|
+
[]
|
68
|
+
end
|
50
69
|
end
|
51
70
|
|
52
71
|
def self.setup(_key)
|
53
72
|
base_uri "#{_key}.api3.nextbigsound.com"
|
54
73
|
end
|
55
74
|
|
56
|
-
|
57
|
-
|
58
|
-
def tidy_metrics(_arry)
|
75
|
+
def self.tidy_metrics(_arry)
|
59
76
|
_arry.map do |day, value|
|
60
77
|
{time: Time.at(day.to_i.days.to_i).utc, volume: value}
|
61
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Georgiou
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|