Class: VersiononeSdk::Update

Inherits:
Object
  • Object
show all
Defined in:
lib/versionone_sdk/update.rb

Instance Method Summary collapse

Constructor Details

#initialize(oClient = nil) ⇒ Update

Returns a new instance of Update.



5
6
7
8
9
10
# File 'lib/versionone_sdk/update.rb', line 5

def initialize(oClient=nil)
  @oClient = oClient
  @dTagTypes = {simple_attribute: 1, single_relationship: 1, multi_relationship: 1}
  @sRelationships = 'BuildProjects,Owner,Parent,Schedule,Scheme,SecurityScope,Status,TestSuite'
  @dRelationships = Hash[@sRelationships.split(',').collect {|v| [v,1]}]
end

Instance Method Details

#updateAsset(sAssetType = nil, sAssetOid = nil, sName = nil, xxValues = nil, yTagType = nil) ⇒ Object

Update a VersionOne asset.

Params:

sAssetType

A REST API asset type such as Scope, Epic, Story, Member, etc. The first part of the OID Token.

sAssetOid

The numerical OID and the second part of the OID token.

sName

Name of attribute to be updated.

xxValues

values to be updated which can be a variety of formats.

yTagType

A optional symbol to identify the type of attribute, e.g.

:simple_attribute, :single_relationship, or :multi_relationship



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/versionone_sdk/update.rb', line 21

def updateAsset(sAssetType=nil,sAssetOid=nil,sName=nil,xxValues=nil,yTagType=nil)
  aValues  = normalizeValues(xxValues)
  # Validate Tag Type
  yTagType = yTagType.to_sym if yTagType.is_a?(String)

  unless yTagType.nil?
    unless @dTagTypes.key?(yTagType)
      raise ArgumentError, "E_BAD_TAG_TYPE: [#{yTagType.to_s}]"
    end
  else
    if sName.nil? || ! sName.kind_of?(String)
      raise ArgumentError, 'E_NO_ATTRIBUTE_NAME'
    elsif @dRelationships.key?(sName)
      aValues.each do |dValue|
        sAct = dValue[:act]
        if sAct    == 'set'
          yTagType =  :single_relationship
        elsif sAct == 'add' || sAct == 'remove'
          yTagType =  :multi_relationship
        else
          raise ArgumentError, "E_BAD_ACT: [#{sAct}]"
        end
      end
    else
      yTagType = :simple_attribute
    end
  end

  xBody \
    = yTagType == :simple_attribute    \
    ? getXmlBodyForSimpleAttributeUpdate(sName,aValues) \
    : yTagType == :single_relationship \
    ? getXmlBodyForSingleRelationship(sName,aValues)    \
    : yTagType == :multi_relationship  \
    ? getXmlBodyForMultiRelationship(sName,aValues)     \
    : nil

  unless xBody.nil?
    oFdRes = @oClient.oFaraday.post do |req|
      req.url getUrlForAssetTypeAndOid(sAssetType,sAssetOid)
      req.headers['Content-Type'] = 'application/xml'
      req.body = xBody
    end
    return oFdRes
  end

  return nil

end