2016-08-22 14:48:31 -04:00
|
|
|
module Bitbucket
|
|
|
|
class Page
|
|
|
|
attr_reader :attrs, :items
|
|
|
|
|
|
|
|
def initialize(raw, type)
|
|
|
|
@attrs = parse_attrs(raw)
|
|
|
|
@items = parse_values(raw, representation_class(type))
|
|
|
|
end
|
|
|
|
|
|
|
|
def next?
|
|
|
|
attrs.fetch(:next, false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def next
|
|
|
|
attrs.fetch(:next)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def parse_attrs(raw)
|
2016-12-07 07:00:06 -05:00
|
|
|
raw.slice(*%w(size page pagelen next previous)).symbolize_keys
|
2016-08-22 14:48:31 -04:00
|
|
|
end
|
|
|
|
|
2016-11-21 23:49:40 -05:00
|
|
|
def parse_values(raw, bitbucket_rep_class)
|
2016-11-21 11:25:47 -05:00
|
|
|
return [] unless raw['values'] && raw['values'].is_a?(Array)
|
2016-12-12 10:29:25 -05:00
|
|
|
|
2016-12-07 07:00:06 -05:00
|
|
|
bitbucket_rep_class.decorate(raw['values'])
|
2016-08-22 14:48:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def representation_class(type)
|
2016-11-17 23:16:22 -05:00
|
|
|
Bitbucket::Representation.const_get(type.to_s.camelize)
|
2016-08-22 14:48:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|