contentful-userland / contentful.ex Goto Github PK
View Code? Open in Web Editor NEWElixir SDK for the Contentful Delivery API
License: MIT License
Elixir SDK for the Contentful Delivery API
License: MIT License
I created the simplest possible get request and it fails.
@space_id MYSPACEID
@access_token MYACCESSTOKEN
entries = Contentful.Delivery.entries(@space_id, @access_token)
# Printing Content Type ID for every entry
Enum.each(entries, fn (entry) -> IO.puts(entry["sys"]["contentType"]["sys"]["id"]) end)
This is a known issue with the Hackney library used by HTTPoison.
I would recommend moving to HTTPotion (which is more portable) or simplehttp.
I am looking at building a simplehttp version.
Here is the stacktrace that was generated:
17:39:20.455 [debug] GET /spaces/MYSPACEID/entries
** (exit) exited in: :gen_fsm.sync_send_all_state_event(#PID<0.157.0>, {:start, 8000}, :infinity)
** (EXIT) an exception was raised:
** (ErlangError) Erlang error: :notsup
(crypto) crypto.erl:317: :crypto.block_encrypt/4
(ssl) ssl_cipher.erl:160: :ssl_cipher.aead_cipher/6
(ssl) ssl_record.erl:396: :ssl_record.cipher_aead/4
(ssl) tls_record.erl:143: :tls_record.encode_plain_text/4
(ssl) tls_connection.erl:357: :tls_connection.encode_handshake/4
(ssl) tls_connection.erl:109: :tls_connection.send_handshake/2
(ssl) ssl_connection.erl:1118: :ssl_connection.client_certify_and_key_exchange/2
(ssl) tls_connection.erl:466: :tls_connection.next_state/4
(stdlib) gen_fsm.erl:257: :gen_fsm.sync_send_all_state_event/3
(ssl) ssl_connection.erl:1656: :ssl_connection.sync_send_all_state_event/2
(ssl) ssl_connection.erl:103: :ssl_connection.handshake/2
(ssl) tls_connection.erl:82: :tls_connection.start_fsm/8
(ssl) ssl_connection.erl:73: :ssl_connection.connect/8
(hackney) d:/dev/Contentful/Tools/contentful_to_neo4j_ex/deps/hackney/src/hackney_connect.erl:247: :hackney_connect.do_connect/5
(hackney) d:/dev/Contentful/Tools/contentful_to_neo4j_ex/deps/hackney/src/hackney_connect.erl:37: :hackney_connect.connect/5
(hackney) d:/dev/Contentful/Tools/contentful_to_neo4j_ex/deps/hackney/src/hackney.erl:316: :hackney.request/5
iex(2)>
17:39:21.164 [error] ** State machine #PID<0.157.0> terminating
** Last message in was {:tcp, #Port<0.6653>,
<<247, 13, 1, 1, 11, 5, 0, 3, 130, 1, 1, 0, 162, 29, 105, 138, 10, 142, 196,
20, 131, 42, 42, 18, 77, 57, 39, 144, 78, 240, 141, 172, 210, 150, 98, 71,
54, 94, 146, 209, 250, 197, 147, 181, 55, 7, 101, 41, ...>>}
** When State == :certify
** Data == [data: [{'StateData',
{:state, :client, {#Reference<0.0.4.1153>, #PID<0.147.0>}, :gen_tcp,
:tls_connection, :tcp, :tcp_closed, :tcp_error, 'cdn.contentful.com', 443,
#Port<0.6653>,
{:ssl_options, :tls, [{3, 3}, {3, 2}, {3, 1}, {3, 0}], :verify_peer,
{&:ssl_verify_hostname.verify_fun/3,
[check_hostname: 'cdn.contentful.com']},
#Function<0.104464233/1 in :hackney_connect.ssl_opts_1/2>, false, false,
:undefined, 99, "", '', "", '', '', '', "", '', :undefined,
:undefined, '', '',
[<<192, 44>>, <<192, 48>>, <<192, 36>>, <<192, 40>>, <<192, 8>>,
<<192, 46>>, <<192, 50>>, <<192, 38>>, <<192, 42>>, <<0, 163>>,
<<0, 106>>, <<0, 157>>, <<0, ...>>, <<...>>, ...],
#Function<2.27451488/4 in :ssl.handle_options/1>, true, 268435456, true,
true, :undefined, false, :undefined, :undefined, :undefined, :undefined,
true, :undefined, [], ...}, {:socket_options, :binary, :raw, 0, 0, false},
'', '', '', 36886, '', 57369, :ssl_session_cache,
{:ssl_crl_cache, {{49173, 53268}, []}}, {3, 3}, false, :ecdhe_rsa,
{:undefined, :undefined}, :undefined, :undefined, '', '', '',
:undefined, '', '', '', 40983, #Reference<0.0.4.1156>, :undefined,
'', {false, :first}, {#PID<0.147.0>, #Reference<0.0.4.1154>},
#Reference<0.0.4.1158>, {[], []}, false, true, false, false, :undefined,
:undefined, :undefined, ...}}]]
** Reason for termination =
** {:notsup,
[{:crypto, :block_encrypt, 4, [file: 'crypto.erl', line: 317]},
{:ssl_cipher, :aead_cipher, 6, [file: 'ssl_cipher.erl', line: 160]},
{:ssl_record, :cipher_aead, 4, [file: 'ssl_record.erl', line: 396]},
{:tls_record, :encode_plain_text, 4, [file: 'tls_record.erl', line: 143]},
{:tls_connection, :encode_handshake, 4,
[file: 'tls_connection.erl', line: 357]},
{:tls_connection, :send_handshake, 2,
[file: 'tls_connection.erl', line: 109]},
{:ssl_connection, :client_certify_and_key_exchange, 2,
[file: 'ssl_connection.erl', line: 1118]},
{:tls_connection, :next_state, 4, [file: 'tls_connection.erl', line: 466]}]}
How safe is that library for a production use ?
Are there features that are not covered by other SDK, say ruby or JS, that are not handled by the Elixir client ?
This is a bit of a stretch, but I'm wondering if there have been thoughts of RichText to HTML API? I'd like to avoid storing the JSON format and converting on the client.
One option is to utilize the Node.js library with a shell call, but keeping it native would be amazing.
I'm not opposed to building a native Elixir implementation, as it doesn't look like an excessively difficult format to work with. I just wanted to check to see if this has been thought about at all!
Hey Devs,
I have a Blogpost that contains one or more Authors. If I do:
Contentful.Delivery.entries(@space_id, @access_token)
I will get the content with the relations, but with nil:
%{"fields" => %{"author" => [nil, nil], "title" => "The article"
Even if I add the %{"include" => 2} as the search parameter, I will still get a nil. Is there another way to load the relations or am I doing it wrong?
excoveralls
integration and displaying the percentage somewhere - has been done in the context of of #27The endpoint is hard-coded to cdn.contentful.com which only shows entries that have been published. By making it a run-time config, one can set the endpoint to preview.contentful.com and retrieve entries that are in draft state.
I received a tweet to the release of v0.2.0
from @hukl that rightfully askes for the filter
and include
options originally present in v0.1.1
:
# v0.0.1
entries = Contentful.Delivery.entries(space_id, access_token, %{
"content_type" => "categoryList",
"include" => 2
})
# v0.2.0
entries = Contentful.Delivery.Entries.fetch_all([], space, "master", access_token)
I carelessly dropped this feature and it needs to be readded in a compatible fashion.
I added dialyxir
in kind of a rush to get typespecs in and then added typespecs all over the place, without paying too much attention to what dialyzer
actually complains about.
dialyzer
(run mix dialyxir --format elixir
Right now there's no way to specify what locale should be used for the requested entities. Everything always comes back in the primary locale as defined in the Contentful interface.
After reading over asaaki/cmark.ex#49, I was wondering if integrating CircleCI really is the way to go, as the status seemed broken for forked repositories.
Just leaving this quick feature request here (cannot do it myself right now):
Let's add the following links to the README (and package also to the header section, next to description line):
Why should we do this? We already provide links to Contentful's API documentation, but don't give GitHub users quick(er) access to the hex package and documentation pages.
#goodFirstContribution
In previous versions, the map that has been replaced with Contentful.SysData
contained a number of important fields. These included:
...
sys: %{
contentType: %{
sys: %{
id: "<content-type-from-model>", # for example: "author"
...
}
},
createdAt: "<created-timestamp>",
updatedAt: "<updated-timestamp>",
locale: "<locale-string>", # eg: "en-GB",
...
}
...
I'd like to update to the latest Contentful version, but my system is reliant on these fields.
Can these fields be returned to the Contentful.Entry
/Contentful.Asset
or Contentful.SysData
structs?
The production endpoint seems to be returning a map with the following attributes:
%{
"fields" => %{
"file" => %{
"contentType" => "image/png",
"details" => %{
"image" => %{"height" => 2000, "width" => 3000},
"size" => 7423579
},
"fileName" => "foo-bar.png",
"url" => "//images.ctfassets.net/.../.../.../foo-bar.png"
},
"title" => "foo-bar"
},
"sys" => %{
"createdAt" => "2020-01-08T11:44:33.417Z",
"environment" => %{
"sys" => %{
"id" => "master",
"linkType" => "Environment",
"type" => "Link"
}
},
"id" => "...",
"locale" => "en-GB",
"revision" => 1,
"space" => %{
"sys" => %{
"id" => "...",
"linkType" => "Space",
"type" => "Link"
}
},
"type" => "Asset",
"updatedAt" => "2020-01-08T11:44:33.417Z"
}
}
But the function expects a minimum of:
%{
"fields" => %{
"description" => desc,
"file" => %{
"contentType" => content_type,
"details" => details,
"fileName" => file_name,
"url" => url
},
"title" => title
},
"sys" => %{"id" => id, "revision" => rev}
}
It seems the production endpoint isn't returning a description
for the Assets, which causes this function to break. Removing the "description" => desc,
line resolves the issue.
Unless I'm missing something, it doesn't appear to be possible to query Entries
with things like the equality operator (https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/equality-operator).
I have an existing query using the 0.1.1 version of this gem that I'm trying to port to 0.3.0. It appears that https://github.com/contentful-labs/contentful.ex/blob/bbf75f30fe371cceffaa00e75c31d780f94425dc/lib/contentful_delivery/delivery.ex#L277 will filter out anything else I try to add to the request.
I have a blog post -> author -> image
relationship. When requesting the blog post, both the author and images show up in the includes
field in the resposne, but the resolve logic in this library doesn't flatten it out properly, and then image source is lost.
VCR'd Fixture: https://gist.github.com/stavro/fb38c303017549feb07e51f4b7665eb0
Expected: Be able to access the author's image.
Actual: Image is not available after this library parses the response. It is in the response though.
Apparently, the actions/setup-elixir
currently runs into trouble when installing Erlang.
The actions/setup-elixir
repo is currently unmaintained (as the Erlang foundation took over). It's recommended to switch to erlef/setup-beam
instead,
We have used it on other projects internally at contentful, so we might want to add it here as well to keep dependencies up to date.
I just implemented this library on a project and ran into a couple issues.
Contentful.Delivery.entries
expects ["items"]
always to be present in the returned response.
access_token
or space_id
the contentful throws a 401 & 404 respectively. Both of which are not handled and the function throws a KeyError
exception.Contentful.Delivery.entries
only does not return the total
& skip
keys returned by the contentful API, which makes it impossible to do pagination properly.I'm planning to submit a PR to address both of these issues, if it's something you'd be interested in.
Might be a good idea to add inch.
If Contentful.ex switched to Tesla, this would enable users to choose which underlying HTTP library to use by defining an Adapter. For example, a team could choose to use Finch (instead of the current HTTPoison) because it is already in use and they want to ensure consistency.
Tesla would also allow teams to include middleware, such as tesla_statsd
, to help monitor their request volume.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.