Class: Locomotive::Mounter::Reader::Api::Runner
- Defined in:
- lib/locomotive/mounter/reader/api.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
Returns the value of attribute uri.
Attributes inherited from Runner
#kind, #mounting_point, #parameters
Instance Method Summary collapse
-
#base_uri_with_scheme ⇒ String
Return the base uri with the scheme ((http:// or https://)) and without the path (/locomotive/…).
-
#prepare ⇒ Object
Call the LocomotiveCMS engine to get a token for the next API calls.
-
#readers ⇒ Array
Ordered list of atomic readers.
-
#uri_with_scheme ⇒ String
Return the uri with the scheme (http:// or https://).
Methods inherited from Runner
Constructor Details
This class inherits a constructor from Locomotive::Mounter::Reader::Runner
Instance Attribute Details
#uri ⇒ Object
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_scheme ⇒ String
Return the base uri with the scheme ((http:// or https://)) and without the path (/locomotive/…)
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 |
#prepare ⇒ Object
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.}") end end |
#readers ⇒ Array
Ordered list of atomic readers
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_scheme ⇒ String
Return the uri with the scheme (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 |