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 +4 -4
- data/.yardopts +8 -0
- data/CHANGELOG.md +21 -0
- data/README.md +163 -22
- data/docs/reference.md +219 -0
- data/docs/sign-in.md +197 -0
- data/docs/websites.md +167 -0
- data/lib/audience-kit/color.rb +68 -0
- data/lib/audience-kit/configuration.rb +54 -0
- data/lib/audience-kit/coordinate.rb +76 -0
- data/lib/audience-kit/cover_pass.rb +57 -0
- data/lib/audience-kit/credential.rb +140 -0
- data/lib/audience-kit/credential_store.rb +86 -0
- data/lib/audience-kit/device_description.rb +29 -0
- data/lib/audience-kit/environment.rb +34 -0
- data/lib/audience-kit/error.rb +190 -0
- data/lib/audience-kit/model.rb +136 -0
- data/lib/audience-kit/models.rb +942 -0
- data/lib/audience-kit/operations.rb +501 -0
- data/lib/audience-kit/queries.rb +632 -0
- data/lib/audience-kit/report_target.rb +34 -0
- data/lib/audience-kit/schema_shape.rb +31 -0
- data/lib/audience-kit/session.rb +580 -0
- data/lib/audience-kit/version.rb +6 -1
- data/lib/audience-kit.rb +119 -23
- data/sig/audience/kit.rbs +651 -14
- metadata +23 -5
- data/lib/audience-kit/event.rb +0 -18
- data/lib/audience-kit/venue.rb +0 -18
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Audience
|
|
4
|
+
module Kit
|
|
5
|
+
# The calls every AudienceKit app makes, so apps are built with little custom code: the same operations the
|
|
6
|
+
# Swift, Kotlin, Node, Python and PHP SDKs run, returning {Model}s with typed readers that are also readable as
|
|
7
|
+
# the API's JSON. Fields a module adds are missing where the audience hasn't installed that module: the SDK asks
|
|
8
|
+
# for them and, if the audience's schema doesn't have one, asks again without.
|
|
9
|
+
#
|
|
10
|
+
# Included in {Session}.
|
|
11
|
+
module Operations
|
|
12
|
+
# @!group The audience and its listings
|
|
13
|
+
|
|
14
|
+
# The audience: its name, subdomain and theme.
|
|
15
|
+
# @return [Audience]
|
|
16
|
+
def audience
|
|
17
|
+
Kit::Audience.new(graphql(Queries::AUDIENCE, operation_name: "Audience"))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# The signed-in person's own profile, or nil when there is none (an API key or service token's session).
|
|
21
|
+
# @return [SelfUser, nil]
|
|
22
|
+
def me
|
|
23
|
+
SelfUser.from(graphql(Queries::ME, operation_name: "Me").dig("me", "self"))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# The audience's venues.
|
|
27
|
+
# @return [Array<Venue>]
|
|
28
|
+
def venues
|
|
29
|
+
Venue.list(shaped(Queries::LISTING_TYPES, :venues, nil, "Venues").dig("venues", "list"))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# The audience's people: promoters, DJs, drag artists and acts.
|
|
33
|
+
# @return [Array<Person>]
|
|
34
|
+
def people
|
|
35
|
+
Person.list(shaped(Queries::LISTING_TYPES, :people, nil, "People").dig("people", "list"))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# The audience's locales.
|
|
39
|
+
# @return [Array<Locale>]
|
|
40
|
+
def locales
|
|
41
|
+
Locale.list(shaped(Queries::LISTING_TYPES, :locales, nil, "Locales")["locales"])
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# The locale closest to a point, or nil when the audience has none.
|
|
45
|
+
# @param near [Coordinate]
|
|
46
|
+
# @return [Locale, nil]
|
|
47
|
+
# @example
|
|
48
|
+
# session.closest_locale(Audience::Kit::Coordinate.new(latitude: 33.45, longitude: -112.07))
|
|
49
|
+
def closest_locale(near)
|
|
50
|
+
data = shaped(Queries::LISTING_TYPES, :closest_locale, { "near" => near.to_input }, "ClosestLocale")
|
|
51
|
+
Locale.from(data["closestLocale"])
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Records the signed-in person's position and says where that is (+venue+, +locale+, +nearbyVenues+,
|
|
55
|
+
# +audience+). Select the fields the app needs and read the result yourself.
|
|
56
|
+
# @param position [Coordinate]
|
|
57
|
+
# @param fields [String] e.g. +"venue { id name } locale { id name }"+
|
|
58
|
+
# @return [Hash]
|
|
59
|
+
def report_location(position, fields)
|
|
60
|
+
data = graphql(Queries.report_location(fields), { "position" => position.to_input },
|
|
61
|
+
operation_name: "ReportLocation")
|
|
62
|
+
object(data, "reportLocation")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Everything the audience lists, read in one go: the audience, its locales, venues, people, upcoming events and
|
|
66
|
+
# event series. A part whose module the audience doesn't have comes back empty.
|
|
67
|
+
# @return [Community]
|
|
68
|
+
def community
|
|
69
|
+
Community.new(audience: optional { audience }, locales: optional { locales } || [],
|
|
70
|
+
venues: optional { venues } || [], people: optional { people } || [],
|
|
71
|
+
events: optional { events } || [], event_series: optional { event_series } || [])
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# The audience's events: upcoming (soonest first) or past, for one locale or venue when given.
|
|
75
|
+
# @param window [String] UPCOMING or PAST
|
|
76
|
+
# @param locale_id [String, nil]
|
|
77
|
+
# @param venue_id [String, nil]
|
|
78
|
+
# @param first [Integer]
|
|
79
|
+
# @return [Array<Event>]
|
|
80
|
+
def events(window: "UPCOMING", locale_id: nil, venue_id: nil, first: 100)
|
|
81
|
+
variables = { "window" => window, "first" => first, "localeId" => locale_id, "venueId" => venue_id }.compact
|
|
82
|
+
Event.list(shaped(Queries::EVENT_TYPES, :events, variables, "Events").dig("events", "list"))
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# One event, or nil when there is none with that ID.
|
|
86
|
+
# @param id [String]
|
|
87
|
+
# @return [Event, nil]
|
|
88
|
+
def event(id)
|
|
89
|
+
Event.from(shaped(Queries::EVENT_TYPES, :event, { "id" => id }, "Event").dig("events", "event"))
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# The audience's recurring event series.
|
|
93
|
+
# @return [Array<EventSeries>]
|
|
94
|
+
def event_series(locale_id: nil, venue_id: nil, first: 100)
|
|
95
|
+
variables = { "first" => first, "localeId" => locale_id, "venueId" => venue_id }.compact
|
|
96
|
+
EventSeries.list(shaped(Queries::EVENT_TYPES, :event_series, variables, "EventSeries").dig("events", "series"))
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# A venue's page: the venue with its description, profile (address, phone, website, social links), chat
|
|
100
|
+
# (whether open, and its latest +recent_messages+ messages) and upcoming events, as far as the audience's
|
|
101
|
+
# modules go. Nil when there is no venue with that ID.
|
|
102
|
+
# @param id [String]
|
|
103
|
+
# @param recent_messages [Integer]
|
|
104
|
+
# @return [Venue, nil]
|
|
105
|
+
def venue_detail(id, recent_messages: 20)
|
|
106
|
+
data = shaped(Queries::VENUE_DETAIL_TYPES, :venue_detail, { "id" => id, "recentMessages" => recent_messages },
|
|
107
|
+
"VenueDetail")
|
|
108
|
+
Venue.from(data.dig("venues", "venue"))
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Which type a global ID names (+__typename+), or nil when there is no such node.
|
|
112
|
+
# @return [String, nil]
|
|
113
|
+
def node_type(id)
|
|
114
|
+
type = graphql(Queries::NODE, { "id" => id }, operation_name: "Node").dig("node", "__typename")
|
|
115
|
+
type.is_a?(String) ? type : nil
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# @!endgroup
|
|
119
|
+
|
|
120
|
+
# @!group Public listings (service token with public:read)
|
|
121
|
+
|
|
122
|
+
# One page (from 1) of the audience's public listings: up to 500 venues, then events, then posts, as its
|
|
123
|
+
# websites show them.
|
|
124
|
+
# @param page [Integer]
|
|
125
|
+
# @return [PublicListingsPage]
|
|
126
|
+
def public_listings_page(page = 1)
|
|
127
|
+
PublicListingsPage.from_h(json(request("/v1/public/listings", query: { "page" => [1, page].max })))
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Every public listing, page by page.
|
|
131
|
+
# @return [Array<PublicListing>]
|
|
132
|
+
def public_listings
|
|
133
|
+
listings = []
|
|
134
|
+
page = 1
|
|
135
|
+
loop do
|
|
136
|
+
found = public_listings_page(page)
|
|
137
|
+
listings.concat(found.listings)
|
|
138
|
+
return listings if found.next_page.nil? || found.next_page <= page
|
|
139
|
+
|
|
140
|
+
page = found.next_page
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# One public listing, or nil when there's none.
|
|
145
|
+
# @param kind [String, Symbol] venue, event or post
|
|
146
|
+
# @param id [String]
|
|
147
|
+
# @return [PublicListing, nil]
|
|
148
|
+
# @raise [ArgumentError] for any other kind
|
|
149
|
+
def public_listing(kind, id)
|
|
150
|
+
path = { "venue" => "venues", "event" => "events", "post" => "posts" }.fetch(kind.to_s) do
|
|
151
|
+
raise ArgumentError, "A listing is a venue, event or post, not #{kind}."
|
|
152
|
+
end
|
|
153
|
+
PublicListing.from(json(request("/v1/public/#{path}/#{URI.encode_uri_component(id)}")))
|
|
154
|
+
rescue Error => e
|
|
155
|
+
raise unless e.code == Error::NOT_FOUND
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# Tonight at a venue, as a screen facing the room shows it: tonight's event, who's on and what's next.
|
|
159
|
+
# @return [Hash]
|
|
160
|
+
def public_tonight(venue_id)
|
|
161
|
+
json(request("/v1/public/venues/#{URI.encode_uri_component(venue_id)}/tonight"))
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# @!endgroup
|
|
165
|
+
|
|
166
|
+
# @!group RSVP, tribes and notifications
|
|
167
|
+
|
|
168
|
+
# Answers an event's RSVP and returns the person's answer as stored.
|
|
169
|
+
# @param event_id [String]
|
|
170
|
+
# @param state [String] ATTENDING, MAYBE, DECLINED or UNSURE
|
|
171
|
+
# @return [String]
|
|
172
|
+
def rsvp_event(event_id, state)
|
|
173
|
+
data = graphql(Queries::RSVP_EVENT, { "eventId" => event_id, "state" => state }, operation_name: "RSVPEvent")
|
|
174
|
+
mine = data.dig("rsvpEvent", "event", "rsvp", "mine")
|
|
175
|
+
raise Error.decoding("The RSVP had no answer.") unless mine.is_a?(String)
|
|
176
|
+
|
|
177
|
+
mine
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Takes back the signed-in person's RSVP, as if they'd never answered, and returns the event's RSVPs
|
|
181
|
+
# afterwards. Someone holding a ticket stays going.
|
|
182
|
+
# @return [EventRSVP]
|
|
183
|
+
def cancel_rsvp(event_id)
|
|
184
|
+
data = graphql(Queries::CANCEL_RSVP, { "eventId" => event_id }, operation_name: "CancelRSVP")
|
|
185
|
+
EventRSVP.from(data.dig("cancelRsvp", "event", "rsvp")) || raise(Error.decoding("The response had no rsvp."))
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Who's going to an event and the first +first+ of them, or nil when there's no such event.
|
|
189
|
+
# @return [EventRSVP, nil]
|
|
190
|
+
def event_rsvp(event_id, first: 50)
|
|
191
|
+
data = graphql(Queries::EVENT_RSVP, { "id" => event_id, "first" => first }, operation_name: "EventRSVP")
|
|
192
|
+
EventRSVP.from(data.dig("events", "event", "rsvp"))
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# The tribes people can identify with here, and the signed-in person's own.
|
|
196
|
+
# @return [Tribes]
|
|
197
|
+
def tribes
|
|
198
|
+
data = graphql(Queries::TRIBES, operation_name: "Tribes")
|
|
199
|
+
Tribes.new(tribes: Tag.list(data["tribes"]), mine: TribeIdentification.list(data.dig("me", "self", "tribes")))
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# Identifies the signed-in person with a tribe and returns their tribes.
|
|
203
|
+
# @param tag_id [String]
|
|
204
|
+
# @param private [Boolean, nil] whether only they see it
|
|
205
|
+
# @return [Array<TribeIdentification>]
|
|
206
|
+
def identify_with_tribe(tag_id, private: nil)
|
|
207
|
+
data = graphql(Queries::IDENTIFY_WITH_TRIBE, { "tagId" => tag_id, "isPrivate" => private }.compact,
|
|
208
|
+
operation_name: "IdentifyWithTribe")
|
|
209
|
+
TribeIdentification.list(object(data, "identifyWithTribe")["tribes"])
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# Removes a tribe from the signed-in person and returns their tribes.
|
|
213
|
+
# @return [Array<TribeIdentification>]
|
|
214
|
+
def leave_tribe(tag_id)
|
|
215
|
+
data = graphql(Queries::LEAVE_TRIBE, { "tagId" => tag_id }, operation_name: "LeaveTribe")
|
|
216
|
+
TribeIdentification.list(object(data, "leaveTribe")["tribes"])
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# Registers a push notification token for the signed-in person.
|
|
220
|
+
# @return [Boolean] whether the API took it
|
|
221
|
+
def register_device(notification_token, app_id: nil, sandbox: nil)
|
|
222
|
+
variables = { "notificationToken" => notification_token, "appId" => app_id, "sandbox" => sandbox }.compact
|
|
223
|
+
graphql(Queries::REGISTER_DEVICE, variables, operation_name: "RegisterDevice")
|
|
224
|
+
.dig("registerDevice", "registered") == true
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
# @!endgroup
|
|
228
|
+
|
|
229
|
+
# @!group Cover and coat check
|
|
230
|
+
|
|
231
|
+
# A venue's cover charge tonight, with the signed-in person's pass and coat check ticket if they have them; nil
|
|
232
|
+
# when there is no such venue.
|
|
233
|
+
# @return [VenueCover, nil]
|
|
234
|
+
def venue_cover(venue_id)
|
|
235
|
+
VenueCover.from(shaped(Queries::VENUE_TICKET_TYPES, :venue_cover, { "id" => venue_id }, "VenueCover")
|
|
236
|
+
.dig("venues", "venue"))
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# Every way into a venue on a night.
|
|
240
|
+
# @param night [String, nil] +YYYY-MM-DD+; tonight by default
|
|
241
|
+
# @return [Array<AdmissionOffer>]
|
|
242
|
+
def venue_offers(venue_id, night: nil)
|
|
243
|
+
variables = { "id" => venue_id, "night" => night }.compact
|
|
244
|
+
AdmissionOffer.list(shaped(Queries::VENUE_TICKET_TYPES, :venue_offers, variables, "VenueOffers")
|
|
245
|
+
.dig("venues", "venue", "tickets", "offers"))
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# The signed-in person's admissions (cover passes and coat check tickets), newest first.
|
|
249
|
+
# @return [Array<Admission>]
|
|
250
|
+
def admissions
|
|
251
|
+
Admission.list(graphql(Queries::ADMISSIONS, operation_name: "Admissions").dig("me", "cover", "admissions"))
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
# Starts buying tonight's cover at a venue: the pending admission and the payment provider's keys. For a Stripe
|
|
255
|
+
# venue, finish the payment with Stripe.js and call {#confirm_cover}; for a Square venue, make a payment token
|
|
256
|
+
# and call {#pay_cover}. Asking again the same night returns the same pass.
|
|
257
|
+
# @param amount_cents [Integer, nil] on a sliding scale, what the buyer chose; the suggested amount by default
|
|
258
|
+
# @return [CoverPurchase]
|
|
259
|
+
def buy_cover(venue_id, amount_cents: nil, currency: "usd")
|
|
260
|
+
variables = { "venueId" => venue_id }
|
|
261
|
+
variables["amount"] = { "cents" => amount_cents, "currency" => currency } if amount_cents
|
|
262
|
+
CoverPurchase.new(object(graphql(Queries::BUY_COVER, variables, operation_name: "BuyCover"), "buyCover"))
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
# Starts paying tonight's coat check at a venue for +quantity+ coats, the same way as {#buy_cover}.
|
|
266
|
+
# @return [CoverPurchase]
|
|
267
|
+
def buy_coat_check(venue_id, quantity: 1)
|
|
268
|
+
data = graphql(Queries::BUY_COAT_CHECK, { "venueId" => venue_id, "quantity" => quantity },
|
|
269
|
+
operation_name: "BuyCoatCheck")
|
|
270
|
+
CoverPurchase.new(object(data, "buyCoatCheck"))
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
# Pays a Square venue's pending admission with a payment token from Square's Web Payments SDK.
|
|
274
|
+
# @return [Admission]
|
|
275
|
+
def pay_cover(admission_id, source_id:, verification_token: nil)
|
|
276
|
+
variables = { "admissionId" => admission_id, "sourceId" => source_id,
|
|
277
|
+
"verificationToken" => verification_token }.compact
|
|
278
|
+
admission(graphql(Queries::PAY_COVER, variables, operation_name: "PayCover"), "payCover")
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
# Confirms a Stripe venue's admission once Stripe has taken the payment.
|
|
282
|
+
# @return [Admission]
|
|
283
|
+
def confirm_cover(admission_id)
|
|
284
|
+
data = graphql(Queries::CONFIRM_COVER, { "admissionId" => admission_id }, operation_name: "ConfirmCover")
|
|
285
|
+
admission(data, "confirmCover")
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
# Refunds an admission that is {Admission#refundable?}.
|
|
289
|
+
# @return [Admission]
|
|
290
|
+
def refund_admission(admission_id)
|
|
291
|
+
data = graphql(Queries::REFUND_ADMISSION, { "admissionId" => admission_id }, operation_name: "RefundAdmission")
|
|
292
|
+
admission(data, "refundAdmission")
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
# @!endgroup
|
|
296
|
+
|
|
297
|
+
# @!group News (Soapbox)
|
|
298
|
+
|
|
299
|
+
# The audience's live articles, pinned first, then newest: a locale's news, or one publication's, when given.
|
|
300
|
+
# Empty when the audience doesn't have Soapbox.
|
|
301
|
+
# @return [Array<Article>]
|
|
302
|
+
def articles(locale_id: nil, publication_id: nil, first: nil)
|
|
303
|
+
variables = { "localeId" => locale_id, "publicationId" => publication_id, "first" => first }.compact
|
|
304
|
+
Article.list(shaped(Queries::SOAPBOX_TYPES, :articles, variables.empty? ? nil : variables, "Articles")
|
|
305
|
+
.dig("soapbox", "articles"))
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
# A page of the audience's live articles, for lists that "Show more". Pass the last page's
|
|
309
|
+
# {ArticlesPage#end_cursor} as +after+ for the next.
|
|
310
|
+
# @return [ArticlesPage]
|
|
311
|
+
def articles_page(locale_id: nil, publication_id: nil, first: 20, after: nil)
|
|
312
|
+
variables = { "localeId" => locale_id, "publicationId" => publication_id, "first" => first,
|
|
313
|
+
"after" => after }.compact
|
|
314
|
+
ArticlesPage.from_connection(shaped(Queries::SOAPBOX_TYPES, :articles_page, variables, "ArticlesPage")
|
|
315
|
+
.dig("soapbox", "articles"))
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
# The audience's national news: articles its admins featured nationally in the last 14 days, most recently
|
|
319
|
+
# featured first (a locale's share of it, when given).
|
|
320
|
+
# @return [Array<Article>]
|
|
321
|
+
def national_articles(locale_id: nil, first: nil)
|
|
322
|
+
variables = { "localeId" => locale_id, "first" => first }.compact
|
|
323
|
+
data = shaped(Queries::SOAPBOX_TYPES, :national_articles, variables.empty? ? nil : variables,
|
|
324
|
+
"NationalArticles")
|
|
325
|
+
Article.list(data.dig("soapbox", "articles"))
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
# One article with its body and what it's about; nil when there's none, or the audience has no Soapbox.
|
|
329
|
+
# @return [Article, nil]
|
|
330
|
+
def article(id)
|
|
331
|
+
Article.from(shaped(Queries::SOAPBOX_TYPES, :article, { "id" => id }, "Article").dig("soapbox", "article"))
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
# Live articles about a venue, event or person, newest first, or a locale's news ("In the news").
|
|
335
|
+
# @param topic [String, Symbol] venue, event, person or locale
|
|
336
|
+
# @return [Array<Article>]
|
|
337
|
+
def articles_about(topic, id, first: nil)
|
|
338
|
+
type, document = Queries.articles_about(topic)
|
|
339
|
+
data = shaped_graphql(Queries::SOAPBOX_TYPES + [type], { "id" => id, "first" => first }.compact,
|
|
340
|
+
"ArticlesAbout", &document)
|
|
341
|
+
listing = data.dig("venues", "venue") || data.dig("events", "event") || data.dig("people", "person") ||
|
|
342
|
+
data["locale"]
|
|
343
|
+
Article.list(listing.is_a?(Hash) ? listing.dig("articles", "list") : nil)
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
# The audience's publications.
|
|
347
|
+
# @return [Array<Publication>]
|
|
348
|
+
def publications
|
|
349
|
+
Publication.list(shaped(Queries::SOAPBOX_TYPES, :publications, nil, "Publications")
|
|
350
|
+
.dig("soapbox", "publications"))
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
# The publications covering a locale, the "local publishers" at the top of its news.
|
|
354
|
+
# @return [Array<Publication>]
|
|
355
|
+
def local_publications(locale_id)
|
|
356
|
+
publications.select { |publication| publication.locale&.id&.casecmp?(locale_id) }
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
# One publication, for its page and its "Write an op-ed" button.
|
|
360
|
+
# @return [Publication, nil]
|
|
361
|
+
def publication(id)
|
|
362
|
+
Publication.from(shaped(Queries::SOAPBOX_TYPES, :publication, { "id" => id }, "Publication")
|
|
363
|
+
.dig("soapbox", "publication"))
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
# The op-eds the signed-in person sent, newest first, with their status and the publication's note.
|
|
367
|
+
# @return [Array<Article>]
|
|
368
|
+
def my_op_eds
|
|
369
|
+
Article.list(shaped(Queries::SOAPBOX_TYPES, :my_op_eds, nil, "MyOpEds").dig("soapbox", "myOpEds"))
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
# Sends a publication an op-ed under the signed-in person's name (+byline+ overrides it). The publication runs
|
|
373
|
+
# it or declines it with a note; {#my_op_eds} shows which.
|
|
374
|
+
# @return [Article]
|
|
375
|
+
def submit_op_ed(publication_id, title:, body:, summary: nil, byline: nil)
|
|
376
|
+
variables = { "publicationId" => publication_id, "title" => title, "body" => body, "summary" => summary,
|
|
377
|
+
"byline" => byline }
|
|
378
|
+
data = graphql(Queries::SUBMIT_OP_ED, variables, operation_name: "SubmitOpEd")
|
|
379
|
+
Article.new(object(object(data, "submitOpEd"), "article"))
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
# @!endgroup
|
|
383
|
+
|
|
384
|
+
# @!group Calendar subscriptions
|
|
385
|
+
|
|
386
|
+
# The signed-in person's calendar subscription, or nil before they made one.
|
|
387
|
+
# @return [CalendarFeed, nil]
|
|
388
|
+
def calendar_feed
|
|
389
|
+
CalendarFeed.from(graphql(Queries::CALENDAR_FEED, operation_name: "CalendarFeed").dig("me", "calendarFeed"))
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
# Their subscription, made on first ask; +reset+ gives it a new link, so the old one stops working.
|
|
393
|
+
# @return [CalendarFeed]
|
|
394
|
+
def create_calendar_feed(reset: false)
|
|
395
|
+
data = graphql(Queries::CREATE_CALENDAR_FEED, { "reset" => reset }, operation_name: "CreateCalendarFeed")
|
|
396
|
+
CalendarFeed.new(object(object(data, "createCalendarFeed"), "calendarFeed"))
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
# Follows a venue in their subscription, so every event there shows up in their calendar (or, with
|
|
400
|
+
# +following: false+, stops). Makes the subscription on first ask.
|
|
401
|
+
# @return [CalendarFeed]
|
|
402
|
+
def follow_venue_in_calendar(venue_id, following: true)
|
|
403
|
+
data = graphql(Queries::SET_CALENDAR_FEED_VENUE, { "venueId" => venue_id, "following" => following },
|
|
404
|
+
operation_name: "SetCalendarFeedVenue")
|
|
405
|
+
CalendarFeed.new(object(object(data, "setCalendarFeedVenue"), "calendarFeed"))
|
|
406
|
+
end
|
|
407
|
+
|
|
408
|
+
# Ends their subscription: calendars subscribed to it stop updating.
|
|
409
|
+
# @return [Boolean]
|
|
410
|
+
def delete_calendar_feed
|
|
411
|
+
graphql(Queries::DELETE_CALENDAR_FEED, operation_name: "DeleteCalendarFeed")
|
|
412
|
+
.dig("deleteCalendarFeed", "deleted") == true
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
# @!endgroup
|
|
416
|
+
|
|
417
|
+
# @!group Chat and moderation
|
|
418
|
+
|
|
419
|
+
# Posts a message as the signed-in person in a venue's or locale's chat room, answering a prompt when
|
|
420
|
+
# +prompt_id+ is given.
|
|
421
|
+
# @param message [String]
|
|
422
|
+
# @param venue_id [String, nil]
|
|
423
|
+
# @param locale_id [String, nil]
|
|
424
|
+
# @param prompt_id [String, nil]
|
|
425
|
+
# @return [ChatMessage]
|
|
426
|
+
def send_chat_message(message, venue_id: nil, locale_id: nil, prompt_id: nil)
|
|
427
|
+
input = { "venueId" => venue_id, "localeId" => locale_id, "message" => message,
|
|
428
|
+
"promptId" => prompt_id }.compact
|
|
429
|
+
data = graphql(Queries::SEND_CHAT_MESSAGE, { "input" => input }, operation_name: "SendMyChatMessage")
|
|
430
|
+
ChatMessage.new(object(object(data, "sendMyChatMessage"), "message"))
|
|
431
|
+
end
|
|
432
|
+
|
|
433
|
+
# Removes one of the signed-in person's own chat messages.
|
|
434
|
+
# @return [String] the removed message's ID
|
|
435
|
+
def remove_chat_message(message_id)
|
|
436
|
+
data = graphql(Queries::REMOVE_CHAT_MESSAGE, { "messageId" => message_id },
|
|
437
|
+
operation_name: "RemoveMyChatMessage")
|
|
438
|
+
deleted = data.dig("removeMyChatMessage", "deletedId")
|
|
439
|
+
deleted.is_a?(String) ? deleted : message_id
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
# Files a report with the audience's admins (App Store guideline 1.2, Google Play's user-generated content
|
|
443
|
+
# policy). Offer {ReportTarget::REASONS} as reasons.
|
|
444
|
+
# @param target_type [String] one of {ReportTarget}'s constants
|
|
445
|
+
# @param id [String]
|
|
446
|
+
# @param reason [String, nil]
|
|
447
|
+
# @param block [Boolean] whether to block the person behind it too
|
|
448
|
+
# @return [ReportResult]
|
|
449
|
+
def report_content(target_type, id, reason: nil, block: false)
|
|
450
|
+
data = graphql(Queries::REPORT_CONTENT,
|
|
451
|
+
{ "targetType" => target_type, "targetId" => id, "reason" => reason, "block" => block },
|
|
452
|
+
operation_name: "ReportContent")
|
|
453
|
+
result = data["reportContent"].is_a?(Hash) ? data["reportContent"] : {}
|
|
454
|
+
ReportResult.new(reported: result["reported"] == true, blocked: result["blocked"] == true)
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
# Blocks a member (their user ID): they and the signed-in person stop seeing each other's messages.
|
|
458
|
+
# @return [void]
|
|
459
|
+
def block_user(user_id)
|
|
460
|
+
graphql(Queries::BLOCK_USER, { "userId" => user_id }, operation_name: "BlockUser")
|
|
461
|
+
nil
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
# Unblocks a member blocked with {#block_user} or a report.
|
|
465
|
+
# @return [void]
|
|
466
|
+
def unblock_user(user_id)
|
|
467
|
+
graphql(Queries::UNBLOCK_USER, { "userId" => user_id }, operation_name: "UnblockUser")
|
|
468
|
+
nil
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
# @!endgroup
|
|
472
|
+
|
|
473
|
+
private
|
|
474
|
+
|
|
475
|
+
def shaped(types, document, variables, operation_name)
|
|
476
|
+
shaped_graphql(types, variables, operation_name) { |shape| Queries.public_send(document, shape) }
|
|
477
|
+
end
|
|
478
|
+
|
|
479
|
+
def optional
|
|
480
|
+
yield
|
|
481
|
+
rescue Error => e
|
|
482
|
+
raise unless e.undefined_field?
|
|
483
|
+
end
|
|
484
|
+
|
|
485
|
+
def object(data, key)
|
|
486
|
+
data[key].is_a?(Hash) ? data[key] : raise(Error.decoding("The response had no #{key}."))
|
|
487
|
+
end
|
|
488
|
+
|
|
489
|
+
def admission(data, key)
|
|
490
|
+
Admission.new(object(object(data, key), "admission"))
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
def json(body)
|
|
494
|
+
decoded = JSON.parse(body)
|
|
495
|
+
decoded.is_a?(Hash) ? decoded : raise(Error.decoding("The response was not a JSON object."))
|
|
496
|
+
rescue JSON::ParserError => e
|
|
497
|
+
raise Error.decoding(e.message)
|
|
498
|
+
end
|
|
499
|
+
end
|
|
500
|
+
end
|
|
501
|
+
end
|