Class: BridgeAPI::ApiArray

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bridge_api/api_array.rb

Constant Summary collapse

META_FIELDS =
%w(meta linked).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, api_client) ⇒ ApiArray

Returns a new instance of ApiArray.



17
18
19
20
21
22
23
24
# File 'lib/bridge_api/api_array.rb', line 17

def initialize(response, api_client)
  @api_client = api_client
  case response.status
    when 200..206
      (response)
      @members = get_response_content(response)
  end
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



11
12
13
# File 'lib/bridge_api/api_array.rb', line 11

def headers
  @headers
end

#membersObject (readonly)

Returns the value of attribute members.



11
12
13
# File 'lib/bridge_api/api_array.rb', line 11

def members
  @members
end

#statusObject (readonly)

Returns the value of attribute status.



11
12
13
# File 'lib/bridge_api/api_array.rb', line 11

def status
  @status
end

Class Method Details

.process_response(response, api_client) ⇒ Object



13
14
15
# File 'lib/bridge_api/api_array.rb', line 13

def self.process_response(response, api_client)
    ApiArray.new(response, api_client)
end

Instance Method Details

#[](i) ⇒ Object



30
31
32
# File 'lib/bridge_api/api_array.rb', line 30

def [](i)
  @members[i]
end

#all_pages!Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/bridge_api/api_array.rb', line 60

def all_pages!
  if pages?
    response = get_page(@next_page)
    (response)
    @members.concat(get_response_content(response))
    while @next_page
      response = get_page(@next_page)
      (response)
      @members.concat(get_response_content(response))
    end
  end
  self
end

#each(&block) ⇒ Object



38
39
40
# File 'lib/bridge_api/api_array.rb', line 38

def each(&block)
  @members.each { |member| block.call(member) }
end

#each_page(&block) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/bridge_api/api_array.rb', line 50

def each_page(&block)
  block.call(@members)
  while @next_page
    response = get_page(@next_page)
    (response)
    block.call(@members)
  end
  @link_hash = {}
end

#lastObject



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

def last
  @members.last
end

#lengthObject



26
27
28
# File 'lib/bridge_api/api_array.rb', line 26

def length
  @members.length
end

#next_pageObject



46
47
48
# File 'lib/bridge_api/api_array.rb', line 46

def next_page
  load_page(@next_page)
end

#pages?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/bridge_api/api_array.rb', line 42

def pages?
  !@next_page.nil?
end