Class: Signatory::API::Base

Inherits:
ActiveResource::Base
  • Object
show all
Defined in:
lib/signatory/api/base.rb,
lib/signatory/legacy_active_resource_hacks.rb

Direct Known Subclasses

Document, DocumentPackage, MergeField, Recipient, Role, Template

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all(*args) ⇒ Object

This implementation is pulled directly from ActiveResource 3.0.0 apidock.com/rails/ActiveResource/Base/all/class



8
9
10
# File 'lib/signatory/legacy_active_resource_hacks.rb', line 8

def all(*args)
  find(:all, *args)
end

.connection(refresh = false) ⇒ Object

ActiveResource < 3.0.0 does not support auth_type



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/signatory/legacy_active_resource_hacks.rb', line 13

def connection(refresh = false)
  if defined?(@connection) || superclass == Object
    @connection = Signatory::API::Connection.new(site, format) if !@_signatory_connection || refresh || @connection.nil?
    @_signatory_connection = true
    @connection.proxy = proxy if proxy
    @connection.user = user if user
    @connection.password = password if password
    @connection.auth_type = auth_type if auth_type
    @connection.timeout = timeout if timeout
    @connection.ssl_options = ssl_options if ssl_options
    @connection
  else
    superclass.connection
  end
end

.escape_url_attrs(*attrs) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/signatory/api/base.rb', line 19

def escape_url_attrs(*attrs)
  attrs.each do |attr|
    define_method attr do
      if Signatory.credentials.api_version == '1.0' || attributes[attr].blank?
        attributes[attr]
      else
        CGI::unescape(attributes[attr])
      end
    end
  end
end

.formatted_collection_nameObject



68
69
70
# File 'lib/signatory/api/base.rb', line 68

def formatted_collection_name
  self.name.split('::').last.downcase.pluralize
end

.formatted_nameObject



64
65
66
# File 'lib/signatory/api/base.rb', line 64

def formatted_name
  self.name.split('::').last.downcase
end

.instantiate_collection(collection, opts) ⇒ Object



57
58
59
60
61
62
# File 'lib/signatory/api/base.rb', line 57

def instantiate_collection(collection, opts)
  if collection.has_key?(formatted_collection_name)
    collection = collection[formatted_collection_name]
  end
  super([collection[formatted_name]].flatten, opts)
end

Instance Method Details

#has_many(sym) ⇒ Object



32
33
34
# File 'lib/signatory/api/base.rb', line 32

def has_many(sym)
  self.__has_many = (self.__has_many || []) + [sym]
end

#idObject



10
11
12
# File 'lib/signatory/api/base.rb', line 10

def id
  guid
end

#instantiate_record(record, opts = {}) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/signatory/api/base.rb', line 36

def instantiate_record(record, opts={})
  (self.__has_many||[]).each do |sym|
    record[sym.to_s] = [record[sym.to_s].try(:[],sym.to_s.singularize)].flatten.compact unless record[sym.to_s].is_a?(Array)
  end

  super(record, opts)
end

#persisted?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/signatory/api/base.rb', line 14

def persisted?
  attributes[:guid].present?
end

#to_xml(options = {}) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/signatory/legacy_active_resource_hacks.rb', line 28

def to_xml(options={})
  fixed_attrs = attributes.clone
  options[:except].each do |k|
    fixed_attrs.delete(k.to_s)
  end
  fixed_attrs.to_xml({:root => self.class.element_name}.merge(options)){|b| yield(b) if block_given?}
end