mr_eko 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -145,7 +145,7 @@ end
145
145
 
146
146
  desc "Load all the codes"
147
147
  task :environment do
148
- require 'lib/mr_eko'
148
+ require_relative 'lib/mr_eko'
149
149
  end
150
150
 
151
151
  desc 'Launch an IRB console'
@@ -0,0 +1,15 @@
1
+ Sequel.migration do
2
+ up do
3
+ create_table(:api_logs) do
4
+ primary_key :id
5
+ DateTime :created_on
6
+
7
+ index :created_on
8
+ end
9
+
10
+ end
11
+
12
+ down do
13
+ drop_table :api_logs
14
+ end
15
+ end
data/lib/mr_eko.rb CHANGED
@@ -22,7 +22,7 @@ EKO_ENV = ENV['EKO_ENV'] || 'development'
22
22
  Sequel.default_timezone = :utc
23
23
 
24
24
  module MrEko
25
- VERSION = '0.6.2'
25
+ VERSION = '0.7.0'
26
26
  USER_DIR = File.join(ENV['HOME'], ".mreko")
27
27
  FINGERPRINTS_DIR = File.join(USER_DIR, 'fingerprints')
28
28
  LOG_DIR = File.join(USER_DIR, 'logs')
@@ -43,9 +43,25 @@ module MrEko
43
43
  end
44
44
 
45
45
  def nest
46
+ handle_rate_limit
46
47
  @nest
47
48
  end
48
49
 
50
+ # A bit ghetto since we can't easily access the
51
+ # HTTP headers Echonest returns detailing the
52
+ # rate limit. @TODO look at fixing this later.
53
+ def handle_rate_limit
54
+
55
+ requests_in_window = @connection[:api_logs].where("created_on >= ?", Time.now - 60).count
56
+
57
+ if requests_in_window >= 120
58
+ puts "Throttling you..."
59
+ sleep 1
60
+ end
61
+
62
+ @connection[:api_logs].insert(:created_on => Time.now)
63
+ end
64
+
49
65
  def md5(filename)
50
66
  Digest::MD5.hexdigest(open(filename).read)
51
67
  end
data/mr_eko.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'mr_eko'
16
- s.version = '0.6.2'
17
- s.date = '2013-08-14'
16
+ s.version = '0.7.0'
17
+ s.date = '2013-12-30'
18
18
  s.rubyforge_project = 'mr_eko'
19
19
  s.license = 'MIT'
20
20
 
@@ -81,6 +81,7 @@ Gem::Specification.new do |s|
81
81
  db/migrate/004_add_code_to_songs.rb
82
82
  db/migrate/005_remove_fades_from_song.rb
83
83
  db/migrate/006_add_song_position.rb
84
+ db/migrate/007_add_api_logs.rb
84
85
  ext/enmfp/LICENSE
85
86
  ext/enmfp/README
86
87
  ext/enmfp/RELEASE_NOTES
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mr_eko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-14 00:00:00.000000000 Z
12
+ date: 2013-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel
@@ -255,6 +255,7 @@ files:
255
255
  - db/migrate/004_add_code_to_songs.rb
256
256
  - db/migrate/005_remove_fades_from_song.rb
257
257
  - db/migrate/006_add_song_position.rb
258
+ - db/migrate/007_add_api_logs.rb
258
259
  - ext/enmfp/LICENSE
259
260
  - ext/enmfp/README
260
261
  - ext/enmfp/RELEASE_NOTES
@@ -302,9 +303,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
302
303
  - - ! '>='
303
304
  - !ruby/object:Gem::Version
304
305
  version: '0'
305
- segments:
306
- - 0
307
- hash: -1468171297287347666
308
306
  required_rubygems_version: !ruby/object:Gem::Requirement
309
307
  none: false
310
308
  requirements: