opencrx 0.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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/opencrx.rb +141 -0
- data/lib/opencrx/version.rb +3 -0
- data/opencrx.gemspec +30 -0
- data/spec/opencrx_spec.rb +45 -0
- metadata +184 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Mike Park
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Opencrx
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'opencrx'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install opencrx
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/opencrx.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
require "opencrx/version"
|
2
|
+
require 'httparty'
|
3
|
+
require 'active_support/inflector'
|
4
|
+
require 'active_support/core_ext'
|
5
|
+
|
6
|
+
module Opencrx
|
7
|
+
|
8
|
+
@@session = nil
|
9
|
+
|
10
|
+
def self.connect(base_url, user, password)
|
11
|
+
self.session = Opencrx::Session.new(base_url, user, password)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.session
|
15
|
+
@@session
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.session=(object)
|
19
|
+
@@session = object
|
20
|
+
end
|
21
|
+
|
22
|
+
class Session
|
23
|
+
include HTTParty
|
24
|
+
|
25
|
+
#debug_output
|
26
|
+
headers 'Accept' => 'text/xml', 'Content-Type' => 'text/xml'
|
27
|
+
format :xml
|
28
|
+
|
29
|
+
def initialize(base_url, user, password)
|
30
|
+
self.class.base_uri(base_url)
|
31
|
+
self.class.basic_auth(user, password)
|
32
|
+
end
|
33
|
+
|
34
|
+
def get(url, options = {})
|
35
|
+
self.class.get(url, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def put(url, options = {})
|
39
|
+
self.class.put(url, options)
|
40
|
+
end
|
41
|
+
|
42
|
+
def post(url, options = {})
|
43
|
+
self.class.post(url, options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module Account
|
48
|
+
SUFFIX = "/opencrx-rest-CRX/org.opencrx.kernel.account1/provider/CRX/segment/Standard/account"
|
49
|
+
KEY = Regexp.new('^org.opencrx.kernel.account1.(.*)$')
|
50
|
+
RESULTSET = 'org.openmdx.kernel.ResultSet'
|
51
|
+
|
52
|
+
def self.get(id)
|
53
|
+
response = session.get(SUFFIX + "/#{id}")
|
54
|
+
#ap Nokogiri.XML(response.body)
|
55
|
+
build_record(response)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.query(params = {})
|
59
|
+
response = session.get(SUFFIX, query: params)
|
60
|
+
key = response.keys.first
|
61
|
+
if key == RESULTSET
|
62
|
+
parse_resultset(response[key])
|
63
|
+
else
|
64
|
+
failure(response)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.post(xml)
|
69
|
+
build_record session.post(SUFFIX, body: xml)
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.put(url, xml)
|
73
|
+
build_record session.put(url, body: xml)
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.session
|
77
|
+
Opencrx::session
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.parse_resultset(hash)
|
81
|
+
hash.map do |key, value|
|
82
|
+
next if %w(href hasMore).include? key
|
83
|
+
build_record(key => value)
|
84
|
+
end.compact
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.build_record(hash)
|
88
|
+
puts "Expected a single key, got [#{hash.keys}]" unless hash.keys.length == 1
|
89
|
+
key = hash.keys.first
|
90
|
+
key.match(KEY)
|
91
|
+
klass_name = $1
|
92
|
+
if (klass = ActiveSupport::Inflector.safe_constantize("Opencrx::Account::#{klass_name}"))
|
93
|
+
klass.new(hash)
|
94
|
+
else
|
95
|
+
puts "Dont understand record type [#{klass_name}]"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.failure(response)
|
100
|
+
ap response.request
|
101
|
+
ap response.response
|
102
|
+
ap response.parsed_response
|
103
|
+
nil
|
104
|
+
end
|
105
|
+
|
106
|
+
class AccountRecord < SimpleDelegator
|
107
|
+
BASEKEY = "org.opencrx.kernel.account1"
|
108
|
+
|
109
|
+
def initialize(attributes)
|
110
|
+
attributes = attributes[key] if attributes.has_key? key
|
111
|
+
super attributes
|
112
|
+
end
|
113
|
+
|
114
|
+
def key
|
115
|
+
"#{BASEKEY}.#{ActiveSupport::Inflector.demodulize self.class}"
|
116
|
+
end
|
117
|
+
|
118
|
+
def save
|
119
|
+
if has_key?('href')
|
120
|
+
Opencrx::Account.put(fetch('href'), xml)
|
121
|
+
else
|
122
|
+
Opencrx::Account.post(xml)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def xml
|
127
|
+
__getobj__.except('owner', 'owningUser', 'owningGroup', 'href', 'version').to_xml(root: key)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
class Contact < AccountRecord
|
132
|
+
end
|
133
|
+
class Group < AccountRecord
|
134
|
+
end
|
135
|
+
class UnspecifiedAccount < AccountRecord
|
136
|
+
end
|
137
|
+
class LegalEntity < AccountRecord
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
data/opencrx.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'opencrx/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "opencrx"
|
8
|
+
spec.version = Opencrx::VERSION
|
9
|
+
spec.authors = ["Mike Park"]
|
10
|
+
spec.email = ["mikep@quake.net"]
|
11
|
+
spec.description = %q{Rest-API to opencrx}
|
12
|
+
spec.summary = %q{Rest API to opencrx}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "httparty"
|
22
|
+
spec.add_dependency "nokogiri"
|
23
|
+
spec.add_dependency "builder"
|
24
|
+
spec.add_dependency "activesupport"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "rspec", "~> 2.6"
|
29
|
+
spec.add_development_dependency "awesome_print"
|
30
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'opencrx'
|
3
|
+
require 'awesome_print'
|
4
|
+
|
5
|
+
describe Opencrx do
|
6
|
+
before do
|
7
|
+
Opencrx::connect("http://demo.opencrx.org", "guest", "guest")
|
8
|
+
end
|
9
|
+
|
10
|
+
context "Clients" do
|
11
|
+
it "should create" do
|
12
|
+
lastName = Time.now.to_s
|
13
|
+
contact = Opencrx::Account::Contact.new(lastName: lastName).save
|
14
|
+
expect(contact.class).to eq(Opencrx::Account::Contact)
|
15
|
+
expect(contact['lastName']).to eq(lastName)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should query" do
|
19
|
+
contacts = Opencrx::Account.query(size: 43)
|
20
|
+
#ap contacts
|
21
|
+
ap contacts.map(&:key)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should get" do
|
25
|
+
contact = Opencrx::Account.get('bf8036d9-d487-11e2-95d2-dd9cebe030de')
|
26
|
+
#ap contact
|
27
|
+
expect(contact['lastName']).to eq('ruby code')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should get and convert back to xml and save" do
|
31
|
+
contact = Opencrx::Account.get('bf8036d9-d487-11e2-95d2-dd9cebe030de')
|
32
|
+
contact['firstName'] = Time.now.to_s
|
33
|
+
#ap contact
|
34
|
+
#puts contact.xml
|
35
|
+
# really expect the date to show up
|
36
|
+
expect(contact.dup.save).to eq(contact)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should fail the get" do
|
40
|
+
contact = Opencrx::Contact.get('bf8036d9-d487-11e2-95d2-dd9cebe030deXX')
|
41
|
+
expect(contact).to_not be
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opencrx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mike Park
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: builder
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: activesupport
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.3'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.3'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rake
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rspec
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.6'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '2.6'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: awesome_print
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
description: Rest-API to opencrx
|
143
|
+
email:
|
144
|
+
- mikep@quake.net
|
145
|
+
executables: []
|
146
|
+
extensions: []
|
147
|
+
extra_rdoc_files: []
|
148
|
+
files:
|
149
|
+
- .gitignore
|
150
|
+
- Gemfile
|
151
|
+
- LICENSE.txt
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- lib/opencrx.rb
|
155
|
+
- lib/opencrx/version.rb
|
156
|
+
- opencrx.gemspec
|
157
|
+
- spec/opencrx_spec.rb
|
158
|
+
homepage: ''
|
159
|
+
licenses:
|
160
|
+
- MIT
|
161
|
+
post_install_message:
|
162
|
+
rdoc_options: []
|
163
|
+
require_paths:
|
164
|
+
- lib
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
none: false
|
167
|
+
requirements:
|
168
|
+
- - ! '>='
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
|
+
none: false
|
173
|
+
requirements:
|
174
|
+
- - ! '>='
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
requirements: []
|
178
|
+
rubyforge_project:
|
179
|
+
rubygems_version: 1.8.25
|
180
|
+
signing_key:
|
181
|
+
specification_version: 3
|
182
|
+
summary: Rest API to opencrx
|
183
|
+
test_files:
|
184
|
+
- spec/opencrx_spec.rb
|