lib/trav3/pagination.rb in trav3-0.2.5 vs lib/trav3/pagination.rb in trav3-0.3.0
- old
+ new
@@ -1,34 +1,38 @@
# frozen_string_literal: true
module Trav3
class Pagination
+ attr_reader :travis
def initialize(travis, result)
@travis = travis
@result = result
end
- def dig(opt)
- @result.dig(opt)
- end
-
def next
- get("#{API_ROOT}#{dig('@pagination').dig('next').dig('@href')}")
+ get(action(:next))
end
def first
- get("#{API_ROOT}#{dig('@pagination').dig('first').dig('@href')}")
+ get(action(:first))
end
def last
- get("#{API_ROOT}#{dig('@pagination').dig('last').dig('@href')}")
+ get(action(:last))
end
- def get(url)
- Trav3::REST.get(travis, url)
+ private
+
+ def action(action)
+ dig('@pagination').dig(action.to_s).dig('@href')
end
- private :get
- attr_reader :travis
+ def dig(opt)
+ @result.dig(opt)
+ end
+
+ def get(path)
+ travis.send(:get_path, path.to_s)
+ end
private :travis
end
end