dor-fetcher 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/dor-fetcher.rb +30 -25
  3. metadata +17 -3
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzdjNDg4MmUzMGFhZWZjMTdmMjNkMGYwY2RiOWI4Zjk2MDQwYzdkOQ==
4
+ ZTJmYWI5ZDJlYjJjNjI4Y2RiNDk4OTVmZDRmYWNmMmU4OTIxNWU5Yw==
5
5
  data.tar.gz: !binary |-
6
- ZWRmZGM5ODA4MTA2NjViMTQ0NGZkZGQ3MjA4MzNjNmRlZTk2MGRlMA==
6
+ ZDFiMDgzZmVjOGJjNmE4MjIzZGQyMzE0ZmM0YjRmMTcxYzA5YjQwNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDA4YzYyNjIxMWYyY2FjZmQ2Nzc1MmUwOTZlYzY1MGNmNjdhY2E4NDUzNWJl
10
- ZWJhMGY1ZWRlOWRhYTRlODlmNGVjNTE1YzI1NGE4ZmU3OTU1OThiMDk2YzI0
11
- NTBlMGU0YTZjMGE1M2E3NDNiNDA4YjI3N2UzMzIyMzQ0OTFhZTQ=
9
+ YTZmZWViYWFjNDcwMjMzMGM4YjE0ZGEyYzU5NDEyNmRiNWNhYzgwZDA1NDA0
10
+ ZGViOTdlYjAzMDMyMzAyMWZhODBkNTNmNTZjOGUwNDM1MmMxMDFjNjg2ZjJi
11
+ YmEzOWE2YWVlNjBhZDhmM2VlMmE2MDQ3OTZlNTVjNmU2NTI5ZTA=
12
12
  data.tar.gz: !binary |-
13
- YTZiZTM0YTFjNDkwZTZiMGIyOWIwOGYyMGU2Mjg5NWYzNjc5ZmJhMzhhN2Fi
14
- OTQzYzU0MDk2M2JmZDcwYTI2MjIzZDdjYTM0NGU3ODA3YzIyMWQzMDQzMWU5
15
- ZWIyZGRiN2ZiZjcyZjgzYTY4Mjk2MWU1MGE0ZDUwZTdjMDEyYzI=
13
+ OGEwZDE2ZGJhNWNjYzA0ODgwOWMzN2RhN2FhNGJlMjIzZjNjZmNmZDJkNTk0
14
+ NmM1NWJlYzZkY2JhODc0MWFhZWE3ODFhZjRlNTU2NDFlMDY1OTYyMTJhOTM5
15
+ NzRiMjdiOWYyYzM2NzI5ZWVkMTRlY2U5MjBjMzk2ZDJjMzM4ZGE=
@@ -1,12 +1,13 @@
1
1
  require 'rest_client'
2
2
  require 'json'
3
+ require 'addressable/uri'
3
4
 
4
5
  module DorFetcher
5
6
 
6
7
  class Client
7
8
 
8
- @@supported_params = [:first_modified, :last_modified]
9
- @@count_only_param = "?rows=0"
9
+ @@supported_params = [:first_modified, :last_modified, :count_only, :status]
10
+ @@count_only_param = "rows=0"
10
11
  @@default_service_url = 'http://127.0.0.1:3000'
11
12
  @@counts_key = 'counts'
12
13
 
@@ -60,13 +61,20 @@ module DorFetcher
60
61
  return query_api('collections', collection, add_count_only_param(params))
61
62
  end
62
63
 
63
- #Get a Hash of all the collections in the digital repository
64
+ #Get a Hash of all the collections in the digital repository that are accessioned
64
65
  #@return [Hash] Hash of all collections including pid/druid, title,
65
66
  #date last modified, and count
66
67
  def list_all_collections
67
68
  return query_api('collections', '', {})
68
69
  end
69
-
70
+
71
+ #Get a Hash of all the collections in the digital repository
72
+ #@return [Hash] Hash of all collections including pid/druid, title,
73
+ #date last modified, and count
74
+ def list_registered_collections
75
+ return query_api('collections', '', {:status=>'registered'})
76
+ end
77
+
70
78
  #Get a Count of all the collections in the digital repository
71
79
  #@return [Integer] Number of all collections
72
80
  def total_collection_count
@@ -91,13 +99,20 @@ module DorFetcher
91
99
  return query_api('apos', apo, add_count_only_param(params))
92
100
  end
93
101
 
94
- #Get a Hash of all the APOs in the digital repository
102
+ #Get a Hash of all the APOs in the digital repository that are accessioned
95
103
  #@return [Hash] Hash of all APOs including pid/druid, title,
96
104
  #date last modified, and count
97
105
  def list_all_apos
98
106
  return query_api('apos', '', {})
99
107
  end
100
-
108
+
109
+ #Get a Hash of all the APOs in the digital repository that are registered
110
+ #@return [Hash] Hash of all APOs including pid/druid, title,
111
+ #date last modified, and count
112
+ def list_registered_apos
113
+ return query_api('apos', '', {:status=>'registereed'})
114
+ end
115
+
101
116
  #Get a Count of all the APOs in the digital repository
102
117
  #@return [Integer] Number of all APOs
103
118
  def total_apo_count
@@ -134,7 +149,9 @@ module DorFetcher
134
149
  #@return [Hash] Hash of all objects governed by the APO including
135
150
  #pid/druid, title, date last modified, and count
136
151
  def query_api(base, druid, params)
137
- url = "#{@site}/#{base}/#{druid}/#{add_params(params)}"
152
+ url = "#{@site}/#{base}"
153
+ url +="/#{druid}" unless druid.nil? || druid.empty?
154
+ url +="#{add_params(params)}" unless params.nil? || params.empty?
138
155
  begin
139
156
  #We need to use this method here for the longer timeout option
140
157
  resp = RestClient::Request.execute(:method=> :get, :url=>url, :timeout=>90000000, :open_timeout=>90000000)
@@ -153,24 +170,12 @@ module DorFetcher
153
170
  #
154
171
  #@param input_params [Hash] {The existing parameters, eg time and tag}
155
172
  #@return [String] parameters in the Hash now formatted into a RESTful parameter string
156
- def add_params(input_params)
157
- args_string = ""
158
-
159
- #Handle Count Only
160
- args_string << @@count_only_param if input_params[:count_only] == true
161
-
162
- #If we did not add in a rows=0 param, args_string will have a size of
163
- #zero
164
- #If we did add in a rows=0 param, this will set count to greater than
165
- #zero
166
- count = args_string.size
167
- @@supported_params.each do |p|
168
- operator = "?"
169
- operator = "&" if count > 0
170
- args_string << "#{operator}#{p.to_s}=#{input_params[p]}" if input_params[p] != nil
171
- count += 1
172
- end
173
- return args_string
173
+ def add_params(input_params)
174
+ input_params.delete_if {|key,value| !@@supported_params.include?(key)}
175
+ uri = Addressable::URI.new
176
+ uri.query_values=input_params
177
+ qs=uri.query.gsub("count_only=true",@@count_only_param)
178
+ return "?#{qs}"
174
179
  end
175
180
 
176
181
  #Add the parameter so query_api knows only to get a count of the documents in solr
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dor-fetcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carrick Rogers
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-11-24 00:00:00.000000000 Z
13
+ date: 2014-12-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -96,6 +96,20 @@ dependencies:
96
96
  - - ! '>='
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: addressable
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :runtime
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
99
113
  description: Wrapper for the Dor Fetcher Services RESTful API.
100
114
  email:
101
115
  - carrickr@stanford.edu
@@ -126,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
140
  version: '0'
127
141
  requirements: []
128
142
  rubyforge_project:
129
- rubygems_version: 2.1.2
143
+ rubygems_version: 2.4.2
130
144
  signing_key:
131
145
  specification_version: 4
132
146
  summary: DorFetcher Gem