alma_rest_api 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/alma_rest_api.rb +31 -10
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 1d61375252e2027bb3aff882c28b6cb9801d2e5d
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: a12866dcb65e95512f3d368cd4881b01b7a383c6
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 92cfcd61cb6dcd96264935fe8dd661eb05a74f980a7ed57cfd0311baef9827694975752b647f9e5e2b07aaae88f8e162445866f01b22ece2dd4eef4367e2fbd5
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: bb97b8014ebfb2bd925fe25c93f24fff188bb1f46ecad3ace2b9a8f403f80fc52e184221d77475b2bbf1b20136374b9dad91083fc70ee8c782d5d3391b805a48
         
     | 
    
        data/lib/alma_rest_api.rb
    CHANGED
    
    | 
         @@ -19,9 +19,13 @@ module AlmaRestApi 
     | 
|
| 
       19 
19 
     | 
    
         
             
                  begin
         
     | 
| 
       20 
20 
     | 
    
         
             
                    response = 
         
     | 
| 
       21 
21 
     | 
    
         
             
                     RestClient.get uri(uri),
         
     | 
| 
       22 
     | 
    
         
            -
                        accept:  
     | 
| 
      
 22 
     | 
    
         
            +
                        accept: configuration.format,
         
     | 
| 
       23 
23 
     | 
    
         
             
                        authorization: 'apikey ' + configuration.api_key
         
     | 
| 
       24 
     | 
    
         
            -
                     
     | 
| 
      
 24 
     | 
    
         
            +
                    if configuration.format == :"application/xml"
         
     | 
| 
      
 25 
     | 
    
         
            +
                      return Nokogiri::XML.parse(response.body)
         
     | 
| 
      
 26 
     | 
    
         
            +
                    else
         
     | 
| 
      
 27 
     | 
    
         
            +
                      return JSON.parse(response.body)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    end
         
     | 
| 
       25 
29 
     | 
    
         
             
                  rescue => e
         
     | 
| 
       26 
30 
     | 
    
         
             
                    raise AlmaApiError, parse_error(e.response)
         
     | 
| 
       27 
31 
     | 
    
         
             
                  end 
         
     | 
| 
         @@ -32,11 +36,15 @@ module AlmaRestApi 
     | 
|
| 
       32 
36 
     | 
    
         
             
                  begin
         
     | 
| 
       33 
37 
     | 
    
         
             
                    response =
         
     | 
| 
       34 
38 
     | 
    
         
             
                     RestClient.put uri(uri),
         
     | 
| 
       35 
     | 
    
         
            -
                      data.to_json,
         
     | 
| 
       36 
     | 
    
         
            -
                      accept:  
     | 
| 
      
 39 
     | 
    
         
            +
                      configuration.format == :"application/xml" ? data.to_xml : data.to_json,
         
     | 
| 
      
 40 
     | 
    
         
            +
                      accept: configuration.format,
         
     | 
| 
       37 
41 
     | 
    
         
             
                      authorization: 'apikey ' + configuration.api_key,
         
     | 
| 
       38 
     | 
    
         
            -
                      content_type:  
     | 
| 
       39 
     | 
    
         
            -
                     
     | 
| 
      
 42 
     | 
    
         
            +
                      content_type: configuration.format
         
     | 
| 
      
 43 
     | 
    
         
            +
                    if configuration.format == :"application/xml"
         
     | 
| 
      
 44 
     | 
    
         
            +
                      return Nokogiri::XML.parse(response.body)
         
     | 
| 
      
 45 
     | 
    
         
            +
                    else
         
     | 
| 
      
 46 
     | 
    
         
            +
                      return JSON.parse(response.body)
         
     | 
| 
      
 47 
     | 
    
         
            +
                    end
         
     | 
| 
       40 
48 
     | 
    
         
             
                  rescue => e
         
     | 
| 
       41 
49 
     | 
    
         
             
                    raise AlmaApiError, parse_error(e.response)
         
     | 
| 
       42 
50 
     | 
    
         
             
                  end 
         
     | 
| 
         @@ -47,11 +55,15 @@ module AlmaRestApi 
     | 
|
| 
       47 
55 
     | 
    
         
             
                  begin
         
     | 
| 
       48 
56 
     | 
    
         
             
                    response =
         
     | 
| 
       49 
57 
     | 
    
         
             
                     RestClient.post uri(uri),
         
     | 
| 
       50 
     | 
    
         
            -
                      data.to_json,
         
     | 
| 
       51 
     | 
    
         
            -
                      accept:  
     | 
| 
      
 58 
     | 
    
         
            +
                      configuration.format == :"application/xml" ? data.to_xml : data.to_json,
         
     | 
| 
      
 59 
     | 
    
         
            +
                      accept: configuration.format,
         
     | 
| 
       52 
60 
     | 
    
         
             
                      authorization: 'apikey ' + configuration.api_key,
         
     | 
| 
       53 
     | 
    
         
            -
                      content_type:  
     | 
| 
       54 
     | 
    
         
            -
                     
     | 
| 
      
 61 
     | 
    
         
            +
                      content_type: configuration.format
         
     | 
| 
      
 62 
     | 
    
         
            +
                    if configuration.format == :"application/xml"
         
     | 
| 
      
 63 
     | 
    
         
            +
                      return Nokogiri::XML.parse(response.body)
         
     | 
| 
      
 64 
     | 
    
         
            +
                    else
         
     | 
| 
      
 65 
     | 
    
         
            +
                      return JSON.parse(response.body)
         
     | 
| 
      
 66 
     | 
    
         
            +
                    end
         
     | 
| 
       55 
67 
     | 
    
         
             
                  rescue => e
         
     | 
| 
       56 
68 
     | 
    
         
             
                    raise AlmaApiError, parse_error(e.response)
         
     | 
| 
       57 
69 
     | 
    
         
             
                  end         
         
     | 
| 
         @@ -77,6 +89,7 @@ module AlmaRestApi 
     | 
|
| 
       77 
89 
     | 
    
         | 
| 
       78 
90 
     | 
    
         
             
                def check_config
         
     | 
| 
       79 
91 
     | 
    
         
             
                  raise NoApiKeyError if configuration.api_key.nil? || configuration.api_key.empty?
         
     | 
| 
      
 92 
     | 
    
         
            +
                  raise InvalidApiFormatError unless [:json, :"application/xml"].include? configuration.format
         
     | 
| 
       80 
93 
     | 
    
         
             
                end
         
     | 
| 
       81 
94 
     | 
    
         | 
| 
       82 
95 
     | 
    
         
             
                def parse_error(err)
         
     | 
| 
         @@ -108,10 +121,12 @@ end 
     | 
|
| 
       108 
121 
     | 
    
         
             
            class Configuration
         
     | 
| 
       109 
122 
     | 
    
         
             
              attr_accessor :api_key
         
     | 
| 
       110 
123 
     | 
    
         
             
              attr_accessor :api_path
         
     | 
| 
      
 124 
     | 
    
         
            +
              attr_accessor :format
         
     | 
| 
       111 
125 
     | 
    
         | 
| 
       112 
126 
     | 
    
         
             
              def initialize
         
     | 
| 
       113 
127 
     | 
    
         
             
                @api_key = ENV['ALMA_APIKEY']
         
     | 
| 
       114 
128 
     | 
    
         
             
                @api_path = ENV['ALMA_APIPATH'] || "https://api-na.hosted.exlibrisgroup.com/almaws/v1"
         
     | 
| 
      
 129 
     | 
    
         
            +
                @format = ENV['ALMA_FORMAT'] || :json
         
     | 
| 
       115 
130 
     | 
    
         
             
              end
         
     | 
| 
       116 
131 
     | 
    
         
             
            end
         
     | 
| 
       117 
132 
     | 
    
         | 
| 
         @@ -121,6 +136,12 @@ class NoApiKeyError < StandardError 
     | 
|
| 
       121 
136 
     | 
    
         
             
              end
         
     | 
| 
       122 
137 
     | 
    
         
             
            end
         
     | 
| 
       123 
138 
     | 
    
         | 
| 
      
 139 
     | 
    
         
            +
            class InvalidApiFormatError < StandardError
         
     | 
| 
      
 140 
     | 
    
         
            +
              def initialize(msg="API format must be :json or :\"application/xml\"")
         
     | 
| 
      
 141 
     | 
    
         
            +
                super
         
     | 
| 
      
 142 
     | 
    
         
            +
              end
         
     | 
| 
      
 143 
     | 
    
         
            +
            end
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
       124 
145 
     | 
    
         
             
            class AlmaApiError < StandardError
         
     | 
| 
       125 
146 
     | 
    
         
             
              def initialize(msg)
         
     | 
| 
       126 
147 
     | 
    
         
             
                msg = "Unknown error from Alma" if msg.empty?
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: alma_rest_api
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Josh Weisman
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2019- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2019-08-26 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rest-client
         
     |