versionone_sdk 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +59 -18
- data/VERSION +1 -1
- data/lib/versionone_sdk.rb +2 -1
- data/lib/versionone_sdk/client.rb +96 -13
- data/lib/versionone_sdk/parser_xml_assets.rb +20 -15
- data/lib/versionone_sdk/update.rb +144 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b73cb7be100cfcc1e7876932bc74f01fc46c159
|
4
|
+
data.tar.gz: 2cb79c808b19d41516e68a7eca08f3e3dd89f6f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cbe7275af7d76974ce395b95c0b3e129f4aeece5aadb3b4ba5711fec210fcd48918c6803427b9fb38a0c690714ec5371f32b0829eb129c27d728326d52e330c
|
7
|
+
data.tar.gz: dac4d6f0c7d1bfaf552556fa18c11fac7ff7999a1eb54a3cf75a51173a0578dbfe40d91c3987c3c41b3e1343f3f0924936bff35459ab6b31c7a7c168724c8c6b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
---------
|
3
|
+
|
4
|
+
- **2014-03-20**: 0.0.3
|
5
|
+
- Add ability to retrieve a single asset using an OID token or Number
|
6
|
+
- Add VersiononeSdk::Update to support updating Assets
|
3
7
|
- **2014-03-17**: 0.0.2
|
4
8
|
- Add VersiononeSdk::Asset object to support value inflation, starting with AssetState.Name
|
5
9
|
- **2014-03-16**: 0.0.1
|
data/README.md
CHANGED
@@ -4,11 +4,15 @@ VersionOne SDK - A Ruby SDK for the VersionOne REST API
|
|
4
4
|
Synopsis
|
5
5
|
--------
|
6
6
|
|
7
|
-
This is a VersionOne SDK
|
7
|
+
This is a VersionOne SDK in Ruby that accesses the VersionOne REST API.
|
8
8
|
|
9
|
-
VersionOne currently
|
9
|
+
VersionOne currently offers SDKs in Java, .NET, Python and JavaScript but not in Ruby or other languages. This SDK seeks to provide an easier way to use the REST API for Ruby applications.
|
10
10
|
|
11
|
-
|
11
|
+
It currently offers the following capabilities:
|
12
|
+
|
13
|
+
1. Ability to retrieve and parse all Assets of a certain type to JSON (via JsonDoc) seeking to match the JSON produced by the VersionOne JavaScript SDK.
|
14
|
+
2. Ability to query Assets transparently whether using Asset Token OIDs (e.g. "Story:1") or Asset Numbers (e.g. "B-1").
|
15
|
+
3. Ability to update Assets using Ruby without needing to manually create XML.
|
12
16
|
|
13
17
|
Installing
|
14
18
|
----------
|
@@ -22,7 +26,7 @@ Download and install versionone_sdk with the following:
|
|
22
26
|
|
23
27
|
require 'versionone_sdk'
|
24
28
|
|
25
|
-
|
29
|
+
params = {
|
26
30
|
:hostname => 'www1.v1host.com',
|
27
31
|
:instance => 'myinstance',
|
28
32
|
:username => 'myusername',
|
@@ -31,7 +35,7 @@ Download and install versionone_sdk with the following:
|
|
31
35
|
:protocol => 'https'
|
32
36
|
}
|
33
37
|
|
34
|
-
v1client = VersiononeSdk::Client.new(
|
38
|
+
v1client = VersiononeSdk::Client.new(params)
|
35
39
|
|
36
40
|
# Retrieve an array of VersiononeSdk::Asset objects
|
37
41
|
|
@@ -41,6 +45,43 @@ Download and install versionone_sdk with the following:
|
|
41
45
|
assetHash = asset.asHash
|
42
46
|
end
|
43
47
|
|
48
|
+
# Retrieve a single asset using an Asset OID Token
|
49
|
+
# Returns a VersiononeSdk::Asset object
|
50
|
+
|
51
|
+
asset = v1client.getAsset("Story:1")
|
52
|
+
asset = v1client.getAsset("Story",1)
|
53
|
+
|
54
|
+
# Retrieve a single asset using an Asset Number
|
55
|
+
|
56
|
+
asset = v1client.getAsset("B-1")
|
57
|
+
asset = v1client.getAsset("B",1)
|
58
|
+
|
59
|
+
# Updating an asset with a simple attribute
|
60
|
+
# Returns a Faraday::Response object
|
61
|
+
|
62
|
+
v1client.updateAsset("Member",20,"Phone","555-555-1212")
|
63
|
+
v1client.updateAsset("Member",20,"Phone",{:value=>"555-555-1212",:act=>"set"})
|
64
|
+
v1client.updateAsset("Member",20,"Phone",{:value=>"555-555-1212",:act=>"set"},\
|
65
|
+
:simple_attribute
|
66
|
+
)
|
67
|
+
|
68
|
+
# Updating an asset with a single-value relationship:
|
69
|
+
|
70
|
+
v1client.updateAsset("Scope",0,"Owner","Member:20")
|
71
|
+
v1client.updateAsset("Scope",0,"Owner",{:value=>"Member:20",:act=>"set"})
|
72
|
+
v1client.updateAsset("Scope",0,"Owner",{:value=>"Member:20",:act=>"set"},:single_relation)
|
73
|
+
|
74
|
+
# Updating an asset with a multi-value relationship: Adding members
|
75
|
+
|
76
|
+
v1client.updateAsset("Scope",0,"Members",["Member:1000","Member:1001"])
|
77
|
+
|
78
|
+
# Updating an asset with a multi-value relatinoship: Adding and removing members
|
79
|
+
|
80
|
+
v1client.updateAsset("Scope",0,"Members",[ \
|
81
|
+
{ :value => "Member:1000", :act => "add" }, \
|
82
|
+
{ :value => "Member:1001", :act => "remove " } \
|
83
|
+
],:multi_relation)
|
84
|
+
|
44
85
|
#Documentation
|
45
86
|
--------------
|
46
87
|
|
@@ -53,24 +94,20 @@ Notes
|
|
53
94
|
-----
|
54
95
|
|
55
96
|
1. Integer Values
|
56
|
-
|
57
|
-
Integer values for Order and AssetState are converted from strings to integers.
|
58
|
-
|
97
|
+
- Integer values for Order and AssetState are converted from strings to integers.
|
59
98
|
2. Nil/Null Values and Empty Strings
|
60
|
-
|
61
|
-
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.
|
62
|
-
|
99
|
+
- 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.
|
63
100
|
3. Inflation
|
64
|
-
|
65
|
-
Some values are inflated. Currently, AssetState is used to derive AssetState.Name as defined here: https://community.versionone.com/Developers/Developer-Library/Concepts/Asset_State
|
66
|
-
|
101
|
+
- Some values are inflated. Currently, AssetState is used to derive AssetState.Name as defined here: https://community.versionone.com/Developers/Developer-Library/Concepts/Asset_State
|
67
102
|
4. Tracking Properties
|
68
|
-
|
69
|
-
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.
|
103
|
+
- 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.
|
70
104
|
|
71
105
|
#Change Log
|
72
106
|
-----------
|
73
107
|
|
108
|
+
- **2014-03-20**: 0.0.3
|
109
|
+
- Add ability to retrieve a single asset using an OID token or Number
|
110
|
+
- Add VersiononeSdk::Update to support updating Assets
|
74
111
|
- **2014-03-17**: 0.0.2
|
75
112
|
- Add VersiononeSdk::Asset object to support value inflation, starting with AssetState.Name
|
76
113
|
- **2014-03-16**: 0.0.1
|
@@ -83,12 +120,16 @@ VersionOne API Documentation
|
|
83
120
|
|
84
121
|
http://community.versionone.com/Developers/Developer-Library/Documentation/API
|
85
122
|
|
123
|
+
VersionOne API Documentation for Updating an Asset
|
124
|
+
|
125
|
+
https://community.versionone.com/Developers/Developer-Library/Recipes/Update_an_Asset
|
126
|
+
|
86
127
|
#Copyright and License
|
87
128
|
----------------------
|
88
129
|
|
89
|
-
|
130
|
+
VersiononeSdk © 2014 by [John Wang](mailto:johncwang@gmail.com).
|
90
131
|
|
91
|
-
|
132
|
+
VersiononeSdk is licensed under the MIT license. Please see the LICENSE document for more information.
|
92
133
|
|
93
134
|
Warranty
|
94
135
|
--------
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/versionone_sdk.rb
CHANGED
@@ -1,22 +1,89 @@
|
|
1
1
|
require 'faraday'
|
2
|
+
require 'versionone_sdk/update'
|
2
3
|
require 'versionone_sdk/parser_xml_assets'
|
3
4
|
|
4
5
|
module VersiononeSdk
|
5
6
|
class Client
|
7
|
+
|
8
|
+
attr_accessor :oFaraday
|
9
|
+
attr_accessor :sInstance
|
10
|
+
|
6
11
|
def initialize(dOptions={})
|
7
|
-
iPort
|
8
|
-
@sProtocol
|
9
|
-
|
10
|
-
@sHostname
|
11
|
-
|
12
|
-
@iPort
|
13
|
-
|
14
|
-
sUsername
|
15
|
-
sPassword
|
16
|
-
@sInstance
|
17
|
-
@
|
18
|
-
@
|
12
|
+
iPort = iPort.to_i if iPort.is_a?(String)
|
13
|
+
@sProtocol = dOptions.has_key?(:protocol) && dOptions[:protocol] \
|
14
|
+
? dOptions[:protocol] : 'https'
|
15
|
+
@sHostname = dOptions.has_key?(:hostname) && dOptions[:hostname] \
|
16
|
+
? dOptions[:hostname] : 'localhost'
|
17
|
+
@iPort = dOptions.has_key?(:port) && dOptions[:port] \
|
18
|
+
? dOptions[:port].to_i : 443
|
19
|
+
sUsername = dOptions.has_key?(:username) ? dOptions[:username] : ''
|
20
|
+
sPassword = dOptions.has_key?(:password) ? dOptions[:password] : ''
|
21
|
+
@sInstance = dOptions.has_key?(:instance) ? dOptions[:instance] : ''
|
22
|
+
@dTypePrefix = { 'B' => 'Story', 'E' => 'Epic' }
|
23
|
+
@sUrl = buildUrl(@sProtocol,@sHostname,@iPort)
|
24
|
+
@oFaraday = Faraday::Connection.new url: @sUrl
|
19
25
|
@oFaraday.basic_auth(sUsername, sPassword)
|
26
|
+
@oUpdate = VersiononeSdk::Update.new(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
def getAsset(xAssetId1=nil,xAssetId2=nil)
|
30
|
+
if !xAssetId1.nil?
|
31
|
+
xAssetId1.strip!
|
32
|
+
|
33
|
+
if xAssetId1 =~ /^([^:]+):([0-9]+)$/
|
34
|
+
sAssetType = $1
|
35
|
+
sAssetOid = $2.to_i
|
36
|
+
return self.getAssetForTypeAndOid( sAssetType, sAssetOid )
|
37
|
+
|
38
|
+
elsif xAssetId1 =~ /^([a-zA-Z])-[0-9]+$/
|
39
|
+
sAssetTypeAbbr = $1.upcase
|
40
|
+
sAssetType = @dTypePrefix.has_key?( sAssetTypeAbbr ) \
|
41
|
+
? @dTypePrefix[ sAssetTypeAbbr ] : ''
|
42
|
+
xAssetId1.upcase!
|
43
|
+
return self.getAssetForTypeAndNumber( sAssetType, xAssetId1 )
|
44
|
+
|
45
|
+
elsif !xAssetId2.nil?
|
46
|
+
if xAssetId2.is_a?(String) && xAssetId2 =~ /^[0-9]+$/
|
47
|
+
xAssetId2 = xAssetId2.to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
if xAssetId2.is_a?(Integer)
|
51
|
+
|
52
|
+
if xAssetId1 =~ /^[a-zA-Z]$/
|
53
|
+
xAssetId1.upcase!
|
54
|
+
sAssetTypeAbbr = xAssetId1
|
55
|
+
sAssetType = @dTypePrefix.has_key?( sAssetTypeAbbr ) \
|
56
|
+
? @dTypePrefix[ sAssetTypeAbbr ] : ''
|
57
|
+
sAssetNumber = xAssetId1 + '-' + xAssetId2.to_s
|
58
|
+
sAssetNumber.upcase!
|
59
|
+
return self.getAssetForTypeAndNumber( sAssetType, sAssetNumber )
|
60
|
+
elsif xAssetId1 =~ /^[a-zA-Z].+$/
|
61
|
+
return self.getAssetForTypeAndOid( xAssetId1, xAssetId2 )
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
else
|
68
|
+
raise RuntimeError, 'E_NO_ASSET_ID'
|
69
|
+
end
|
70
|
+
raise RuntimeError, "E_UNKNOWN_ASSET_ID [#{xAssetId1}][#{xAssetId2.to_s}]"
|
71
|
+
end
|
72
|
+
|
73
|
+
def getAssetForTypeAndOid(sAssetType=nil,sAssetOid=nil)
|
74
|
+
sUrl = self.getUrlForAssets( sAssetType, sAssetOid )
|
75
|
+
puts(sUrl)
|
76
|
+
oRes = @oFaraday.get sUrl
|
77
|
+
oParser = VersiononeSdk::ParserXmlAssets.new({:url => @sUrl})
|
78
|
+
aDoc = oParser.getDocForAssetXml( oRes.body )
|
79
|
+
end
|
80
|
+
|
81
|
+
def getAssetForTypeAndNumber(sAssetType=nil,sAssetNumber=nil)
|
82
|
+
sUrl = self.getUrlForAssetTypeAndNumber( sAssetType, sAssetNumber )
|
83
|
+
oRes = @oFaraday.get sUrl
|
84
|
+
oParser = VersiononeSdk::ParserXmlAssets.new({:url => @sUrl})
|
85
|
+
aDocs = oParser.getDocsForAssetsXml( oRes.body )
|
86
|
+
return aDocs[0]
|
20
87
|
end
|
21
88
|
|
22
89
|
def getAssets(sAssetType=nil,xIds=nil)
|
@@ -32,12 +99,27 @@ module VersiononeSdk
|
|
32
99
|
return oRes
|
33
100
|
end
|
34
101
|
|
35
|
-
def
|
102
|
+
def getUrlForAssetTypeAndNumber(sAssetType=nil,sAssetNumber=nil)
|
103
|
+
aUrl = [ @sUrl, @sInstance, 'rest-1.v1/Data',sAssetType + %Q!?where=Number="#{sAssetNumber}"!]
|
104
|
+
sUrl = aUrl.join('/')
|
105
|
+
return sUrl
|
106
|
+
end
|
107
|
+
|
108
|
+
def getUrlForAssets(sAssetType=nil,sAssetOid=nil)
|
36
109
|
aUrl = [ @sUrl, @sInstance, 'rest-1.v1/Data',sAssetType]
|
110
|
+
if sAssetOid.is_a?(Integer)
|
111
|
+
aUrl.push( sAssetOid )
|
112
|
+
elsif sAssetOid.kind_of?(String) && sAssetOid =~ /^[0-9]+$/
|
113
|
+
aUrl.push( sAssetOid )
|
114
|
+
end
|
37
115
|
sUrl = aUrl.join('/')
|
38
116
|
return sUrl
|
39
117
|
end
|
40
118
|
|
119
|
+
def updateAsset(sAssetType=nil,sAssetOid=nil,sName=nil,xxValues=nil,yTagType=nil)
|
120
|
+
return @oUpdate.updateAsset(sAssetType,sAssetOid,sName,xxValues,yTagType)
|
121
|
+
end
|
122
|
+
|
41
123
|
private
|
42
124
|
|
43
125
|
def buildUrl(sProtocol='http',sHostname='localhost',iPort=80)
|
@@ -63,5 +145,6 @@ module VersiononeSdk
|
|
63
145
|
sBaseUrl += ':' + iPort.to_s if iPort != 80
|
64
146
|
return sBaseUrl
|
65
147
|
end
|
148
|
+
|
66
149
|
end
|
67
150
|
end
|
@@ -18,34 +18,39 @@ module VersiononeSdk
|
|
18
18
|
oBlock = oXml.xpath("//Assets/Asset")
|
19
19
|
aDocs = []
|
20
20
|
oBlock.map do |oNodeAsset|
|
21
|
-
|
22
|
-
unless
|
23
|
-
aDocs.push(
|
21
|
+
oAsset = self.getJsondocForXmlAssetNode( oNodeAsset )
|
22
|
+
unless oAsset.nil?
|
23
|
+
aDocs.push(oAsset)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
return aDocs
|
27
27
|
end
|
28
|
+
def getDocForAssetXml(xAsset=nil)
|
29
|
+
oXml = Nokogiri::XML::Document.parse(xAsset)
|
30
|
+
oAsset = self.getJsondocForXmlAssetNode( oXml.root )
|
31
|
+
return oAsset
|
32
|
+
end
|
28
33
|
def getJsondocForXmlAssetNode(oNodeAsset=nil)
|
29
34
|
if oNodeAsset.nil?
|
30
35
|
raise RuntimeError, 'E_NIL_NODE'
|
31
36
|
end
|
32
|
-
|
33
|
-
|
37
|
+
oAsset = VersiononeSdk::Asset.new
|
38
|
+
oAsset.bIsStrict = false
|
34
39
|
if oNodeAsset.attribute('id')
|
35
40
|
sId = oNodeAsset.attribute('id').value
|
36
41
|
if sId =~ /^(.+):([0-9]+)$/
|
37
42
|
sObjectType = $1
|
38
43
|
iObjectId = $2.to_i
|
39
|
-
|
40
|
-
|
41
|
-
|
44
|
+
oAsset.setProp(:__id__sObjectDomain,'Versionone')
|
45
|
+
oAsset.setProp(:__id__sObjectType,sObjectType)
|
46
|
+
oAsset.setProp(:__id__iObjectId, iObjectId)
|
42
47
|
end
|
43
48
|
end
|
44
49
|
if oNodeAsset.attribute('href').value
|
45
50
|
sUrl = @sUrl \
|
46
51
|
? @sUrl + oNodeAsset.attribute('href').value
|
47
52
|
: oNodeAsset.attribute('href').value
|
48
|
-
|
53
|
+
oAsset.setProp(:__id__sObjectUrl,sUrl)
|
49
54
|
end
|
50
55
|
oNodeAsset.children.each do |oNodeChild|
|
51
56
|
if oNodeChild.name == 'Attribute'
|
@@ -53,7 +58,7 @@ module VersiononeSdk
|
|
53
58
|
yPropKey = oNodeChild.attribute('name').to_s.to_sym
|
54
59
|
sPropVal = oNodeChild.text
|
55
60
|
sPropVal = nil if sPropVal == ''
|
56
|
-
|
61
|
+
oAsset.setProp(yPropKey,sPropVal)
|
57
62
|
end
|
58
63
|
elsif oNodeChild.name == 'Relation'
|
59
64
|
yPropKey = oNodeChild.attribute('name').to_s.to_sym
|
@@ -61,21 +66,21 @@ module VersiononeSdk
|
|
61
66
|
oNodeRelation.children.each do |oNodeRelationChild|
|
62
67
|
if oNodeRelationChild.name == 'Asset'
|
63
68
|
if oNodeRelationChild.attribute('idref').value
|
64
|
-
|
69
|
+
oAsset.pushProp(yPropKey,oNodeRelationChild.attribute('idref').value)
|
65
70
|
end
|
66
71
|
else
|
67
72
|
raise RuntimeError, "E_UNKNOWN_RELATION_CHILD_NAME #{oNodeRelationChild.name}"
|
68
73
|
end
|
69
74
|
end
|
70
75
|
if oNodeRelation.children.count == 0
|
71
|
-
|
76
|
+
oAsset.setProp(yPropKey,[])
|
72
77
|
end
|
73
78
|
else
|
74
79
|
raise RuntimeError, "E_UNKNOWN_ASSET_NODE_NAME #{oNodeChild.name}"
|
75
80
|
end
|
76
81
|
end
|
77
|
-
|
78
|
-
return
|
82
|
+
oAsset.inflate
|
83
|
+
return oAsset
|
79
84
|
end
|
80
85
|
end
|
81
|
-
end
|
86
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module VersiononeSdk
|
4
|
+
class Update
|
5
|
+
|
6
|
+
def initialize(oClient=nil)
|
7
|
+
@oClient = oClient
|
8
|
+
@sTagTypes = {:simple_attribute=>1,:single_relationship=>1,:multi_relationship=>1}
|
9
|
+
@sRelationships = 'BuildProjects,Owner,Parent,Schedule,Scheme,SecurityScope,Status,TestSuite'
|
10
|
+
@dRelationships = Hash[@sRelationships.split(',').collect {|v| [v,1]}]
|
11
|
+
end
|
12
|
+
|
13
|
+
# Update a VersionOne asset.
|
14
|
+
#
|
15
|
+
# Params:
|
16
|
+
# +sAssetType+:: A REST API asset type such as Scope, Epic, Story, Member, etc. The first part of the OID Token.
|
17
|
+
# +sAssetOid+:: The numerical OID and the second part of the OID token.
|
18
|
+
# +sName+:: Name of attribute to be updated.
|
19
|
+
# +xxValues+:: values to be updated which can be a variety of formats.
|
20
|
+
# +yTagType+:: A optional symbol to identify the type of attribute, e.g.
|
21
|
+
# :simple_attribute, :single_relationship, or :multi_relationship
|
22
|
+
|
23
|
+
def updateAsset(sAssetType=nil,sAssetOid=nil,sName=nil,xxValues=nil,yTagType=nil)
|
24
|
+
|
25
|
+
aValues = normalizeValues(xxValues)
|
26
|
+
# Validate Tag Type
|
27
|
+
yTagType = yTagType.to_sym if yTagType.is_a?(String)
|
28
|
+
|
29
|
+
unless yTagType.nil?
|
30
|
+
unless @dTagTypes.has_key?(yTagType)
|
31
|
+
raise ArgumentError, "E_BAD_TAG_TYPE: [#{yTagType.to_s}]"
|
32
|
+
end
|
33
|
+
else
|
34
|
+
if sName.nil? || ! sName.kind_of?(String)
|
35
|
+
raise ArgumentError, 'E_NO_ATTRIBUTE_NAME'
|
36
|
+
elsif @dRelationships.has_key?(sName)
|
37
|
+
aValues.each do |dValue|
|
38
|
+
sAct = dValue[:act]
|
39
|
+
if sAct == 'set'
|
40
|
+
yTagType = :single_relationship
|
41
|
+
elsif sAct == 'add' || sAct == 'remove'
|
42
|
+
yTagType = :multi_relationship
|
43
|
+
else
|
44
|
+
raise ArgumentError, "E_BAD_ACT: [#{sAct}]"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
else
|
48
|
+
yTagType = :simple_attribute
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
xBody \
|
53
|
+
= yTagType == :simple_attribute \
|
54
|
+
? getXmlBodyForSimpleAttributeUpdate(sName,aValues) \
|
55
|
+
: yTagType == :single_relationship \
|
56
|
+
? getXmlBodyForSingleRelationship(aValues) \
|
57
|
+
: yTagType == :multi_relationship \
|
58
|
+
? getXmlBodyForMultiRelationship(aValues) \
|
59
|
+
: nil
|
60
|
+
|
61
|
+
unless xBody.nil?
|
62
|
+
oFdRes = @oClient.oFaraday.post do |req|
|
63
|
+
req.url getUrlForAssetTypeAndOid(sAssetType,sAssetOid)
|
64
|
+
req.headers['Content-Type'] = 'application/xml'
|
65
|
+
req.body = xBody
|
66
|
+
end
|
67
|
+
return oFdRes
|
68
|
+
end
|
69
|
+
|
70
|
+
return nil
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def normalizeValues(xxValues=nil)
|
77
|
+
aValues = []
|
78
|
+
|
79
|
+
if xxValues.is_a?(String)
|
80
|
+
aValues = [{:value => xxValues,:act=>'set'}]
|
81
|
+
elsif xxValues.is_a?(Hash)
|
82
|
+
aValues = [xxValues]
|
83
|
+
elsif xxValues.is_a?(Array)
|
84
|
+
xxValues.each do |xxSubValue|
|
85
|
+
if xxSubValue.is_a?(String)
|
86
|
+
sAct = xxValues.length > 1 ? 'add' : 'set'
|
87
|
+
aValues.push({:value=>xxSubValue,:act=>sAct})
|
88
|
+
elsif xxSubValue.is_a?(Hash)
|
89
|
+
aValues.push(xxSubValue)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
return aValues
|
95
|
+
end
|
96
|
+
|
97
|
+
def getUrlForAssetTypeAndOid(sAssetType=nil,sAssetOid=nil)
|
98
|
+
sUrl = File.join('/'+@oClient.sInstance,'rest-1.oauth.v1/Data',sAssetType,sAssetOid.to_s)
|
99
|
+
return sUrl
|
100
|
+
end
|
101
|
+
|
102
|
+
def getXmlBodyForSimpleAttributeUpdate(sName=nil,aValues=[])
|
103
|
+
sValue = aValues.length>0 && aValues[0].has_key?(:value) \
|
104
|
+
? aValues[0][:value] : nil
|
105
|
+
oBuilder = Nokogiri::XML::Builder.new do |xml|
|
106
|
+
xml.Asset {
|
107
|
+
xml.Attribute(sValue, :name => sName, :act => 'set')
|
108
|
+
}
|
109
|
+
end
|
110
|
+
return oBuilder.to_xml
|
111
|
+
end
|
112
|
+
|
113
|
+
def getXmlBodyForSingleRelationship(sName=nil,aValues=[])
|
114
|
+
sValue = aValues.length>0 && aValues[0].has_key?(:value) \
|
115
|
+
? aValues[0][:value] : nil
|
116
|
+
oBuilder = sValue.nil? \
|
117
|
+
? Nokogiri::XML::Builder.new { |xml| xml.Asset { \
|
118
|
+
xml.Relation(:name=>sName,:act=>'set')
|
119
|
+
} }
|
120
|
+
: Nokogiri::XML::Builder.new { |xml| xml.Asset { \
|
121
|
+
xml.Relation(:name=>sName,:act=>'set') {
|
122
|
+
xml.Asset(:idref=>sValue)
|
123
|
+
}
|
124
|
+
} }
|
125
|
+
return oBuilder.to_xml
|
126
|
+
end
|
127
|
+
|
128
|
+
def getgetXmlBodyForMultiRelationship(sName=nil, aValues=[])
|
129
|
+
oBuilder = aValues.length == 0 \
|
130
|
+
? Nokogiri::XML::Builder.new { |xml| xml.Asset { \
|
131
|
+
xml.Relation(:name=>sName,:act=>'set')
|
132
|
+
} }
|
133
|
+
: Nokogiri::XML::Builder.new { |xml| xml.Asset { \
|
134
|
+
xml.Relation(:name=>sName) {
|
135
|
+
aValues.each do |dValue|
|
136
|
+
xml.Asset(:idref=>dValue[:value],:act=>dValue[:act])
|
137
|
+
end
|
138
|
+
}
|
139
|
+
} }
|
140
|
+
return oBuilder.to_xml
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: versionone_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Wang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/versionone_sdk/asset.rb
|
86
86
|
- lib/versionone_sdk/client.rb
|
87
87
|
- lib/versionone_sdk/parser_xml_assets.rb
|
88
|
+
- lib/versionone_sdk/update.rb
|
88
89
|
- test/test_setup.rb
|
89
90
|
homepage: http://johnwang.com/
|
90
91
|
licenses:
|