aleph_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b66c529a807fedc74fc2906f3f2d9cb43c1fabca
4
+ data.tar.gz: 19b7f15ef2d1ea93c10bd3a8e665deabd4631d92
5
+ SHA512:
6
+ metadata.gz: c533420154c0cd1bc6352c9e2c17a61b0a016095610b7aa2bebc0561d9449445b8c3fff4697bc302be396733c14c60478d375e57c80f3b45c2af4bc5962513b0
7
+ data.tar.gz: cbf4b67132b92fcfcf5339ce61a20b6ff28667afb4b651a7c8cce160ec09baa020f58659751393706241143f759fca6612c81e53f2319c616a1ff619265f411e
data/.gitignore ADDED
@@ -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,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0"
4
+ - "2.1"
5
+ - "2.2"
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in your gemspec
4
+ gemspec
5
+
6
+ if !ENV["CI"]
7
+ group :development do
8
+ gem "hashdiff"
9
+ #gem "patron", github: "toland/patron", branch: :master
10
+ gem "pry", "~> 0.9.12.6"
11
+ gem "pry-byebug", "<= 1.3.2"
12
+ gem "pry-rescue", "~> 1.4.2"
13
+ gem "pry-stack_explorer", "~> 0.4.9.1"
14
+ gem "pry-syntax-hacks", "~> 0.0.6"
15
+ end
16
+ end
17
+
18
+ group :test do
19
+ gem "codeclimate-test-reporter", require: nil
20
+ end
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # AlephApi
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/aleph_api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'aleph_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install aleph_api
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/aleph_api/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ task :benchmark do
9
+ require_relative "./benchmark/joffrey/mab_document"
10
+ require_relative "./benchmark/joffrey/mab_xml_parser"
11
+
12
+ #Benchmark::Joffrey::MabDocument.new.call
13
+ Benchmark::Joffrey::MabXmlParser.new.call
14
+ end
data/aleph_api.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aleph_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "aleph_api"
8
+ spec.version = AlephApi::VERSION
9
+ spec.authors = ["Michael Sievers"]
10
+ spec.summary = %q{A ruby wrapper for the aleph rest and xservices apis}
11
+ spec.homepage = "http://github.com/ubpb/aleph_api"
12
+
13
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ spec.bindir = "exe"
15
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_dependency "activesupport"
19
+ spec.add_dependency "faraday"
20
+
21
+ spec.add_development_dependency "bundler", ">= 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", ">= 3.0.0", "< 4.0.0"
24
+ spec.add_development_dependency "simplecov", ">= 0.8.0"
25
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "aleph_api"
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
+ begin
10
+ require "pry"
11
+ Pry.start
12
+ rescue
13
+ require "irb"
14
+ IRB.start
15
+ end
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ require "faraday/middleware"
2
+ require_relative "../../../aleph_api"
3
+
4
+ module AlephApi::Faraday
5
+ module Response
6
+ class EnforceUtf8EncodedBody < Faraday::Middleware
7
+ def call(request_env)
8
+ @app.call(request_env).on_complete do |_response_env|
9
+ _response_env.body.force_encoding("utf-8")
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ require_relative "../circulation_actions"
2
+
3
+ class AlephApi::RestfulApiClient::Patron::CirculationActions::Cash
4
+ def initialize(client, patron_id, cash_id = nil)
5
+ @client = client
6
+ @cash_id = cash_id
7
+ @patron_id = patron_id
8
+ end
9
+
10
+ def get(options = {})
11
+ if @cash_id
12
+ @client.http(:get, "/patron/#{@patron_id}/circulationActions/cash/#{@cash_id}", options).try do |_response|
13
+ _response.body
14
+ end
15
+ else
16
+ @client.http(:get, "/patron/#{@patron_id}/circulationActions/cash", options).try do |_response|
17
+ _response.body
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative "../circulation_actions"
2
+
3
+ class AlephApi::RestfulApiClient::Patron::CirculationActions::Loans
4
+ def initialize(client, patron_id, loan_id = nil)
5
+ @client = client
6
+ @loan_id = loan_id
7
+ @patron_id = patron_id
8
+ end
9
+
10
+ def get(options = {})
11
+ if @loan_id
12
+ @client.http(:get, "/patron/#{@patron_id}/circulationActions/loans/#{@loan_id}", options).try do |_response|
13
+ _response.body
14
+ end
15
+ else
16
+ @client.http(:get, "/patron/#{@patron_id}/circulationActions/loans", options).try do |_response|
17
+ _response.body
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ require_relative "../requests"
2
+
3
+ class AlephApi::RestfulApiClient::Patron::CirculationActions::Requests::Holds
4
+ def initialize(client, patron_id, hold_id = nil)
5
+ @client = client
6
+ @hold_id = hold_id
7
+ @patron_id = patron_id
8
+ end
9
+
10
+ def get(options = {})
11
+ if @hold_id
12
+ @client.http(:get, "/patron/#{@patron_id}/circulationActions/requests/holds/#{@hold_id}", options).try do |_response|
13
+ _response.body
14
+ end
15
+ else
16
+ @client.http(:get, "/patron/#{@patron_id}/circulationActions/requests/holds", options).try do |_response|
17
+ _response.body
18
+ end
19
+ end
20
+ end
21
+
22
+ def delete(options = {})
23
+ if @hold_id
24
+ @client.http(:delete, "/patron/#{@patron_id}/circulationActions/requests/holds/#{@hold_id}", options).try do |_response|
25
+ _response.body
26
+ end
27
+ else
28
+ raise ArgumentError, "No hold id given!"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ require_relative "../circulation_actions"
2
+
3
+ class AlephApi::RestfulApiClient::Patron::CirculationActions::Requests
4
+ require_relative "./requests/holds"
5
+
6
+ def initialize(client, patron_id)
7
+ @client = client
8
+ @patron_id = patron_id
9
+ end
10
+
11
+ def get(options = {})
12
+ @client.http(:get, "/patron/#{@patron_id}/circulationActions/requests", options).try do |_response|
13
+ _response.body
14
+ end
15
+ end
16
+
17
+ def holds(hold_id = nil)
18
+ Holds.new(@client, @patron_id, hold_id)
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ require_relative "../patron"
2
+
3
+ class AlephApi::RestfulApiClient::Patron::CirculationActions
4
+ require_relative "./circulation_actions/cash"
5
+ require_relative "./circulation_actions/loans"
6
+ require_relative "./circulation_actions/requests"
7
+
8
+ def initialize(client, patron_id)
9
+ @client = client
10
+ @patron_id = patron_id
11
+ end
12
+
13
+ def get(options = {})
14
+ @client.http(:get, "/patron/#{@patron_id}/circulationActions", options).try do |_response|
15
+ _response.body
16
+ end
17
+ end
18
+
19
+ def cash(cash_id = nil)
20
+ Cash.new(@client, @patron_id, cash_id)
21
+ end
22
+
23
+ def loans(loan_id = nil)
24
+ Loans.new(@client, @patron_id, loan_id)
25
+ end
26
+
27
+ def requests
28
+ Requests.new(@client, @patron_id)
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ require_relative "../restful_api_client"
2
+
3
+ class AlephApi::RestfulApiClient::Patron
4
+ require_relative "./patron/circulation_actions"
5
+
6
+ def initialize(client, patron_id)
7
+ @client = client
8
+ @patron_id = patron_id
9
+ end
10
+
11
+ def get(options = {})
12
+ @client.http(:get, "/patron/#{@patron_id}", options).try do |_response|
13
+ _response.body
14
+ end
15
+ end
16
+
17
+ def circulationActions
18
+ CirculationActions.new(@client, @patron_id)
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ require_relative "../record"
2
+
3
+ class AlephApi::RestfulApiClient::Record::Items
4
+ def initialize(client, record_id, item_id = nil)
5
+ @client = client
6
+ @item_id = item_id
7
+ @record_id = record_id
8
+ end
9
+
10
+ def get(options = {})
11
+ if @item_id
12
+ @client.http(:get, "/record/#{@record_id}/items/#{@item_id}", options).try do |_response|
13
+ _response.body
14
+ end
15
+ else
16
+ @client.http(:get, "/record/#{@record_id}/items", options).try do |_response|
17
+ _response.body
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ require_relative "../restful_api_client"
2
+
3
+ class AlephApi::RestfulApiClient::Record
4
+ require_relative "./record/items"
5
+
6
+ def initialize(client, record_id)
7
+ @client = client
8
+ @record_id = record_id
9
+ end
10
+
11
+ def get(options = {})
12
+ @client.http(:get, "/record/#{@record_id}", options).try do |_response|
13
+ _response.body
14
+ end
15
+ end
16
+
17
+ def items(item_id = nil)
18
+ Items.new(@client, @record_id, item_id)
19
+ end
20
+ end
@@ -0,0 +1,56 @@
1
+ require "faraday"
2
+ require_relative "./faraday/response/enforce_utf8_encoded_body"
3
+ require_relative "../aleph_api"
4
+
5
+ # if patron curl based http client is available, require it
6
+ begin require "patron"; rescue LoadError; end
7
+
8
+ class AlephApi::RestfulApiClient
9
+ require_relative "./restful_api_client/patron"
10
+ require_relative "./restful_api_client/record"
11
+
12
+ RESTFUL_API_DEFAULT_PORT = 1891
13
+ RESTFUL_API_DEFAULT_ROOT_PATH="/rest-dlf"
14
+ RESTFUL_API_DEFAULT_SCHEME = "http"
15
+
16
+ # don's use a constant here, because faraday treats them diffrently
17
+ @@faraday_adapter = defined?(::Patron) ? :patron : ::Faraday.default_adapter
18
+
19
+ attr_accessor :host
20
+ attr_accessor :url
21
+
22
+ def url
23
+ @url || "#{RESTFUL_API_DEFAULT_SCHEME}://#{@host}:#{RESTFUL_API_DEFAULT_PORT}#{RESTFUL_API_DEFAULT_ROOT_PATH}"
24
+ end
25
+
26
+ def initialize(options = {})
27
+ options.symbolize_keys.try do |_sanitized_options|
28
+ @host = (_sanitized_options[:host] || ENV["ALEPH_RESTFUL_API_HOST"] || ENV["ALEPH_API_HOST"]).try(:strip)
29
+ @url = (_sanitized_options[:url] || ENV["ALEPH_RESTFUL_API_URL"]).try(:strip)
30
+ end
31
+ end
32
+
33
+ def patron(patron_id)
34
+ Patron.new(self, patron_id)
35
+ end
36
+
37
+ def record(record_id)
38
+ Record.new(self, record_id)
39
+ end
40
+
41
+ # inter-client api
42
+ def http(method, path, options = {})
43
+ # http://www.intridea.com/blog/2012/3/12/faraday-one-http-client-to-rule-them-all
44
+ connection = ::Faraday.new do |_builder|
45
+ _builder.request :url_encoded
46
+ _builder.use AlephApi::Faraday::Response::EnforceUtf8EncodedBody
47
+ _builder.adapter @@faraday_adapter
48
+ end
49
+
50
+ connection.send(method, "#{self.url}#{path}", options) do |_request|
51
+ # some http libraries (e.g. patron) have tight connection timeouts which
52
+ # may lead to (unnecessary) errors when used with aleph, so we raise 'em
53
+ _request.options.open_timeout = 20 # seconds
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ module AlephApi
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ require "faraday"
2
+ require_relative "../aleph_api"
3
+
4
+ class AlephApi::XServicesClient
5
+ attr_accessor :host
6
+ attr_accessor :url
7
+
8
+ def url
9
+ @url || (@host ? "#{@host}/X" : nil)
10
+ end
11
+
12
+ def initialize(options = {})
13
+ options.symbolize_keys.try do |_sanitized_options|
14
+ @host = (_sanitized_options[:host] || ENV["ALEPH_X_XSERVICES_HOST"] || ENV["ALEPH_API_HOST"]).try(:strip)
15
+ @url = (_sanitized_options[:url] || ENV["ALEPH_X_SERVICES_URL"]).try(:strip)
16
+ end
17
+ end
18
+
19
+ def get(params = {})
20
+ Faraday.get(self.url, params).body
21
+ end
22
+
23
+ def post(params = {})
24
+ Faraday.post(self.url, params).body
25
+ end
26
+ end
data/lib/aleph_api.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "active_support"
2
+ require "active_support/core_ext"
3
+ require "aleph_api/version"
4
+
5
+ module AlephApi
6
+ require_relative "./aleph_api/restful_api_client"
7
+ require_relative "./aleph_api/x_services_client"
8
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aleph_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Sievers
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: 4.0.0
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 3.0.0
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: 4.0.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: simplecov
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 0.8.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 0.8.0
103
+ description:
104
+ email:
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - ".gitignore"
110
+ - ".rspec"
111
+ - ".travis.yml"
112
+ - Gemfile
113
+ - README.md
114
+ - Rakefile
115
+ - aleph_api.gemspec
116
+ - bin/console
117
+ - bin/setup
118
+ - lib/aleph_api.rb
119
+ - lib/aleph_api/faraday/response/enforce_utf8_encoded_body.rb
120
+ - lib/aleph_api/restful_api_client.rb
121
+ - lib/aleph_api/restful_api_client/patron.rb
122
+ - lib/aleph_api/restful_api_client/patron/circulation_actions.rb
123
+ - lib/aleph_api/restful_api_client/patron/circulation_actions/cash.rb
124
+ - lib/aleph_api/restful_api_client/patron/circulation_actions/loans.rb
125
+ - lib/aleph_api/restful_api_client/patron/circulation_actions/requests.rb
126
+ - lib/aleph_api/restful_api_client/patron/circulation_actions/requests/holds.rb
127
+ - lib/aleph_api/restful_api_client/record.rb
128
+ - lib/aleph_api/restful_api_client/record/items.rb
129
+ - lib/aleph_api/version.rb
130
+ - lib/aleph_api/x_services_client.rb
131
+ homepage: http://github.com/ubpb/aleph_api
132
+ licenses: []
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.4.8
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: A ruby wrapper for the aleph rest and xservices apis
154
+ test_files: []