Class: Locomotive::Mounter::Reader::Api::Base

Inherits:
Object
  • Object
show all
Includes:
Utils::Output
Defined in:
lib/locomotive/mounter/reader/api/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner) ⇒ Base

Returns a new instance of Base.



15
16
17
18
# File 'lib/locomotive/mounter/reader/api/base.rb', line 15

def initialize(runner)
  self.runner  = runner
  self.items   = {}
end

Instance Attribute Details

#itemsObject

Returns the value of attribute items.



10
11
12
# File 'lib/locomotive/mounter/reader/api/base.rb', line 10

def items
  @items
end

#runnerObject

Returns the value of attribute runner.



10
11
12
# File 'lib/locomotive/mounter/reader/api/base.rb', line 10

def runner
  @runner
end

Instance Method Details

#add_content_asset(url, folder = nil) ⇒ String

Build a new content asset from an url and a folder and add it to the global list of the content assets.

Parameters:

  • url (String)

    The url of the content asset.

  • folder (String) (defaults to: nil)

    The folder of the content asset (optional).

Returns:

  • (String)

    The local path (not absolute) of the content asset.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/locomotive/mounter/reader/api/base.rb', line 46

def add_content_asset(url, folder = nil)
  content_assets = self.mounting_point.resources[:content_assets]

  if (url =~ /^https?:\/\//).nil?
    url = URI.join(self.uri_with_scheme, url)
  else
    url = URI(url)
  end

  asset = Locomotive::Mounter::Models::ContentAsset.new(uri: url, folder: folder)

  content_assets[url.path] = asset

  asset.local_filepath
end

#get(resource_name, locale = nil, dont_filter_attributes = false) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/locomotive/mounter/reader/api/base.rb', line 28

def get(resource_name, locale = nil, dont_filter_attributes = false)
  attribute_names = dont_filter_attributes ? nil : self.safe_attributes

  begin
    Locomotive::Mounter::EngineApi.fetch(resource_name, {}, locale, attribute_names)
  rescue ApiReadException => e
    raise ReaderException.new(e.message)
  end
end

#mounting_pointObject



20
21
22
# File 'lib/locomotive/mounter/reader/api/base.rb', line 20

def mounting_point
  self.runner.mounting_point
end

#readObject



24
25
26
# File 'lib/locomotive/mounter/reader/api/base.rb', line 24

def read
  self.output_title(:pulling)
end