Class: BridgeAPI::ApiArray
- Inherits:
-
Object
- Object
- BridgeAPI::ApiArray
- Includes:
- Enumerable
- Defined in:
- lib/bridge_api/api_array.rb
Constant Summary collapse
- META_FIELDS =
%w(meta linked).freeze
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#members ⇒ Object
readonly
Returns the value of attribute members.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #[](i) ⇒ Object
- #all_pages! ⇒ Object
- #each(&block) ⇒ Object
- #each_page(&block) ⇒ Object
-
#initialize(response, api_client) ⇒ ApiArray
constructor
A new instance of ApiArray.
- #last ⇒ Object
- #length ⇒ Object
- #linked ⇒ Object
- #meta ⇒ Object
- #next_page ⇒ Object
- #pages? ⇒ Boolean
Constructor Details
#initialize(response, api_client) ⇒ ApiArray
Returns a new instance of ApiArray.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bridge_api/api_array.rb', line 17 def initialize(response, api_client) @api_client = api_client @linked = {} @meta = {} case response.status when *((200..206).to_a + [302]) (response) @members = get_response_content(response) end end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
11 12 13 |
# File 'lib/bridge_api/api_array.rb', line 11 def headers @headers end |
#members ⇒ Object (readonly)
Returns the value of attribute members.
11 12 13 |
# File 'lib/bridge_api/api_array.rb', line 11 def members @members end |
#status ⇒ Object (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
Instance Method Details
#[](i) ⇒ Object
32 33 34 |
# File 'lib/bridge_api/api_array.rb', line 32 def [](i) @members[i] end |
#all_pages! ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/bridge_api/api_array.rb', line 71 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
40 41 42 |
# File 'lib/bridge_api/api_array.rb', line 40 def each(&block) @members.each { |member| block.call(member) } end |
#each_page(&block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/bridge_api/api_array.rb', line 60 def each_page(&block) block.call(@members, @linked, @meta) while @next_page response = get_page(@next_page) (response, false) @members = get_response_content(response) block.call(@members, @linked, @meta) end @link_hash = {} end |
#last ⇒ Object
36 37 38 |
# File 'lib/bridge_api/api_array.rb', line 36 def last @members.last end |
#length ⇒ Object
28 29 30 |
# File 'lib/bridge_api/api_array.rb', line 28 def length @members.length end |
#linked ⇒ Object
52 53 54 |
# File 'lib/bridge_api/api_array.rb', line 52 def linked @linked end |
#meta ⇒ Object
48 49 50 |
# File 'lib/bridge_api/api_array.rb', line 48 def @meta end |
#next_page ⇒ Object
56 57 58 |
# File 'lib/bridge_api/api_array.rb', line 56 def next_page load_page(@next_page) end |
#pages? ⇒ Boolean
44 45 46 |
# File 'lib/bridge_api/api_array.rb', line 44 def pages? !@next_page.nil? end |