Module: Prismic

Defined in:
lib/prismic.rb,
lib/prismic/api.rb,
lib/prismic/form.rb,
lib/prismic/version.rb,
lib/prismic/cache/lru.rb,
lib/prismic/predicates.rb,
lib/prismic/experiments.rb,
lib/prismic/json_parsers.rb,
lib/prismic/fragments/date.rb,
lib/prismic/fragments/link.rb,
lib/prismic/fragments/text.rb,
lib/prismic/with_fragments.rb,
lib/prismic/fragments/color.rb,
lib/prismic/fragments/embed.rb,
lib/prismic/fragments/group.rb,
lib/prismic/fragments/image.rb,
lib/prismic/fragments/number.rb,
lib/prismic/fragments/select.rb,
lib/prismic/fragments/slices.rb,
lib/prismic/fragments/fragment.rb,
lib/prismic/fragments/geopoint.rb,
lib/prismic/fragments/multiple.rb,
lib/prismic/fragments/separator.rb,
lib/prismic/fragments/timestamp.rb,
lib/prismic/fragments/boolean_field.rb,
lib/prismic/fragments/structured_text.rb,
lib/prismic/fragments/integration_field.rb

Defined Under Namespace

Modules: DefaultHTTPClient, Fragments, JsonParser, Predicates, WithFragments Classes: API, AlternateLanguage, BasicNullCache, Document, Error, Experiment, Experiments, Field, Form, HtmlSerializer, LinkResolver, LruCache, Ref, Response, SearchForm, Variation

Constant Summary collapse

'io.prismic.experiment'
'io.prismic.preview'
VERSION =
'1.8.2'
DefaultCache =

This default instance is used by the API to avoid creating a new instance per request (which would make the cache useless).

LruCache.new

Class Method Summary collapse

Class Method Details

.api(url) ⇒ API .api(url, opts) ⇒ API .api(url, access_token) ⇒ API

Return an API instance The access token and HTTP client can be provided.

The HTTP Client must responds to same method than DefaultHTTPClient.

Overloads:

  • .api(url) ⇒ API

    Simpler syntax (no configuration)

    Parameters:

    • url (String)

      The URL of the prismic.io repository

  • .api(url, opts) ⇒ API

    Standard use

    Parameters:

    • url (String)

      The URL of the prismic.io repository

    • opts (Hash)

      The options

    Options Hash (opts):

    • :access_token (String) — default: nil

      The access_token

    • :http_client (Object) — default: DefaultHTTPClient

      The HTTP client to use

    • :api_cache (Object) — default: nil

      The caching object for the /api endpoint cache (for instance Prismic::Cache) to use

    • :cache (Object) — default: nil

      The caching object (for instance Prismic::Cache) to use, or false for no caching

  • .api(url, access_token) ⇒ API

    Provide the access_token (only)

    Parameters:

    • url (String)

      The URL of the prismic.io repository

    • access_token (String)

      The access token

Returns:

  • (API)

    The API instance related to this repository

Raises:

  • PrismicWSConnectionError



65
66
67
68
69
70
71
72
# File 'lib/prismic.rb', line 65

def self.api(url, opts=nil)
  if (not url =~ /\A#{URI::regexp(['http', 'https'])}\z/)
    raise ArgumentError.new("Valid web URI expected")
  end
  opts ||= {}
  opts = {access_token: opts} if opts.is_a?(String)
  API.start(url, opts)
end

.html_serializer(&blk) ⇒ Object



681
682
683
# File 'lib/prismic.rb', line 681

def self.html_serializer(&blk)
  HtmlSerializer.new(&blk)
end

Build a LinkResolver instance The LinkResolver will help to build URL specific to an application, based on a generic prismic.io’s Document link.

Parameters:

  • ref (Ref)

    The ref to use

Yield Parameters:

Yield Returns:

  • (String)

    The application specific URL of the given document

Returns:



677
678
679
# File 'lib/prismic.rb', line 677

def self.link_resolver(ref, &blk)
  LinkResolver.new(ref, &blk)
end

.oauth_check_token(url, oauth_opts, api_opts = nil) ⇒ String

Check a token and return an access_token

This method allows to check the token received when the user has been redirected from the OAuth2 server. It returns an access_token that can be used to authenticate the user on the API.

Parameters:

  • url (String)

    The URL of the prismic.io repository

  • oauth_opts (Hash)

    The OAuth2 options

  • api_opts (Hash) (defaults to: nil)

    The API options (the same than accepted by the api method)

Options Hash (oauth_opts):

  • :client_id (String)

    The Application’s client ID

  • :redirect_uri (String)

    The Application’s secret

Returns:

  • (String)

    the access_token

Raises:

  • PrismicWSConnectionError



116
117
118
119
120
# File 'lib/prismic.rb', line 116

def self.oauth_check_token(url, oauth_opts, api_opts=nil)
  api_opts ||= {}
  api_opts = {access_token: api_opts} if api_opts.is_a?(String)
  API.oauth_check_token(url, oauth_opts, api_opts)
end

.oauth_initiate_url(url, oauth_opts, api_opts = nil) ⇒ String

Build the URL where the user can be redirected to authenticated himself using OAuth2. @note: The endpoint depends on the repository, so an API call is made to fetch it.

Parameters:

  • url (String)

    The URL of the prismic.io repository

  • oauth_opts (Hash)

    The OAuth2 options

  • api_opts (Hash) (defaults to: nil)

    The API options (the same than accepted by the api method)

Options Hash (oauth_opts):

  • :client_id (String)

    The Application’s client ID

  • :redirect_uri (String)

    The Application’s secret

  • :scope (String)

    The desired scope

Returns:

  • (String)

    The built URL

Raises:

  • PrismicWSConnectionError



93
94
95
96
97
# File 'lib/prismic.rb', line 93

def self.oauth_initiate_url(url, oauth_opts, api_opts=nil)
  api_opts ||= {}
  api_opts = {access_token: api_opts} if api_opts.is_a?(String)
  API.oauth_initiate_url(url, oauth_opts, api_opts)
end