arxiv 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,10 +12,22 @@ require 'arxiv/models/manuscript'
12
12
 
13
13
  module Arxiv
14
14
 
15
+ module Error
16
+ class ManuscriptNotFound < StandardError ; end
17
+ class MalformedId < StandardError ; end
18
+ end
19
+
20
+ ID_FORMAT = /^\d{4}\.\d{4}(?:v\d+)?$/
21
+
15
22
  def self.get(id)
23
+ raise Arxiv::Error::MalformedId, "Manuscript ID format is invalid" unless id =~ ID_FORMAT
24
+
16
25
  url = ::URI.parse("http://export.arxiv.org/api/query?id_list=#{id}")
17
26
  response = ::Nokogiri::XML(open(url)).remove_namespaces!
18
27
  manuscript = Arxiv::Manuscript.parse(response.to_s, single: id)
28
+
29
+ raise Arxiv::Error::ManuscriptNotFound, "Manuscript #{id} doesn't exist on arXiv" if manuscript.title.nil?
30
+ manuscript
19
31
  end
20
32
 
21
33
  end
@@ -1,3 +1,3 @@
1
1
  module Arxiv
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ module Arxiv
4
+
5
+ RSpec::Matchers.define :fetch_valid_manuscript do |expected|
6
+ match do |actual|
7
+ expected_title = "Laser frequency comb techniques for precise astronomical spectroscopy"
8
+ actual.is_a?(Arxiv::Manuscript) && actual.title == expected_title
9
+ end
10
+ end
11
+
12
+ describe "get" do
13
+ it "should fetch a manuscript when passed a valid id" do
14
+ Arxiv.get('1202.0819').should fetch_valid_manuscript
15
+ end
16
+ it "should fetch a manuscript when passed a valid id with a version number" do
17
+ Arxiv.get('1202.0819v1').should fetch_valid_manuscript
18
+ end
19
+ it "should raise a manuscript not found error when the manuscript cannot be found on arXiv" do
20
+ lambda { Arxiv.get('1234.1234') }.should raise_error(Arxiv::Error::ManuscriptNotFound)
21
+ end
22
+ it "should raise a malformed id error when the manuscript id has an incorrect format" do
23
+ lambda { Arxiv.get('cond-mat0709123') }.should raise_error(Arxiv::Error::MalformedId)
24
+ end
25
+ end
26
+
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arxiv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -15,7 +15,7 @@ date: 2012-02-14 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: happymapper
18
- requirement: &2153612280 !ruby/object:Gem::Requirement
18
+ requirement: &2153141080 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *2153612280
26
+ version_requirements: *2153141080
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
- requirement: &2153611860 !ruby/object:Gem::Requirement
29
+ requirement: &2153140660 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *2153611860
37
+ version_requirements: *2153140660
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rspec
40
- requirement: &2153611440 !ruby/object:Gem::Requirement
40
+ requirement: &2153140240 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,7 +45,7 @@ dependencies:
45
45
  version: '0'
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *2153611440
48
+ version_requirements: *2153140240
49
49
  description: Makes interacting with arXiv data really easy.
50
50
  email:
51
51
  - coryschires@gmail.com
@@ -68,6 +68,7 @@ files:
68
68
  - lib/arxiv/models/manuscript.rb
69
69
  - lib/arxiv/string_scrubber.rb
70
70
  - lib/arxiv/version.rb
71
+ - spec/arxiv/arxiv_spec.rb
71
72
  - spec/arxiv/models/author_spec.rb
72
73
  - spec/arxiv/models/category_spec.rb
73
74
  - spec/arxiv/models/link_spec.rb
@@ -98,6 +99,7 @@ signing_key:
98
99
  specification_version: 3
99
100
  summary: Ruby wrapper accessing the arXiv API
100
101
  test_files:
102
+ - spec/arxiv/arxiv_spec.rb
101
103
  - spec/arxiv/models/author_spec.rb
102
104
  - spec/arxiv/models/category_spec.rb
103
105
  - spec/arxiv/models/link_spec.rb