DPLibrary 0.0.2 → 0.0.3

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: 91e697afe886a3e40c3ce4e85b5c5c61344d11eb
4
+ data.tar.gz: dff0774a163ab798176f6dc698f4805f652dbfca
5
+ SHA512:
6
+ metadata.gz: 1f9278ab8144088824001e1874d5ea6741b49cbb840ad737b05adb1068315f1545ef0651355fbe8372963a37fdf09c1d6c88811ea64dc69b14fba3685cec9e80
7
+ data.tar.gz: fb0731b9864dc2a5124aad3845a5ee3d42b5823a974ccb98d40a36dabe949f057c73e496a4e65feb59bb69124d81ad04a35fd301b2d7591efcb94181a8385f6b
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service: travis-ci
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - jruby-19mode
7
+ - rbx-19mode
8
+ - ruby-head
9
+ - jruby-head
data/DPLibrary.gemspec CHANGED
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'pry'
28
28
  spec.add_development_dependency 'bundler', '~> 1.3'
29
29
  spec.add_development_dependency 'rake'
30
+ spec.add_development_dependency 'coveralls'
30
31
  end
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
+ [![Build Status](https://travis-ci.org/[phereford]/[DPLibrary].png)](https://travis-ci.org/[phereford]/[DPLibrary])
1
2
  [![Code Climate](https://codeclimate.com/github/phereford/DPLibrary.png)](https://codeclimate.com/github/phereford/DPLibrary)
3
+ [![Coverage Status](https://coveralls.io/repos/phereford/DPLibrary/badge.png)](https://coveralls.io/r/phereford/DPLibrary)
2
4
  # DPLibrary
3
5
 
4
6
  A simple ruby API wrapper around the [Digital Public Library of
@@ -43,11 +45,81 @@ the most sense.
43
45
 
44
46
  ## Usages
45
47
 
48
+ After setting your api_key to DPLibrary.api_key, it's time to start
49
+ querying the DPLA!!
50
+
51
+ For reference, you should glance at the [DPLA API
52
+ Reference](http://dp.la/info/developers).
53
+
54
+ Let's get started!
55
+ ```
56
+ @documents_collection = DPLibrary::DocumentCollection.new({q: 'chicken'})
57
+ @documents_collection.count # => returns the total count of your query.
58
+ @documents_collection.limit # => the limit of documents per query
59
+ @documents_collection.offset # => pagination offset in results
60
+ @documents_collection.documents # => Returns an array of document objects
61
+ ```
62
+
63
+ ```
64
+ @document = DPLibrary::DocumentCollection.new({q: 'chicken'}).documents.first
65
+ @document.collection # => returns a collection object
66
+ @document.original_record # => returns an original record object
67
+
68
+ ## Attributes for documents
69
+ :id, :url, :source, :title, :description, :subject, :language, :format,
70
+ :type, :publisher, :creaetor, :provider, :collection, :score,
71
+ :original_record
72
+ ```
73
+
74
+ Now there are many types of parameters you can pass in the
75
+ DocumentCollection initialize method. For a complete list, check out the
76
+ [DPLA API Reference](http://dp.la/info/developers).
77
+
78
+ For the lazy, here is a brief list of what those params can be. It's
79
+ pretty straightforward what the params do.
80
+
81
+ ```
82
+ q # => query string
83
+ sourceResource.id
84
+ sourceResource.contributor
85
+ sourceResource.date.begin
86
+ sourceResource.date.end
87
+ sourceResource.extent
88
+ sourceResource.language.name
89
+ sourceResource.language.iso639
90
+ sourceResource.format
91
+ sourceResource.stateLocatedIn.name
92
+ sourceResource.stateLocatedIn.iso3166-2
93
+ sourceResource.spatial.name
94
+ sourceResource.spatial.country
95
+ sourceResource.spatial.region
96
+ sourceResource.spatial.county
97
+ sourceResource.spatial.state
98
+ sourceResource.spatial.city
99
+ sourceResource.spatial.iso3166-2
100
+ sourceResource.spatial.coordinates
101
+ sourceResource.subject.@id
102
+ sourceResource.subject.type
103
+ sourceResource.subject.name
104
+ sourceResource.temporal.begin
105
+ sourceResource.temporal.end
106
+ sourceResource.title
107
+ sourceResource.type
108
+ hasView.@id
109
+ hasView.format
110
+ isPartOf.@id
111
+ isPartOf.name
112
+ isShownAt
113
+ object
114
+ provider.@id
115
+ provider.name
116
+ ```
117
+
46
118
  ## ToDo's
47
119
  * Write Tests
48
120
  * Create fixtures for tests
49
- * Write up usage documentation
50
121
  * Dry up lib files
122
+ * Write up collection.find method for querying collections
51
123
 
52
124
  ## Contributing
53
125
 
@@ -1,17 +1,23 @@
1
1
  module DPLibrary
2
2
  class Collection
3
- attr_accessor :id,
4
- :title,
5
- :name
3
+ attr_accessor :collection_items
6
4
 
7
- def initialize(hash)
8
- set_values(hash)
5
+ def initialize(collection_response)
6
+ set_values(collection_response)
9
7
  end
10
8
 
11
- def set_values(collection_hash)
12
- self.id = collection_hash['id']
13
- self.title = collection_hash['title']
14
- self.name = collection_hash['name']
9
+ def set_values(collection_response)
10
+ @collection_items = []
11
+ if (collection_response.is_a?(Array))
12
+ @collection_items = collection_response.map {|h| create_collection_item(h)}
13
+ else
14
+ @collection_items << CollectionItem.new(collection_response)
15
+ end
16
+ @collection_items
17
+ end
18
+
19
+ def create_collection_item(collection_item_hash)
20
+ CollectionItem.new(collection_item_hash)
15
21
  end
16
22
  end
17
23
  end
@@ -0,0 +1,17 @@
1
+ module DPLibrary
2
+ class CollectionItem
3
+ attr_accessor :id,
4
+ :title,
5
+ :name
6
+
7
+ def initialize(collection_hash)
8
+ set_values(collection_hash)
9
+ end
10
+
11
+ def set_values(collection_hash)
12
+ self.id = collection_hash['id']
13
+ self.title = collection_hash['title']
14
+ self.name = collection_hash['name']
15
+ end
16
+ end
17
+ end
@@ -48,8 +48,8 @@ module DPLibrary
48
48
  OriginalRecord.new(original_record_hash)
49
49
  end
50
50
 
51
- def create_collection(collection_hash)
52
- Collection.new(collection_hash)
51
+ def create_collection(collection_response)
52
+ Collection.new(collection_response)
53
53
  end
54
54
  end
55
55
  end
@@ -1,3 +1,3 @@
1
1
  module DPLibrary
2
- VERSION = "0.0.2"
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/DPLibrary.rb CHANGED
@@ -8,6 +8,7 @@ module DPLibrary
8
8
  autoload :Base, 'DPLibrary/base'
9
9
  autoload :DocumentCollection, 'DPLibrary/document_collection'
10
10
  autoload :Collection, 'DPLibrary/collection'
11
+ autoload :CollectionItem, 'DPLibrary/collection_item'
11
12
  autoload :Document, 'DPLibrary/document'
12
13
  autoload :Provider, 'DPLibrary/provider'
13
14
  autoload :OriginalRecord, 'DPLibrary/original_record'
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe DPLibrary::Document do
4
+ subject { DPLibrary::Document.new( YAML.load_file( './spec/fixtures/document.yml' ) ) }
5
+
6
+ context 'initialize' do
7
+ its(:id) { should eql '8ce4474d8b1eefffaa5ce4ce34369c43' }
8
+ its(:url) { should eql 'http://www.biodiversitylibrary.org/item/79580' }
9
+ its(:source) { should eql 'Library of Congress' }
10
+ its(:title) { should eql 'The chicken cholera preventive and exterminator, a treatise giving the cause, symptoms, prevention, and extermination of chicken cholera' }
11
+ its(:description) { should eql 'Test' }
12
+ its(:subject) { should eql [{'name'=>"Chicken cholera"}] }
13
+ its(:language) { should eql [{'iso639_3'=>'eng', 'name'=>'English'}] }
14
+ its(:format) { should eql 'Book' }
15
+ its(:type) { should eql 'text' }
16
+ its(:publisher) { should eql 'Wooster [Ohio]Republican steam press print,1875' }
17
+ its(:creator) { should eql 'Hill, A. J' }
18
+ its(:provider) { should be_kind_of DPLibrary::Provider }
19
+ its(:collection) { should be_kind_of DPLibrary::Collection }
20
+ its(:original_record) { should be_kind_of DPLibrary::OriginalRecord }
21
+ its(:score) { should eql 1.9722701 }
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe DPLibrary::OriginalRecord do
4
+ subject { DPLibrary::OriginalRecord.new( YAML.load_file( './spec/fixtures/original_record.yml' ) ) }
5
+
6
+ context 'initialize' do
7
+ its(:id) { should eql 'oai:biodiversitylibrary.org:item/79580' }
8
+ its(:title) { should eql 'The chicken cholera preventive and exterminator, a treatise giving the cause, symptoms, prevention, and extermination of chicken cholera;' }
9
+ its(:url) { should eql 'http://www.biodiversitylibrary.org/item/79580' }
10
+ its(:description) { should eql 'Test' }
11
+ its(:source) { should eql 'Library of Congress' }
12
+ its(:date) { should eql '2012-06-22T02:33:26Z' }
13
+ its(:label) { should eql 'The chicken cholera preventive and exterminator, a treatise giving the cause, symptoms, prevention, and extermination of chicken cholera;' }
14
+ its(:language) { should eql 'English' }
15
+ its(:type) { should eql ['text', 'Book'] }
16
+ its(:creator) { should eql 'Hill, A. J.' }
17
+ its(:publisher) { should eql 'Wooster [Ohio]Republican steam press print,1875.' }
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'yaml'
3
+
4
+ describe DPLibrary::Provider do
5
+ subject { DPLibrary::Provider.new( YAML.load_file( './spec/fixtures/provider.yml' ) ) }
6
+
7
+ context 'initialize' do
8
+ its(:name) { should eql 'Biodiversity Heritage Library' }
9
+ its(:id) { should eql 'http://dp.la/api/contributor/bhl' }
10
+ end
11
+ end
@@ -0,0 +1,37 @@
1
+ 'id': 8ce4474d8b1eefffaa5ce4ce34369c43
2
+ 'isShownAt': http://www.biodiversitylibrary.org/item/79580
3
+ 'dataProvider': Library of Congress
4
+ 'score': 1.9722701
5
+ sourceResource:
6
+ collection:
7
+ 'id': 24087df2c58f149a8167a9589cffd830
8
+ 'title': Volumes
9
+ 'name': Library of Congress
10
+ 'title': The chicken cholera preventive and exterminator, a treatise giving the cause, symptoms, prevention, and extermination of chicken cholera
11
+ 'description': Test
12
+ 'subject':
13
+ - 'name': 'Chicken cholera'
14
+ 'language':
15
+ -
16
+ 'iso639_3': 'eng'
17
+ 'name': 'English'
18
+ 'format': Book
19
+ 'type': text
20
+ 'publisher': Wooster [Ohio]Republican steam press print,1875
21
+ 'creator': Hill, A. J
22
+ provider:
23
+ '@id': http://dp.la/api/contributor/bhl
24
+ 'name': Biodiversity Heritage Library
25
+ originalRecord:
26
+ 'id': oai:biodiversitylibrary.org:item/79580
27
+ 'title': The chicken cholera preventive and exterminator, a treatise giving the cause, symptoms, prevention, and extermination of chicken cholera;
28
+ 'handle': http://www.biodiversitylibrary.org/item/79580
29
+ 'description': Test
30
+ 'contributor': Library of Congress
31
+ 'subject': Chicken cholera
32
+ 'datestamp': '2012-06-22T02:33:26Z'
33
+ 'label': The chicken cholera preventive and exterminator, a treatise giving the cause, symptoms, prevention, and extermination of chicken cholera;
34
+ 'language': English
35
+ 'type': ["text", "Book"]
36
+ 'creator': Hill, A. J.
37
+ 'publisher': Wooster [Ohio]Republican steam press print,1875.
@@ -0,0 +1,12 @@
1
+ 'id': oai:biodiversitylibrary.org:item/79580
2
+ 'title': The chicken cholera preventive and exterminator, a treatise giving the cause, symptoms, prevention, and extermination of chicken cholera;
3
+ 'handle': http://www.biodiversitylibrary.org/item/79580
4
+ 'description': Test
5
+ 'contributor': Library of Congress
6
+ 'subject': Chicken cholera
7
+ 'datestamp': '2012-06-22T02:33:26Z'
8
+ 'label': The chicken cholera preventive and exterminator, a treatise giving the cause, symptoms, prevention, and extermination of chicken cholera;
9
+ 'language': English
10
+ 'type': ["text", "Book"]
11
+ 'creator': Hill, A. J.
12
+ 'publisher': Wooster [Ohio]Republican steam press print,1875.
@@ -0,0 +1,2 @@
1
+ '@id': http://dp.la/api/contributor/bhl
2
+ 'name': Biodiversity Heritage Library
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'DPLibrary'
2
2
  require 'rspec'
3
3
  require 'vcr'
4
+ require 'coveralls'
5
+
6
+ Coveralls.wear!
4
7
 
5
8
  VCR.configure do |config|
6
9
  config.configure_rspec_metadata!
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: DPLibrary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - phereford
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-05 00:00:00.000000000 Z
11
+ date: 2013-07-23 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: faraday
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: faraday_middleware
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: vcr
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
@@ -94,23 +83,20 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: pry
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: bundler
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ~>
116
102
  - !ruby/object:Gem::Version
@@ -118,7 +104,6 @@ dependencies:
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ~>
124
109
  - !ruby/object:Gem::Version
@@ -126,17 +111,29 @@ dependencies:
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: rake
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ! '>='
115
+ - - '>='
132
116
  - !ruby/object:Gem::Version
133
117
  version: '0'
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ! '>='
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: coveralls
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
140
137
  - !ruby/object:Gem::Version
141
138
  version: '0'
142
139
  description: Ruby API wrapper for the Digital Public Library of America API
@@ -146,7 +143,9 @@ executables: []
146
143
  extensions: []
147
144
  extra_rdoc_files: []
148
145
  files:
146
+ - .coveralls.yml
149
147
  - .gitignore
148
+ - .travis.yml
150
149
  - DPLibrary.gemspec
151
150
  - Gemfile
152
151
  - LICENSE.txt
@@ -155,6 +154,7 @@ files:
155
154
  - lib/DPLibrary.rb
156
155
  - lib/DPLibrary/base.rb
157
156
  - lib/DPLibrary/collection.rb
157
+ - lib/DPLibrary/collection_item.rb
158
158
  - lib/DPLibrary/configuration.rb
159
159
  - lib/DPLibrary/connection.rb
160
160
  - lib/DPLibrary/document.rb
@@ -163,41 +163,48 @@ files:
163
163
  - lib/DPLibrary/provider.rb
164
164
  - lib/DPLibrary/request.rb
165
165
  - lib/DPLibrary/version.rb
166
- - spec/DPLibrary/item_spec.rb
166
+ - spec/DPLibrary/collection_spec.rb
167
+ - spec/DPLibrary/document_collection_spec.rb
168
+ - spec/DPLibrary/document_spec.rb
169
+ - spec/DPLibrary/original_record_spec.rb
170
+ - spec/DPLibrary/provider_spec.rb
167
171
  - spec/cassettes/DPLibrary_Item/_new/.yml
172
+ - spec/fixtures/document.yml
173
+ - spec/fixtures/original_record.yml
174
+ - spec/fixtures/provider.yml
168
175
  - spec/spec_helper.rb
169
176
  homepage: http://github.com/phereford/DPLibrary
170
177
  licenses:
171
178
  - MIT
179
+ metadata: {}
172
180
  post_install_message:
173
181
  rdoc_options: []
174
182
  require_paths:
175
183
  - lib
176
184
  required_ruby_version: !ruby/object:Gem::Requirement
177
- none: false
178
185
  requirements:
179
- - - ! '>='
186
+ - - '>='
180
187
  - !ruby/object:Gem::Version
181
188
  version: '0'
182
- segments:
183
- - 0
184
- hash: -1346765738714870131
185
189
  required_rubygems_version: !ruby/object:Gem::Requirement
186
- none: false
187
190
  requirements:
188
- - - ! '>='
191
+ - - '>='
189
192
  - !ruby/object:Gem::Version
190
193
  version: '0'
191
- segments:
192
- - 0
193
- hash: -1346765738714870131
194
194
  requirements: []
195
195
  rubyforge_project:
196
- rubygems_version: 1.8.24
196
+ rubygems_version: 2.0.3
197
197
  signing_key:
198
- specification_version: 3
198
+ specification_version: 4
199
199
  summary: A ruby gem that is an API wrapper for the DPLA
200
200
  test_files:
201
- - spec/DPLibrary/item_spec.rb
201
+ - spec/DPLibrary/collection_spec.rb
202
+ - spec/DPLibrary/document_collection_spec.rb
203
+ - spec/DPLibrary/document_spec.rb
204
+ - spec/DPLibrary/original_record_spec.rb
205
+ - spec/DPLibrary/provider_spec.rb
202
206
  - spec/cassettes/DPLibrary_Item/_new/.yml
207
+ - spec/fixtures/document.yml
208
+ - spec/fixtures/original_record.yml
209
+ - spec/fixtures/provider.yml
203
210
  - spec/spec_helper.rb
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe DPLibrary::DocumentCollection do
4
- subject do
5
- DPLibrary.stub(:api_key).and_return('bb9ec047f463cd046c8a26c4237a3349')
6
- DPLibrary::DocumentCollection.new({q: 'chicken'})
7
- end
8
-
9
- context '.new', :vcr do
10
- it { should_not be nil }
11
- end
12
-
13
- context '#set_method' do
14
- its(:count) { should be_kind_of(Integer) }
15
- end
16
- end