from_hyrax 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04ff2831a75d87ea2767af9d221b42f2949c1a24e8a240d71eaae7b4c30d5b2f
4
- data.tar.gz: 3837675c0b8b7a152eebc07e3e95c0e8471549f632fce63e29e91ff6686d1d13
3
+ metadata.gz: bc37017312a929f14a93fb14cc52628a6c5375e9e7c0390097d722299f912f98
4
+ data.tar.gz: 8b7170e120b5f243be4745425c9e76575342784e8c1d7447b19407ec8965117c
5
5
  SHA512:
6
- metadata.gz: 0c5136f153b658bec6c475f45fed49bc6d40aa4001f087ba31e554479bae5c196b351b6d759527b528c274d67d83fd6369a410bffb2985ac3ff6eb48208c7686
7
- data.tar.gz: 13d4a731c4a59c6c14d53b09d158783a2c51522a7290532720f94f46780d828d8726b670dc630ca3f964a3db9297148e3043d112ccc74158bd8dbde9d29a7267
6
+ metadata.gz: eb5545c4ac7823e3bde4bb02801dedeb90c0d2f45e360b0e43740257518f58bee6b4a3c3d40a26a5257b80b4d0b033764a82ea380d4dfeb56c0fa5b6cd799583
7
+ data.tar.gz: e06683c9524ce851d9a90acaeaac3b0d4f5bf4aface55e5d218b1a63f38bedb592fd1fe37f830a18f790ae954a9709611fae26ba64c33ac14154fa48f4f6794f
@@ -5,18 +5,19 @@ class FromHyraxController < ActionController::Base
5
5
  require 'net/http'
6
6
 
7
7
  def hyrax_api
8
- uri = URI("http://#{params[:repo]}/to_spotlight/api/#{params[:api_type]}")
9
- response = ::Net::HTTP.get_response(uri)
8
+ return nil unless instances.include?(params[:repo])
9
+ uri = URI("https://#{params[:repo]}/to_spotlight/api/#{params[:api_type]}")
10
+ response = get_response(uri)
10
11
  render html: response.body.html_safe
11
12
  end
12
13
 
13
14
  def index
14
- @instances = FromHyrax::Engine.config['hyrax_instances'] || []
15
+ instances
15
16
  end
16
17
 
17
18
  def new
18
19
  uri = URI("http://#{params[:repo]}/to_spotlight/api/fields?work=#{params[:work]}")
19
- response = ::Net::HTTP.get_response(uri)
20
+ response = get_response(uri)
20
21
  @hyrax_fields = eval(response.body)
21
22
  @spotlight_fields = spotlight_fields.map { |f| [f[:label], f[:field_name]] }
22
23
  end
@@ -26,11 +27,13 @@ class FromHyraxController < ActionController::Base
26
27
  # use Spotlight::Engine.config.upload_fields to get spotlight fields list
27
28
  # map {|f| [f.label, f.field_name]}
28
29
  @mappings = params[:transfer][:mappings].permit!.to_h.map { |_, v| v unless v['spotlight']['0'].empty? }.compact #use hash.values
29
- @res = Net::HTTP.post URI("http://#{params[:repo]}/to_spotlight/receive"),
30
- { transfer: params[:transfer],
31
- mappings: @mappings,
32
- token: 'secret_token' }.to_json,
33
- 'Content-Type' => 'application/json'
30
+ #@res = Net::HTTP.post URI("http://#{params[:repo]}/to_spotlight/receive"),
31
+ # { transfer: params[:transfer],
32
+ # mappings: @mappings,
33
+ # token: 'secret_token' }.to_json,
34
+ # 'Content-Type' => 'application/json'
35
+ post_options = { transfer: params[:transfer], mappings: @mappings, token: 'secret_token' }
36
+ @res = post_response URI("http://#{params[:repo]}/to_spotlight/receive"), post_options
34
37
  end
35
38
 
36
39
  def receive
@@ -39,6 +42,23 @@ class FromHyraxController < ActionController::Base
39
42
 
40
43
  private
41
44
 
45
+ def get_response uri
46
+ http = Net::HTTP.new(uri.host, uri.port)
47
+ http.use_ssl = true
48
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
49
+ request = Net::HTTP::Get.new(uri.request_uri)
50
+ http.request(request)
51
+ end
52
+
53
+ def post_response uri, options={}
54
+ http = Net::HTTP.new(uri.host, uri.port)
55
+ http.use_ssl = true
56
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
57
+ request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
58
+ request.body = options.to_json
59
+ http.request(request)
60
+ end
61
+
42
62
  def instances
43
63
  @instances ||= FromHyrax::Engine.config['hyrax_instances'] || []
44
64
  end
@@ -1,3 +1,3 @@
1
1
  module FromHyrax
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: from_hyrax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sephirothkod