audience-kit 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8725e7f93ac02aff7ab3a98961b43ccc102bd32747589b7696656d936ef9703
4
- data.tar.gz: 642c773381040caeb6537d93c9a2a567a6f6642087a7ec46293965982e87b0ec
3
+ metadata.gz: 35a1a1f65b6a460df736aa90fbfc8a178e62f8e3f05601456da6631f1dde14e5
4
+ data.tar.gz: 91f55bbd8197fec40464c2cda4e315447480b509eb824c666e3c1d25d7cb804b
5
5
  SHA512:
6
- metadata.gz: 10efb35cc8a4537fd0434827265bcdd473e45b4ee8f0d6df0e0f71492205c1f9eda4953c08415623239c4b850f5caf04250adcd4561cad08e0a6000b3ef6d793
7
- data.tar.gz: 4458f0d02963b6a961aa3371d704094f14222cef2d398f2aaffef34b2b55a543c44c1a70aaf91b785ef52726e34c058dc5e1d4400eb8110c5193d377592665ed
6
+ metadata.gz: 9fcf65b2e8cb0f2a010fd3e445d1d9afabca5ecf9d8b464963b6e951dcfdba755ff59af441e9ec0b2d709b5371bb2506b58fbe1927eab0374e0a8f85fed59858
7
+ data.tar.gz: 11759564a2b06b6d6e29d0476e85944a5b7e3c718050b2d09176913de60b0c46500f18830a516cfa9e447bd4b4a3e512acdd33650fc71d4ea5e7a93233f16639
data/.yardopts ADDED
@@ -0,0 +1,8 @@
1
+ --markup markdown
2
+ --title "AudienceKit SDK for Ruby"
3
+ --readme README.md
4
+ --no-private
5
+ lib/**/*.rb
6
+ -
7
+ CHANGELOG.md
8
+ docs/*.md
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## [0.3.0] - 2026-11-26
2
+
3
+ A rewrite on the AudienceKit GraphQL API, with the same calls as the PHP, Node, Python, Swift and Kotlin SDKs. 0.2
4
+ read two REST endpoints the API no longer serves, so every 0.2 call fails; upgrade.
5
+
6
+ - Add `Audience::Kit::Session`: sign in with Facebook (token or OAuth code), Google, Sign in with Apple or an App
7
+ Review code, or use a service token (`akst_...`, renewed as needed) or an application API key; refresh, sign out
8
+ and delete the account
9
+ - Keep the credential in any store: `SessionCredentialStore` for Rails, Rack and Sinatra sessions,
10
+ `MemoryCredentialStore`, or an object of your own
11
+ - Read the audience, venues, people, locales, events, event series and the whole community in one call, with
12
+ queries shaped to the audience's modules
13
+ - Add the public listings, RSVP, tribes, device registration, cover and coat check, Soapbox news and op-eds,
14
+ calendar subscriptions, chat and moderation
15
+ - Add typed, read-only models (`Venue`, `Event`, `Person`, `Article`, `Admission`, `Money`...) that stay readable as
16
+ the API's JSON, and `Coordinate`, `Color` and `CoverPass`
17
+ - Every failure is an `Audience::Kit::Error` with a `code` from the API's vocabulary
18
+ - `Venue.find` and `Event.find` read over GraphQL with the module-level session, which now needs a host or audience
19
+ ID as well as the token; `AUDIENCEKIT_*` environment variables (the `AUDIENCE_KIT_*` names still work)
20
+ - Add guides (signing in, building a website, reference), runnable examples, YARD docs and RBS signatures
21
+
1
22
  ## [0.2.0] - 2026-11-25
2
23
 
3
24
  First release under the AudienceKit SDK License 1.2 (0.1.x were MIT), published from GitHub Actions with
data/README.md CHANGED
@@ -1,48 +1,193 @@
1
- # Audience::Kit
1
+ # AudienceKit for Ruby
2
2
 
3
- Ruby bindings for the AudienceKit API. Requires Ruby 3.2 or newer.
3
+ A Ruby 3.2+ client for the [AudienceKit](https://audiencekit.com) API, for Rails and Sinatra sites, jobs, bots and
4
+ scripts: sign a person in (or use an audience's API key or service token), then read the audience's venues, people,
5
+ locales, events, news, chat and cover charges with the same calls the Swift, Kotlin, Node, Python and PHP SDKs make, so
6
+ a site is built with little custom code. Part of the [AudienceKit SDK](../README.md) repository, versioned on its own.
4
7
 
5
8
  ## Installation
6
9
 
7
- Add this line to your application's Gemfile:
8
-
9
10
  ```ruby
10
- gem 'audience-kit'
11
+ # Gemfile
12
+ gem "audience-kit", "~> 0.3"
11
13
  ```
12
14
 
13
- And then execute:
15
+ ```sh
16
+ bundle install
17
+ ```
14
18
 
15
- $ bundle install
19
+ Or `gem install audience-kit`. The only dependency is [Faraday](https://lostisland.github.io/faraday/) 2.x, so the
20
+ gem works with whatever adapter your app already uses.
16
21
 
17
- Or install it yourself as:
22
+ ## Quick start
18
23
 
19
- $ gem install audience-kit
24
+ A script or job that reads an audience needs no sign-in, only a token an admin made in the audience's console: an
25
+ application API key for the GraphQL reads, or a service token (`akst_...`) with `public:read` for the public
26
+ listings. Put it in the environment:
20
27
 
21
- ## Usage
28
+ ```sh
29
+ export AUDIENCEKIT_TOKEN=... # never commit it
30
+ export AUDIENCEKIT_HOST=hotmess.social # names the audience; or AUDIENCEKIT_AUDIENCE_ID=<uuid>
31
+ ```
22
32
 
23
33
  ```ruby
24
34
  require "audience-kit"
25
35
 
36
+ session = Audience::Kit::Session.from_env
37
+
38
+ session.events.each do |event| # upcoming, soonest first
39
+ puts "#{event.start_at&.strftime("%a %-l:%M%P")} #{event.name} at #{event.venue_name || "TBA"}"
40
+ end
41
+ ```
42
+
43
+ A site that acts for a person signs them in first:
44
+
45
+ ```ruby
46
+ session = Audience::Kit::Session.new(
47
+ configuration: Audience::Kit::Configuration.new(
48
+ host: "hotmess.social", # names the audience; or audience_id: "<uuid>"
49
+ facebook_app_id: "123456789" # the Facebook app your login dialog uses
50
+ ),
51
+ store: Audience::Kit::SessionCredentialStore.new(session_hash) # Rails' session, Rack's, Sinatra's
52
+ )
53
+ device = Audience::Kit::DeviceDescription.new(identifier: browser_id)
54
+
55
+ # Facebook (a token or an OAuth code), Google, Sign in with Apple, or an App Review code...
56
+ session.sign_in_with_facebook_code(params[:code], redirect_uri: callback_url, device: device)
57
+
58
+ venue = session.venue_detail(session.venues.first.id) # with its profile, chat and upcoming events
59
+ event = session.events(venue_id: venue.id).first
60
+ session.rsvp_event(event.id, "ATTENDING")
61
+ session.send_chat_message("Hello from Ruby", venue_id: venue.id)
62
+
63
+ # Any operation of your own:
64
+ session.graphql("query Me { me { self { id name } } }")
65
+ ```
66
+
67
+ Read on:
68
+
69
+ - [Signing people in](docs/sign-in.md) on a Rails or Sinatra site: Facebook, Google, Apple, App Review codes, keeping
70
+ the session in the framework's session, signing out and deleting an account.
71
+ - [Building a website](docs/websites.md) from an audience: API keys and service tokens, public listings, the community
72
+ in one call, Soapbox news, calendar subscriptions, cover passes and caching.
73
+ - [Reference](docs/reference.md): every call, model and helper. The YARD reference is on
74
+ [RubyDoc.info](https://rubydoc.info/gems/audience-kit), and `bundle exec rake yard` builds it locally.
75
+ - [Examples](examples/README.md): runnable programs for a listings page, a news digest, member actions and a
76
+ community export.
77
+
78
+ ## What you get back
79
+
80
+ Every call returns a model (`Audience::Kit::Venue`, `Event`, `Person`, `Locale`, `Admission`, `Article`...) with
81
+ snake_case readers: times are `Time`, money is `Money` (`charge.total&.format # => "$12.00"`), points are
82
+ `Coordinate`, and yes-or-no fields end in `?` (`event.canceled?`, `venue.hidden?`). A model is also readable as the
83
+ API's JSON, so `venue["locale"]["name"]` works and fields the model has no reader for are still there; `to_h` and
84
+ `to_json` give you that Hash. Models are read-only.
85
+
86
+ Fields a module adds (Facebook Pages, Google Places, RSVP, People, Ticketing, Friends, Chat, Soapbox) are missing
87
+ where the audience hasn't installed that module: the SDK asks for them and, if the audience's schema doesn't have
88
+ one, asks the schema which fields it has and runs the query again with only those (cached for the session). The
89
+ matching readers return nil or an empty Array.
90
+
91
+ Every call carries `X-AudienceKit-Client`, `X-AudienceKit-API-Version` and, for staging builds,
92
+ `X-AudienceKit-Environment`. Requests go to the API instance the credential's `endpoint` names, so a credential
93
+ issued by the preview API talks to the preview API.
94
+
95
+ ### Errors
96
+
97
+ Every failure is an `Audience::Kit::Error`. Its `code` is one of the API's (`UNAUTHENTICATED`, `FORBIDDEN`,
98
+ `NOT_FOUND`, `INVALID` with per-field messages in `fields`, `RATE_LIMITED`, `CONFLICT`, `INTERNAL`) or the SDK's own
99
+ (`NOT_SIGNED_IN`, `SIGN_IN_REJECTED`, `NETWORK`, `DECODING`, `UPDATE_REQUIRED`...), all constants on the class.
100
+ When the API refuses a person's session, the SDK forgets the credential, so check `signed_in?` and sign in again; a
101
+ service token's session is traded again once before that.
102
+
103
+ ```ruby
104
+ begin
105
+ session.rsvp_event(event_id, "ATTENDING")
106
+ rescue Audience::Kit::Error => e
107
+ return redirect_to(sign_in_path) if e.unauthenticated?
108
+
109
+ flash[:alert] = e.message # written for people
110
+ end
111
+ ```
112
+
113
+ ### Keeping the session
114
+
115
+ Pass a `store:` to keep the credential wherever your app keeps secrets. `SessionCredentialStore` keeps it in a Rails,
116
+ Rack or Sinatra session; the default `MemoryCredentialStore` lives as long as the object. Any object with `load`,
117
+ `save(credential)` and `delete` works. The token is as good as a password: never log it (`Credential#inspect` leaves
118
+ it out). `Credential#to_h` and `Credential.from_h` round-trip the API's JSON.
119
+
120
+ ### The module-level session
121
+
122
+ Scripts that talk to one audience can skip making a session:
123
+
124
+ ```ruby
26
125
  Audience::Kit.configure do |c|
27
- c.token = ENV["AUDIENCE_KIT_TOKEN"] # optional bearer token
28
- c.base_url = "https://api.audiencekit.io" # the default
126
+ c.token = ENV.fetch("AUDIENCEKIT_TOKEN")
127
+ c.host = "hotmess.social"
29
128
  end
30
129
 
31
- Audience::Kit::Venue.find(1).data # => { "id" => 1, ... }
32
- Audience::Kit::Event.find(42).data
130
+ Audience::Kit.session.venues
131
+ Audience::Kit::Venue.find(venue_id) # a venue's page; raises NOT_FOUND when there's none
132
+ Audience::Kit::Event.find(event_id)
133
+ Audience::Kit.query("query { locales { id name } }")
33
134
  ```
34
135
 
35
- HTTP failures raise `Audience::Kit::Error`.
136
+ Without `configure`, it reads `AUDIENCEKIT_TOKEN`, `AUDIENCEKIT_HOST`, `AUDIENCEKIT_AUDIENCE_ID`,
137
+ `AUDIENCEKIT_BASE_URL` and `AUDIENCEKIT_ENVIRONMENT` (and the 0.2 releases' `AUDIENCE_KIT_*` names).
138
+
139
+ ### Upgrading from 0.2
140
+
141
+ 0.2 read two REST endpoints the API no longer serves, so every 0.2 call fails; upgrade. In 0.3,
142
+ `Venue.find` and `Event.find` read over GraphQL with the module-level session, so set a host or audience ID as well as
143
+ the token. `data` still returns the record's JSON, now with the schema's camelCase keys, and typed readers sit beside
144
+ it. The default API is `https://api.audiencekit.com`.
145
+
146
+ ## Related Ruby gems
147
+
148
+ Two open-source (MIT) gems from the team behind AudienceKit, for the server side of a Rails app on PostgreSQL. They
149
+ don't talk to the AudienceKit API; reach for them when your app keeps listings of its own (a city guide that mirrors
150
+ an audience's venues and events into its database, say):
151
+
152
+ - [**graph_query**](https://github.com/lwm-luminx/graph_query) ([guide](https://lwm-luminx.github.io/graph_query/)):
153
+ graph traversals and Cypher queries over Active Record, in one recursive CTE with no database extension. Walk
154
+ locales within locales to their venues and events (`washington.traverse(:contains, depth: 0..).traverse(:has_venue)`)
155
+ and get relations back.
156
+ - [**retcon**](https://github.com/lwm-luminx/retcon) ([guide](https://lwm-luminx.github.io/retcon/)): retroactive
157
+ continuity for Active Record. Field-level history with attribution, proposals reviewed like pull requests, and
158
+ repair of bad edits without losing the good work after them, for records many people edit.
36
159
 
37
160
  ## Development
38
161
 
39
- After checking out the repo, `cd ruby` and run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run the specs and RuboCop. The specs measure coverage with SimpleCov (`coverage/index.html`); every line and branch of `lib/` is covered, and CI fails if a change leaves any uncovered. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
162
+ ```sh
163
+ cd ruby
164
+ bin/setup
165
+ bundle exec rake # specs (every line and branch of lib/ covered) and RuboCop
166
+ bundle exec rake yard # the API reference, in doc/
167
+ bin/console # a prompt with the gem loaded
168
+ bin/graphql-documents build/graphql # every document, for the schema check (graphql@16 installed at the repo root):
169
+ node ../scripts/graphql/check.mjs --schema ../graphql/schema.graphql --endpoint consumer build/graphql
170
+ ```
40
171
 
41
- To install this gem onto your local machine, run `bundle exec rake install`. The gem keeps its own version in `lib/audience-kit/version.rb`, separate from the Swift and Kotlin SDKs' `VERSION`. Releases publish themselves: once a change that raises the version (with a `CHANGELOG.md` entry) merges to `main`, the `release` job in `.github/workflows/ruby.yml` builds the gem and pushes it to [rubygems.org](https://rubygems.org/gems/audience-kit) with RubyGems trusted publishing (no API key is stored), then tags the commit `ruby-<version>`. Don't use `bundle exec rake release`, which would push a bare version tag that the Swift package's release tags share.
172
+ The GraphQL documents live in `lib/audience-kit/queries.rb`, built from the audience's `SchemaShape` the way the
173
+ other SDKs build theirs; keep them in step when the shared queries change. The models are in
174
+ `lib/audience-kit/models.rb`; each reads only what the documents ask for, and keeps the rest in `to_h`. Signatures
175
+ for the public API are in `sig/`.
176
+
177
+ ## Releasing
178
+
179
+ The gem keeps its own version in `lib/audience-kit/version.rb`, separate from the Swift and Kotlin SDKs' `VERSION`.
180
+ Releases publish themselves: once a change that raises the version (with a [`CHANGELOG.md`](CHANGELOG.md) entry)
181
+ merges to `main`, the `release` job in `.github/workflows/ruby.yml` builds the gem and pushes it to
182
+ [rubygems.org](https://rubygems.org/gems/audience-kit) with RubyGems trusted publishing (no API key is stored), then
183
+ tags the commit `ruby-<version>`. Don't use `bundle exec rake release`, which would push a bare version tag that the
184
+ Swift package's release tags share.
42
185
 
43
186
  ## Contributing
44
187
 
45
- Bug reports and pull requests are welcome on GitHub at https://github.com/lwm-luminx/audience-kit-sdk (the gem lives in `ruby/`). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/lwm-luminx/audience-kit-sdk/blob/main/ruby/CODE_OF_CONDUCT.md).
188
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lwm-luminx/audience-kit-sdk (the gem lives
189
+ in `ruby/`). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected
190
+ to adhere to the [code of conduct](https://github.com/lwm-luminx/audience-kit-sdk/blob/main/ruby/CODE_OF_CONDUCT.md).
46
191
 
47
192
  ## License
48
193
 
@@ -52,7 +197,3 @@ prohibited without Love Wins Media's written permission and an audience ID or to
52
197
  license is granted, misrepresenting the work is prohibited, and changed versions may be made only in a fork after
53
198
  written notice. See the
54
199
  [root README](../README.md#license) for details.
55
-
56
- ## Code of Conduct
57
-
58
- Everyone interacting in the Audience::Kit project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/lwm-luminx/audience-kit-sdk/blob/main/ruby/CODE_OF_CONDUCT.md).
data/docs/reference.md ADDED
@@ -0,0 +1,219 @@
1
+ # Ruby SDK reference
2
+
3
+ Everything in the `audience-kit` gem, by what it is for. Everything is in the `Audience::Kit` namespace, and every call
4
+ can raise `Audience::Kit::Error`. The YARD reference on [RubyDoc.info](https://rubydoc.info/gems/audience-kit) has
5
+ each method's parameters and return types; `bundle exec rake yard` builds it locally.
6
+
7
+ ## Session
8
+
9
+ ### Making one
10
+
11
+ | Call | What it does |
12
+ | --- | --- |
13
+ | `Session.new(configuration:, store:, http:)` | A session for one audience. `store:` defaults to a `MemoryCredentialStore`; `http:` is a Faraday connection of your own (one is made when it's nil). |
14
+ | `Session.from_env(env = ENV, http:)` | Configured from `AUDIENCEKIT_TOKEN`, `AUDIENCEKIT_BASE_URL`, `AUDIENCEKIT_AUDIENCE_ID`, `AUDIENCEKIT_HOST` and `AUDIENCEKIT_ENVIRONMENT`. A token starting `akst_` is a service token; anything else is sent as a bearer token. |
15
+ | `Session.build(configuration:, token:, http:)` | The same, from values you already have. |
16
+
17
+ `Configuration.new` takes `base_url:` (`https://api.audiencekit.com`), `host:` (the host that names the audience),
18
+ `audience_id:`, `facebook_app_id:`, `environment:` (`Environment::PRODUCTION` or `Environment::STAGING`) and
19
+ `trusted_credential_origins:`. It's a `Data`, so `configuration.with(host: "...")` makes a changed copy.
20
+
21
+ ### Signing in and out
22
+
23
+ | Call | Returns | What it does |
24
+ | --- | --- | --- |
25
+ | `sign_in_with_facebook_token(access_token, device:)` | `Credential` | Trades a Facebook user access token. |
26
+ | `sign_in_with_facebook_code(code, redirect_uri:, device:, facebook_app_id: nil)` | `Credential` | Trades the code from Facebook's OAuth dialog. |
27
+ | `sign_in_with_google(id_token, device:, name: nil, access_token: nil)` | `Credential` | Trades a Google ID token. |
28
+ | `sign_in_with_apple(identity_token, device:, authorization_code:, redirect_uri:, nonce:, first_name:, last_name:)` | `Credential` | Trades a Sign in with Apple credential; every keyword but `device:` is optional. |
29
+ | `sign_in_with_review_code(code, device:)` | `Credential` | Signs an App Reviewer in while the audience is in review. |
30
+ | `connect_facebook(code, redirect_uri:, device:)`, `connect_google(id_token, device:)` | `Credential` | Adds a provider to the signed-in account. |
31
+ | `use_service_token(token)` | `Credential` | Acts as the audience with a service token, renewed as needed. |
32
+ | `use_bearer_token(token)` | | Sends an application API key (or a session JWT) as is. |
33
+ | `adopt(credential)` | | Uses a credential minted elsewhere, or one you stored. |
34
+ | `refresh_session` | `Credential` | Re-issues the token for the same session. |
35
+ | `switch_audience(audience_id)` | `Credential` | Moves a platform-console session to another audience. |
36
+ | `sign_out` | | Forgets the credential and revokes the token. |
37
+ | `delete_account` | `Boolean` | Deletes the signed-in person's account for good. |
38
+ | `signed_in?`, `credential`, `session_token` | | The stored session. |
39
+ | `session_rejected(token)` | `Boolean` | Forgets the session after a connection the SDK didn't make itself was refused. |
40
+
41
+ `DeviceDescription.new(identifier:, type: "web", model: nil, version: nil, build: nil)` describes the browser or
42
+ server signing in.
43
+
44
+ ### The audience and its listings
45
+
46
+ | Call | Returns |
47
+ | --- | --- |
48
+ | `branding(host:, app:)` | `Hash`: the audience's public branding (no sign-in) |
49
+ | `audience_id` | `String` |
50
+ | `audience` | `Audience` |
51
+ | `me` | `SelfUser` or nil |
52
+ | `venues` | `Array<Venue>` |
53
+ | `venue_detail(id, recent_messages: 20)` | `Venue` or nil, with its profile, chat and upcoming events |
54
+ | `people` | `Array<Person>` |
55
+ | `locales` | `Array<Locale>` |
56
+ | `closest_locale(coordinate)` | `Locale` or nil |
57
+ | `report_location(coordinate, fields)` | `Hash` of the fields you select |
58
+ | `events(window: "UPCOMING", locale_id: nil, venue_id: nil, first: 100)` | `Array<Event>`; `window: "PAST"` for what has ended |
59
+ | `event(id)` | `Event` or nil |
60
+ | `event_series(locale_id: nil, venue_id: nil, first: 100)` | `Array<EventSeries>` |
61
+ | `community` | `Community`: the audience, locales, venues, people, events and series |
62
+ | `node_type(id)` | `String` or nil: which type a global ID names |
63
+
64
+ ### Public listings (service token with `public:read`)
65
+
66
+ | Call | Returns |
67
+ | --- | --- |
68
+ | `public_listings` | `Array<PublicListing>`: every page |
69
+ | `public_listings_page(page = 1)` | `PublicListingsPage` (`listings`, `page_count`, `next_page`) |
70
+ | `public_listing(:venue \| :event \| :post, id)` | `PublicListing` or nil |
71
+ | `public_tonight(venue_id)` | `Hash`: tonight at a venue, as a room screen shows it |
72
+
73
+ ### RSVP, tribes and notifications
74
+
75
+ | Call | Returns |
76
+ | --- | --- |
77
+ | `rsvp_event(event_id, "ATTENDING" \| "MAYBE" \| "DECLINED" \| "UNSURE")` | `String`: the answer as stored |
78
+ | `cancel_rsvp(event_id)` | `EventRSVP` |
79
+ | `event_rsvp(event_id, first: 50)` | `EventRSVP` or nil, with the first attendees |
80
+ | `tribes` | `Tribes` (`tribes`, an `Array<Tag>`; `mine`, an `Array<TribeIdentification>`) |
81
+ | `identify_with_tribe(tag_id, private: nil)`, `leave_tribe(tag_id)` | `Array<TribeIdentification>` |
82
+ | `register_device(notification_token, app_id: nil, sandbox: nil)` | `Boolean` |
83
+
84
+ ### Cover and coat check
85
+
86
+ | Call | Returns |
87
+ | --- | --- |
88
+ | `venue_cover(venue_id)` | `VenueCover` or nil: tonight's charge, and the viewer's pass and coat check ticket |
89
+ | `venue_offers(venue_id, night: nil)` | `Array<AdmissionOffer>`: every way in on a night |
90
+ | `buy_cover(venue_id, amount_cents: nil, currency: "usd")` | `CoverPurchase` |
91
+ | `buy_coat_check(venue_id, quantity: 1)` | `CoverPurchase` |
92
+ | `pay_cover(admission_id, source_id:, verification_token: nil)` | `Admission` (Square) |
93
+ | `confirm_cover(admission_id)` | `Admission` (Stripe) |
94
+ | `refund_admission(admission_id)` | `Admission` |
95
+ | `admissions` | `Array<Admission>` |
96
+
97
+ ### News (Soapbox)
98
+
99
+ | Call | Returns |
100
+ | --- | --- |
101
+ | `articles(locale_id: nil, publication_id: nil, first: nil)` | `Array<Article>` |
102
+ | `articles_page(locale_id: nil, publication_id: nil, first: 20, after: nil)` | `ArticlesPage` (`articles`, `end_cursor`, `next_page?`) |
103
+ | `national_articles(locale_id: nil, first: nil)` | `Array<Article>` |
104
+ | `article(id)` | `Article` or nil, with its body and subjects |
105
+ | `articles_about(:venue \| :event \| :person \| :locale, id, first: nil)` | `Array<Article>` |
106
+ | `publications`, `local_publications(locale_id)` | `Array<Publication>` |
107
+ | `publication(id)` | `Publication` or nil |
108
+ | `my_op_eds` | `Array<Article>`, with `status` and `review_note` |
109
+ | `submit_op_ed(publication_id, title:, body:, summary: nil, byline: nil)` | `Article` |
110
+
111
+ Every Soapbox call returns an empty Array or nil for an audience without Soapbox.
112
+
113
+ ### Calendar subscriptions
114
+
115
+ | Call | Returns |
116
+ | --- | --- |
117
+ | `calendar_feed` | `CalendarFeed` or nil |
118
+ | `create_calendar_feed(reset: false)` | `CalendarFeed` |
119
+ | `follow_venue_in_calendar(venue_id, following: true)` | `CalendarFeed` |
120
+ | `delete_calendar_feed` | `Boolean` |
121
+
122
+ ### Chat and moderation
123
+
124
+ | Call | Returns |
125
+ | --- | --- |
126
+ | `send_chat_message(message, venue_id:)` or `(message, locale_id:)`, with `prompt_id:` | `ChatMessage` |
127
+ | `remove_chat_message(message_id)` | `String`: the removed ID |
128
+ | `report_content(ReportTarget::..., id, reason: nil, block: false)` | `ReportResult` (`reported?`, `blocked?`) |
129
+ | `block_user(user_id)`, `unblock_user(user_id)` | |
130
+
131
+ `ReportTarget` has the targets (`MESSAGE`, `PERSON`, `PHOTO`, `PING`, `PRIVATE_MESSAGE`, `POST`, `POST_COMMENT`,
132
+ `VENUE`) and `REASONS`, the reasons the apps offer. Keep `ReportTarget::INTIMATE_IMAGE`'s wording: the API gives those
133
+ reports a 48-hour deadline.
134
+
135
+ ### Your own operations
136
+
137
+ | Call | Returns |
138
+ | --- | --- |
139
+ | `graphql(document, variables = nil, operation_name: nil, endpoint: GraphQLEndpoint::CONSUMER)` | `Hash`: the response's `data` |
140
+ | `shaped_graphql(types, variables, operation_name) { \|shape\| document }` | `Hash`: built for the audience's modules |
141
+ | `schema_fields(types)`, `cached_schema_fields(types)` | `Hash{String => Array<String>}` |
142
+ | `request(path, method: :get, query: {}, body: nil, authenticated: true, headers: {})` | `String`: a REST response's body |
143
+ | `url(string)` | `String` or nil: a URL the API sent, made absolute |
144
+
145
+ `Queries` has every document the SDK sends, and the field lists to build your own from
146
+ (`Queries.event_fields(shape)`, `Queries::ADMISSION_FIELDS`, `Queries.chat_room(kind)` for an Action Cable client...).
147
+ `SchemaShape.everything` asks for every module's fields; `Queries.all` returns every document, by name.
148
+
149
+ ## The module-level session
150
+
151
+ | Call | What it does |
152
+ | --- | --- |
153
+ | `Audience::Kit.configure { \|c\| ... }` | Sets `token`, `host`, `audience_id` and `base_url` for the shared session (the environment comes from `AUDIENCEKIT_ENVIRONMENT`). |
154
+ | `Audience::Kit.session` | The shared session, made from `configure` or the environment on first use. |
155
+ | `Audience::Kit.session = session` | Uses a session you made. |
156
+ | `Audience::Kit.query(document, variables = nil)` | `graphql` on the shared session. |
157
+ | `Audience::Kit.reset!` | Forgets the shared session and configuration (for tests). |
158
+ | `Venue.find(id)`, `Event.find(id)` | A venue's or an event's page with the shared session; raises `NOT_FOUND` when there's none. |
159
+
160
+ ## Models
161
+
162
+ Each model has snake_case, read-only readers, and is also readable as the API's JSON (`model["field"]`,
163
+ `model.dig(...)`, `to_h`, `to_json`; `data` is kept for 0.2 code). `Model.from(json)` and `Model.list(json)` build them
164
+ from Hashes you cached. Times are `Time`, money is `Money`, and yes-or-no readers end in `?`.
165
+
166
+ | Model | Readers |
167
+ | --- | --- |
168
+ | `Audience` | `id`, `name`, `subdomain`, `theme`; `color(token, dark: false)` |
169
+ | `SelfUser` | `id`, `name`, `first_name`, `last_name`, `email_address`, `admin?`, `presence` |
170
+ | `Profile` | `id`, `name`, `avatar_url` |
171
+ | `Locale` | `id`, `name`, `label`, `city_names`, `banner_url`, `place_id` |
172
+ | `Location` | `id`, `address`, `place_id`; `coordinate` |
173
+ | `Venue` | `id`, `name`, `hidden?`, `order`, `photo_url`, `banner_url`, `locale`, `location`, `tags`, `facebook_page`; on its page `description`, `address`, `phone`, `website`, `social_links`, `chat_open`, `recent_messages`, `upcoming_events`; `coordinate` |
174
+ | `Person` | `id`, `name`, `avatar_url`, `banner_url`, `order`, `global?`, `like_required?`, `tags`, `locales`, `facebook_page`, `home_venue`, `involvements` |
175
+ | `Event` | `id`, `name`, `description`, `start_at`, `end_at`, `featured?`, `canceled?`, `banner_url`, `source_url`, `locale`, `tags`, `venue_name`, `venue`, `rsvp`, `rsvp_count`, `hosts`, `lineup`, `jockeys`, `jockey_label`, `ticket_url`, `offers`, `cover`; `effective_hosts`, `ended?` |
176
+ | `EventSeries` | `id`, `name`, `description`, `recurrence_text`, `starts_on`, `start_time`, `time_zone`, `duration_minutes`, `banner_url`, `locale`, `tags`, `venue_name`, `venue` |
177
+ | `EventRSVP` | `count`, `mine`, `mine_source`, `going`, `interested`, `tickets`, `attendees`; `going?`, `attendee_profiles` |
178
+ | `Tag` | `id`, `name`, `color_hex`, `tribe?`; `color` |
179
+ | `TribeIdentification` | `private?`, `tag` |
180
+ | `Money` | `cents`, `currency`; `amount`, `format` (`"$12.00"`, also `to_s`) |
181
+ | `CoverCharge` | `amount`, `fee`, `total`, `night`, `from`, `payable?`, `event`, `coat_check`, `scale_min`, `scale_max`, `scale_suggested`; `sliding_scale?`, `coat_check?` |
182
+ | `Admission` | `id`, `status`, `kind`, `night`, `quantity`, `tier`, `claim_check_number`, `amount`, `fee`, `total`, `refundable?`, `pass_secret`, `scan_count`, `checked_in_at`, `created_at`, `profile`, `venue`, `event`; `paid?`, `pass_code` |
183
+ | `AdmissionOffer` | `price`, `url`, `seller_key`, `seller_name` |
184
+ | `CoverPurchase` | `admission`, `provider`, `payment_intent_client_secret`, `publishable_key`, `stripe_account_id`, `square_application_id`, `square_location_id` |
185
+ | `VenueCover` | `id`, `name`, `charge`, `viewer_admission`, `viewer_coat_check` |
186
+ | `ChatMessage` | `id`, `body`, `name`, `user_id`, `avatar_url`, `photo_url`, `sent_at`, `role`, `kind`, `title`, `pinned?` |
187
+ | `Article` | `id`, `slug`, `title`, `summary`, `byline`, `kind`, `published_at`, `edited?`, `pinned?`, `teaser?`, `canonical_url`, `disclosure`, `hero_photo_url`, `hero_alt_text`, `publication`, `body`, `subjects`, `viewer_ad_free?`, `featured_nationally?`, `status`, `review_note`, `submitted_at` |
188
+ | `Publication` | `id`, `name`, `masthead`, `about`, `website_url`, `photo_url`, `trusted?`, `accepts_op_eds?`, `op_ed_guidelines`, `locale`, `person`, `ad_free_offered?`, `ad_free_tip_cents`, `ad_free_days` |
189
+ | `CalendarFeed` | `url`, `webcal_url`, `google_url`, `venue_ids`; `follows?(venue_id)` |
190
+ | `PublicListing` | `kind`, `id`, `path`, `visibility`, `title`, `description`, `address`, `phone`, `website`, `listed`, `image`, `start_at`, `end_at`, `venue_name`, `ticket_url`, `canceled`, `cover_cents`; `public?` |
191
+ | `Page` | A Facebook Page: `id`, `name`, `photo_url`, `banner_url` |
192
+
193
+ `ArticlesPage`, `PublicListingsPage`, `Community`, `ReportResult` and `Tribes` are `Data` value objects.
194
+
195
+ ## Credentials and stores
196
+
197
+ `Credential` has `token`, `user_id` (nil for a service session), `audience_id`, `role` (`member`, `admin`,
198
+ `venue_device`, `service`...), `endpoint`, `venue_device_id`, `expires_at`, `api_version`, `scopes` and `audience`, with
199
+ `expired?`, `expires_within?(seconds)`, `service?`, `scope?(scope)`, `origin`, `Credential.from_h` and `to_h`. Its
200
+ `inspect` leaves the token out.
201
+
202
+ A credential store is any object with `load`, `save(credential)` and `delete` (`CredentialStore` documents the
203
+ interface). `MemoryCredentialStore` lasts as long as the object and `SessionCredentialStore.new(session, key:)` keeps
204
+ the credential in a Rails, Rack or Sinatra session.
205
+
206
+ ## Helpers
207
+
208
+ | Name | What it does |
209
+ | --- | --- |
210
+ | `Coordinate` | A latitude and longitude, with an optional beacon. `Coordinate.from_wkt`, `to_wkt`, `to_input`, `distance_to` in meters. |
211
+ | `Color` | `Color.from_hex`, `Color.from_theme(theme, token, dark:)`, `to_css`, `to_hex`. |
212
+ | `CoverPass` | `CoverPass.code(admission_id, pass_secret, epoch_seconds = nil)` makes a pass's door code (`HMC1.<id>.<window>.<signature>`), the same one the apps show; `code?`, `window`, `seconds_until_next_window`. |
213
+ | `Audience::Kit` | `VERSION`, `API_VERSION`, `PRODUCTION_BASE_URL`, the header names, `client_header` and `older?`. |
214
+
215
+ ## Errors
216
+
217
+ `Error` carries `code` (a constant on the class), the HTTP `status`, the GraphQL `errors` (`GraphQLError`s with
218
+ `message`, `path`, `extensions` and `code`), for `INVALID` per-field messages in `fields`, and for `UPDATE_REQUIRED` the
219
+ `minimum_sdk_version`. `unauthenticated?` and `undefined_field?` answer the common questions.