Coder Social home page Coder Social logo

ruby-kit's Introduction

Ruby development kit for prismic.io

Gem Version Build Status

Getting Started

The prismic kit is compatible with Ruby 1.9.3 or later.

Install the kit for your project

(Assuming that Ruby is installed on your computer, as well as RubyGems)

To install the gem on your computer, run in shell:

gem install prismic.io --pre

then add in your code:

require 'prismic'

To add the gem as a dependency to your project with Bundler, you can add this line in your Gemfile:

gem 'prismic.io', require: 'prismic'

Get started

The quickstart is not available for Ruby yet, but if you understand Javascript you can easily adapt the code.

Configuring Alternative API Caches

The default cache stores data in-memory, in the server. You may want to use a different cache, for example to share it between several servers (with memcached or similar). A null cache (does no caching) is also available if you need a predictible behavior for testing or VCR. To use it (or any other compliant cache), simply add api_cache: Prismic::BasicNullCache.new to the options passed to Prismic.api.

Changelog

Need to see what changed, or to upgrade your kit? We keep our changelog on this repository's "Releases" tab.

Install the kit locally

Of course, you're going to need Ruby installed on your computer, as well as RubyGems and Bundler.

Clone the kit, then run bundle install.

Test

Please write tests for any bugfix or new feature, by placing your tests in the spec/ folder, following the RSpec syntax. Launch the tests by running rspec

If you find existing code that is not optimally tested and wish to make it better, we really appreciate it; but you should document it on its own branch and its own pull request.

Documentation

Please document any bugfix or new feature, using the Yard syntax. Don't worry about generating the doc, we'll take care of that.

If you find existing code that is not optimally documented and wish to make it better, we really appreciate it; but you should document it on its own branch and its own pull request.

Contributing

We hope you'll get involved! Read our Contributors' Guide for details.

Licence

This software is licensed under Apache 2.0 license

Copyright 2013-2021 Prismic [email protected] (https://prismic.io)

ruby-kit's People

Contributors

alistairholt avatar alterenzo avatar angeloashmore avatar arnaudlewis avatar brettchalupa avatar cooknat avatar dependabot[bot] avatar dinduks avatar dohzya avatar erwan avatar faresd avatar francois2metz avatar levimykel avatar marcmcintosh avatar mbrung avatar orlezio avatar patrickae avatar raph22 avatar rudyrigot avatar smd686s avatar spnkr avatar srenault avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ruby-kit's Issues

Test feature request, testing webhooks

Is your feature request related to a problem? Please describe.

Describe the solution you'd like

Describe alternatives you've considered

Additional context

Problem with OAuth : accessing releases

Honestly, I'm not sure it comes from the kit, it could be me forgetting a step somewhere.

I have a working website based on a public API, everything works fine.

I add an application, and make sure its token allows access to master + releases:
screen shot 2013-11-25 at 9 08 35 am

I've edited the prismic.yml file, and have restarted the server in case it need to parse it upon booting:
screen shot 2013-11-25 at 9 09 58 am

I can now signin to prismic.io on my website, and get the selectbox to change releases, but it doesn't list any release in there (and there is one pending, with changes pushed onto it)
screen shot 2013-11-25 at 9 12 28 am

I tried copy-pasting the "Permanent access token" field from the settings into the token field in prismic.yml; all it did is that I now get the selectbox all the time (I don't need to sign in), but without any releases either.

Is there anything I'm doing wrong?

Ruby 2.7 deprecation warnings

1.8.0 version of the gem still relies on deprecated URI.unescape method. Running the gem with Ruby 2.7.0+ with default warnings settings, outputs at every execution of json_parsers this line:
ruby/gems/2.7.0/gems/prismic.io-1.8.0/lib/prismic/json_parsers.rb:60: warning: is obsolete

There's an open PR addressing that, any plans on merging it and releasing a new version?

Recent merge breaks specs?

Am working on a potential PR (to add option for null api cache to aid ruby projects that use VCR) and after pull of recent merge (3285f6d), specs break because of undefined local variable or method `token_cache' for Prismic::API:Class at line 128 of lib/prismic/api.rb

Bug: Release without description causes error in Prismic Ruby client

If you create a Release without a description, which is possible by Publishing a document and choosing "Publish at a specific date and time", the ref returned by Prismic's API will have a null label and the Prismic client will fail to parse the entire response.

https://github.com/prismicio-community/ruby-kit/blob/1.7.0/lib/prismic/api.rb#L222

Found this in version 1.7.0, but still appears to be an issue on master. This line will fail with a "NoMethodError: undefined method `downcase' for nil:NilClass" ruby-kit/api.rb at 1.7.0 · prismicio-community/ruby-kit · GitHub 1

Versions

  • ruby-kit:
  • gem version:

Reproduction

Additional Details

https://community.prismic.io/t/release-without-description-causes-error-in-prismic-ruby-client/7514


Steps to reproduce

What is Expected?

What is actually happening?

undefined method `link_to' for #<Prismic::Ref:0x00000005995f20>

Hi. I have an article which has references.

However, having the article and calling the method as_html(api.master_ref) I get the following error: undefined methodlink_to' for #Prismic::Ref:0x00000005995f20`. I suspect that I have to add a custom link_resolver so that all documents have my website's base url. However, I haven't found anything relevant in your API or ruby-kit documentation. The only thing I managed to do is to add a custom link_to method in Prismic::Ref object that maps to my website like:

ref.class.send(:define_method, :link_to, ->(link) { "#{link.type.pluralize}/#{link.slug}" })

I guess the proc body could be a class or my custom link_resolver method. But I am wondering, is this the way to go?

undefined method `parse' for Time:Class (NoMethodError)

Getting the following error:

/Users/allaire/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/prismic.io-1.6.1/lib/prismic/json_parsers.rb:272:in `document_parser': undefined method `parse' for Time:Class (NoMethodError)

Solution is to add require time to json_parsers.rb or to add it in my script.

Script:

require 'prismic'

api = Prismic.api('...')
response = api.query(Prismic::Predicates.at("document.type", "landings"))
documents = response.results

p documents

IntegrationFields support

I'm using the beta IntegrationFields functionality in my repo, and ruby-kit doesn't support it (there's no FragmentParser for the type) - throws a NoMethodError.

JSON Parsers Error

Hi,

I'm getting an undefined method 'call' for nil:NilClass when trying a simple query. The strange thing is that everything works fine using v1.1.0 but we need to use >1.3 because we want to take advantage of slices.

Code

    api = Prismic.api('https://MYDOMAIN.prismic.io/api')
    response = api
        .form('everything')
        .query(Prismic::Predicates::at('document.type', 'page'))
        .submit(api.master_ref)

Relevant Stack Trace

/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:197:in `block (2 levels) in group_parser'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:197:in `each'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:197:in `map'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:197:in `block in group_parser'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:196:in `each'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:196:in `group_parser'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:215:in `call'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:215:in `fragment_parser'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:206:in `block in slices_parser'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:205:in `each'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:205:in `slices_parser'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:215:in `call'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:215:in `fragment_parser'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:233:in `block in document_parser'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:232:in `each'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:232:in `map'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:232:in `document_parser'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:248:in `block in results_parser'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:247:in `map'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:247:in `results_parser'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic/json_parsers.rb:262:in `response_parser'
/home.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/prismic.io-1.3.2/lib/prismic.rb:271:in `submit'

Threadsafe?

I don't think the kit is threadsafe, which is not a big issue since threads are not idiomatic in Ruby, but still, some may want to use them, we could check what it needs to fix that.

Missing data when doing .as_json

Hey,

When I try to see my structured text data as json it shows it like that

["bio", {"blocks"=>[{"text"=>"Italic Test", "spans"=>[], "label"=>nil}, {"text"=>"Preformatted test", "spans"=>[], "label"=>nil}, {"text"=>"Bold Test", "spans"=>[{"start"=>0, "end"=>9}], "label"=>nil}]}]

As you can see, I does not show all the informations (span types, text type) like the api page says it is suppose to return.

Am i doing this incorrectly?

@documents.each do |doc|
  = doc.as_json

Thanks!

Label Spans within paragraphs are Failing

Spans with the new type of 'label' are failing. The issue seems to be in

module Prismic
  module JsonParser
    class << self

      def structured_text_parser(json)
        def self.span_parser(span)
          case span['type']
          when 'em'
            Prismic::Fragments::StructuredText::Span::Em.new(span['start'], span['end'], span['label'])
          when 'strong'
            Prismic::Fragments::StructuredText::Span::Strong.new(span['start'], span['end'], span['label'])
          when 'hyperlink'
            Prismic::Fragments::StructuredText::Span::Hyperlink.new(span['start'], span['end'], link_parser(span['data']), span['label'])
          else
            puts "Unknown span_parser type: #{span['type']}"
          end
        end

I've monkeypatched the ruby kit to create a generic tag:

module Prismic
  module JsonParser
    class << self

      def structured_text_parser(json)
        def self.span_parser(span)
          case span['type']
          when 'em'
            Prismic::Fragments::StructuredText::Span::Em.new(span['start'], span['end'], span['label'])
          when 'strong'
            Prismic::Fragments::StructuredText::Span::Strong.new(span['start'], span['end'], span['label'])
          when 'hyperlink'
            Prismic::Fragments::StructuredText::Span::Hyperlink.new(span['start'], span['end'], link_parser(span['data']), span['label'])
          when 'label'
            Prismic::Fragments::StructuredText::Span::SpanTag.new(span['start'], span['end'], span['data']['label'])
          else
            puts "Unknown span_parser type: #{span['type']}"
          end
        end

        blocks = json['value'].map do |block|
          case block['type']
          when 'paragraph'
            spans = block['spans'].map {|span| span_parser(span) }
            Prismic::Fragments::StructuredText::Block::Paragraph.new(block['text'], spans, block['label'])
          when 'preformatted'
            spans = block['spans'].map {|span| span_parser(span) }
            Prismic::Fragments::StructuredText::Block::Preformatted.new(block['text'], spans, block['label'])
          when /^heading(\d+)$/
            heading = $1
            spans = block['spans'].map {|span| span_parser(span) }
            Prismic::Fragments::StructuredText::Block::Heading.new(
              block['text'],
              spans,
              heading.to_i,
              block['label']
            )
          when 'o-list-item'
            spans = block['spans'].map {|span| span_parser(span) }
            Prismic::Fragments::StructuredText::Block::ListItem.new(
              block['text'],
              spans,
              true,  # ordered
              block['label']
            )
          when 'list-item'
            spans = block['spans'].map {|span| span_parser(span) }
            Prismic::Fragments::StructuredText::Block::ListItem.new(
              block['text'],
              spans,
              false,  # unordered
              block['label']
            )
          when 'image'
            view = Prismic::Fragments::Image::View.new(
              block['url'],
              block['dimensions']['width'],
              block['dimensions']['height'],
              block['alt'],
              block['copyright'],
              block['linkTo'] ? link_parser(block['linkTo']) : nil
            )
            Prismic::Fragments::StructuredText::Block::Image.new(view, block['label'])
          when 'embed'
            boembed = block['oembed']
            Prismic::Fragments::Embed.new(
              boembed['type'],
              boembed['provider_name'],
              boembed['provider_url'],
              boembed['html'],
              boembed
            )
          else
            puts "Unknown bloc type: #{block['type']}"
          end
        end
        Prismic::Fragments::StructuredText.new(blocks)
      end

    end
  end
end

module Prismic
  module Fragments
    class StructuredText < Fragment

      class Span

        class SpanTag < Span
          def serialize(text, link_resolver = nil)
            "<span#{class_code}>#{text}</span>"
          end
        end

      end

    end
  end
end

Thoughts? I'd like to see if the tag approach is worth submitting a pull request.

Best,

Sean

Kaminari Pagination

I use Kaminari for pagination. A simple monkeypatch helped get the results to work correctly:

module Prismic
  class Documents
    def current_page
      @page
    end
    def limit_value
      @results_per_page
    end
  end
end

Might be good to bake in. Thanks!

Predicates ignored when a form AND predicates are used

Basically, when you write something like:
@api.create_search_form("products").query(%([[:d = any(document.tags, ["Cupcake", "Macaron"])]])).submit(@master_ref).size.should == 11
the query method is simply ignored (all the documents matching the form are returned no matter what additional predicates are submitted inside query).

The origin is the same problem described in issue #3 of the JS kit, simply the two kits react differently:

  • in JS, the extra q is pushed into an array which makes it an array of two items, and two q URL parameters are sent, which returns a 500.
  • in Ruby, adding a predicate is done through a SearchForm::set method, which handles a Hash, so there can only be one value at a time.

I'm waiting for the answer on how to handle it in JS to fix it here the same way; I'm working on it on a branch I've only pushed on my GitHub fork so far, and I've written it as a test that fails for now, as it should (the test works by calling the real LesBonnesChoses API, to make sure it's happening in the real world).

Default LRU cache expires data in 5 seconds

Found at https://github.com/prismicio/ruby-kit/blob/master/lib/prismic/api.rb#L177

# Fetch the API information from the Prismic.io server
...
api_cache.get_or_set(cache_key, nil, 5) {
... # Calls the API here
}
...

If Prismic users use the default cache (Prismic::LruCache), this line will instruct that LRU cache to expire data in 5 seconds, which IMO doesn't make sense. The LRU cache should fill up until it's defined maximum (which is 100 keys by default) and when it's full just discard the LRU key. From what I understand, these 5 seconds are used to prevent stale content, as the cache key used doesn't include the latest master ref.

I don't have a full understanding of the codebase, but I think this cache could be much better if the cache key would only include the API ref and not expire data at all, especially lower-traffic sites like mine would benefit because as of now the default cache almost never gets any hits. I would be willing to work on a PR if you could hint me to the places in the code where the cache key is generated.

Wrong caching configuration options in Readme

To configure an alternative cache passing:api_cache option to Prismic.api initializer is not enough, my VCR-based specs keeps failing due to cache interactions unless I set :cache option key too.

Net::OpenTimeout (execution expired) errors when trying to access the API

Since 2021-05-20 I've been getting a bunch of timeouts Net::OpenTimeout (execution expired) when using this gem to access the Prismic API. These happen sporadically but frequently. I cannot reliably reproduce them, but I can reproduce them by just refreshing pages that rely on the Prismic API enough times.

The traceback on the error points to my init_api method which is simply:

def init_api
  Prismic.api(ENV['PRISMIC_URL'], ENV['PRISMIC_ACCESS_TOKEN'])
end

Most of the time this works fine but regularly it will fail. There is nothing in the Prismic status dashboard to indicate an issue with the API endpoint.

You can test this by going to https://www.littlefutures.org/blog and refreshing a bunch of times or trying to click into the various blog posts. Eventually one of them will timeout and 500.

Now, yes I should be handling these exceptions, but also, this never happened before 2021-05-20, I haven't changed any code on or around then. So I'm wondering what is going on. Any ideas?

Support "Slices" fragment type

Currently it looks like the ruby-kit doesn't support fragments of type "Slices". An error is thrown when a document is retrieved which contains such a fragment.

Make Rails generators

An idea for later: build generators into the Rails gem, in order to easily generate the extra code that is in the Rails starter kit into any existing Rails app: prismic_service.rb, prismic_helper.rb, prismic.yml, and the routes and controllers to handle OAuth2.

API V2 Support?

Currently tinkering with prismic on a rails app, and looks like this gem only supports api V1. I can't find any documentation regarding the change diff between API versions - are there any plans to update this gem to support v2 as well as v1?

Problem with OAuth : private API

Honestly, I'm not sure it comes from the kit, it could be me forgetting a step somewhere.

I have a working website based on a public API, everything works fine.

I add an application, and make sure its token allows access to master + releases:
screen shot 2013-11-25 at 9 08 35 am

I've edited the prismic.yml file, and have restarted the server in case it need to parse it upon booting:
screen shot 2013-11-25 at 9 09 58 am

I can now signin to prismic.io on my website, and get the selectbox to change releases.

Now, I'm switching my API from public to private in my settings, and now I'm getting this:
screen shot 2013-11-25 at 9 18 47 am

Is there anything I'm doing wrong?

support awesome_print

the api has a lot of nested data structures, and this is how it prints out:

image

should (:)) support awesome_print, like most ruby objects, so it looks more like this:

image

url method on Document?

Suddenly thinking, since now we can do documentLink.url(link_resolver(@maybe_ref)) instead of link_resolver(@maybe_ref).link_to(documentLink), maybe it would be cool to be able to do the same for Document (document.url(link_resolver(@maybe_ref)) instead of link_resolver(@maybe_ref).link_to(documentLink))? It's a bold choice, not sure what the implications would be.

On a broader topic, since passing a function is very different depending on the technology, there is no unified way to build a front-office URL from a Document or a DocumentLink object. Maybe we should make it a requirement for the other kits to implement a url method on Link and Document classes?

Today, the ways to do it seem to be (I didn't test those):

  • In Java:
    • for DocumentLink objects: prismic.linkResolver.resolveLink(documentLink);
    • for Document objects: prismic.linkResolver.resolveDocument(document);
  • In JavaScript:
    • for DocumentLink objects: ctx.linkResolver(ctx, docLink);, or docLink.url(ctx.linkResolver); actually is already there.
    • for Document objects: actually, not possible easily today.
  • In PHP:
    • for DocumentLink objects: $linkResolver.resolveLink($documentLink);
    • for Document objects: $linkResolver.resolveDocument($document);
  • In Scala:
    • for DocumentLink objects: ctx.linkResolver.apply(documentLink);
    • for Document objects: ctx.linkResolver.apply(documentLink);

Well, no matter what we do, we have to make all of them consistent. I say through a url method in Document and DocumentLink objects is a nice way, but I'm opened to be challenged about it. :)

EOF error when fetching documents with broken links

Hey, everyone!

My team uses the following code to fetch all documents in our Prismic repository:

client = Prismic.api('https://<my_repo_host>/api')
response = client.all({ 'page' => current_page, 'pageSize' => 100 })

This worked well us until we started getting EOF errors from the client.all call. After a little bit of digging around, I discovered that it was caused by a broken link in a single document:

image

For context, this was a Content Relationship field linking to a now-archived internal document.

Would it be possible to update this Gem to handle this a little more gracefully, like maybe adding a nested error field for the offending document or even just returning nil for its body? The alternative solution that we have is just querying documents one by one and skipping the document when we run into the EOFError, which is possible but not preferable.

Thanks in advance! I'm also happy to add more details if needed.

fetchLinks does not work when fetching a StructureText or Title field

I have a content relationship between a page and another document (Team page + Team Member document). On Team Member, I have two structured text fields (name and title) and an image.

I can load the image fine using a query like:

document = api.get_by_uid('team-page', 'team', { fetchLinks: "team-member.picture" })

However, I cannot load the title or name:

document = api.get_by_uid('team-page', 'team', { fetchLinks: "team-member.name" }) # throws an exception

This is because the parser + JSON response do not match. The parser expects a type like StructuredText for the field, but the JSON response only has "heading1" for the field. You can see the example response below.

It's unclear how exactly to fix the JSON parser in this case.

[{"id"=>"** SOME ID **",
    "uid"=>"team",
    "type"=>"team-page",
    "href"=>
     "** SOME URL **",
    "tags"=>[],
    "first_publication_date"=>"2018-02-09T09:58:18+0000",
    "last_publication_date"=>"2018-02-09T09:58:18+0000",
    "slugs"=>["team"],
    "linked_documents"=>nil,
    "lang"=>"en-us",
    "alternate_languages"=>[],
    "data"=>
     {"team-page"=>
       {"team-members"=>
         {"type"=>"Link.document",
          "value"=>
           {"document"=>
             {"id"=>"** SOME ID **",
              "type"=>"team-member",
              "tags"=>[],
              "lang"=>"en-us",
              "slug"=>"joe-smitch",
              "data"=>
               {"team-member"=>
                 {"job-title"=>
                   [{"type"=>"heading1",
                     "text"=>"Engineer",
                     "spans"=>[]}],
                  "name"=>
                   [{"type"=>"heading1",
                     "text"=>"Joe Smith",
                     "spans"=>[]}],
                  "picture"=>
                   {"type"=>"Image",
                    "value"=>
                     {"main"=>
                       {"dimensions"=>{"width"=>449, "height"=>449},
                        "alt"=>nil,
                        "copyright"=>nil,
                        "url"=>
                         "*** URL ***"},
                      "views"=>
                       {"thumbnail"=>
                         {"dimensions"=>{"width"=>300, "height"=>300},
                          "alt"=>nil,
                          "copyright"=>nil,
                          "url"=>
                           "*** URL ***"}}}}}}},
            "isBroken"=>false}}}}}],
 "version"=>"** SOME VERSION **",
 "license"=>"All Rights Reserved"}

Cannot install v1.8.1

I've noticed that v.1.8.1 of this gem was released in January (2 months+) but it is not available on Rubygems https://rubygems.org/gems/prismic.io

Did someone maybe forget to push the --tags? I'm not very familiar with what mechanism actually makes the next version available. So I apologise if I'm doing something stupid!

Anyhow, the end effect is that bundle install prismic.io with no other dependencies in a Gemfile with
source "https://rubygems.org"
installs version 1.8.0, not 1.8.1

Allowing private repositories

The behavior with private repositories has been for a while:

  1. if you configure only the client ID and client secret, you get a 402.
  2. if you configure also the token, then it works, but you're logged in even if you don't have the rights to be.

I think that the right way to do it is 1. but that a private API used not to return a valid token only from a client ID and a client secret. It looks like that has been fixed on the API side, it needs to be fixed on the kit's side.

Better errors on initialization

If you call Prismic.api and pass nil or an empty string "", the library fails with cryptic errors.

Prismic.api(nil) 
# => NoMethodError: undefined method `+' for nil:NilClass

Prismic.api("")
# => NoMethodError: undefined method `request_uri' for #<URI::Generic ?>

We ran into this problem when passing the API URL as an ENV var.

api = Prismic.api(ENV['PRISMIC_API_URL'])

The var didn't get set on deploy, and when the page loaded, we saw that first error. After some quick investigation, we realized the issue was an empty ENV var. However, I'd recommend adding a custom error. If you pass nil or an empty string, the library could throw a EmptyKeyError or something similar so it's way more clear what the error actually is.

api#get should cache response body instead of response object

api.rb:177 onwards reads:

      api_cache.get_or_set(cache_key, nil, 5) {
        res = http_client.get(url, data, 'Accept' => 'application/json')
        case res.code
        when '200'
          res

and later, line 207 onwards:

      resp = get(url, access_token, http_client, api_cache)
      json = JSON.load(resp.body)

This works with an in-memory cache, as the actual object is stored in memory.

This construct does not allow us to use a Redis-based cache, as Redis will store the string representation of the HTTP client's response (e.g. Net::HTTPOK) instead of the actual response's body.

Suggested change: have line 181 return res.body.

Is anyone maintaining this repo?

Is anyone maintaining this repo? I have just opened 2 PRs, one of them being an updated version of someone's PR from September.

FetchLinks demo can't work

Hello,

I'm trying to have this example working on my project :
https://prismic.io/docs/ruby/query-the-api/fetch-linked-document-fields

I have 2 custom types : "etude" and "auteur"

  • "etude" has a linkedDocument to "auteur" named "auteur"
  • "auteur" has several properties but I'm trying at least to get "nom" (StructuredText)

So when I try to get the study, it works :
study = Prismic.api('https://****.prismic.io/api').query(Prismic::Predicates.at('document.type', 'etude')}).results[0]

Then I added the fetchlink :
study = Prismic.api('https://****.prismic.io/api').query(Prismic::Predicates.at('document.type', 'etude'), {'fetchLinks' => 'auteur.nom'}).results[0]
I got an error pointing this line : undefined method "call' for nil:NilClass"

I tried to simply put "auteur" or "etude.auteur" and the error disapeared, but I'm unable to get the linked "auteur" as a top-level document. I tried those syntaxes, I always get an empty array or null :

  • author = study["etude.auteur-link"] --> null
  • author = study["etude.auteur"] --> []
  • author = study["auteur.nom"] --> null

I can't have it work. Do you have any idea ?

Thanks

Lost of data after modifying a Mask

Hi,

We have over 50 documents under a certain mask. One of the field was not being used by anything so we have decided to remove it from the mask.

Since then, I am unable to retrieve the datas from that mask. All the documents are being shown in the Prismic Dashboard. I am also able to retrieve my content from {my_prismic_url}/api by doing this simple query [:d = at(document.type, "my-mask")]. The same query is being used in our ruby implementation.

Once I updated a field of a document of my mask, I was able to retrieve that document. This is why I suspect the problem comes from the caching of the gem.

I have tried to setting the cache option to Prismic::BasicNullCache.new with no effects.

Could you guys give me a hand to figure out where the issue would come from? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.