Class: LearnSprout::Page

Inherits:
Object
  • Object
show all
Includes:
Connection
Defined in:
lib/learnsprout/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, type, extras = {}) ⇒ Page

Returns a new instance of Page.



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

def initialize(url, type, extras = {})
    @items = []
    @type = type
    @extras = extras
    data = get(url)

    @nextUrl = data["next"].to_s
    # Remove base URL if it's included
    prefix = LearnSprout.endpoint.to_s
    if @nextUrl[0, prefix.length] == prefix
        @nextUrl = @nextUrl[prefix.length, @nextUrl.length - prefix.length]
    end

    #TODO handle non-page URL?
    data["data"].each do |item|
        extras.each do |key, value|
            item[key] = value
        end
        @items << type.new(item)
    end
end

Instance Attribute Details

#itemsObject

Returns the value of attribute items.



5
6
7
# File 'lib/learnsprout/page.rb', line 5

def items
  @items
end

Instance Method Details

#nextObject



29
30
31
# File 'lib/learnsprout/page.rb', line 29

def next
    return Page.new(@nextUrl, @type, @extras)
end