dor-fetcher 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/dor-fetcher.rb +79 -10
- metadata +72 -10
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZDAyYWRlOTUzZDYwNjQxNDI1MjgwMGIyMzhlYTRmNGU2YTEwMTk3Ng==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5a1fe464fcac95b99e0136e9b2efed102927f6c3
|
4
|
+
data.tar.gz: 1ef59399da0edc8abfb759d0f385b7ef3fff0a56
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YWJkNzRiYTQwODQ0ZDgyNWFhN2EzMTRkZmE3YmFkZWI4ZTY5OGRjZTFkMmUy
|
11
|
-
OTQ2NGJkOGM2ODQ1M2NjNzBiM2MyMzEwOGYzZjM2ZTJkODhkYTE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MTUxOThlMTUzMjlmNzg1MDdmODAwZmY5ZjEwYmNmODc3ZTA2MmM0MjQwMmMy
|
14
|
-
NDRiODQwY2I1NjRhYTUyMzg2YWU1M2ZmYzc2ZTA5NWYzZTU3ZmU4MTk2ZGE4
|
15
|
-
NjAyOGU4NjBlYzYyMDYyYWUyZjliMjYzYjUyYjJjNjA2ZTRjMWY=
|
6
|
+
metadata.gz: 1ee6988a6c963de4f25c3fd11debfa586f7aa8d2b5467ea04f163e46c61f850f8efa12ebfde2fe0897cfb5e8a72a14ef690fc38bbfe10356750fe1fb223aa7d9
|
7
|
+
data.tar.gz: 0233b07bb7d84b5aba138aaf488d9339e289b26cea04be5492ec39058e7677828ae3290f584929819907133936d05cef175e4dea97c0ada13392fd1768fa7ce4
|
data/lib/dor-fetcher.rb
CHANGED
@@ -9,48 +9,87 @@ module DorFetcher
|
|
9
9
|
@@count_only_param = "?rows=0"
|
10
10
|
@@default_service_url = 'http://127.0.0.1:3000'
|
11
11
|
|
12
|
-
#
|
12
|
+
#Create a new instance of DorFetcher::Client
|
13
|
+
#@param options [Hash] Currently supports only :service_url, the base
|
14
|
+
#url for API queries. Defaults to http://127.0.0.1:3000
|
15
|
+
#@example
|
16
|
+
# df = DorFetcher::Client.new({:service_url='http://SERVICEURL'})
|
13
17
|
def initialize options = {}
|
14
18
|
#TODO: Check for a well formed URL and a 200 from the destination before just accepting this
|
15
19
|
@service_url = options[:service_url] || @@default_service_url
|
16
20
|
end
|
17
|
-
|
21
|
+
|
22
|
+
|
23
|
+
#Get a hash of all members of a collection and the collection itself
|
24
|
+
#
|
25
|
+
#@param collection [String] we expect pid/druid
|
26
|
+
#@param params [Hash] we expect :count_only or any of @@supported_params
|
27
|
+
#@return [Hash] Hash of all objects in the collection including
|
28
|
+
#pid/druid, title, date last modified, and count
|
18
29
|
def get_collection(collection, params = {})
|
19
30
|
return query_api('collection', collection, params)
|
20
31
|
end
|
21
32
|
|
33
|
+
#Get the count of the number of items in a collection, including the
|
34
|
+
#collection object itself
|
35
|
+
#@param collection [String] we expect pid/druid
|
36
|
+
#@param params [Hash] we expect :count_only or any of @@supported_params
|
37
|
+
#@return [Integer] Number found
|
22
38
|
def get_count_for_collection(collection, params = {})
|
23
39
|
return query_api('collection', collection, add_count_only_param(params))
|
24
40
|
end
|
25
41
|
|
42
|
+
#Get a Hash of all the collections in the digital repository
|
43
|
+
#@return [Hash] Hash of all collections including pid/druid, title,
|
44
|
+
#date last modified, and count
|
26
45
|
def list_all_collections
|
27
46
|
return query_api('collection', '', {})
|
28
47
|
end
|
29
48
|
|
49
|
+
#Get a Count of all the collections in the digital repository
|
50
|
+
#@return [Integer] Number of all collections
|
30
51
|
def total_collection_count
|
31
52
|
return query_api('collection', '', {:count_only=>true})
|
32
53
|
end
|
33
54
|
|
34
|
-
#
|
55
|
+
#Get the APO and all objects governed by the APO
|
56
|
+
#@param apo [String] pid/druid of the APO
|
57
|
+
#@param params [Hash] we expect :count_only or any of @@supported_params
|
58
|
+
#@return [Hash] Hash of all objects governed by the APO including
|
59
|
+
#pid/druid, title, date last modified, and count
|
35
60
|
def get_apo(apo, params= {})
|
36
61
|
return query_api('apo', apo, params)
|
37
62
|
end
|
38
63
|
|
64
|
+
#Get the count of the number of objects in an APO, including the
|
65
|
+
#APO object itself
|
66
|
+
#@param apo [String] we expect pid/druid
|
67
|
+
#@param params [Hash] we expect :count_only or any of @@supported_params
|
68
|
+
#@return [Integer] Number found
|
39
69
|
def get_count_for_apo(apo, params={})
|
40
70
|
return query_api('apo', apo, add_count_only_param(params))
|
41
71
|
end
|
42
72
|
|
73
|
+
#Get a Hash of all the APOs in the digital repository
|
74
|
+
#@return [Hash] Hash of all APOs including pid/druid, title,
|
75
|
+
#date last modified, and count
|
43
76
|
def list_all_apos
|
44
77
|
return query_api('apo', '', {})
|
45
78
|
end
|
46
79
|
|
80
|
+
#Get a Count of all the APOs in the digital repository
|
81
|
+
#@return [Integer] Number of all APOs
|
47
82
|
def total_apo_count
|
48
83
|
return query_api('apo', '', {:count_only=>true})
|
49
84
|
end
|
50
85
|
|
86
|
+
#Method to parse full Hash into an array containing only the druids
|
87
|
+
#
|
88
|
+
#@param response [Hash] Hash as returned by query_api
|
89
|
+
#@return [Array] the array listing all druids in the supplied Hash
|
51
90
|
def druid_array(response)
|
52
91
|
return_list = []
|
53
|
-
j =
|
92
|
+
j = response
|
54
93
|
j.keys.each do |key|
|
55
94
|
j[key].each do |item|
|
56
95
|
return_list << item['druid'] if item['druid'] != nil
|
@@ -58,9 +97,17 @@ module DorFetcher
|
|
58
97
|
end
|
59
98
|
return return_list
|
60
99
|
end
|
61
|
-
|
100
|
+
#Query a RESTful API and return the JSON result as a Hash
|
101
|
+
#@param base [String] The name of controller of the Rails App you wish to
|
102
|
+
#route to
|
103
|
+
#@param druid [String] The druid/pid of the object you wish to query,
|
104
|
+
#or empty string for no specific druid
|
105
|
+
#@param params [Hash] we expect :count_only or any of @@supported_params
|
106
|
+
#@return [Hash] Hash of all objects governed by the APO including
|
107
|
+
#pid/druid, title, date last modified, and count
|
62
108
|
def query_api(base, druid, params)
|
63
109
|
url = "#{@service_url}/#{base}/#{druid}#{add_params(params)}"
|
110
|
+
|
64
111
|
begin
|
65
112
|
resp = Net::HTTP.get_response(URI.parse(url))
|
66
113
|
rescue
|
@@ -68,26 +115,48 @@ module DorFetcher
|
|
68
115
|
end
|
69
116
|
|
70
117
|
return resp.body.to_i if params[:count_only] == true
|
71
|
-
return resp.body
|
72
|
-
|
118
|
+
return JSON[resp.body] #Convert the response JSON to a Ruby Hash
|
73
119
|
end
|
74
120
|
|
75
|
-
|
121
|
+
#Transform a parameter hash into a RESTful API parameter format
|
122
|
+
#
|
123
|
+
#@param input_params [Hash] {The existing parameters, eg time and tag}
|
124
|
+
#@return [String] parameters in the Hash now formatted into a RESTful parameter string
|
125
|
+
def add_params(input_params)
|
76
126
|
args_string = ""
|
77
127
|
|
78
128
|
#Handle Count Only
|
79
|
-
args_string << @@count_only_param if
|
129
|
+
args_string << @@count_only_param if input_params[:count_only] == true
|
80
130
|
|
131
|
+
#If we did not add in a rows=0 param, args_string will have a size of
|
132
|
+
#zero
|
133
|
+
#If we did add in a rows=0 param, this will set count to greater than
|
134
|
+
#zero
|
135
|
+
count = args_string.size
|
81
136
|
@@supported_params.each do |p|
|
82
|
-
|
137
|
+
operator = "?"
|
138
|
+
operator = "&" if count > 0
|
139
|
+
args_string << "#{operator}#{p.to_s}=#{input_params[p]}" if input_params[p] != nil
|
140
|
+
count += 1
|
83
141
|
end
|
84
142
|
return args_string
|
85
143
|
end
|
86
144
|
|
145
|
+
#Add the parameter so query_api knows only to get a count of the documents in solr
|
146
|
+
#
|
147
|
+
#@param params [Hash] {The existing parameters, eg time and tag}
|
148
|
+
#@return [Hash] the params Hash plus the key/value set :count_only=>true
|
87
149
|
def add_count_only_param(params)
|
88
150
|
params.store(:count_only, true)
|
89
151
|
return params
|
90
152
|
end
|
153
|
+
|
154
|
+
#Get the Base URL this instance will run RESTful API calls against
|
155
|
+
#@return [String] the url
|
156
|
+
def service_url
|
157
|
+
return @service_url
|
158
|
+
end
|
159
|
+
|
91
160
|
end
|
92
161
|
|
93
162
|
end
|
metadata
CHANGED
@@ -1,38 +1,100 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dor-fetcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carrick Rogers
|
8
|
+
- Laney McGlohon
|
9
|
+
- Bess Sadler
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
13
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
16
|
name: rspec
|
15
17
|
requirement: !ruby/object:Gem::Requirement
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - ">="
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '0'
|
20
22
|
type: :development
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
23
25
|
requirements:
|
24
|
-
- -
|
26
|
+
- - ">="
|
25
27
|
- !ruby/object:Gem::Version
|
26
28
|
version: '0'
|
27
|
-
|
28
|
-
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: vcr
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: webmock
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: yard
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: coveralls
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
description: Wrapper for the Dor Fetcher Services RESTful API.
|
86
|
+
email:
|
87
|
+
- carrickr@stanford.edu
|
88
|
+
- laneymcg@stanford.edu
|
89
|
+
- bess@stanford.edu
|
29
90
|
executables: []
|
30
91
|
extensions: []
|
31
92
|
extra_rdoc_files: []
|
32
93
|
files:
|
33
94
|
- lib/dor-fetcher.rb
|
34
95
|
homepage: http://www.stanford.edu
|
35
|
-
licenses:
|
96
|
+
licenses:
|
97
|
+
- Apache-2.0
|
36
98
|
metadata: {}
|
37
99
|
post_install_message:
|
38
100
|
rdoc_options: []
|
@@ -40,17 +102,17 @@ require_paths:
|
|
40
102
|
- lib
|
41
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
42
104
|
requirements:
|
43
|
-
- -
|
105
|
+
- - ">="
|
44
106
|
- !ruby/object:Gem::Version
|
45
107
|
version: '0'
|
46
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
109
|
requirements:
|
48
|
-
- -
|
110
|
+
- - ">="
|
49
111
|
- !ruby/object:Gem::Version
|
50
112
|
version: '0'
|
51
113
|
requirements: []
|
52
114
|
rubyforge_project:
|
53
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.2.2
|
54
116
|
signing_key:
|
55
117
|
specification_version: 4
|
56
118
|
summary: DorFetcher Gem
|