nbs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3472ce3ad1a172c5eb9b4ce9fe3b02b2a715bbd4
4
+ data.tar.gz: 661096db410d6abf23099ad26329e00c76ff81d3
5
+ SHA512:
6
+ metadata.gz: 0dd24d6c5d7c431fa35bdce8851eaaea1691367d5d337facfb1dabc653a3ac41a2b1bc25b6e02681c75f134bcd09718dd1aeac5934df1430abb8ab44ab531b30
7
+ data.tar.gz: 47d77cf5e24e20e0c5e5409fc797d1ab6c9397e80cb1f286b7cee0b3dcf1d8cd04ca1aa879e76d3b5e89061cbbb355657db6979cecc76946ffc1beb1a028cff9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nbs.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 David Georgiou
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # Nbs
2
+
3
+ Simple wrapper for the [NextBigSound](https://www.nextbigsound.com) [api](https://api3.nextbigsound.com)
4
+
5
+ Requires key and granted access from NextBigSound
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'nbs'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install nbs
22
+
23
+ ## Usage
24
+
25
+ Set config variables, at the moment all that is needed is access key:
26
+
27
+ Nbs.access_key = "your_access_key"
28
+
29
+ ### Artist search
30
+
31
+ Nbs.artist_search("a tribe called quest")
32
+
33
+ returns
34
+ ```
35
+ [
36
+ [0] {
37
+ :id => "7440",
38
+ :name => "A Tribe Called Quest",
39
+ :music_brainz_id => "9689aa5a-4471-4fb4-9721-07cecda0fa9f"
40
+ },
41
+ [1] {
42
+ :id => "80756",
43
+ :name => "De La Soul feat. A Tribe Called Quest",
44
+ :music_brainz_id => nil
45
+ },
46
+ [2] {
47
+ :id => "66202",
48
+ :name => "A Tribe Called Quest, Aphrodite, Groove Armada & The Chi-Lites",
49
+ :music_brainz_id => nil
50
+ }
51
+ ]
52
+ ```
53
+
54
+ ### Metrics
55
+ instance based on nbs id
56
+ ```
57
+ default_options = {
58
+ from: 7 days ago (epoch time),
59
+ to: now (epoch time)
60
+ }
61
+ nbs = Nbs.new(7440, default_options)
62
+ ```
63
+
64
+ `nbs.metrics[:facebook]` returns
65
+
66
+ ```
67
+ [
68
+ [0] {
69
+ :time => 2017-05-30 00:00:00 UTC,
70
+ :volume => 1589996
71
+ },
72
+ [1] {
73
+ :time => 2017-05-31 00:00:00 UTC,
74
+ :volume => 1590014
75
+ },
76
+ [2] {
77
+ :time => 2017-06-01 00:00:00 UTC,
78
+ :volume => 1590044
79
+ },
80
+ [3] {
81
+ :time => 2017-06-02 00:00:00 UTC,
82
+ :volume => 1589990
83
+ },
84
+ [4] {
85
+ :time => 2017-06-03 00:00:00 UTC,
86
+ :volume => 1589967
87
+ },
88
+ [5] {
89
+ :time => 2017-06-04 00:00:00 UTC,
90
+ :volume => 1589941
91
+ },
92
+ [6] {
93
+ :time => 2017-06-05 00:00:00 UTC,
94
+ :volume => 1589968
95
+ }
96
+ ]
97
+ ```
98
+
99
+ available metrics via gem (more available through api)
100
+
101
+ >*facebook, instagram, twitter, youtube*
102
+
103
+ Typically results go as far back as 3 months
104
+
105
+ ## Development
106
+
107
+ 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.
108
+
109
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
110
+
111
+ ## Contributing
112
+
113
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nbs.
114
+
115
+
116
+ ## License
117
+
118
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nbs"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ module Configuration
2
+
3
+ def configuration
4
+ yield self
5
+ end
6
+
7
+ def define_setting(name, default = nil)
8
+ class_variable_set("@@#{name}", default)
9
+
10
+ define_class_method "#{name}=" do |value|
11
+ class_variable_set("@@#{name}", value)
12
+ end
13
+
14
+ define_class_method name do
15
+ class_variable_get("@@#{name}")
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def define_class_method(name, &block)
22
+ (class << self; self; end).instance_eval do
23
+ define_method name, &block
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,3 @@
1
+ class Nbs
2
+ VERSION = "0.1.0"
3
+ end
data/lib/nbs.rb ADDED
@@ -0,0 +1,62 @@
1
+ require "nbs/version"
2
+ require "nbs/configuration"
3
+ require "httparty"
4
+ require 'active_support/all'
5
+
6
+ class Nbs
7
+ include HTTParty
8
+ extend Configuration
9
+
10
+ define_setting :access_key
11
+ # define_setting :least_favorite_liquid, "seltzer water"
12
+
13
+ base_uri "entintel.api3.nextbigsound.com"
14
+
15
+ def initialize(_nbs_id=356, _options = {}) # kanye west
16
+ @nbs_id = "#{_nbs_id}.json"
17
+ @options = {from: (Time.now - 2.day).to_i, to: Time.now.to_i}.merge(_options)
18
+ end
19
+
20
+ def all_metrics
21
+ @all_metrics_raw ||= self.class.post("/metrics/artist/#{@nbs_id}", @options).parsed_response
22
+ if @tidied.blank?
23
+ @tidied = {}
24
+ @all_metrics_raw.each do |am|
25
+ @tidied[am["Service"]["name"].downcase] = am["Metric"] if am["Metric"].present?
26
+ end
27
+ end
28
+ @tidied
29
+ end
30
+
31
+ def metrics
32
+ if @metrics.blank?
33
+ @metrics = {}
34
+ @metrics[:facebook] = tidy_metrics(all_metrics['facebook']['fans']) if all_metrics['facebook']['fans'].present?
35
+ @metrics[:twitter] = tidy_metrics(all_metrics['twitter']['fans']) if all_metrics['twitter']['fans'].present?
36
+ @metrics[:youtube] = tidy_metrics(all_metrics['youtube']['fans']) if all_metrics['youtube']['fans'].present?
37
+ @metrics[:instagram] = tidy_metrics(all_metrics['instagram']['fans']) if all_metrics['instagram']['fans'].present?
38
+ end
39
+ @metrics
40
+ end
41
+
42
+ def self.artist_search(_name)
43
+ if @name != _name
44
+ @name = _name
45
+ result = get("/artists/search.json", { query: {q: "#{_name}"}}).parsed_response
46
+ @artist_search = []
47
+ result.each do |id, values|
48
+ @artist_search << {id: id, name: values["name"], music_brainz_id: values["music_brainz_id"]}
49
+ end
50
+ end
51
+ @artist_search
52
+ end
53
+
54
+ private
55
+
56
+ def tidy_metrics(_arry)
57
+ _arry.map do |day, value|
58
+ {time: Time.at(day.to_i.days.to_i).utc, volume: value}
59
+ end
60
+ end
61
+
62
+ end
data/nbs.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nbs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nbs"
8
+ spec.version = Nbs::VERSION
9
+ spec.authors = ["David Georgiou"]
10
+ spec.email = ["david.georgiou@gmail.com"]
11
+
12
+ spec.summary = %q{Simple interface to the next big sound api}
13
+ spec.description = %q{Simple NextBigSound wrapper. requires private key from NBS}
14
+ spec.homepage = "https://github.com/eicore/nbs"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.14"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "awesome_print", '~> 1.6'
36
+ spec.add_dependency "httparty", "~> 0.13.1"
37
+ spec.add_dependency "activesupport", ">= 4.0.0"
38
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nbs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Georgiou
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: awesome_print
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.13.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.13.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 4.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 4.0.0
83
+ description: Simple NextBigSound wrapper. requires private key from NBS
84
+ email:
85
+ - david.georgiou@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/setup
97
+ - lib/nbs.rb
98
+ - lib/nbs/configuration.rb
99
+ - lib/nbs/version.rb
100
+ - nbs.gemspec
101
+ homepage: https://github.com/eicore/nbs
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.6.11
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Simple interface to the next big sound api
125
+ test_files: []