Class: Locomotive::Mounter::Reader::Api::Runner

Inherits:
Runner
  • Object
show all
Defined in:
lib/locomotive/mounter/reader/api.rb

Instance Attribute Summary collapse

Attributes inherited from Runner

#kind, #mounting_point, #parameters

Instance Method Summary collapse

Methods inherited from Runner

#initialize, #reload, #run!

Constructor Details

This class inherits a constructor from Locomotive::Mounter::Reader::Runner

Instance Attribute Details

#uriObject

Returns the value of attribute uri.



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

def uri
  @uri
end

Instance Method Details

#base_uri_with_schemeString

Return the base uri with the scheme ((http:// or https://)) and without the path (/locomotive/…)

Returns:

  • (String)

    The uri starting by http:// or https:// and without the path



55
56
57
# File 'lib/locomotive/mounter/reader/api.rb', line 55

def base_uri_with_scheme
  self.uri_with_scheme.to_s[/^https?:\/\/[^\/]+/] || self.uri_with_scheme
end

#prepareObject

Call the LocomotiveCMS engine to get a token for the next API calls



24
25
26
27
28
29
30
31
32
33
# File 'lib/locomotive/mounter/reader/api.rb', line 24

def prepare
  credentials = self.parameters.select { |k, _| %w(uri email password api_key).include?(k.to_s) }
  self.uri    = credentials[:uri]

  begin
    Locomotive::Mounter::EngineApi.set_token(credentials)
  rescue Exception => e
    raise Locomotive::Mounter::ReaderException.new("unable to get an API token: #{e.message}")
  end
end

#readersArray

Ordered list of atomic readers

Returns:

  • (Array)

    List of classes



39
40
41
# File 'lib/locomotive/mounter/reader/api.rb', line 39

def readers
  [SiteReader, ContentAssetsReader, SnippetsReader, ContentTypesReader, ContentEntriesReader, PagesReader, ThemeAssetsReader, TranslationsReader]
end

#uri_with_schemeString

Return the uri with the scheme (http:// or https://)

Returns:

  • (String)

    The uri starting by http:// or https://



47
48
49
# File 'lib/locomotive/mounter/reader/api.rb', line 47

def uri_with_scheme
  self.uri =~ /^http/ ? self.uri : "http://#{self.uri}"
end