entrez 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/README.rdoc CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  Entrez is a simple API for making HTTP requests to Entrez utilities (eutils: http://eutils.ncbi.nlm.nih.gov/).
4
4
 
5
+ == Installation
6
+
7
+ gem install entrez
8
+
9
+ or if you use Bundler awesomeness:
10
+
11
+ # Gemfile
12
+ gem 'entrez'
13
+
14
+ It requires httparty.
15
+
5
16
  == Usage
6
17
 
7
18
  Entrez.efetch(<database>, parameters)
@@ -20,9 +31,19 @@ Email is obtained from an environment variable ENTREZ_EMAIL on your computer.
20
31
  I set mine in my ~/.bash_profile:
21
32
  export ENTREZ_EMAIL='jared@redningja.com'
22
33
 
34
+ == NCBI query limits
35
+
36
+ NCBI recommends no more than 3 URL requests per second: http://www.ncbi.nlm.nih.gov/books/NBK25497/#chapter2.Usage_Guidelines_and_Requiremen
37
+ This gem respects this limit. It will delay the next request if the last 3 have been made within 1 second.
38
+ The amount of delay time is no more than what is necessary to make the next request "respectful".
39
+
23
40
  == What about EInfo, ESummary, EPost, ESearch, ELink, EGQuery, and ESpell?
24
41
 
25
42
  For my purposes, I only needed EFetch.
26
43
  But if you would like to contribute, please feel free.
27
44
  After seeing the code, assuming you know how to submit requests to einfo et al,
28
- It should be trivial to implement them here.
45
+ It should be easy to implement them here.
46
+
47
+ == Compatibility
48
+
49
+ http://test.rubygems.org/gems/entrez
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ task :default => :test
5
+
6
+ desc 'Run rspec tests'
7
+ task :test do
8
+ sh 'rspec spec/'
9
+ end
data/lib/entrez.rb CHANGED
@@ -9,9 +9,29 @@ class Entrez
9
9
  class << self
10
10
 
11
11
  def efetch(db, params = {})
12
+ respect_query_limit
13
+ request_times << Time.now.to_f
12
14
  get '/efetch.fcgi', :query => {db: db}.merge(params)
13
15
  end
14
16
 
17
+ def request_times
18
+ @request_times ||= []
19
+ end
20
+
21
+ private
22
+
23
+ def respect_query_limit
24
+ three_requests_ago = request_times[-3]
25
+ return unless three_requests_ago
26
+ three_requests_ago = three_requests_ago.to_f
27
+ now = Time.now.to_f
28
+ enough_time_has_passed = now > three_requests_ago + 1
29
+ unless enough_time_has_passed
30
+ STDERR.puts "sleeping #{now - three_requests_ago}"
31
+ sleep(now - three_requests_ago)
32
+ end
33
+ end
34
+
15
35
  end
16
36
 
17
37
  end
@@ -1,3 +1,3 @@
1
1
  module Entrez
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/spec/entrez_spec.rb CHANGED
@@ -8,8 +8,12 @@ describe Entrez do
8
8
  end
9
9
 
10
10
  it 'should efetch results' do
11
- rs_number = 9268480.to_s
12
- Entrez.efetch('snp', {id: rs_number, retmode: 'xml'}).should eq(file_fixture('efetch.xml'))
11
+ Entrez.efetch('snp', {id: 9268480, retmode: 'xml'}).should eq(file_fixture('efetch.xml'))
12
+ end
13
+
14
+ it 'should respect query limit' do
15
+ requests = proc { 4.times { Entrez.efetch('snp', id: 9268480) } }
16
+ requests.should take_longer_than(1.0)
13
17
  end
14
18
 
15
19
  end
@@ -4,4 +4,12 @@ module Macros
4
4
  File.open(File.join(File.dirname(__FILE__), 'fixtures/', file_name)).read
5
5
  end
6
6
 
7
+ # Return how long it takes to run block.
8
+ def timer
9
+ start_time = Time.now
10
+ yield
11
+ end_time = Time.now
12
+ end_time - start_time
13
+ end
14
+
7
15
  end
@@ -0,0 +1,9 @@
1
+ RSpec::Matchers.define :take_longer_than do |seconds|
2
+ match do |process|
3
+ @elapsed_time = timer(&process)
4
+ @elapsed_time.should > seconds
5
+ end
6
+ failure_message_for_should do
7
+ "Expected process to take longer than #{seconds} seconds (actual: #{@elapsed_time})"
8
+ end
9
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entrez
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
4
+ prerelease:
5
+ version: 0.2.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Jared Ning
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-02-03 00:00:00 -06:00
13
+ date: 2011-03-07 00:00:00 -06:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,8 +21,6 @@ dependencies:
25
21
  requirements:
26
22
  - - ">="
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
24
  version: "0"
31
25
  type: :runtime
32
26
  version_requirements: *id001
@@ -38,10 +32,6 @@ dependencies:
38
32
  requirements:
39
33
  - - "="
40
34
  - !ruby/object:Gem::Version
41
- segments:
42
- - 2
43
- - 4
44
- - 0
45
35
  version: 2.4.0
46
36
  type: :development
47
37
  version_requirements: *id002
@@ -55,6 +45,7 @@ extensions: []
55
45
  extra_rdoc_files: []
56
46
 
57
47
  files:
48
+ - .gemtest
58
49
  - .gitignore
59
50
  - .rvmrc
60
51
  - Gemfile
@@ -67,6 +58,7 @@ files:
67
58
  - spec/spec_helper.rb
68
59
  - spec/support/fixtures/efetch.xml
69
60
  - spec/support/macros.rb
61
+ - spec/support/matchers.rb
70
62
  has_rdoc: true
71
63
  homepage: https://github.com/ordinaryzelig/entrez
72
64
  licenses: []
@@ -81,21 +73,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
73
  requirements:
82
74
  - - ">="
83
75
  - !ruby/object:Gem::Version
84
- segments:
85
- - 0
86
76
  version: "0"
87
77
  required_rubygems_version: !ruby/object:Gem::Requirement
88
78
  none: false
89
79
  requirements:
90
80
  - - ">="
91
81
  - !ruby/object:Gem::Version
92
- segments:
93
- - 0
94
82
  version: "0"
95
83
  requirements: []
96
84
 
97
85
  rubyforge_project: entrez
98
- rubygems_version: 1.3.7
86
+ rubygems_version: 1.6.1
99
87
  signing_key:
100
88
  specification_version: 3
101
89
  summary: HTTP requests to Entrez E-utilities
@@ -104,3 +92,4 @@ test_files:
104
92
  - spec/spec_helper.rb
105
93
  - spec/support/fixtures/efetch.xml
106
94
  - spec/support/macros.rb
95
+ - spec/support/matchers.rb