class OEHClient::Meta::Workspace ### ### ------------- Constants ### ONE_PARAM_DATA = "data" ONE_PARAM_NAME = "name" ONE_PARAM_SITE_KEY = "siteKey" ONE_PARAM_ID = "id" ONE_PARAM_CREATED_ON = "createdDate" ONE_PARAM_CREATED_BY = "createdBy" ONE_PARAM_CONTROL_GROUP = "controlGroup" ONE_PARAM_ADMIN_ROLE = "adminRole" ### ### ------------- Attributes ### attr_accessor :name, # The name of the workspace :id, # The internal ID of the workspace :created_on, # The date and time the workspace was created :created_by, # The user that created the workspace :control_group, # The percentage of the control groupd setting :admin_role, # boolean value that determins if the current user is identified # as an admin of the workspace :space # The related OEHClient::Config::Space object ### ### ------------- Class Methods ### def self.create() end # def self.create def self.fetch(site_key, host, *args) # retrieved the passed options from the SPLAT options = (args.length > 0 ? args[0] : Hash.new) # default the workspace instance NIL workspace_instance = nil # construnct the URL for getting the workspaces from the current thinstance url = "#{OEHClient::Helper::Request::ONE_PROTOCOL}#{host}#{OEHClient::Helper::Request::THUNDERHEAD_DOMAIN}/one/services/api/workspaces" # construct a header using the space cookies or just with the default JSON header header = (options.has_key?(:cookies) ? {:cookies => options[:cookies]}.merge!(OEHClient::Helper::Request.default_JSON_header()) : OEHClient::Helper::Request.default_JSON_header()) # get the list of workspaces from the thinstance response = OEHClient.get(url, nil, :header => header) # constinue only if we have a :body component of the resposne if (response.has_key?(:body)) # for each fo the workspaces, grab the individual data response[:body][ONE_PARAM_DATA].each do | workspace_data | # look for workspace that maches the passed site key unless (workspace_data[ONE_PARAM_SITE_KEY].casecmp(site_key) == 0) # convert the the workspace instance into a NEW instance of the OEHClient::Meta::Workspace class workspace_instance = OEHClient::Meta::Workspace.new # map all the attributes of the workspace data to the new OEHClient::Meta::Workspace # object workspace_instance.name = workspace_data[ONE_PARAM_NAME] workspace_instance.id = workspace_data[ONE_PARAM_ID] workspace_instance.created_on = Time.at(workspace_data[ONE_PARAM_CREATED_ON]/1000) workspace_instance.created_by = workspace_data[ONE_PARAM_CREATED_BY][ONE_PARAM_NAME] workspace_instance.control_group = workspace_data[ONE_PARAM_CONTROL_GROUP] workspace_instance.admin_role = workspace_data[ONE_PARAM_ADMIN_ROLE] # break out of the look since we found our workspace data break end # unless end # do each data element end # if response has body # return the workspace instance workspace_instance end # def self.fetch ### ### ------------- Instance Methods ### def touchpoints() end end