versionone_sdk 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +4 -0
- data/LICENSE +20 -0
- data/README.md +86 -0
- data/Rakefile +19 -0
- data/VERSION +1 -0
- data/lib/versionone_sdk/client.rb +67 -0
- data/lib/versionone_sdk/parser_xml_assets.rb +79 -0
- data/lib/versionone_sdk.rb +4 -0
- data/test/test_setup.rb +11 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b929a84fe8986422cdc95404986d18e2a0eec9e5
|
4
|
+
data.tar.gz: fa773d457e79500251f754a7a317e7c26bf03c9e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 762acd0b035a50e2e1b8b080c91d00ebcf2d6033e6d7c6bdc9198a3f37b7772adebcf2ea01d65a79efebd0e4ad9257ed56fc064796f9e5463c8e09beb677dbfc
|
7
|
+
data.tar.gz: e419b27a5ef24b59672482fd1197ddb15f9ab307ffac0dab98298a00f64ee4eed71ad8bf61e544ca6c40bdaeebb52f7d62c245f839af3cbebce34892786d7416
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 John Wang
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
VersionOne SDK - A Ruby SDK for the VersionOne REST API
|
2
|
+
=======================================================
|
3
|
+
|
4
|
+
Synopsis
|
5
|
+
--------
|
6
|
+
|
7
|
+
This is a VersionOne SDK for Ruby that accesses the VersionOne REST API.
|
8
|
+
|
9
|
+
VersionOne currently provides official SDKs for Java, .NET, Python and JavaScript, but not for Ruby and other languages. VersionOne describes the use case for SDKs as the following: "All access to VersionOne is provided by the API endpoints. The most common use is to manipulate data in VersionOne. Doing so with the rest-1.v1/Data endpoint requires manipulation of XML, which can be tedious. Therefore, there are a number of API wrappers that abstract the details of HTTP and VersionOne's XML serialization: SDK.Java, SDK.NET, SDK.Python, SDK.JavaScript."
|
10
|
+
|
11
|
+
A primary goal of this project is to convert VersionOne REST API XML responses to JSON.
|
12
|
+
|
13
|
+
Installing
|
14
|
+
----------
|
15
|
+
|
16
|
+
Download and install versionone_sdk with the following:
|
17
|
+
|
18
|
+
gem install versionone_sdk
|
19
|
+
|
20
|
+
#Examples
|
21
|
+
---------
|
22
|
+
|
23
|
+
require 'versionone_sdk'
|
24
|
+
|
25
|
+
dParams = {
|
26
|
+
:hostname => 'www1.v1host.com',
|
27
|
+
:instance => 'myinstance',
|
28
|
+
:username => 'myusername',
|
29
|
+
:password => 'mypassword',
|
30
|
+
:port => 443,
|
31
|
+
:protocol => 'https'
|
32
|
+
}
|
33
|
+
|
34
|
+
v1client = VersiononeSdk::Client.new(dParams)
|
35
|
+
|
36
|
+
# Retrieve an array of JsonDoc::Document objects
|
37
|
+
|
38
|
+
assets = oClient.getAssets('Scope')
|
39
|
+
|
40
|
+
assets.each do |asset|
|
41
|
+
assetHash = asset.asHash
|
42
|
+
end
|
43
|
+
|
44
|
+
#Documentation
|
45
|
+
--------------
|
46
|
+
|
47
|
+
This gem is 100% documented with YARD, an exceptional documentation library. To see documentation for this, and all the gems installed on your system use:
|
48
|
+
|
49
|
+
$ gem install yard
|
50
|
+
$ yard server -g
|
51
|
+
|
52
|
+
Notes
|
53
|
+
-----
|
54
|
+
|
55
|
+
1. Nil/Null Values and Empty Strings
|
56
|
+
|
57
|
+
The VersionOne JavaScript API provides empty strings when no value is present. This SDK uses Ruby nil values and JSON null values for empty strings. The primary reason for this is to support easy indexing using Elasticsearch.
|
58
|
+
|
59
|
+
2. Tracking Properties
|
60
|
+
|
61
|
+
In addition to the standard VersionOne properties, this modules adds the following generic properties for tracking: :__id__sObjectDomain, :__id__sObjectType, :__id__iObjectId, :__id__sObjectUrl. The object domain is set to 'Versionone', while object type and object id correspond to VersionOne Asset types and ids. The URL is the full URL for the resource including protocol, host and port.
|
62
|
+
|
63
|
+
#Change Log
|
64
|
+
-----------
|
65
|
+
|
66
|
+
- **2014-03-16**: 0.0.1
|
67
|
+
- Initial release
|
68
|
+
|
69
|
+
#Links
|
70
|
+
------
|
71
|
+
|
72
|
+
VersionOne API Documentation
|
73
|
+
|
74
|
+
http://community.versionone.com/Developers/Developer-Library/Documentation/API
|
75
|
+
|
76
|
+
#Copyright and License
|
77
|
+
----------------------
|
78
|
+
|
79
|
+
Elastirad © 2014 by [John Wang](mailto:johncwang@gmail.com).
|
80
|
+
|
81
|
+
Elastirad is licensed under the MIT license. Please see the LICENSE document for more information.
|
82
|
+
|
83
|
+
Warranty
|
84
|
+
--------
|
85
|
+
|
86
|
+
This software is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantibility and fitness for a particular purpose.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
desc 'Default: run unit tests.'
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
desc 'Test the library.'
|
8
|
+
Rake::TestTask.new do |t|
|
9
|
+
t.libs << 'lib'
|
10
|
+
t.pattern = 'test/**/test_*.rb'
|
11
|
+
t.verbose = false
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Generate YARD documentation.'
|
15
|
+
task :gendoc do
|
16
|
+
#puts 'yard doc generation disabled until JRuby build native extensions for redcarpet or yard removes the dependency.'
|
17
|
+
system "yardoc"
|
18
|
+
system "yard stats --list-undoc"
|
19
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'versionone_sdk/parser_xml_assets'
|
3
|
+
|
4
|
+
module VersiononeSdk
|
5
|
+
class Client
|
6
|
+
def initialize(dOptions={})
|
7
|
+
iPort = iPort.to_i if iPort.is_a?(String)
|
8
|
+
@sProtocol = dOptions.has_key?(:protocol) && dOptions[:protocol] \
|
9
|
+
? dOptions[:protocol] : 'https'
|
10
|
+
@sHostname = dOptions.has_key?(:hostname) && dOptions[:hostname] \
|
11
|
+
? dOptions[:hostname] : 'localhost'
|
12
|
+
@iPort = dOptions.has_key?(:port) && dOptions[:port] \
|
13
|
+
? dOptions[:port].to_i : 443
|
14
|
+
sUsername = dOptions.has_key?(:username) ? dOptions[:username] : ''
|
15
|
+
sPassword = dOptions.has_key?(:password) ? dOptions[:password] : ''
|
16
|
+
@sInstance = dOptions.has_key?(:instance) ? dOptions[:instance] : ''
|
17
|
+
@sUrl = buildUrl(@sProtocol,@sHostname,@iPort)
|
18
|
+
@oFaraday = Faraday::Connection.new url: @sUrl
|
19
|
+
@oFaraday.basic_auth(sUsername, sPassword)
|
20
|
+
end
|
21
|
+
|
22
|
+
def getAssets(sAssetType=nil,xIds=nil)
|
23
|
+
oRes = self.getAssetsXml(sAssetType,xIds)
|
24
|
+
oParser = VersiononeSdk::ParserXmlAssets.new({:url => @sUrl})
|
25
|
+
aDocs = oParser.getDocsForAssetsXml( oRes.body )
|
26
|
+
return aDocs
|
27
|
+
end
|
28
|
+
|
29
|
+
def getAssetsXml(sAssetType=nil,xIds=nil)
|
30
|
+
sUrl = self.getUrlForAssets(sAssetType)
|
31
|
+
oRes = @oFaraday.get sUrl
|
32
|
+
return oRes
|
33
|
+
end
|
34
|
+
|
35
|
+
def getUrlForAssets(sAssetType=nil)
|
36
|
+
aUrl = [ @sUrl, @sInstance, 'rest-1.v1/Data',sAssetType]
|
37
|
+
sUrl = aUrl.join('/')
|
38
|
+
return sUrl
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def buildUrl(sProtocol='http',sHostname='localhost',iPort=80)
|
44
|
+
if sHostname.nil?
|
45
|
+
sHostname = 'localhost'
|
46
|
+
elsif sHostname.is_a?(String)
|
47
|
+
sHostname.strip!
|
48
|
+
if sHostname.length < 1
|
49
|
+
sHostname = 'localhost'
|
50
|
+
end
|
51
|
+
else
|
52
|
+
raise ArgumentError, 'E_HOSTNAME_IS_NOT_A_STRING'
|
53
|
+
end
|
54
|
+
if iPort.nil?
|
55
|
+
iPort = 80
|
56
|
+
elsif iPort.is_a?(String) && iPort =~ /^[0-9]+$/
|
57
|
+
iPort = iPort.to_i
|
58
|
+
elsif ! iPort.kind_of?(Integer)
|
59
|
+
raise ArgumentError, 'E_PORT_IS_NOT_AN_INTEGER'
|
60
|
+
end
|
61
|
+
sBaseUrl = "#{sProtocol}://#{sHostname}"
|
62
|
+
sBaseUrl.sub!(/\/+\s*$/,'')
|
63
|
+
sBaseUrl += ':' + iPort.to_s if iPort != 80
|
64
|
+
return sBaseUrl
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'jsondoc'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module VersiononeSdk
|
5
|
+
class ParserXmlAssets
|
6
|
+
def initialize(dOptions={})
|
7
|
+
@sUrl = dOptions.has_key?(:url) ? dOptions[:url] : ''
|
8
|
+
end
|
9
|
+
def getDocsForAssetsXmlPath(sPath=nil)
|
10
|
+
if File.exists?(sPath)
|
11
|
+
return self.getDocsForAssetsXml(IO.read(sPath))
|
12
|
+
end
|
13
|
+
return []
|
14
|
+
end
|
15
|
+
def getDocsForAssetsXml(xAssets=nil)
|
16
|
+
oXml = Nokogiri::XML::Document.parse(xAssets)
|
17
|
+
oBlock = oXml.xpath("//Assets/Asset")
|
18
|
+
aDocs = []
|
19
|
+
oBlock.map do |oNodeAsset|
|
20
|
+
oJsondoc = self.getJsondocForXmlAssetNode( oNodeAsset )
|
21
|
+
unless oJsondoc.nil?
|
22
|
+
aDocs.push(oJsondoc)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
return aDocs
|
26
|
+
end
|
27
|
+
def getJsondocForXmlAssetNode(oNodeAsset=nil)
|
28
|
+
if oNodeAsset.nil?
|
29
|
+
raise RuntimeError, 'E_NIL_NODE'
|
30
|
+
end
|
31
|
+
oJsondoc = JsonDoc::Document.new
|
32
|
+
oJsondoc.bIsStrict = false
|
33
|
+
if oNodeAsset.attribute('id')
|
34
|
+
sId = oNodeAsset.attribute('id').value
|
35
|
+
if sId =~ /^(.+):([0-9]+)$/
|
36
|
+
sObjectType = $1
|
37
|
+
iObjectId = $2.to_i
|
38
|
+
oJsondoc.setProp(:__id__sObjectDomain,'Versionone')
|
39
|
+
oJsondoc.setProp(:__id__sObjectType,sObjectType)
|
40
|
+
oJsondoc.setProp(:__id__iObjectId, iObjectId)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
if oNodeAsset.attribute('href').value
|
44
|
+
sUrl = @sUrl \
|
45
|
+
? @sUrl + oNodeAsset.attribute('href').value
|
46
|
+
: oNodeAsset.attribute('href').value
|
47
|
+
oJsondoc.setProp(:__id__sObjectUrl,sUrl)
|
48
|
+
end
|
49
|
+
oNodeAsset.children.each do |oNodeChild|
|
50
|
+
if oNodeChild.name == 'Attribute'
|
51
|
+
if oNodeChild.attribute('name')
|
52
|
+
yPropKey = oNodeChild.attribute('name').to_s.to_sym
|
53
|
+
sPropVal = oNodeChild.text
|
54
|
+
sPropVal = nil if sPropVal == ''
|
55
|
+
oJsondoc.setProp(yPropKey,sPropVal)
|
56
|
+
end
|
57
|
+
elsif oNodeChild.name == 'Relation'
|
58
|
+
yPropKey = oNodeChild.attribute('name').to_s.to_sym
|
59
|
+
oNodeRelation = oNodeChild
|
60
|
+
oNodeRelation.children.each do |oNodeRelationChild|
|
61
|
+
if oNodeRelationChild.name == 'Asset'
|
62
|
+
if oNodeRelationChild.attribute('idref').value
|
63
|
+
oJsondoc.pushProp(yPropKey,oNodeRelationChild.attribute('idref').value)
|
64
|
+
end
|
65
|
+
else
|
66
|
+
raise RuntimeError, "E_UNKNOWN_RELATION_CHILD_NAME #{oNodeRelationChild.name}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
if oNodeRelation.children.count == 0
|
70
|
+
oJsondoc.setProp(yPropKey,[])
|
71
|
+
end
|
72
|
+
else
|
73
|
+
raise RuntimeError, "E_UNKNOWN_ASSET_NODE_NAME #{oNodeChild.name}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
return oJsondoc
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/test/test_setup.rb
ADDED
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: versionone_sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Wang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: jsondoc
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 0.0.4
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 0.0.4
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: nokogiri
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
description: A Ruby SDK for the VersionOne REST API
|
74
|
+
email: john@johnwang.com
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- CHANGELOG.md
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- VERSION
|
84
|
+
- lib/versionone_sdk.rb
|
85
|
+
- lib/versionone_sdk/client.rb
|
86
|
+
- lib/versionone_sdk/parser_xml_assets.rb
|
87
|
+
- test/test_setup.rb
|
88
|
+
homepage: http://johnwang.com/
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.2.1
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: VersionOne SDK - A Ruby SDK for the VersionOne REST API
|
112
|
+
test_files: []
|