scrapy_cloud_ex v0.1.1 ScrapyCloudEx.Endpoints.App.Comments View Source

Wraps the Comments endpoint.

The comments API lets you add comments directly to scraped data, which can later be viewed on the items page.

Link to this section Summary

Types

A comment

Functions

Archives a single comment

Retrieves comments for a job, optionally indexed by item or item/field

Updates a single comment by id

Retrieves the number of items with unarchived comments by job

Link to this section Types

Link to this type comment() View Source
comment() :: %{required(String.t()) => integer() | boolean() | String.t()}

A comment.

Map with the following keys:

  • "id" - the comment id (integer/0).
  • "text" - the comment text (String.t/0).
  • "created" - the created date (String.t/0).
  • "archived" - the archived date (or nil if not archived) (String.t/0).
  • "author" - the comment author (String.t/0).
  • "avatar" - the gravatar URL for the author (String.t/0).
  • "editable" - a boolean value indicating whether the comment can be edited (boolean/0).

Link to this section Functions

Archives a single comment.

The id must be a comment id, or have at least 4 sections (i.e. refer to an item).

The opts value is documented here.

See docs regarding deleting by comment id (DELETE method) or by item/field identifier (DELETE method).

Examples

ScrapyCloudEx.Endpoints.App.Comments.delete("API_KEY", 456789)
ScrapyCloudEx.Endpoints.App.Comments.delete("API_KEY", "14/13/12/11")
ScrapyCloudEx.Endpoints.App.Comments.delete("API_KEY", "14/13/12/11/logo")
Link to this function get(api_key, composite_id, opts \\ []) View Source
get(String.t(), String.t(), Keyword.t()) ::
  ScrapyCloudEx.result(%{required(String.t()) => [comment()]})

Retrieves comments for a job, optionally indexed by item or item/field.

The composite_id must have at least 3 sections (i.e. refer to a job). When using an id with 4 sections (i.e. refering to an item), the comments for fields within that item will also be returned.

The return values will be a map whose keys are strings indicating the item index/field identifier (e.g. "11", "11/logo").

The opts value is documented here.

See docs here and here (GET method).

Examples

# Retrieve all comments for project 14, spider 13, job 12
ScrapyCloudEx.Endpoints.App.Comments.get("API_KEY", "14/13/12")

# Retrieve comments for item at index 11 (including comments on its fields)
# for project 14, spider 13, job 12
ScrapyCloudEx.Endpoints.App.Comments.get("API_KEY", "14/13/12/11")

# As above, but retrieve only comment for field "logo"
ScrapyCloudEx.Endpoints.App.Comments.get("API_KEY", "14/13/12/11/logo")
Link to this function post(api_key, composite_id, params \\ [], opts \\ []) View Source

Creates a single comment.

The composite_id must have at least 4 sections (i.e. refer to an item).

The following parameters are supported in the params argument:

  • :text - the comment text.

The opts value is documented here.

See docs (POST method).

Examples

ScrapyCloudEx.Endpoints.App.Comments.post("API_KEY", "14/13/12/11", text: "some text")
ScrapyCloudEx.Endpoints.App.Comments.post("API_KEY", "14/13/12/11/logo", text: "some text")
Link to this function put(api_key, id, params \\ [], opts \\ []) View Source

Updates a single comment by id.

The id is a numerical id, as returned e.g. by get/3 or post/4 and NOT a binary index/field identifier (such as "11/logo").

The following parameters are supported in the params argument:

  • :text - the comment text.

The opts value is documented here.

See docs (PUT method).

Example

ScrapyCloudEx.Endpoints.App.Comments.put("API_KEY", 123456, text: "foo bar")
Link to this function stats(api_key, project_id, opts \\ []) View Source

Retrieves the number of items with unarchived comments by job.

Returns a map containing job ids as keys, and unarchived comment counts as values. Only jobs with unarchived comments are present in the map.

The opts value is documented here.

See docs.

Example

ScrapyCloudEx.Endpoints.App.Comments.stats("API_KEY", "123")
# {:ok, %{"123/1/4" => 1}}