Module: SFRest

Defined in:
lib/sfrest.rb,
lib/sfrest/info.rb,
lib/sfrest/role.rb,
lib/sfrest/site.rb,
lib/sfrest/task.rb,
lib/sfrest/user.rb,
lib/sfrest/audit.rb,
lib/sfrest/error.rb,
lib/sfrest/group.rb,
lib/sfrest/stage.rb,
lib/sfrest/theme.rb,
lib/sfrest/usage.rb,
lib/sfrest/backup.rb,
lib/sfrest/update.rb,
lib/sfrest/domains.rb,
lib/sfrest/version.rb,
lib/sfrest/codebase.rb,
lib/sfrest/variable.rb,
lib/sfrest/collection.rb,
lib/sfrest/connection.rb,
lib/sfrest/pathbuilder.rb

Overview

Base Class for SF rest API sdk

Defined Under Namespace

Classes: AccessDeniedError, ActionForbiddenError, Audit, Backup, BadRequestError, Codebase, Collection, Connection, Domains, Group, Info, InvalidApiVersion, InvalidDataError, InvalidResponse, Pathbuilder, Role, SFError, Site, Stage, Task, TaskNotDoneError, Theme, UnprocessableEntity, Update, Usage, User, Variable

Constant Summary collapse

VERSION =

Just tracks the version of sfrest.

'0.0.25'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.base_urlObject

Returns the value of attribute base_url.



34
35
36
# File 'lib/sfrest.rb', line 34

def base_url
  @base_url
end

.connObject

Returns the value of attribute conn.



34
35
36
# File 'lib/sfrest.rb', line 34

def conn
  @conn
end

.passwordObject

Returns the value of attribute password.



34
35
36
# File 'lib/sfrest.rb', line 34

def password
  @password
end

.userObject

Returns the value of attribute user.



34
35
36
# File 'lib/sfrest.rb', line 34

def user
  @user
end

Class Method Details

.find_data_from_results(res, field, datapat, key) ⇒ Object

Extract the return data for ‘key’ based on the result object

Parameters:

  • res (Hash)

    result from a request to /collections or /site

  • field (String)

    data field to search

  • datapat (String)

    regex-like pattern to match to the data field

  • key (String)

    one of the user data returned (id, name, domain…)

Returns:

  • (Object)

    Integer, String, Array, Hash depending on the collection data



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/sfrest.rb', line 54

def self.find_data_from_results(res, field, datapat, key)
  data = res.reject { |k| k.to_s.match(/time|count/) }
  raise InvalidDataError('The data you are searching is not a hash') unless data.is_a?(Hash)

  data.each_value do |datum|
    datum.each do |dat|
      return dat[key] if dat[field].to_s =~ /#{datapat}/
    end
  end
  nil
end

.new(url, user, password) ⇒ Object

returns a connection object to the SF Rest api for a specific factory

Parameters:

  • url (String)

    Base url of the Site Factory

  • user (String)

    username of a user on the factory

  • password (String)

    api password for the user on the factory



40
41
42
43
44
45
# File 'lib/sfrest.rb', line 40

def new(url, user, password)
  @base_url = url
  @user = user
  @password = password
  @conn = SFRest::Connection.new(@base_url, @user, @password)
end