Class: PaychexAPI::ApiArray
- Inherits:
-
Object
- Object
- PaychexAPI::ApiArray
- Includes:
- Enumerable
- Defined in:
- lib/paychex_api/api_array.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#members ⇒ Object
readonly
Returns the value of attribute members.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#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
- #next_page ⇒ Object
- #pages? ⇒ Boolean
Constructor Details
#initialize(response, api_client) ⇒ ApiArray
Returns a new instance of ApiArray.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/paychex_api/api_array.rb', line 15 def initialize(response, api_client) @meta_fields = %w(metadata links) @api_client = api_client @links = [] @metadata = {} 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.
9 10 11 |
# File 'lib/paychex_api/api_array.rb', line 9 def headers @headers end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
9 10 11 |
# File 'lib/paychex_api/api_array.rb', line 9 def links @links end |
#members ⇒ Object (readonly)
Returns the value of attribute members.
9 10 11 |
# File 'lib/paychex_api/api_array.rb', line 9 def members @members end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/paychex_api/api_array.rb', line 9 def @metadata end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
9 10 11 |
# File 'lib/paychex_api/api_array.rb', line 9 def status @status end |
Class Method Details
Instance Method Details
#[](i) ⇒ Object
31 32 33 |
# File 'lib/paychex_api/api_array.rb', line 31 def [](i) @members[i] end |
#all_pages! ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/paychex_api/api_array.rb', line 62 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
39 40 41 |
# File 'lib/paychex_api/api_array.rb', line 39 def each(&block) @members.each { |member| block.call(member) } end |
#each_page(&block) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/paychex_api/api_array.rb', line 51 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
35 36 37 |
# File 'lib/paychex_api/api_array.rb', line 35 def last @members.last end |
#length ⇒ Object
27 28 29 |
# File 'lib/paychex_api/api_array.rb', line 27 def length @members.length end |
#next_page ⇒ Object
47 48 49 |
# File 'lib/paychex_api/api_array.rb', line 47 def next_page load_page(@next_page) end |
#pages? ⇒ Boolean
43 44 45 |
# File 'lib/paychex_api/api_array.rb', line 43 def pages? !@next_page.nil? end |