--- !ruby/object:Gem::Specification name: wcc-contentful version: !ruby/object:Gem::Version version: 0.3.0.pre.rc platform: ruby authors: - Watermark Dev autorequire: bindir: bin cert_chain: [] date: 2018-10-12 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: dotenv requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '2.2' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '2.2' - !ruby/object:Gem::Dependency name: httplog requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.0' - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '10.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '10.0' - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '3.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '3.0' - !ruby/object:Gem::Dependency name: rspec_junit_formatter requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 0.3.0 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 0.3.0 - !ruby/object:Gem::Dependency name: vcr requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '4.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '4.0' - !ruby/object:Gem::Dependency name: webmock requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '3.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '3.0' - !ruby/object:Gem::Dependency name: generator_spec requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 0.9.4 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 0.9.4 - !ruby/object:Gem::Dependency name: rails requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '5.1' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '5.1' - !ruby/object:Gem::Dependency name: rspec-rails requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '3.7' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '3.7' - !ruby/object:Gem::Dependency name: sqlite3 requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: timecop requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 0.9.1 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 0.9.1 - !ruby/object:Gem::Dependency name: contentful requirement: !ruby/object:Gem::Requirement requirements: - - '=' - !ruby/object:Gem::Version version: 2.6.0 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - '=' - !ruby/object:Gem::Version version: 2.6.0 - !ruby/object:Gem::Dependency name: contentful-management requirement: !ruby/object:Gem::Requirement requirements: - - '=' - !ruby/object:Gem::Version version: 2.0.2 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - '=' - !ruby/object:Gem::Version version: 2.0.2 - !ruby/object:Gem::Dependency name: graphql requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.7' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.7' - !ruby/object:Gem::Dependency name: http requirement: !ruby/object:Gem::Requirement requirements: - - ">" - !ruby/object:Gem::Version version: '1.0' - - "<" - !ruby/object:Gem::Version version: '3.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">" - !ruby/object:Gem::Version version: '1.0' - - "<" - !ruby/object:Gem::Version version: '3.0' - !ruby/object:Gem::Dependency name: pg requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.0' - !ruby/object:Gem::Dependency name: typhoeus requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.3' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.3' - !ruby/object:Gem::Dependency name: activesupport requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '5' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '5' - !ruby/object:Gem::Dependency name: dry-validation requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 0.11.1 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 0.11.1 - !ruby/object:Gem::Dependency name: wcc-base requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 0.3.1 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 0.3.1 description: Contentful API wrapper library exposing an ActiveRecord-like interface email: - dev@watermark.org executables: [] extensions: [] extra_rdoc_files: [] files: - ".rspec" - Gemfile - README.md - app/controllers/wcc/contentful/application_controller.rb - app/controllers/wcc/contentful/webhook_controller.rb - app/jobs/wcc/contentful/delayed_sync_job.rb - app/jobs/wcc/contentful/webhook_enable_job.rb - bin/console - bin/rails - bin/rspec - bin/setup - config/initializers/mime_types.rb - config/routes.rb - lib/wcc/contentful.rb - lib/wcc/contentful/client_ext.rb - lib/wcc/contentful/configuration.rb - lib/wcc/contentful/content_type_indexer.rb - lib/wcc/contentful/engine.rb - lib/wcc/contentful/exceptions.rb - lib/wcc/contentful/graphql.rb - lib/wcc/contentful/graphql/builder.rb - lib/wcc/contentful/graphql/types.rb - lib/wcc/contentful/helpers.rb - lib/wcc/contentful/indexed_representation.rb - lib/wcc/contentful/model.rb - lib/wcc/contentful/model_builder.rb - lib/wcc/contentful/model_methods.rb - lib/wcc/contentful/model_singleton_methods.rb - lib/wcc/contentful/rails.rb - lib/wcc/contentful/services.rb - lib/wcc/contentful/simple_client.rb - lib/wcc/contentful/simple_client/http_adapter.rb - lib/wcc/contentful/simple_client/management.rb - lib/wcc/contentful/simple_client/response.rb - lib/wcc/contentful/simple_client/typhoeus_adapter.rb - lib/wcc/contentful/store.rb - lib/wcc/contentful/store/base.rb - lib/wcc/contentful/store/cdn_adapter.rb - lib/wcc/contentful/store/lazy_cache_store.rb - lib/wcc/contentful/store/memory_store.rb - lib/wcc/contentful/store/postgres_store.rb - lib/wcc/contentful/sys.rb - lib/wcc/contentful/version.rb - wcc-contentful.gemspec homepage: https://github.com/watermarkchurch/wcc-contentful/wcc-contentful licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '2.3' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">" - !ruby/object:Gem::Version version: 1.3.1 requirements: [] rubyforge_project: rubygems_version: 2.6.11 signing_key: specification_version: 4 summary: '[![Gem Version](https://badge.fury.io/rb/wcc-contentful.svg)](https://badge.fury.io/rb/wcc-contentful) [![CircleCI](https://circleci.com/gh/watermarkchurch/wcc-contentful.svg?style=svg)](https://circleci.com/gh/watermarkchurch/wcc-contentful) Full documentation: https://www.rubydoc.info/github/watermarkchurch/wcc-contentful # WCC::Contentful ## Installation Add this line to your application''s Gemfile: ```ruby gem ''wcc-contentful'', require: ''wcc/contentful/rails'' ``` And then execute: $ bundle Or install it yourself as: $ gem install wcc-contentful ## Configure ```ruby WCC::Contentful.configure do |config| config.access_token = config.space = end WCC::Contentful.init! ``` ## Usage ### WCC::Contentful::Model API The WCC::Contentful::Model API exposes Contentful data as a set of dynamically generated Ruby objects. These objects are based on the content types in your Contentful space. All these objects are generated by WCC::Contentful.init! The following examples show how to use this API to find entries of the `page` content type: ```ruby # Find objects by id WCC::Contentful::Model::Page.find(''1E2ucWSdacxxf233sfa3'') # => # # Find objects by field WCC::Contentful::Model::Page.find_by(slug: ''/some-slug'') # => # # Use operators to filter by a field # must use full notation for sys attributes (except ID) WCC::Contentful::Model::Page.find_all(''sys.created_at'' => { lte: Date.today }) # => [#, ... ] # Nest queries to mimick joins WCC::Contentful::Model::Page.find_by(subpages: { slug: ''/some-slug'' }) # => # # Pass the preview flag to use the preview client (must have set preview_token config param) preview_redirect = WCC::Contentful::Model::Redirect.find_by({ slug: ''draft-redirect'' }, preview: true) # => # preview_redirect_object.href # => ''http://www.somesite.com/slug-for-redirect'' ``` See the {WCC::Contentful::Model} documentation for more details. ### Store API The Store layer is used by the Model API to access Contentful data in a raw form. The Store layer returns entries as hashes parsed from JSON, conforming to the object structure returned from the Contentful CDN. The following examples show how to use the Store API to retrieve raw data from the store: ```ruby store = WCC::Contentful::Services.instance.store # => # {"sys"=> # ... # "fields"=> # ...} store.find_by(content_type: ''page'', filter: { slug: ''/some-slug'' }) # => {"sys"=> # ... # "fields"=> # ...} query = store.find_all(content_type: ''page'').eq(''group'', ''some-group'') # => # {"sys"=> # ... # "fields"=> # ...} query.result # => # query.result.force # => [{"sys"=> ...}, {"sys"=> ...}, ...] ``` See the {WCC::Contentful::Store} documentation for more details. ### Direct CDN API (SimpleClient) The SimpleClient is the bottom layer, and is used to get raw data directly from the Contentful CDN. It handles response parsing and paging, but does not resolve links or transform the result into a Model class. The following examples show how to use the SimpleClient to retrieve data directly from the Contentful CDN: ```ruby client = WCC::Contentful::Services.instance.client # => # # "{\n \"sys\": {\n ... response.raw # => {"sys"=> # ... # "fields"=> # ...} client.asset(''5FsqsbMECsM62e04U8sY4Y'').raw # => {"sys"=> # ... # "fields"=> # ...} response = client.entries(''fields.group'' => ''some-group'', ''limit'' => 5) # => # 99 response.first # => {"sys"=> # ... # "fields"=> # ...} response.items => # response.items.count # Careful! This evaluates the lazy iterator and gets all pages # => 99 response.includes # => {"4xNnFJ77egkSMEogE2yISa"=> # {"sys"=> ...} # "6Fwukxxkxa6qQCC04WCaqg"=> # {"sys"=> ...} # ...} ``` The client handles Paging automatically within the lazy iterator returned by #items. This lazy iterator does not respect the `limit` param - that param is only passed through to the API to set the page size. Entries included via the `include` parameter are made available on the #includes field. This is a hash of ` => ` and makes it easy to grab links. This hash is added to lazily as you enumerate the pages. See the {WCC::Contentful::SimpleClient} documentation for more details. ### Accessing the APIs within application code The Model API is best exposed by defining your own model classes in the `app/models` directory which inherit from the WCC::Contentful models. ```ruby # app/models/page.rb class Page < WCC::Contentful::Model::Page # You can add additional methods here end # app/controllers/pages_controller.rb class PagesController < ApplicationController def show @page = Page.find_by(slug: params[:slug]) raise Exceptions::PageNotFoundError, params[:slug] unless @page end end ``` The {WCC::Contentful::Services} singleton gives access to the other configured services. You can also include the {WCC::Contentful::ServiceAccessors} concern to define these services as attributes in a class. ```ruby class MyJob < ApplicationJob include WCC::Contentful::ServiceAccessors def perform Page.find(...) store.find(...) client.entries(...) end end ``` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/watermarkchurch/wcc-contentful. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. ## License The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). ## Code of Conduct Everyone interacting in the WCC::Contentful project''s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/watermarkchurch/wcc-contentful/blob/master/CODE_OF_CONDUCT.md).' test_files: []