Class: Locomotive::Mounter::Writer::Api::Runner
- Defined in:
- lib/locomotive/mounter/writer/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
-
#content_assets_writer ⇒ Object
Get the writer to push content assets.
-
#prepare ⇒ Object
Call the LocomotiveCMS engine to get a token for the next API calls.
-
#writers ⇒ Array
Ordered list of atomic writers.
Methods inherited from Runner
#force?, #initialize, #run!, #write_all
Constructor Details
This class inherits a constructor from Locomotive::Mounter::Writer::Runner
Instance Attribute Details
#uri ⇒ Object
Returns the value of attribute uri.
20 21 22 |
# File 'lib/locomotive/mounter/writer/api.rb', line 20 def uri @uri end |
Instance Method Details
#content_assets_writer ⇒ Object
Get the writer to push content assets
63 64 65 66 67 |
# File 'lib/locomotive/mounter/writer/api.rb', line 63 def content_assets_writer @content_assets_writer ||= ContentAssetsWriter.new(self.mounting_point, self).tap do |writer| writer.prepare end 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 34 35 36 37 38 |
# File 'lib/locomotive/mounter/writer/api.rb', line 24 def prepare # by default, do not push data (content entries and editable elements) self.parameters[:data] ||= false credentials = self.parameters.select { |k, _| %w(uri email password api_key).include?(k.to_s) } ssl_version = self.parameters[:ssl_version] ? self.parameters[:ssl_version].to_sym : :SSLv3 self.uri = credentials[:uri] begin Locomotive::Mounter::EngineApi.ssl_version(ssl_version) Locomotive::Mounter::EngineApi.set_token(credentials) rescue Exception => e raise Locomotive::Mounter::WriterException.new("unable to get an API token: #{e.}") end end |
#writers ⇒ Array
Ordered list of atomic writers
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/locomotive/mounter/writer/api.rb', line 44 def writers [SiteWriter, SnippetsWriter, ContentTypesWriter, ContentEntriesWriter, TranslationsWriter, PagesWriter, ThemeAssetsWriter].tap do |_writers| # modify the list depending on the parameters if self.parameters if self.parameters[:data] == false && !(self.parameters[:only].try(:include?, 'content_entries')) _writers.delete(ContentEntriesWriter) end if self.parameters[:translations] == false && !(self.parameters[:only].try(:include?, 'translations')) _writers.delete(TranslationsWriter) end end end end |