biola_web_services 0.1.0
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.
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
module BiolaWebServices
|
|
2
|
+
|
|
3
|
+
require 'rest_client'
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
mattr_accessor :url
|
|
7
|
+
self.url = 'https://ws.biola.edu'
|
|
8
|
+
|
|
9
|
+
mattr_accessor :auth_type
|
|
10
|
+
self.auth_type = :cert # :cert or :login
|
|
11
|
+
|
|
12
|
+
mattr_accessor :cert_path
|
|
13
|
+
self.cert_path = ''
|
|
14
|
+
|
|
15
|
+
mattr_accessor :key_path
|
|
16
|
+
self.key_path = ''
|
|
17
|
+
|
|
18
|
+
mattr_accessor :key_password
|
|
19
|
+
self.key_password = ''
|
|
20
|
+
|
|
21
|
+
mattr_accessor :username
|
|
22
|
+
self.username = ''
|
|
23
|
+
|
|
24
|
+
mattr_accessor :password
|
|
25
|
+
self.password = ''
|
|
26
|
+
|
|
27
|
+
mattr_accessor :verify_ssl
|
|
28
|
+
self.verify_ssl = true
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
mattr_accessor :cert
|
|
33
|
+
self.cert = nil
|
|
34
|
+
|
|
35
|
+
mattr_accessor :key
|
|
36
|
+
self.key = nil
|
|
37
|
+
|
|
38
|
+
def self.connect_with_cert(service_name)
|
|
39
|
+
|
|
40
|
+
if self.cert.nil?
|
|
41
|
+
self.cert = OpenSSL::X509::Certificate.new(File.read(self.cert_path))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
if self.key.nil?
|
|
45
|
+
self.key = OpenSSL::PKey::RSA.new(File.read(self.key_path), self.key_password)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
return RestClient::Resource.new(
|
|
49
|
+
"#{self.url}/#{service_name}/rest",
|
|
50
|
+
:ssl_client_cert => self.cert,
|
|
51
|
+
:ssl_client_key => self.key,
|
|
52
|
+
:verify_ssl => self.verify_ssl
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.connect_with_login(service_name)
|
|
58
|
+
return RestClient::Resource.new(
|
|
59
|
+
"#{self.url}/#{service_name}/rest",
|
|
60
|
+
:user=>self.username,
|
|
61
|
+
:password=>self.password
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
public
|
|
66
|
+
|
|
67
|
+
def self.connection(service_name)
|
|
68
|
+
if self.auth_type == :cert
|
|
69
|
+
return self.connect_with_cert(service_name)
|
|
70
|
+
else
|
|
71
|
+
return self.connect_with_login(service_name)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def self.method_missing(m)
|
|
76
|
+
BiolaWebServices::Service.new(m)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module BiolaWebServices
|
|
2
|
+
|
|
3
|
+
class Service
|
|
4
|
+
|
|
5
|
+
require 'json'
|
|
6
|
+
|
|
7
|
+
@service_name = nil
|
|
8
|
+
|
|
9
|
+
def initialize(service_name)
|
|
10
|
+
@service_name = service_name
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def call(method_name, args)
|
|
14
|
+
response = BiolaWebServices.connection(@service_name.to_s)[method_name.to_s].post(args)
|
|
15
|
+
begin
|
|
16
|
+
JSON.parse response
|
|
17
|
+
rescue
|
|
18
|
+
response
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def method_missing(m, *args)
|
|
23
|
+
|
|
24
|
+
method_name = m.to_s.camelcase.delete('?!')
|
|
25
|
+
modifier = m.to_s[-1, 1]
|
|
26
|
+
args = args[0] if args.length == 1
|
|
27
|
+
|
|
28
|
+
case modifier
|
|
29
|
+
when '?'
|
|
30
|
+
response = call(method_name, args)
|
|
31
|
+
%w(true t yes y 1).include?(response.to_s.downcase.strip)
|
|
32
|
+
when '!'
|
|
33
|
+
call(method_name, args)
|
|
34
|
+
else
|
|
35
|
+
begin
|
|
36
|
+
call(method_name, args)
|
|
37
|
+
rescue
|
|
38
|
+
nil
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: biola_web_services
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 27
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 1
|
|
9
|
+
- 0
|
|
10
|
+
version: 0.1.0
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Adam Crownoble
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2010-09-07 00:00:00 -07:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies: []
|
|
21
|
+
|
|
22
|
+
description: Simple Ruby wrapper for Biola Web Services REST calls
|
|
23
|
+
email: adam.crownoble@biola.edu
|
|
24
|
+
executables: []
|
|
25
|
+
|
|
26
|
+
extensions: []
|
|
27
|
+
|
|
28
|
+
extra_rdoc_files: []
|
|
29
|
+
|
|
30
|
+
files:
|
|
31
|
+
- lib/biola_web_services.rb
|
|
32
|
+
- lib/biola_web_services/biola_web_services.rb
|
|
33
|
+
- lib/biola_web_services/service.rb
|
|
34
|
+
has_rdoc: true
|
|
35
|
+
homepage: http://biola.edu/it
|
|
36
|
+
licenses: []
|
|
37
|
+
|
|
38
|
+
post_install_message:
|
|
39
|
+
rdoc_options: []
|
|
40
|
+
|
|
41
|
+
require_paths:
|
|
42
|
+
- lib
|
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
|
+
none: false
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
hash: 3
|
|
49
|
+
segments:
|
|
50
|
+
- 0
|
|
51
|
+
version: "0"
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
none: false
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
hash: 3
|
|
58
|
+
segments:
|
|
59
|
+
- 0
|
|
60
|
+
version: "0"
|
|
61
|
+
requirements: []
|
|
62
|
+
|
|
63
|
+
rubyforge_project:
|
|
64
|
+
rubygems_version: 1.3.7
|
|
65
|
+
signing_key:
|
|
66
|
+
specification_version: 3
|
|
67
|
+
summary: Biola Web Services helper methods
|
|
68
|
+
test_files: []
|
|
69
|
+
|