Class: ET::GetSupportRest

Inherits:
BaseObject show all
Defined in:
lib/exact-target-api/get_support_rest.rb

Direct Known Subclasses

CUDSupportRest

Instance Attribute Summary collapse

Attributes inherited from BaseObject

#client, #endpoint, #lastRequestID, #obj, #props

Instance Method Summary collapse

Methods inherited from BaseObject

#stringify_keys!, #symbolize_keys!

Constructor Details

#initializeGetSupportRest

Returns a new instance of GetSupportRest.



5
6
7
# File 'lib/exact-target-api/get_support_rest.rb', line 5

def initialize
  super
end

Instance Attribute Details

#lastPageNumberObject (readonly)

Returns the value of attribute lastPageNumber.



3
4
5
# File 'lib/exact-target-api/get_support_rest.rb', line 3

def lastPageNumber
  @lastPageNumber
end

#urlPropsObject (readonly)

Returns the value of attribute urlProps.



3
4
5
# File 'lib/exact-target-api/get_support_rest.rb', line 3

def urlProps
  @urlProps
end

#urlPropsRequiredObject (readonly)

Returns the value of attribute urlPropsRequired.



3
4
5
# File 'lib/exact-target-api/get_support_rest.rb', line 3

def urlPropsRequired
  @urlPropsRequired
end

Instance Method Details

#get(props = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
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
# File 'lib/exact-target-api/get_support_rest.rb', line 9

def get(props = nil)
  if props and props.is_a? Hash then
    @props = props
  end

  completeURL = @endpoint
  additionalQS = {}

  if @props and @props.is_a? Hash then
    @props.each do |k,v|
      if @urlProps.include?(k) then
        completeURL.sub!("{#{k}}", v)
      else
        additionalQS[k] = v
      end
    end
  end

  @urlPropsRequired.each do |value|
    if !@props || !@props.has_key?(value) then
      raise "Unable to process request due to missing required prop: #{value}"
    end
  end

  @urlProps.each do |value|
    completeURL.sub!("/{#{value}}", "")
  end

  obj = ET::GetRest.new(@authStub, completeURL,additionalQS)

  if obj.results.has_key?('page')
    @lastPageNumber = obj.results['page']
    pageSize = obj.results['pageSize']
    if obj.results.has_key?('count') then
      count = obj.results['count']
    elsif obj.results.has_key?('totalCount') then
      count = obj.results['totalCount']
    end

    if !count.nil? && count > (@lastPageNumber * pageSize)
      obj.moreResults = true
    end
  end
  obj
end

#getMoreResultsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/exact-target-api/get_support_rest.rb', line 55

def getMoreResults
  if props and props.is_a? Hash
    @props = props
  end

  originalPageValue = "1"
  removePageFromProps = false

  if !@props.nil? && @props.has_key?('$page')
    originalPageValue = @props['page']
  else
    removePageFromProps = true
  end

  if @props.nil?
    @props = {}
  end

  @props['$page'] = @lastPageNumber + 1

  obj = self.get

  if removePageFromProps then
    @props.delete('$page')
  else
    @props['$page'] = originalPageValue
  end

  obj
end