beehiiv_api 1.0.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/beehiiv_api.rb +1181 -0
  3. metadata +62 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 49a90588c24186317ba259f464fed06fb2030d09c5eeed4378ed17046eab8b4c
4
+ data.tar.gz: 57ae3af205d1af0d4d929caa342a5be8e393d530f0519f19f154a35408b466fb
5
+ SHA512:
6
+ metadata.gz: 0cce6348430346352093e49187747e7353ef65bc5929b350961246ebe223c48c58ee2b13099ac6e039b8a52d5c503f9d5a1ece414616a8a8ee676de324fcdf53
7
+ data.tar.gz: 3be778c58f7adaf25fd6f0452f0cfb898fbdb27540ef00fe413fdf4ca17e2ce4ae4f5e852937be247598179aaefbace8d41b878397b427287ece98de00561dd8
@@ -0,0 +1,1181 @@
1
+ # Generated by Sideko (sideko.dev)
2
+ # frozen_string_literal: true
3
+ require 'json'
4
+ require 'http'
5
+
6
+ class RequestError < StandardError
7
+ attr_reader :status_code, :method, :url, :data, :response
8
+
9
+ def initialize(method, url, response)
10
+ @status_code = response.status
11
+ @method = method
12
+ @url = url
13
+ begin
14
+ @data = response.parse
15
+ rescue
16
+ @data = nil
17
+ end
18
+ @response = response
19
+
20
+ super("received #{status_code} from #{method} #{url} with #{message}")
21
+ end
22
+ end
23
+
24
+ module AuthProvider
25
+ def add_auth(http_client, req_kwargs)
26
+ raise NotImplementedError, "You must implement the 'add_auth' method"
27
+ end
28
+ end
29
+
30
+ class AuthBasic
31
+ include AuthProvider
32
+
33
+ attr_accessor :username, :password
34
+
35
+ def initialize(username: nil, password: nil)
36
+ @username = username
37
+ @password = password
38
+ end
39
+
40
+ def add_auth(http_client, req_kwargs)
41
+ if !@username.nil? && !@password.nil?
42
+ http_client = http_client.basic_auth(user: @username, pass: @password)
43
+ end
44
+
45
+ return http_client, req_kwargs
46
+ end
47
+ end
48
+
49
+ class AuthBearer
50
+ include AuthProvider
51
+
52
+ attr_accessor :val
53
+
54
+ def initialize(val: nil)
55
+ @val = val
56
+ end
57
+
58
+ def add_auth(http_client, req_kwargs)
59
+ if !@val.nil?
60
+ headers = req_kwargs.fetch(:headers, {})
61
+ headers["Authorization"] = "Bearer " + @val
62
+ req_kwargs[:headers] = headers
63
+ end
64
+
65
+ return http_client, req_kwargs
66
+ end
67
+ end
68
+
69
+ class AuthKeyQuery
70
+ include AuthProvider
71
+
72
+ attr_accessor :query_name, :val
73
+
74
+ def initialize(query_name: nil, val: nil)
75
+ @query_name = query_name
76
+ @val = val
77
+ end
78
+
79
+ def add_auth(http_client, req_kwargs)
80
+ if !val.nil?
81
+ params = req_kwargs.fetch(:params, {})
82
+ params[query_name] = val
83
+ req_kwargs[:params] = params
84
+ end
85
+
86
+ return http_client, req_kwargs
87
+ end
88
+ end
89
+
90
+ class AuthKeyHeader
91
+ include AuthProvider
92
+
93
+ attr_accessor :header_name, :val
94
+
95
+ def initialize(header_name: nil, val: nil)
96
+ @header_name = header_name
97
+ @val = val
98
+ end
99
+
100
+ def add_auth(http_client, req_kwargs)
101
+ if !@val.nil?
102
+ headers = req_kwargs.fetch(:headers, {})
103
+ headers[@header_name] = @val
104
+ req_kwargs[:headers] = headers
105
+ end
106
+
107
+ return http_client, req_kwargs
108
+ end
109
+ end
110
+
111
+ class AuthKeyCookie
112
+ include AuthProvider
113
+
114
+ attr_accessor :cookie_name, :val
115
+
116
+ def initialize(cookie_name: nil, val: nil)
117
+ @cookie_name = cookie_name
118
+ @val = val
119
+ end
120
+
121
+ def add_auth(http_client, req_kwargs)
122
+ if !@val.nil?
123
+ http_client = http_client.cookies(@cookie_name => @val)
124
+ end
125
+
126
+ return http_client, req_kwargs
127
+ end
128
+ end
129
+
130
+ class Client
131
+ def initialize(bearer_auth: nil, base_url: 'https://api.beehiiv.com/v2')
132
+ @_base_url = base_url
133
+ # register auth providers
134
+ @_auth = {}
135
+ @_auth[:"bearerAuth"] = AuthBearer.new(val: bearer_auth)
136
+ end
137
+
138
+ def _client_with_auth(auth_names, **req_kwargs)
139
+ http_client = HTTP
140
+ auth_names.each do |auth_name|
141
+ provider = @_auth[auth_name]
142
+ http_client, req_kwargs = provider.add_auth(http_client, req_kwargs) if provider
143
+ end
144
+
145
+ return http_client, req_kwargs
146
+ end
147
+
148
+
149
+ # Delete a custom field from a publication
150
+ def delete_publications_publication_id_custom_fields(publication_id, id)
151
+ _url = @_base_url + "/publications/#{publication_id}/custom_fields/#{id}"
152
+ _kwargs = {
153
+ params: {}
154
+ }
155
+ _http_client, _req_kwargs = self._client_with_auth(
156
+ [:"bearerAuth", ],
157
+ **_kwargs
158
+ )
159
+
160
+
161
+ _response = _http_client.delete(
162
+ _url,
163
+
164
+ **_req_kwargs
165
+ )
166
+ if !_response.status.success?
167
+ raise RequestError.new(
168
+ method="delete",
169
+ url=_url,
170
+ response=_response
171
+ )
172
+ end
173
+
174
+ return _response.body.empty? ? '' : _response.parse
175
+ end
176
+
177
+ # Delete or Archive a post. Any post that has been confirmed will have it's status changed to `archived`. Posts in the `draft` status will be permenantly deleted.
178
+ def delete_posts_post_id(publication_id, post_id)
179
+ _url = @_base_url + "/publications/#{publication_id}/posts/#{post_id}"
180
+ _kwargs = {
181
+ params: {}
182
+ }
183
+ _http_client, _req_kwargs = self._client_with_auth(
184
+ [:"bearerAuth", ],
185
+ **_kwargs
186
+ )
187
+
188
+
189
+ _response = _http_client.delete(
190
+ _url,
191
+
192
+ **_req_kwargs
193
+ )
194
+ if !_response.status.success?
195
+ raise RequestError.new(
196
+ method="delete",
197
+ url=_url,
198
+ response=_response
199
+ )
200
+ end
201
+
202
+ return _response.body.empty? ? '' : _response.parse
203
+ end
204
+
205
+ # Delete a segment. Deleting the segment does not effect the subscriptions in the segment.
206
+ def delete_publications_publication_id_segments_segment_id(publication_id, segment_id)
207
+ _url = @_base_url + "/publications/#{publication_id}/segments/#{segment_id}"
208
+ _kwargs = {
209
+ params: {}
210
+ }
211
+ _http_client, _req_kwargs = self._client_with_auth(
212
+ [:"bearerAuth", ],
213
+ **_kwargs
214
+ )
215
+
216
+
217
+ _response = _http_client.delete(
218
+ _url,
219
+
220
+ **_req_kwargs
221
+ )
222
+ if !_response.status.success?
223
+ raise RequestError.new(
224
+ method="delete",
225
+ url=_url,
226
+ response=_response
227
+ )
228
+ end
229
+
230
+ return _response.body.empty? ? '' : _response.parse
231
+ end
232
+
233
+ # Delete a subscription.
234
+ #
235
+ # **This cannot be undone** All data associated with the subscription will also be deleted. We recommend unsubscribing when possible instead of deleting.
236
+ #
237
+ # If a premium subscription is deleted they will no longer be billed.
238
+ def delete_subscriptions_subscription_id(publication_id, subscription_id)
239
+ _url = @_base_url + "/publications/#{publication_id}/subscriptions/#{subscription_id}"
240
+ _kwargs = {
241
+ params: {}
242
+ }
243
+ _http_client, _req_kwargs = self._client_with_auth(
244
+ [:"bearerAuth", ],
245
+ **_kwargs
246
+ )
247
+
248
+
249
+ _response = _http_client.delete(
250
+ _url,
251
+
252
+ **_req_kwargs
253
+ )
254
+ if !_response.status.success?
255
+ raise RequestError.new(
256
+ method="delete",
257
+ url=_url,
258
+ response=_response
259
+ )
260
+ end
261
+
262
+ return _response.body.empty? ? '' : _response.parse
263
+ end
264
+
265
+ # Retrieve all publications associated with your API key.
266
+ def get_publications(direction: nil, expand: nil, limit: nil, order_by: nil, page: nil)
267
+ _url = @_base_url + "/publications"
268
+ _kwargs = {
269
+ params: {}
270
+ }
271
+ if direction != nil
272
+ _kwargs[:params][:"direction"] = direction
273
+ end
274
+ if expand != nil
275
+ _kwargs[:params][:"expand[]"] = expand
276
+ end
277
+ if limit != nil
278
+ _kwargs[:params][:"limit"] = limit
279
+ end
280
+ if order_by != nil
281
+ _kwargs[:params][:"order_by"] = order_by
282
+ end
283
+ if page != nil
284
+ _kwargs[:params][:"page"] = page
285
+ end
286
+ _http_client, _req_kwargs = self._client_with_auth(
287
+ [:"bearerAuth", ],
288
+ **_kwargs
289
+ )
290
+
291
+
292
+ _response = _http_client.get(
293
+ _url,
294
+
295
+ **_req_kwargs
296
+ )
297
+ if !_response.status.success?
298
+ raise RequestError.new(
299
+ method="get",
300
+ url=_url,
301
+ response=_response
302
+ )
303
+ end
304
+
305
+ return _response.body.empty? ? '' : _response.parse
306
+ end
307
+
308
+ # Retrieve a single publication
309
+ def get_publications_publication_id(publication_id, expand: nil)
310
+ _url = @_base_url + "/publications/#{publication_id}"
311
+ _kwargs = {
312
+ params: {}
313
+ }
314
+ if expand != nil
315
+ _kwargs[:params][:"expand[]"] = expand
316
+ end
317
+ _http_client, _req_kwargs = self._client_with_auth(
318
+ [:"bearerAuth", ],
319
+ **_kwargs
320
+ )
321
+
322
+
323
+ _response = _http_client.get(
324
+ _url,
325
+
326
+ **_req_kwargs
327
+ )
328
+ if !_response.status.success?
329
+ raise RequestError.new(
330
+ method="get",
331
+ url=_url,
332
+ response=_response
333
+ )
334
+ end
335
+
336
+ return _response.body.empty? ? '' : _response.parse
337
+ end
338
+
339
+ # Returns a list of Subscription Update objects for a publication
340
+ def get_subscription_updates_for_publiciation(publication_id)
341
+ _url = @_base_url + "/publications/#{publication_id}/bulk_subscription_updates"
342
+ _kwargs = {
343
+ params: {}
344
+ }
345
+ _http_client, _req_kwargs = self._client_with_auth(
346
+ [:"bearerAuth", ],
347
+ **_kwargs
348
+ )
349
+
350
+
351
+ _response = _http_client.get(
352
+ _url,
353
+
354
+ **_req_kwargs
355
+ )
356
+ if !_response.status.success?
357
+ raise RequestError.new(
358
+ method="get",
359
+ url=_url,
360
+ response=_response
361
+ )
362
+ end
363
+
364
+ return _response.body.empty? ? '' : _response.parse
365
+ end
366
+
367
+ # Returns a single Subscription Update object for a publication
368
+ def get_publications_publication_id_subcription_updates_id(publication_id, id)
369
+ _url = @_base_url + "/publications/#{publication_id}/bulk_subscription_updates/#{id}"
370
+ _kwargs = {
371
+ params: {}
372
+ }
373
+ _http_client, _req_kwargs = self._client_with_auth(
374
+ [:"bearerAuth", ],
375
+ **_kwargs
376
+ )
377
+
378
+
379
+ _response = _http_client.get(
380
+ _url,
381
+
382
+ **_req_kwargs
383
+ )
384
+ if !_response.status.success?
385
+ raise RequestError.new(
386
+ method="get",
387
+ url=_url,
388
+ response=_response
389
+ )
390
+ end
391
+
392
+ return _response.body.empty? ? '' : _response.parse
393
+ end
394
+
395
+ # Retrieve all custom fields belonging to a specific publication
396
+ def get_publications_publication_id_custom_fields(publication_id)
397
+ _url = @_base_url + "/publications/#{publication_id}/custom_fields"
398
+ _kwargs = {
399
+ params: {}
400
+ }
401
+ _http_client, _req_kwargs = self._client_with_auth(
402
+ [:"bearerAuth", ],
403
+ **_kwargs
404
+ )
405
+
406
+
407
+ _response = _http_client.get(
408
+ _url,
409
+
410
+ **_req_kwargs
411
+ )
412
+ if !_response.status.success?
413
+ raise RequestError.new(
414
+ method="get",
415
+ url=_url,
416
+ response=_response
417
+ )
418
+ end
419
+
420
+ return _response.body.empty? ? '' : _response.parse
421
+ end
422
+
423
+ # View a specific custom field on a publication
424
+ def get_publications_publication_id_custom_fields_id(publication_id, id)
425
+ _url = @_base_url + "/publications/#{publication_id}/custom_fields/#{id}"
426
+ _kwargs = {
427
+ params: {}
428
+ }
429
+ _http_client, _req_kwargs = self._client_with_auth(
430
+ [:"bearerAuth", ],
431
+ **_kwargs
432
+ )
433
+
434
+
435
+ _response = _http_client.get(
436
+ _url,
437
+
438
+ **_req_kwargs
439
+ )
440
+ if !_response.status.success?
441
+ raise RequestError.new(
442
+ method="get",
443
+ url=_url,
444
+ response=_response
445
+ )
446
+ end
447
+
448
+ return _response.body.empty? ? '' : _response.parse
449
+ end
450
+
451
+ # Retrieve all Email Blasts
452
+ def get_publications_publication_id_email_blasts(publication_id, direction: nil, expand: nil, limit: nil, order_by: nil, page: nil)
453
+ _url = @_base_url + "/publications/#{publication_id}/email_blasts"
454
+ _kwargs = {
455
+ params: {}
456
+ }
457
+ if direction != nil
458
+ _kwargs[:params][:"direction"] = direction
459
+ end
460
+ if expand != nil
461
+ _kwargs[:params][:"expand[]"] = expand
462
+ end
463
+ if limit != nil
464
+ _kwargs[:params][:"limit"] = limit
465
+ end
466
+ if order_by != nil
467
+ _kwargs[:params][:"order_by"] = order_by
468
+ end
469
+ if page != nil
470
+ _kwargs[:params][:"page"] = page
471
+ end
472
+ _http_client, _req_kwargs = self._client_with_auth(
473
+ [:"bearerAuth", ],
474
+ **_kwargs
475
+ )
476
+
477
+
478
+ _response = _http_client.get(
479
+ _url,
480
+
481
+ **_req_kwargs
482
+ )
483
+ if !_response.status.success?
484
+ raise RequestError.new(
485
+ method="get",
486
+ url=_url,
487
+ response=_response
488
+ )
489
+ end
490
+
491
+ return _response.body.empty? ? '' : _response.parse
492
+ end
493
+
494
+ # Retrieve an Email Blast
495
+ def get_publications_publication_id_email_blasts_email_blast_id(publication_id, email_blast_id, expand: nil)
496
+ _url = @_base_url + "/publications/#{publication_id}/email_blasts/#{email_blast_id}"
497
+ _kwargs = {
498
+ params: {}
499
+ }
500
+ if expand != nil
501
+ _kwargs[:params][:"expand[]"] = expand
502
+ end
503
+ _http_client, _req_kwargs = self._client_with_auth(
504
+ [:"bearerAuth", ],
505
+ **_kwargs
506
+ )
507
+
508
+
509
+ _response = _http_client.get(
510
+ _url,
511
+
512
+ **_req_kwargs
513
+ )
514
+ if !_response.status.success?
515
+ raise RequestError.new(
516
+ method="get",
517
+ url=_url,
518
+ response=_response
519
+ )
520
+ end
521
+
522
+ return _response.body.empty? ? '' : _response.parse
523
+ end
524
+
525
+ # Retrieve all posts belonging to a specific publication
526
+ def get_posts(publication_id, audience: nil, content_tags: nil, direction: nil, expand: nil, limit: nil, order_by: nil, page: nil, platform: nil, status: nil)
527
+ _url = @_base_url + "/publications/#{publication_id}/posts"
528
+ _kwargs = {
529
+ params: {}
530
+ }
531
+ if audience != nil
532
+ _kwargs[:params][:"audience"] = audience
533
+ end
534
+ if content_tags != nil
535
+ _kwargs[:params][:"content_tags[]"] = content_tags
536
+ end
537
+ if direction != nil
538
+ _kwargs[:params][:"direction"] = direction
539
+ end
540
+ if expand != nil
541
+ _kwargs[:params][:"expand[]"] = expand
542
+ end
543
+ if limit != nil
544
+ _kwargs[:params][:"limit"] = limit
545
+ end
546
+ if order_by != nil
547
+ _kwargs[:params][:"order_by"] = order_by
548
+ end
549
+ if page != nil
550
+ _kwargs[:params][:"page"] = page
551
+ end
552
+ if platform != nil
553
+ _kwargs[:params][:"platform"] = platform
554
+ end
555
+ if status != nil
556
+ _kwargs[:params][:"status"] = status
557
+ end
558
+ _http_client, _req_kwargs = self._client_with_auth(
559
+ [:"bearerAuth", ],
560
+ **_kwargs
561
+ )
562
+
563
+
564
+ _response = _http_client.get(
565
+ _url,
566
+
567
+ **_req_kwargs
568
+ )
569
+ if !_response.status.success?
570
+ raise RequestError.new(
571
+ method="get",
572
+ url=_url,
573
+ response=_response
574
+ )
575
+ end
576
+
577
+ return _response.body.empty? ? '' : _response.parse
578
+ end
579
+
580
+ # Retreive a single Post belonging to a specific publication
581
+ def get_posts_post_id(publication_id, post_id, expand: nil)
582
+ _url = @_base_url + "/publications/#{publication_id}/posts/#{post_id}"
583
+ _kwargs = {
584
+ params: {}
585
+ }
586
+ if expand != nil
587
+ _kwargs[:params][:"expand[]"] = expand
588
+ end
589
+ _http_client, _req_kwargs = self._client_with_auth(
590
+ [:"bearerAuth", ],
591
+ **_kwargs
592
+ )
593
+
594
+
595
+ _response = _http_client.get(
596
+ _url,
597
+
598
+ **_req_kwargs
599
+ )
600
+ if !_response.status.success?
601
+ raise RequestError.new(
602
+ method="get",
603
+ url=_url,
604
+ response=_response
605
+ )
606
+ end
607
+
608
+ return _response.body.empty? ? '' : _response.parse
609
+ end
610
+
611
+ # Retrieve details about the publication's referral program, including milestones and rewards.
612
+ def get_publications_public_referral_program(publication_id, limit: nil, page: nil)
613
+ _url = @_base_url + "/publications/#{publication_id}/referral_program"
614
+ _kwargs = {
615
+ params: {}
616
+ }
617
+ if limit != nil
618
+ _kwargs[:params][:"limit"] = limit
619
+ end
620
+ if page != nil
621
+ _kwargs[:params][:"page"] = page
622
+ end
623
+ _http_client, _req_kwargs = self._client_with_auth(
624
+ [:"bearerAuth", ],
625
+ **_kwargs
626
+ )
627
+
628
+
629
+ _response = _http_client.get(
630
+ _url,
631
+
632
+ **_req_kwargs
633
+ )
634
+ if !_response.status.success?
635
+ raise RequestError.new(
636
+ method="get",
637
+ url=_url,
638
+ response=_response
639
+ )
640
+ end
641
+
642
+ return _response.body.empty? ? '' : _response.parse
643
+ end
644
+
645
+ # Retrieve information about all segments belonging to a specific publication
646
+ def get_publications_publication_id_segments(publication_id, direction: nil, limit: nil, order_by: nil, page: nil, status: nil, type: nil)
647
+ _url = @_base_url + "/publications/#{publication_id}/segments"
648
+ _kwargs = {
649
+ params: {}
650
+ }
651
+ if direction != nil
652
+ _kwargs[:params][:"direction"] = direction
653
+ end
654
+ if limit != nil
655
+ _kwargs[:params][:"limit"] = limit
656
+ end
657
+ if order_by != nil
658
+ _kwargs[:params][:"order_by"] = order_by
659
+ end
660
+ if page != nil
661
+ _kwargs[:params][:"page"] = page
662
+ end
663
+ if status != nil
664
+ _kwargs[:params][:"status"] = status
665
+ end
666
+ if type != nil
667
+ _kwargs[:params][:"type"] = type
668
+ end
669
+ _http_client, _req_kwargs = self._client_with_auth(
670
+ [:"bearerAuth", ],
671
+ **_kwargs
672
+ )
673
+
674
+
675
+ _response = _http_client.get(
676
+ _url,
677
+
678
+ **_req_kwargs
679
+ )
680
+ if !_response.status.success?
681
+ raise RequestError.new(
682
+ method="get",
683
+ url=_url,
684
+ response=_response
685
+ )
686
+ end
687
+
688
+ return _response.body.empty? ? '' : _response.parse
689
+ end
690
+
691
+ # Retrieve a single segment belonging to a specific publication
692
+ def get_publications_publication_id_segments_segment_id(publication_id, segment_id)
693
+ _url = @_base_url + "/publications/#{publication_id}/segments/#{segment_id}"
694
+ _kwargs = {
695
+ params: {}
696
+ }
697
+ _http_client, _req_kwargs = self._client_with_auth(
698
+ [:"bearerAuth", ],
699
+ **_kwargs
700
+ )
701
+
702
+
703
+ _response = _http_client.get(
704
+ _url,
705
+
706
+ **_req_kwargs
707
+ )
708
+ if !_response.status.success?
709
+ raise RequestError.new(
710
+ method="get",
711
+ url=_url,
712
+ response=_response
713
+ )
714
+ end
715
+
716
+ return _response.body.empty? ? '' : _response.parse
717
+ end
718
+
719
+ # List the Subscriber Ids from the most recent calculation of a specific publication.
720
+ def get_publications_publication_id_segments_segment_id_results(publication_id, segment_id, limit: nil, page: nil)
721
+ _url = @_base_url + "/publications/#{publication_id}/segments/#{segment_id}/results"
722
+ _kwargs = {
723
+ params: {}
724
+ }
725
+ if limit != nil
726
+ _kwargs[:params][:"limit"] = limit
727
+ end
728
+ if page != nil
729
+ _kwargs[:params][:"page"] = page
730
+ end
731
+ _http_client, _req_kwargs = self._client_with_auth(
732
+ [:"bearerAuth", ],
733
+ **_kwargs
734
+ )
735
+
736
+
737
+ _response = _http_client.get(
738
+ _url,
739
+
740
+ **_req_kwargs
741
+ )
742
+ if !_response.status.success?
743
+ raise RequestError.new(
744
+ method="get",
745
+ url=_url,
746
+ response=_response
747
+ )
748
+ end
749
+
750
+ return _response.body.empty? ? '' : _response.parse
751
+ end
752
+
753
+ # Retrieve all subscriptions belonging to a specific publication
754
+ def get_subscriptions(publication_id, direction: nil, email: nil, expand: nil, limit: nil, order_by: nil, page: nil, status: nil, tier: nil)
755
+ _url = @_base_url + "/publications/#{publication_id}/subscriptions"
756
+ _kwargs = {
757
+ params: {}
758
+ }
759
+ if direction != nil
760
+ _kwargs[:params][:"direction"] = direction
761
+ end
762
+ if email != nil
763
+ _kwargs[:params][:"email"] = email
764
+ end
765
+ if expand != nil
766
+ _kwargs[:params][:"expand[]"] = expand
767
+ end
768
+ if limit != nil
769
+ _kwargs[:params][:"limit"] = limit
770
+ end
771
+ if order_by != nil
772
+ _kwargs[:params][:"order_by"] = order_by
773
+ end
774
+ if page != nil
775
+ _kwargs[:params][:"page"] = page
776
+ end
777
+ if status != nil
778
+ _kwargs[:params][:"status"] = status
779
+ end
780
+ if tier != nil
781
+ _kwargs[:params][:"tier"] = tier
782
+ end
783
+ _http_client, _req_kwargs = self._client_with_auth(
784
+ [:"bearerAuth", ],
785
+ **_kwargs
786
+ )
787
+
788
+
789
+ _response = _http_client.get(
790
+ _url,
791
+
792
+ **_req_kwargs
793
+ )
794
+ if !_response.status.success?
795
+ raise RequestError.new(
796
+ method="get",
797
+ url=_url,
798
+ response=_response
799
+ )
800
+ end
801
+
802
+ return _response.body.empty? ? '' : _response.parse
803
+ end
804
+
805
+ # Retrieve a single subscription belonging to a specific email address in a specific publication
806
+ def get_subscriptions_email(publication_id, email, expand: nil)
807
+ _url = @_base_url + "/publications/#{publication_id}/subscriptions/by_email/#{email}"
808
+ _kwargs = {
809
+ params: {}
810
+ }
811
+ if expand != nil
812
+ _kwargs[:params][:"expand[]"] = expand
813
+ end
814
+ _http_client, _req_kwargs = self._client_with_auth(
815
+ [:"bearerAuth", ],
816
+ **_kwargs
817
+ )
818
+
819
+
820
+ _response = _http_client.get(
821
+ _url,
822
+
823
+ **_req_kwargs
824
+ )
825
+ if !_response.status.success?
826
+ raise RequestError.new(
827
+ method="get",
828
+ url=_url,
829
+ response=_response
830
+ )
831
+ end
832
+
833
+ return _response.body.empty? ? '' : _response.parse
834
+ end
835
+
836
+ # Retrieve a single subscription belonging to a specific subscriber in a specific publication
837
+ def get_subscriptions_subscriber_id(publication_id, subscriber_id, expand: nil)
838
+ _url = @_base_url + "/publications/#{publication_id}/subscriptions/by_subscriber_id/#{subscriber_id}"
839
+ _kwargs = {
840
+ params: {}
841
+ }
842
+ if expand != nil
843
+ _kwargs[:params][:"expand[]"] = expand
844
+ end
845
+ _http_client, _req_kwargs = self._client_with_auth(
846
+ [:"bearerAuth", ],
847
+ **_kwargs
848
+ )
849
+
850
+
851
+ _response = _http_client.get(
852
+ _url,
853
+
854
+ **_req_kwargs
855
+ )
856
+ if !_response.status.success?
857
+ raise RequestError.new(
858
+ method="get",
859
+ url=_url,
860
+ response=_response
861
+ )
862
+ end
863
+
864
+ return _response.body.empty? ? '' : _response.parse
865
+ end
866
+
867
+ # Retrieve a single subscription belonging to a specific publication
868
+ def get_subscriptions_subscription_id(publication_id, subscription_id, expand: nil)
869
+ _url = @_base_url + "/publications/#{publication_id}/subscriptions/#{subscription_id}"
870
+ _kwargs = {
871
+ params: {}
872
+ }
873
+ if expand != nil
874
+ _kwargs[:params][:"expand[]"] = expand
875
+ end
876
+ _http_client, _req_kwargs = self._client_with_auth(
877
+ [:"bearerAuth", ],
878
+ **_kwargs
879
+ )
880
+
881
+
882
+ _response = _http_client.get(
883
+ _url,
884
+
885
+ **_req_kwargs
886
+ )
887
+ if !_response.status.success?
888
+ raise RequestError.new(
889
+ method="get",
890
+ url=_url,
891
+ response=_response
892
+ )
893
+ end
894
+
895
+ return _response.body.empty? ? '' : _response.parse
896
+ end
897
+
898
+ # Update a custom field on a publication
899
+ def patch_publications_publication_id_custom_fields_id(data: nil, publication_id, id)
900
+ _url = @_base_url + "/publications/#{publication_id}/custom_fields/#{id}"
901
+ _kwargs = {
902
+ params: {}
903
+ }
904
+ _http_client, _req_kwargs = self._client_with_auth(
905
+ [:"bearerAuth", ],
906
+ **_kwargs
907
+ )
908
+
909
+
910
+ _response = _http_client.patch(
911
+ _url,
912
+ json: data,
913
+ **_req_kwargs
914
+ )
915
+ if !_response.status.success?
916
+ raise RequestError.new(
917
+ method="patch",
918
+ url=_url,
919
+ response=_response
920
+ )
921
+ end
922
+
923
+ return _response.body.empty? ? '' : _response.parse
924
+ end
925
+
926
+ # Bulk update subscriptions' Status value
927
+ def patch_subscriptions_bulk_update_status(data: nil, publication_id)
928
+ _url = @_base_url + "/publications/#{publication_id}/subscriptions"
929
+ _kwargs = {
930
+ params: {}
931
+ }
932
+ _http_client, _req_kwargs = self._client_with_auth(
933
+ [:"bearerAuth", ],
934
+ **_kwargs
935
+ )
936
+
937
+
938
+ _response = _http_client.patch(
939
+ _url,
940
+ json: data,
941
+ **_req_kwargs
942
+ )
943
+ if !_response.status.success?
944
+ raise RequestError.new(
945
+ method="patch",
946
+ url=_url,
947
+ response=_response
948
+ )
949
+ end
950
+
951
+ return _response.body.empty? ? '' : _response.parse
952
+ end
953
+
954
+ # Bulk update subscriptions' field values (standard fields and custom fields)
955
+ def patch_subscriptions_bulk_actions_bulk_update(data: nil, publication_id)
956
+ _url = @_base_url + "/publications/#{publication_id}/subscriptions/bulk_actions"
957
+ _kwargs = {
958
+ params: {}
959
+ }
960
+ _http_client, _req_kwargs = self._client_with_auth(
961
+ [:"bearerAuth", ],
962
+ **_kwargs
963
+ )
964
+
965
+
966
+ _response = _http_client.patch(
967
+ _url,
968
+ json: data,
969
+ **_req_kwargs
970
+ )
971
+ if !_response.status.success?
972
+ raise RequestError.new(
973
+ method="patch",
974
+ url=_url,
975
+ response=_response
976
+ )
977
+ end
978
+
979
+ return _response.body.empty? ? '' : _response.parse
980
+ end
981
+
982
+ # Update a subscriber
983
+ def method_1patch_subscriptions_subscription_id(data, publication_id, subscription_id)
984
+ _url = @_base_url + "/publications/#{publication_id}/subscriptions/#{subscription_id}"
985
+ _kwargs = {
986
+ params: {}
987
+ }
988
+ _http_client, _req_kwargs = self._client_with_auth(
989
+ [:"bearerAuth", ],
990
+ **_kwargs
991
+ )
992
+
993
+
994
+ _response = _http_client.patch(
995
+ _url,
996
+ json: data,
997
+ **_req_kwargs
998
+ )
999
+ if !_response.status.success?
1000
+ raise RequestError.new(
1001
+ method="patch",
1002
+ url=_url,
1003
+ response=_response
1004
+ )
1005
+ end
1006
+
1007
+ return _response.body.empty? ? '' : _response.parse
1008
+ end
1009
+
1010
+ # Create a custom field on a publication, for use in subscriptions
1011
+ def post_publications_publication_id_custom_fields(data: nil, publication_id)
1012
+ _url = @_base_url + "/publications/#{publication_id}/custom_fields"
1013
+ _kwargs = {
1014
+ params: {}
1015
+ }
1016
+ _http_client, _req_kwargs = self._client_with_auth(
1017
+ [:"bearerAuth", ],
1018
+ **_kwargs
1019
+ )
1020
+
1021
+
1022
+ _response = _http_client.post(
1023
+ _url,
1024
+ json: data,
1025
+ **_req_kwargs
1026
+ )
1027
+ if !_response.status.success?
1028
+ raise RequestError.new(
1029
+ method="post",
1030
+ url=_url,
1031
+ response=_response
1032
+ )
1033
+ end
1034
+
1035
+ return _response.body.empty? ? '' : _response.parse
1036
+ end
1037
+
1038
+ # Create new subscriptions for a publication.
1039
+ def post_subscriptions(data, publication_id, sales: nil)
1040
+ _url = @_base_url + "/publications/#{publication_id}/subscriptions"
1041
+ _kwargs = {
1042
+ params: {}
1043
+ }
1044
+ if sales != nil
1045
+ _kwargs[:params][:"sales"] = sales
1046
+ end
1047
+ _http_client, _req_kwargs = self._client_with_auth(
1048
+ [:"bearerAuth", ],
1049
+ **_kwargs
1050
+ )
1051
+
1052
+
1053
+ _response = _http_client.post(
1054
+ _url,
1055
+ json: data,
1056
+ **_req_kwargs
1057
+ )
1058
+ if !_response.status.success?
1059
+ raise RequestError.new(
1060
+ method="post",
1061
+ url=_url,
1062
+ response=_response
1063
+ )
1064
+ end
1065
+
1066
+ return _response.body.empty? ? '' : _response.parse
1067
+ end
1068
+
1069
+ # Update a custom field on a publication
1070
+ def put_publications_publication_id_custom_fields_id(data: nil, publication_id, id)
1071
+ _url = @_base_url + "/publications/#{publication_id}/custom_fields/#{id}"
1072
+ _kwargs = {
1073
+ params: {}
1074
+ }
1075
+ _http_client, _req_kwargs = self._client_with_auth(
1076
+ [:"bearerAuth", ],
1077
+ **_kwargs
1078
+ )
1079
+
1080
+
1081
+ _response = _http_client.put(
1082
+ _url,
1083
+ json: data,
1084
+ **_req_kwargs
1085
+ )
1086
+ if !_response.status.success?
1087
+ raise RequestError.new(
1088
+ method="put",
1089
+ url=_url,
1090
+ response=_response
1091
+ )
1092
+ end
1093
+
1094
+ return _response.body.empty? ? '' : _response.parse
1095
+ end
1096
+
1097
+ # Bulk update subscriptions' Status value
1098
+ def put_subscriptions_bulk_update_status(data: nil, publication_id)
1099
+ _url = @_base_url + "/publications/#{publication_id}/subscriptions"
1100
+ _kwargs = {
1101
+ params: {}
1102
+ }
1103
+ _http_client, _req_kwargs = self._client_with_auth(
1104
+ [:"bearerAuth", ],
1105
+ **_kwargs
1106
+ )
1107
+
1108
+
1109
+ _response = _http_client.put(
1110
+ _url,
1111
+ json: data,
1112
+ **_req_kwargs
1113
+ )
1114
+ if !_response.status.success?
1115
+ raise RequestError.new(
1116
+ method="put",
1117
+ url=_url,
1118
+ response=_response
1119
+ )
1120
+ end
1121
+
1122
+ return _response.body.empty? ? '' : _response.parse
1123
+ end
1124
+
1125
+ # Bulk update subscriptions' field values (standard fields and custom fields)
1126
+ def put_subscriptions_bulk_actions_bulk_update(data: nil, publication_id)
1127
+ _url = @_base_url + "/publications/#{publication_id}/subscriptions/bulk_actions"
1128
+ _kwargs = {
1129
+ params: {}
1130
+ }
1131
+ _http_client, _req_kwargs = self._client_with_auth(
1132
+ [:"bearerAuth", ],
1133
+ **_kwargs
1134
+ )
1135
+
1136
+
1137
+ _response = _http_client.put(
1138
+ _url,
1139
+ json: data,
1140
+ **_req_kwargs
1141
+ )
1142
+ if !_response.status.success?
1143
+ raise RequestError.new(
1144
+ method="put",
1145
+ url=_url,
1146
+ response=_response
1147
+ )
1148
+ end
1149
+
1150
+ return _response.body.empty? ? '' : _response.parse
1151
+ end
1152
+
1153
+ # Update a subscriber
1154
+ def put_subscriptions_subscription_id(data, publication_id, subscription_id)
1155
+ _url = @_base_url + "/publications/#{publication_id}/subscriptions/#{subscription_id}"
1156
+ _kwargs = {
1157
+ params: {}
1158
+ }
1159
+ _http_client, _req_kwargs = self._client_with_auth(
1160
+ [:"bearerAuth", ],
1161
+ **_kwargs
1162
+ )
1163
+
1164
+
1165
+ _response = _http_client.put(
1166
+ _url,
1167
+ json: data,
1168
+ **_req_kwargs
1169
+ )
1170
+ if !_response.status.success?
1171
+ raise RequestError.new(
1172
+ method="put",
1173
+ url=_url,
1174
+ response=_response
1175
+ )
1176
+ end
1177
+
1178
+ return _response.body.empty? ? '' : _response.parse
1179
+ end
1180
+
1181
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beehiiv_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Sideko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-01-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.1
27
+ description: |-
28
+ Swarm public API
29
+
30
+ **THE NEWSLETTER PLATFORM BUILT FOR GROWTH.**
31
+
32
+ *Built by newsletter people*
33
+ email: team@sideko.dev
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - lib/beehiiv_api.rb
39
+ homepage:
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.3.5
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: beehiiv_api 1.0.0
62
+ test_files: []