https://github.com/norman-thomas/op_ex
Open Publishing API Wrapper in Elixir
https://github.com/norman-thomas/op_ex
api-wrapper elixir
Last synced: 22 days ago
JSON representation
Open Publishing API Wrapper in Elixir
- Host: GitHub
- URL: https://github.com/norman-thomas/op_ex
- Owner: norman-thomas
- Created: 2019-02-01T15:46:04.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-12T00:06:56.000Z (over 7 years ago)
- Last Synced: 2025-02-26T15:49:54.613Z (over 1 year ago)
- Topics: api-wrapper, elixir
- Language: Elixir
- Size: 31.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# op-ex
Light-weight Open Publishing API Wrapper in Elixir
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `op_ex` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:op_ex, "~> 0.1.0"}
]
end
```
## Usage
First, obtain an access or bearer token and create a new context via:
```elixir
# using access token
ctx = OpenPublishing.Context.new(access_token: "1_1R_3")
# or
# using bearer / auth token
ctx = OpenPublishing.Context.new(auth_token: "supersecrettoken")
```
### Loading a document
```elixir
doc = OpenPublishing.Object.Document.load(ctx, 1387, [":basic"])
IO.puts "ID: #{to_string(doc.id)}"
IO.puts "Title:" <> doc.title
IO.puts "Subtitle:" <> doc.subtitle
```
### Streaming events
```elixir
event_filters = [OpenPublishing.Event.Request.document_metadata_changed]
from = DateTime.from_iso8601("2018-01-01T00:00:00Z")
events =
ctx
|> OpenPublishing.Event.stream(:list_status, event_filters, from)
|> Stream.filter(fn event -> event.app_id == 0 end)
|> Stream.map(fn event -> event.reference_id end)
|> Enum.take(1000)
```