Module: Cirneco::Api
Instance Method Summary collapse
- #delete_metadata(doi, options = {}) ⇒ Object
- #get_doi(doi, options = {}) ⇒ Object
- #get_dois(options = {}) ⇒ Object
- #get_media(doi, options = {}) ⇒ Object
- #get_metadata(doi, options = {}) ⇒ Object
- #post_media(doi, options = {}) ⇒ Object
- #post_metadata(data, options = {}) ⇒ Object
- #put_doi(doi, options = {}) ⇒ Object
- #put_metadata(doi, options = {}) ⇒ Object
Instance Method Details
#delete_metadata(doi, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/cirneco/api.rb', line 33 def (doi, ={}) return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless [:username].present? && [:password].present? mds_url = [:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org' url = "#{mds_url}/metadata/#{doi}" Maremma.delete(url, username: [:username], password: [:password]) end |
#get_doi(doi, options = {}) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/cirneco/api.rb', line 53 def get_doi(doi, ={}) return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless [:username].present? && [:password].present? mds_url = [:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org' url = "#{mds_url}/doi/#{doi}" Maremma.get(url, username: [:username], password: [:password]) end |
#get_dois(options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cirneco/api.rb', line 62 def get_dois(={}) return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless [:username].present? && [:password].present? mds_url = [:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org' url = "#{mds_url}/doi" response = Maremma.get(url, username: [:username], password: [:password]) response.body["data"] = response.body["data"].split("\n") if response.body["data"].present? response end |
#get_media(doi, options = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/cirneco/api.rb', line 84 def get_media(doi, ={}) return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless [:username].present? && [:password].present? mds_url = [:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org' url = "#{mds_url}/media/#{doi}" response = Maremma.get(url, accept: 'application/xml', username: [:username], password: [:password]) if response.body["data"].present? && ![:raw] response.body["data"] = response.body["data"].split("\n").map do |m| mime_type, url = m.split('=', 2) { mime_type: mime_type, url: url } end end response end |
#get_metadata(doi, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/cirneco/api.rb', line 24 def (doi, ={}) return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless [:username].present? && [:password].present? mds_url = [:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org' url = "#{mds_url}/metadata/#{doi}" Maremma.get(url, accept: 'application/xml', username: [:username], password: [:password], raw: true) end |
#post_media(doi, options = {}) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cirneco/api.rb', line 73 def post_media(doi, ={}) return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless [:username].present? && [:password].present? payload = [:raw] ? [:media] : [:media].map { |m| "#{m[:mime_type]}=#{m[:url]}" }.join("\n") mds_url = [:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org' url = "#{mds_url}/media/#{doi}" Maremma.post(url, content_type: 'text/plain;charset=UTF-8', data: payload, username: [:username], password: [:password]) end |
#post_metadata(data, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/cirneco/api.rb', line 6 def (data, ={}) return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless [:username].present? && [:password].present? mds_url = [:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org' url = "#{mds_url}/metadata" Maremma.post(url, content_type: 'application/xml;charset=UTF-8', data: data, username: [:username], password: [:password]) end |
#put_doi(doi, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cirneco/api.rb', line 42 def put_doi(doi, ={}) return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless [:username].present? && [:password].present? payload = "doi=#{doi}\nurl=#{[:url]}" mds_url = [:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org' url = "#{mds_url}/doi/#{doi}" Maremma.put(url, content_type: 'text/plain;charset=UTF-8', data: payload, username: [:username], password: [:password]) end |
#put_metadata(doi, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/cirneco/api.rb', line 15 def (doi, ={}) return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless [:username].present? && [:password].present? mds_url = [:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org' url = "#{mds_url}/metadata/#{doi}" Maremma.put(url, content_type: 'application/xml;charset=UTF-8', data: [:data], username: [:username], password: [:password]) end |