Class: Locomotive::Coal::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/coal/client.rb

Direct Known Subclasses

ClientV2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, credentials, options = {}) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
14
# File 'lib/locomotive/coal/client.rb', line 7

def initialize(uri, credentials, options = {})
  if uri.blank? || credentials.blank?
    raise MissingURIOrCredentialsError.new('URI and/or credentials are missing')
  else
    @options = { path_prefix: 'locomotive' }.merge(options).with_indifferent_access
    @uri, @credentials = prepare_uri(uri), credentials.with_indifferent_access
  end
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



5
6
7
# File 'lib/locomotive/coal/client.rb', line 5

def credentials
  @credentials
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/locomotive/coal/client.rb', line 5

def options
  @options
end

#uriObject (readonly)

Returns the value of attribute uri.



5
6
7
# File 'lib/locomotive/coal/client.rb', line 5

def uri
  @uri
end

Instance Method Details

#accountsObject



24
25
26
# File 'lib/locomotive/coal/client.rb', line 24

def accounts
  @accounts ||= Resources::Accounts.new(uri, connection)
end

#content_assetsObject



55
56
57
# File 'lib/locomotive/coal/client.rb', line 55

def content_assets
  @content_assets ||= Resources::ContentAssets.new(uri, connection)
end

#content_entries(content_type) ⇒ Object



50
51
52
53
# File 'lib/locomotive/coal/client.rb', line 50

def content_entries(content_type)
  @content_entries ||= {}
  @content_entries[content_type.slug] ||= Resources::ContentEntries.new(uri, connection, content_type)
end

#content_typesObject Also known as: contents



44
45
46
# File 'lib/locomotive/coal/client.rb', line 44

def content_types
  @content_types ||= Resources::ContentTypes.new(uri, connection)
end

#current_siteObject



36
37
38
# File 'lib/locomotive/coal/client.rb', line 36

def current_site
  @current_site ||= Resources::CurrentSite.new(uri, connection)
end

#engine_versionObject Also known as: version



75
76
77
# File 'lib/locomotive/coal/client.rb', line 75

def engine_version
  @engine_version ||= Resources::EngineVersion.new(uri, connection).version
end

#membershipsObject



32
33
34
# File 'lib/locomotive/coal/client.rb', line 32

def memberships
  @memberships ||= Resources::Memberships.new(uri, connection)
end

#my_accountObject



20
21
22
# File 'lib/locomotive/coal/client.rb', line 20

def 
  @my_account ||= Resources::MyAccount.new(uri, connection)
end

#pagesObject



40
41
42
# File 'lib/locomotive/coal/client.rb', line 40

def pages
  @pages ||= Resources::Pages.new(uri, connection)
end

#resetObject



89
90
91
# File 'lib/locomotive/coal/client.rb', line 89

def reset
  @token = @my_account = @sites = @current_site = @pages = @content_types = @theme_assets = @content_assets = @translations = nil
end

#scope_by(site_or_handle) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/locomotive/coal/client.rb', line 81

def scope_by(site_or_handle)
  if site_or_handle.respond_to?(:handle)
    @current_site, site_or_handle = site_or_handle, site_or_handle.handle
  end
  options[:handle] = site_or_handle
  self
end

#sectionsObject



67
68
69
# File 'lib/locomotive/coal/client.rb', line 67

def sections
  @sections ||= Resources::Sections.new(uri, connection)
end

#sitesObject



28
29
30
# File 'lib/locomotive/coal/client.rb', line 28

def sites
  @sites ||= Resources::Sites.new(uri, connection)
end

#snippetsObject



63
64
65
# File 'lib/locomotive/coal/client.rb', line 63

def snippets
  @snippets ||= Resources::Snippets.new(uri, connection)
end

#ssl?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/locomotive/coal/client.rb', line 93

def ssl?
  !!self.options[:ssl]
end

#theme_assetsObject



59
60
61
# File 'lib/locomotive/coal/client.rb', line 59

def theme_assets
  @theme_assets ||= Resources::ThemeAssets.new(uri, connection)
end

#tokenObject



16
17
18
# File 'lib/locomotive/coal/client.rb', line 16

def token
  @token ||= Resources::Token.new(uri, credentials).get
end

#translationsObject



71
72
73
# File 'lib/locomotive/coal/client.rb', line 71

def translations
  @translations ||= Resources::Translations.new(uri, connection)
end