Class: DribbbleBucketApi::BucketCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/dribbble_bucket_api/bucket_collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page.



28
29
30
# File 'lib/dribbble_bucket_api/bucket_collection.rb', line 28

def current_page
  @current_page
end

#total_entriesObject

Returns the value of attribute total_entries.



28
29
30
# File 'lib/dribbble_bucket_api/bucket_collection.rb', line 28

def total_entries
  @total_entries
end

#total_pagesObject

Returns the value of attribute total_pages.



28
29
30
# File 'lib/dribbble_bucket_api/bucket_collection.rb', line 28

def total_pages
  @total_pages
end

Class Method Details

.retrieve(options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dribbble_bucket_api/bucket_collection.rb', line 5

def self.retrieve(options)
  # ensure we have a connection
  unless options[:connection]
    raise ArgumentError, %Q(
      Options hash must contain :connection
      e.g: DribbbleBucketApi::BucketCollection.load(connection: connection)
    )
  end
  # load the username
  username = options[:connection].username
  # load the page
  response = PublicSite.new.user_buckets({
    username: username,
    page: options[:page] || 1
  })
  # create the new array
  new(response.buckets).tap do |arr|
    arr.total_entries = response.total_entries
    arr.total_pages = response.total_pages
    arr.current_page = response.current_page
  end
end

Instance Method Details

#next_pageObject



30
31
32
# File 'lib/dribbble_bucket_api/bucket_collection.rb', line 30

def next_page
  current_page + 1
end

#prev_pageObject



34
35
36
# File 'lib/dribbble_bucket_api/bucket_collection.rb', line 34

def prev_page
  [current_page - 1, 1].max
end