class PlutoraRest::Calls
Attributes
token[R]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/plutora_rest.rb, line 18 def initialize(opts = {}) #- Use to initilze the object and connect to plutora # => token # oauth_url = opts[:oauthURL] || 'https://usoauth.plutora.com/oauth/token' params = {'grant_type' => 'password', 'client_id' => opts[:client_id], 'client_secret' => opts[:client_secret], 'username' => opts[:username], 'password' => opts[:password]} headers = {'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded'} @base_url= opts[:baseURL] || "https://usapi.plutora.com/" rConnect=plutora_post({:url => oauth_url, :params => params, :headers => headers}) rConnect=JSON.parse(rConnect) @token=rConnect['access_token'] @expires_in=rConnect['expires_in'] @expiresAt=DateTime.now + @expires_in.to_i.seconds @refresh_token=rConnect['refresh_token'] @oauthURL=oauth_url @clientID=opts[:client_id] @clientSecret=opts[:client_secret] return @token end
Public Instance Methods
create_Change(opts = {})
click to toggle source
# File lib/plutora_rest/sections/changes.rb, line 146 def create_Change(opts = {}) if opts[:params] == nil raise "Create Change requires Parameters" end url = "#{@base_url}Changes" headers = { 'Authorization' => "Bearer #{(opts[:token] == nil ? @token : opts[:token])}", 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded' } resp=plutora_post({:url => url, :params => opts[:params], :headers => headers}) return (resp.code == 204 ? true : false) end
formatResp(opts)
click to toggle source
# File lib/plutora_rest.rb, line 115 def formatResp(opts) json_convert=Hash.from_xml(opts[:xml]).to_json return JSON.parse(json_convert) end
get_AdditionalInformation_FieldID(opts = {})
click to toggle source
# File lib/plutora_rest/sections/changes.rb, line 168 def get_AdditionalInformation_FieldID(opts = {}) if opts[:fieldname] == nil raise "get Additional Information (Field ID) options variable 'fieldname' requires a value." end sId = nil if opts[:data].class == Hash if opts[:data]['Name'] == opts[:fieldname] sID = opts[:data]['Id'] end else opts[:data].each do |fields| if fields['Name'] == opts[:fieldname] sID = fields['Id'] end end end return (sID == nil ? false : sID) end
get_AdditionalInformation_FieldValue(opts = {})
click to toggle source
# File lib/plutora_rest/sections/changes.rb, line 191 def get_AdditionalInformation_FieldValue(opts = {}) if opts[:fieldname] == nil raise "get Additional Information (Field Value) options variable 'fieldname' requires a value." end sValue=nil if opts[:data].class == Hash if opts[:data]['Name'] == opts[:fieldname] case opts[:data]['DataType'] when 'DatePicker' if !opts[:data]['Date'].class == Hash sValue = opts[:data]['Date'] end when 'ListField' if opts[:data]['ListItem'].class == Hash if opts[:data]['ListItem'].size > 1 sValue = opts[:data]['ListItem']['Value'] end end when 'FreeText' if opts[:data]['Text'].class == String sValue = opts[:data]['Text'] end when 'TimePicker' if !opts[:data]['Time'].class == Hash sValue = opts[:data]['Time'] end when 'Number' if opts[:data]['Number'].class == String sValue = opts[:data]['Number'] end when 'DateTimePicker' if !opts[:data]['DateTime'].class == Hash sValue = opts[:data]['DateTime'] end when 'ListSelect' if !opts[:data]['MultilListItem'].class == Hash sValue = opts[:data]['MultilListItem'] end else sValue=nil end end else opts[:data].each do |items| if items['Name'] == opts[:fieldname] case items['DataType'] when 'DatePicker' if !items['Date'].class == Hash sValue = items['Date'] end when 'ListField' if items['ListItem'].class == Hash if items['ListItem'].size > 1 sValue = items['ListItem']['Value'] end end when 'FreeText' if items['Text'].class == String sValue = items['Text'] end when 'TimePicker' if !items['Time'].class == Hash sValue = items['Time'] end when 'Number' if items['Number'].class == String sValue = items['Number'] end when 'DateTimePicker' if !items['DateTime'].class == Hash sValue = items['DateTime'] end when 'ListSelect' if !items['MultilListItem'].class == Hash sValue = items['MultilListItem'] end else sValue=nil end break end end end return (sValue == nil ? false : sValue) end
get_Changes(opts = {})
click to toggle source
# File lib/plutora_rest/sections/changes.rb, line 13 def get_Changes(opts = {}) vRetry=0 begin token=opts[:token] || @token url = "#{@base_url}Changes" headers = {'Authorization' => 'Bearer ' + token} resp=plutora_get({:url => url, :headers => headers}) resp=formatResp({:xml => resp}) return resp rescue puts "-----> Get Changes Error <-----" puts $! puts $@ puts "<----------------------------->" if $! == "500 Internal Server Error" vRetry+=1 retry if vRetry < 2 end end end
get_ChangesById(opts = {})
click to toggle source
# File lib/plutora_rest/sections/changes.rb, line 38 def get_ChangesById(opts = {}) vRetry=0 begin if opts[:id] == nil raise "Changes By Id requires an ID value!" end url = "#{@base_url}Changes/#{opts[:id]}" headers = {'Authorization' => 'Bearer ' + (opts[:token] == nil ? @token : opts[:token])} resp=formatResp({:xml => plutora_get({:url => url, :headers => headers})}) return resp rescue puts "-----> Get Changes By Id Error <-----" puts $! puts $@ puts "<----------------------------------->" if $! == "500 Internal Server Error" vRetry+=1 retry if vRetry < 2 end end end
get_ChangesById_AdditionalInformation(opts = {})
click to toggle source
# File lib/plutora_rest/sections/changes.rb, line 64 def get_ChangesById_AdditionalInformation(opts = {}) if opts[:id] == nil raise "Changes By Id - Additional Information requires an ID value!" end url = "#{@base_url}Changes/#{opts[:id]}/additionalInformation" headers = {'Authorization' => "Bearer #{(opts[:token] == nil ? @token : opts[:token])}"} resp=formatResp({:xml => plutora_get({:url => url, :headers => headers})}) return resp end
get_ChangesFilter(opts = {})
click to toggle source
# File lib/plutora_rest/sections/changes.rb, line 78 def get_ChangesFilter(opts = {}) if opts[:searchfilter] == nil raise "Change by Filter - Search Filters required!" end headers = {'Authorization' => "Bearer #{(opts[:token] == nil ? @token : opts[:token])}", 'Content-Type' => 'application/json'} url = "#{@base_url}Changes/filter" resp=formatResp({:xml=> plutora_post({:url => url, :params => opts[:searchfilter], :headers => headers})}) # resp=plutora_post({:url => url, :params => opts[:searchfilter], :headers => headers}) # resp=pluotra_post_json({:url => url, :params => opts[:searchfilter], :headers => headers}) return resp end
get_LookupField_ValueID(opts = {})
click to toggle source
# File lib/plutora_rest/sections/lookupfields.rb, line 31 def get_LookupField_ValueID(opts = {}) if opts[:type] == nil raise "Get Lookup Field Value Id requires a Type value." end if opts[:value] == nil raise "Get Lookup Field Value Id requires a Value to lookup." end sId = '' if opts[:data].class == Hash if opts[:data]['Type'] == opts[:type] if opts[:data]['Value'] == opts[:value] sID = opts[:data]['Id'] end end else opts[:data].each do |fields| if fields['Type'] == opts[:type] if fields['Value'] == opts[:value] sID = fields['Id'] end end end end return (sID == '' ? false : sID) end
get_ReleaseById_Systems(opts = {})
click to toggle source
# File lib/plutora_rest/sections/releases.rb, line 54 def get_ReleaseById_Systems(opts = {}) if opts[:id] == nil raise "Release By Id Systems requires an ID value!" end url "#{@base_url}releases/#{opts[:id]}/system" headers = {'Authorization' => 'Bearer ' + (opts[:token] == nil ? @token : opts[:token])} resp=formatResp({:xml => plutora_get({:url => url, :headers => headers})}) return resp end
get_Releases(opts = {})
click to toggle source
# File lib/plutora_rest/sections/releases.rb, line 13 def get_Releases(opts = {}) token=opts[:token] || @token url = "#{@base_url}releases" headers = {'Authorization' => 'Bearer ' + token} resp=plutora_get({:url => url, :headers => headers}) resp=formatResp({:xml => resp}) return resp end
get_ReleasesById(opts = {})
click to toggle source
# File lib/plutora_rest/sections/releases.rb, line 26 def get_ReleasesById(opts = {}) if opts[:id] == nil raise "Releases By Id requires an ID value!" end url = "#{@base_url}releases/#{opts[:id]}" headers = {'Authorization' => 'Bearer ' + (opts[:token] == nil ? @token : opts[:token])} resp=formatResp({:xml => plutora_get({:url => url, :headers => headers})}) return resp end
get_ReleasesById_AdditionalInformation(opts = {})
click to toggle source
# File lib/plutora_rest/sections/releases.rb, line 40 def get_ReleasesById_AdditionalInformation(opts = {}) if opts[:id] == nil raise "Release By Id Additional Information requires an ID value!" end url "#{@base_url}releases/#{opts[:id]}/additionalInformation" headers = {'Authorization' => 'Bearer ' + (opts[:token] == nil ? @token : opts[:token])} resp=formatResp({:xml => plutora_get({:url => url, :headers => headers})}) return resp end
get_Systems(opts = {})
click to toggle source
# File lib/plutora_rest/sections/systems.rb, line 13 def get_Systems(opts = {}) vRetry=0 begin token=opts[:token] || @token url = "#{@base_url}systems" headers = {'Authorization' => 'Bearer ' + token} resp=plutora_get({:url => url, :headers => headers}) resp=formatResp({:xml => resp}) return resp rescue puts "-----> Get Systems Error <-----" puts $! puts $@ puts "<----------------------------->" if $! == "500 Internal Server Error" vRetry+=1 retry if vRetry < 2 end end end
get_SystemsById(opts = {})
click to toggle source
# File lib/plutora_rest/sections/systems.rb, line 38 def get_SystemsById(opts = {}) if opts[:id] == nil raise "Systems By Id requires an ID value!" end url = "#{@base_url}systems/#{opts[:id]}" headers = {'Authorization' => 'Bearer ' + (opts[:token] == nil ? @token : opts[:token])} resp=formatResp({:xml => plutora_get({:url => url, :headers => headers})}) return resp end
get_Systems_ByRoleType(opts = {})
click to toggle source
# File lib/plutora_rest/sections/changes.rb, line 281 def get_Systems_ByRoleType(opts = {}) if opts[:roletype] == nil raise "get Systems By Role Type requires a Role Type value." end sSystems='' if opts[:data].class == Hash if opts[:data]['SystemRoleType'] == opts[:roletype] sSystems= opts[:data]['System'] end else opts[:data].each do |systems| if systems['SystemRoleType'] == opts[:roletype] sSystems.concat(";#{systems['System']}") end end sSystems = sSystems[1..-1] end if sSystems == '' return false else return sSystems end end
get_lookupfields_byType(opts = {})
click to toggle source
# File lib/plutora_rest/sections/lookupfields.rb, line 13 def get_lookupfields_byType(opts = {}) if opts[:type] == nil raise "Get Lookup Fields, Type value is required!" end url = "#{@base_url}lookupfields/#{opts[:type]}" headers = {'Authorization' => 'Bearer ' + (opts[:token] == nil ? @token : opts[:token])} resp=formatResp({:xml => plutora_get({:url => url, :headers => headers})}) return resp end
pluotra_post_json(opts = {})
click to toggle source
# File lib/plutora_rest.rb, line 95 def pluotra_post_json(opts = {}) body=opts[:params].to_json puts body return RestClient.post(opts[:url], body, opts[:headers]) # return RestClient.post(opts[:url], "{}", opts[:headers]) end
plutora_get(opts)
click to toggle source
# File lib/plutora_rest.rb, line 103 def plutora_get(opts) resp=RestClient.get(opts[:url], opts[:headers]) return resp end
plutora_post(opts)
click to toggle source
# File lib/plutora_rest.rb, line 90 def plutora_post(opts) resp=RestClient.post(opts[:url], opts[:params], opts[:headers]) return resp end
plutora_put(opts)
click to toggle source
# File lib/plutora_rest.rb, line 109 def plutora_put(opts) resp=RestClient.put(opts[:url], opts[:params], opts[:headers]) return resp end
refresh_token_if_expired()
click to toggle source
# File lib/plutora_rest.rb, line 51 def refresh_token_if_expired begin if token_expired? params={'grant_type' => 'refresh_token', 'refresh_token' => @refresh_token, 'client_id' => @clientID, 'client_secret' => @clientSecret } headers = {'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded' } refreshConnect=plutora_post({:url => @oauthURL, :params => params, :headers => headers}) refreshConnect=JSON.parse(refreshConnect) @token=refreshConnect['access_token'] @expires_in=refreshConnect['expires_in'] @expiresAt=DateTime.now + @expires_in.to_i.seconds @refresh_token=refreshConnect['refresh_token'] return @token end rescue puts "<----- Refresh Token If Expired ----->" puts $! puts $@ puts "<------------------------------------>" end end
token_expired?()
click to toggle source
# File lib/plutora_rest.rb, line 83 def token_expired? expiry=Time.at(@expiresAt) return true if expiry < Time.now false end
update_ChangesById(opts = {})
click to toggle source
# File lib/plutora_rest/sections/changes.rb, line 99 def update_ChangesById(opts = {}) if opts[:id] == nil raise "Changes By Id requires an ID value!" end if opts[:params] == nil raise "Changes By Id requires Parameters!" end url = "#{@base_url}Changes/#{opts[:id]}" headers = { 'Authorization' => "Bearer #{(opts[:token] == nil ? @token : opts[:token])}", 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded' #'Content-Type' => 'application/json' } resp=plutora_put({:url => url, :params => opts[:params], :headers => headers}) return (resp.code == 204 ? true : false) end
update_ChangesById_AdditionalInformation(opts = {})
click to toggle source
# File lib/plutora_rest/sections/changes.rb, line 121 def update_ChangesById_AdditionalInformation(opts = {}) if opts[:id] == nil raise "Changes By Id - Additional Information requires an ID value!" end if opts[:params] == nil raise "Changes By Id - Additional Information requires Parameters!" end url = "#{@base_url}Changes/#{opts[:id]}/additionalInformation" headers = { 'Authorization' => "Bearer #{(opts[:token] == nil ? @token : opts[:token])}", 'Content-Type' => 'application/json' } resp=plutora_put({:url => url, :params => opts[:params], :headers => headers}) return (resp.code == 204 ? true : false) end
update_ReleasesById(opts = {})
click to toggle source
# File lib/plutora_rest/sections/releases.rb, line 72 def update_ReleasesById(opts = {}) if opts[:id] == nil raise "Update Releases By Id requires an ID value!" end if opts[:params] == nil raise "Update Releasee By Id requires Parameters!" end url = "#{@base_url}releases/#{opts[:id]}" headers = { 'Authorization' => "Bearer #{(opts[:token] == nil ? @token : opts[:token])}", 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded' #'Content-Type' => 'application/json' } resp=plutora_put({:url => url, :params => opts[:params], :headers => headers}) return (resp.code == 204 ? true : false) end
update_ReleasesById_AdditionalInformation(opts = {})
click to toggle source
# File lib/plutora_rest/sections/releases.rb, line 94 def update_ReleasesById_AdditionalInformation(opts = {}) if opts[:id] == nil raise "Update Releases By Id requires an ID value!" end if opts[:params] == nil raise "Update Releasee By Id requires Parameters!" end url = "#{@base_url}releases/#{opts[:id]}/additionalInformation" headers = { 'Authorization' => "Bearer #{(opts[:token] == nil ? @token : opts[:token])}", 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded' #'Content-Type' => 'application/json' } resp=plutora_put({:url => url, :params => opts[:params], :headers => headers}) return (resp.code == 204 ? true : false) end