Class: PaychexAPI::ApiArray
- Inherits:
-
Object
- Object
- PaychexAPI::ApiArray
- Includes:
- Enumerable
- Defined in:
- lib/paychex_api/api_array.rb
Constant Summary collapse
- MAX_PAGES =
100
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
- #members ⇒ Object
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
- #next_page ⇒ Object
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #[](index) ⇒ Object
- #all_pages! ⇒ Object
- #each ⇒ Object
- #each_page {|members, @linked, @meta| ... } ⇒ Object
-
#initialize(response, api_client) ⇒ ApiArray
constructor
A new instance of ApiArray.
- #last ⇒ Object
- #length ⇒ Object
- #pages? ⇒ Boolean
- #size ⇒ Object
Constructor Details
#initialize(response, api_client) ⇒ ApiArray
Returns a new instance of ApiArray.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/paychex_api/api_array.rb', line 18 def initialize(response, api_client) @meta_fields = %w[metadata links] @api_client = api_client @links = [] @metadata = {} @errors = response.body['errors'] if response.body.is_a?(Hash) && response.body.key?('errors') case response.status when *((200..206).to_a + [302]) (response) @members = get_response_content(response) end end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
11 12 13 |
# File 'lib/paychex_api/api_array.rb', line 11 def errors @errors end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
11 12 13 |
# File 'lib/paychex_api/api_array.rb', line 11 def headers @headers end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
11 12 13 |
# File 'lib/paychex_api/api_array.rb', line 11 def links @links end |
#members ⇒ Object
31 32 33 |
# File 'lib/paychex_api/api_array.rb', line 31 def members @members || [] end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
11 12 13 |
# File 'lib/paychex_api/api_array.rb', line 11 def @metadata end |
#next_page ⇒ Object
59 60 61 |
# File 'lib/paychex_api/api_array.rb', line 59 def next_page load_page(@next_page) end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
11 12 13 |
# File 'lib/paychex_api/api_array.rb', line 11 def status @status end |
Class Method Details
Instance Method Details
#[](index) ⇒ Object
43 44 45 |
# File 'lib/paychex_api/api_array.rb', line 43 def [](index) members[index] end |
#all_pages! ⇒ Object
74 75 76 77 78 79 |
# File 'lib/paychex_api/api_array.rb', line 74 def all_pages! return self unless pages? combine_page combine_pages self end |
#each ⇒ Object
51 52 53 |
# File 'lib/paychex_api/api_array.rb', line 51 def each members.each { |member| yield(member) } end |
#each_page {|members, @linked, @meta| ... } ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/paychex_api/api_array.rb', line 63 def each_page yield(members, @linked, @meta) while @next_page response = get_page(@next_page) (response, false) @members = get_response_content(response) yield(members, @linked, @meta) end @link_hash = {} end |
#last ⇒ Object
47 48 49 |
# File 'lib/paychex_api/api_array.rb', line 47 def last members.last end |
#length ⇒ Object
39 40 41 |
# File 'lib/paychex_api/api_array.rb', line 39 def length members.length end |
#pages? ⇒ Boolean
55 56 57 |
# File 'lib/paychex_api/api_array.rb', line 55 def pages? !@next_page.nil? end |
#size ⇒ Object
35 36 37 |
# File 'lib/paychex_api/api_array.rb', line 35 def size length end |