alma 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9e55ff048167a0ab10d80f1480ba2b18cc9fdb10
4
+ data.tar.gz: 87f0c5b9c23ac7a7c3c5927866f6f204db71656b
5
+ SHA512:
6
+ metadata.gz: f047816c46187fc7ed8521156cfe4b5be6aa192f6fa1f67bf68f2330ec8a206d1423ace8d9232eabb7bc496f9472d1cfc89a1289f14aa67445d533949f02f603
7
+ data.tar.gz: 5912e6b39e09e6c6f5b29ac70e8223eaf1b2a343524b2f7a774641c63c452e63e8bf55b14ec4e2c6d2ec26eaeeffb469a4006562b24373b55bd13b4164981e5b
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ alma
@@ -0,0 +1 @@
1
+ ruby-2.3.3
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.13.7
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at chad.nelson@temple.edu. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in alma.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Chad Nelson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,98 @@
1
+ # Alma
2
+
3
+ A client for Web Services provided by the Ex Libris's Alma Library System.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'alma', :git => "https://github.com/tulibraries/alma_rb.git"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install alma_rb
20
+
21
+ ## Usage
22
+
23
+ ### Configuration
24
+
25
+ You'll need to configure the Alma gem to ensure you query the appropriate data. To do so in a rails app, create `config/initializers/alma.rb` with :
26
+
27
+ ```ruby
28
+ Alma.configure do |config|
29
+ # You have to set te apikey
30
+ config.apikey = 'EXAMPLE_EL_DEV_NETWORK_APPLICATION_KEY'
31
+ # Alma gem defaults to querying Ex Libris's North American Api servers. You can override that here.
32
+ config.region = "https://api-eu.hosted.exlibrisgroup.com
33
+ end
34
+ ```
35
+
36
+ Now you can access those configuration attributes with `Alma.configuration.apikey`
37
+
38
+ ### Making Requests
39
+
40
+ #### Get a list of Users
41
+ ```ruby
42
+ users = Alma::User.find
43
+
44
+ users.total count
45
+ > 402
46
+
47
+ users.list.first.id
48
+ > 123456789
49
+ ```
50
+
51
+ #### Get a Single user
52
+ ```ruby
53
+ user = Alma::User.find({:user_id => 123456789})
54
+
55
+ user.first_name
56
+ > Chad
57
+
58
+ user.email
59
+ > chad.nelson@fictional.edu
60
+ ```
61
+
62
+ Once you have a user, you can also request that users loans, fines, requests.
63
+
64
+ ```ruby
65
+ fines = user.fines
66
+ fines.sum
67
+ > 20.0
68
+
69
+ fines.list.first.title
70
+ > Practical Object Oriented Design with Ruby
71
+
72
+ user.loans.list
73
+ [\<Item Object 1\>, \<Item Oject 2\>]
74
+ ```
75
+
76
+ Loans, fines and Requests can also be accessed statically
77
+
78
+ ```ruby
79
+ fines = Alma::User.get_fines({:user_id => 123456789})
80
+
81
+ loans = Alma::User.get_loans({:user_id => 123456789})
82
+
83
+ ```
84
+ ## Development
85
+
86
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
87
+
88
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/alma. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
93
+
94
+
95
+ ## License
96
+
97
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
98
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'alma/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alma"
8
+ spec.version = Alma::VERSION
9
+ spec.authors = ["Chad Nelson"]
10
+ spec.email = ["chad.nelson@temple.edu"]
11
+
12
+ spec.summary = %q{Client for Ex Libris Alma Web Services}
13
+ spec.description = %q{Client for Ex Libris Alma Web Services}
14
+ spec.homepage = "https://github.com/tulibraries/alma_rb"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency 'ezwadl'
25
+
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.13"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency 'webmock'
31
+ spec.add_development_dependency 'pry'
32
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "alma"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ require 'alma/version'
2
+ require 'alma/config'
3
+ require 'alma/api'
4
+ require 'alma/alma_record'
5
+ require 'alma/user'
6
+ require 'alma/result_set'
7
+ require 'alma/loan_set'
8
+ require 'alma/user_set'
9
+ require 'alma/fine_set'
10
+ require 'alma/user_set'
11
+ require 'alma/request_set'
12
+
13
+ module Alma
14
+
15
+ ROOT = File.dirname __dir__
16
+ WADL_DIR = File.join(Alma::ROOT, 'lib','alma','wadl')
17
+
18
+ end
@@ -0,0 +1,28 @@
1
+ module Alma
2
+ class AlmaRecord
3
+
4
+ def initialize(record)
5
+ @raw_record = record
6
+ post_initialize()
7
+ end
8
+
9
+ def method_missing(name)
10
+ return response[name.to_s] if response.has_key?(name.to_s)
11
+ super.method_missing name
12
+ end
13
+
14
+ def respond_to_missing?(name, include_private = false)
15
+ response.has_key?(name.to_s) || super
16
+ end
17
+
18
+ def response
19
+ @raw_record
20
+ end
21
+
22
+ def post_initialize
23
+ # Subclasses can define this method to perform extra initialization
24
+ # after the super class init.
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ require 'ezwadl'
2
+
3
+ module Alma
4
+ module Api
5
+
6
+
7
+ def default_params
8
+ { :query => { :apikey => Alma.configuration.apikey } }
9
+ end
10
+
11
+ def query_merge(hash)
12
+ {:query => default_params[:query].merge(hash)}
13
+ end
14
+
15
+ def resources
16
+ @resources ||= load_wadl
17
+ end
18
+
19
+ def load_wadl(wadl_filename = nil)
20
+ wadl_filename ||= set_wadl_filename
21
+ parsed_wadl = EzWadl::Parser.parse(File.join(Alma::WADL_DIR, wadl_filename)) do |rs|
22
+ rs.first.path = Alma.configuration.region
23
+ end
24
+ parsed_wadl.first
25
+ end
26
+
27
+ def set_wadl_filename
28
+ # Each class including this module should define this
29
+ raise NotImplementedError 'You must define the wadl_filename method'
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,20 @@
1
+ module Alma
2
+ class << self
3
+ attr_accessor :configuration
4
+ end
5
+
6
+ def self.configure()
7
+ self.configuration ||= Configuration.new
8
+ yield(configuration) if block_given?
9
+ end
10
+
11
+ class Configuration
12
+ attr_accessor :apikey, :region
13
+
14
+ def initialize
15
+ @apikey = "TEST_API_KEY"
16
+ @region = 'https://api-na.hosted.exlibrisgroup.com'
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ module Alma
2
+ class FineSet < ResultSet
3
+
4
+ def top_level_key
5
+ 'fees'
6
+ end
7
+
8
+ def response_records_key
9
+ 'fee'
10
+ end
11
+
12
+ def sum
13
+ @ws_response['fees'].fetch('total_sum', 0)
14
+ end
15
+
16
+ def currency
17
+ @ws_response['fees'].fetch('total_sum', nil)
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ module Alma
2
+ class LoanSet
3
+
4
+ attr_reader :total_record_count, :list
5
+
6
+ def initialize(ws_response)
7
+ @ws_response = ws_response
8
+ @total_record_count = ws_response.fetch(total_record_count, 0)
9
+ @list ||= list_results
10
+ end
11
+
12
+ def response_records
13
+ @ws_response['item_loans'].fetch('item_loan',[])
14
+ end
15
+
16
+ def list_results
17
+ response_records.map do |loan|
18
+ Alma::AlmaRecord.new(loan)
19
+ end
20
+ end
21
+
22
+ end
23
+ end