moderation_api 3.2.0 → 3.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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/moderation_api/authors.rb +759 -0
  3. data/lib/moderation_api/content.rb +506 -0
  4. data/lib/moderation_api/models/operations/allowcontent_request.rb +45 -0
  5. data/lib/moderation_api/models/operations/allowcontent_request.rbi +26 -0
  6. data/lib/moderation_api/models/operations/allowcontent_requestbody.rb +67 -0
  7. data/lib/moderation_api/models/operations/allowcontent_requestbody.rbi +32 -0
  8. data/lib/moderation_api/models/operations/allowcontent_response.rb +51 -0
  9. data/lib/moderation_api/models/operations/allowcontent_response.rbi +32 -0
  10. data/lib/moderation_api/models/operations/allowcontent_responsebody.rb +35 -0
  11. data/lib/moderation_api/models/operations/allowcontent_responsebody.rbi +14 -0
  12. data/lib/moderation_api/models/operations/blockauthor_request.rb +45 -0
  13. data/lib/moderation_api/models/operations/blockauthor_request.rbi +26 -0
  14. data/lib/moderation_api/models/operations/blockauthor_requestbody.rb +35 -0
  15. data/lib/moderation_api/models/operations/blockauthor_requestbody.rbi +14 -0
  16. data/lib/moderation_api/models/operations/blockauthor_response.rb +51 -0
  17. data/lib/moderation_api/models/operations/blockauthor_response.rbi +32 -0
  18. data/lib/moderation_api/models/operations/blockauthor_responsebody.rb +35 -0
  19. data/lib/moderation_api/models/operations/blockauthor_responsebody.rbi +14 -0
  20. data/lib/moderation_api/models/operations/executeaction_requestbody.rb +29 -2
  21. data/lib/moderation_api/models/operations/executeaction_requestbody.rbi +12 -0
  22. data/lib/moderation_api/models/operations/rejectcontent_request.rb +45 -0
  23. data/lib/moderation_api/models/operations/rejectcontent_request.rbi +26 -0
  24. data/lib/moderation_api/models/operations/rejectcontent_requestbody.rb +67 -0
  25. data/lib/moderation_api/models/operations/rejectcontent_requestbody.rbi +32 -0
  26. data/lib/moderation_api/models/operations/rejectcontent_response.rb +51 -0
  27. data/lib/moderation_api/models/operations/rejectcontent_response.rbi +32 -0
  28. data/lib/moderation_api/models/operations/rejectcontent_responsebody.rb +35 -0
  29. data/lib/moderation_api/models/operations/rejectcontent_responsebody.rbi +14 -0
  30. data/lib/moderation_api/models/operations/suspendauthor_request.rb +45 -0
  31. data/lib/moderation_api/models/operations/suspendauthor_request.rbi +26 -0
  32. data/lib/moderation_api/models/operations/suspendauthor_requestbody.rb +43 -0
  33. data/lib/moderation_api/models/operations/suspendauthor_requestbody.rbi +20 -0
  34. data/lib/moderation_api/models/operations/suspendauthor_response.rb +51 -0
  35. data/lib/moderation_api/models/operations/suspendauthor_response.rbi +32 -0
  36. data/lib/moderation_api/models/operations/suspendauthor_responsebody.rb +35 -0
  37. data/lib/moderation_api/models/operations/suspendauthor_responsebody.rbi +14 -0
  38. data/lib/moderation_api/models/operations/unblockauthor_request.rb +45 -0
  39. data/lib/moderation_api/models/operations/unblockauthor_request.rbi +26 -0
  40. data/lib/moderation_api/models/operations/unblockauthor_requestbody.rb +35 -0
  41. data/lib/moderation_api/models/operations/unblockauthor_requestbody.rbi +14 -0
  42. data/lib/moderation_api/models/operations/unblockauthor_response.rb +51 -0
  43. data/lib/moderation_api/models/operations/unblockauthor_response.rbi +32 -0
  44. data/lib/moderation_api/models/operations/unblockauthor_responsebody.rb +35 -0
  45. data/lib/moderation_api/models/operations/unblockauthor_responsebody.rbi +14 -0
  46. data/lib/moderation_api/models/operations.rb +20 -0
  47. data/lib/moderation_api/moderationapi.rb +2 -2
  48. data/lib/moderation_api/sdkconfiguration.rb +2 -2
  49. data/lib/moderation_api.rb +1 -1
  50. metadata +42 -2
@@ -1481,5 +1481,764 @@ module ModerationApi
1481
1481
 
1482
1482
  end
1483
1483
  end
1484
+
1485
+ sig {
1486
+ params(
1487
+ body: Models::Operations::BlockAuthorRequestBody,
1488
+ id: ::String,
1489
+ project_id: T.nilable(::String),
1490
+ timeout_ms: T.nilable(Integer),
1491
+ http_headers: T.nilable(T::Hash[T.any(String, Symbol), String])
1492
+ )
1493
+ .returns(Models::Operations::BlockAuthorResponse)
1494
+ }
1495
+ def block(body:, id:, project_id: nil, timeout_ms: nil, http_headers: nil)
1496
+ # block - Block author
1497
+ # Block an author with the built-in block action. A blocked author cannot post new content until unblocked.
1498
+ request = Models::Operations::BlockAuthorRequest.new(
1499
+ id: id,
1500
+ body: body,
1501
+ project_id: project_id
1502
+ )
1503
+ url, params = @sdk_configuration.get_server_details
1504
+ base_url = Utils.template_url(url, params)
1505
+ url = Utils.generate_url(
1506
+ Models::Operations::BlockAuthorRequest,
1507
+ base_url,
1508
+ "/authors/{id}/block",
1509
+ request
1510
+ )
1511
+ headers = Utils.get_headers(request)
1512
+ headers = T.cast(headers, T::Hash[String, String])
1513
+ req_content_type, data, form = Utils.serialize_request_body(request, false, false, :body, :json)
1514
+ headers["content-type"] = req_content_type
1515
+ raise StandardError, "request body is required" if data.nil? && form.nil?
1516
+
1517
+ if form && !form.empty?
1518
+ body = Utils.encode_form(form)
1519
+ elsif Utils.match_content_type(req_content_type, "application/x-www-form-urlencoded")
1520
+ body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
1521
+ else
1522
+ body = data
1523
+ end
1524
+
1525
+ headers["Accept"] = "application/json"
1526
+ headers["user-agent"] = @sdk_configuration.user_agent
1527
+
1528
+ security = @sdk_configuration.security_source&.call
1529
+
1530
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
1531
+ timeout ||= @sdk_configuration.timeout
1532
+
1533
+ connection = @sdk_configuration.client
1534
+
1535
+ hook_ctx = SDKHooks::HookContext.new(
1536
+ config: @sdk_configuration,
1537
+ base_url: base_url,
1538
+ oauth2_scopes: nil,
1539
+ operation_id: "blockAuthor",
1540
+ security_source: @sdk_configuration.security_source
1541
+ )
1542
+
1543
+ error = T.let(nil, T.nilable(StandardError))
1544
+ http_response = T.let(nil, T.nilable(Faraday::Response))
1545
+
1546
+ begin
1547
+ http_response = T.must(connection).post(url) do |req|
1548
+ req.body = body
1549
+ req.headers.merge!(headers)
1550
+ req.options.timeout = timeout unless timeout.nil?
1551
+ Utils.configure_request_security(req, security)
1552
+ http_headers&.each do |key, value|
1553
+ req.headers[key.to_s] = value
1554
+ end
1555
+
1556
+ @sdk_configuration.hooks.before_request(
1557
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
1558
+ hook_ctx: hook_ctx
1559
+ ),
1560
+ request: req
1561
+ )
1562
+ end
1563
+
1564
+ rescue StandardError => e
1565
+ error = e
1566
+ ensure
1567
+ if http_response.nil? || Utils.error_status?(http_response.status)
1568
+ http_response = @sdk_configuration.hooks.after_error(
1569
+ error: error,
1570
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
1571
+ hook_ctx: hook_ctx
1572
+ ),
1573
+ response: http_response
1574
+ )
1575
+ else
1576
+ http_response = @sdk_configuration.hooks.after_success(
1577
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
1578
+ hook_ctx: hook_ctx
1579
+ ),
1580
+ response: http_response
1581
+ )
1582
+ end
1583
+
1584
+ if http_response.nil?
1585
+ raise error if !error.nil?
1586
+ raise "no response"
1587
+ end
1588
+ end
1589
+
1590
+ content_type = http_response.headers.fetch("Content-Type", "application/octet-stream")
1591
+ if Utils.match_status_code(http_response.status, ["200"])
1592
+ if Utils.match_content_type(content_type, "application/json")
1593
+ http_response = @sdk_configuration.hooks.after_success(
1594
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
1595
+ hook_ctx: hook_ctx
1596
+ ),
1597
+ response: http_response
1598
+ )
1599
+ response_data = http_response.env.response_body
1600
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Operations::BlockAuthorResponseBody)
1601
+ response = Models::Operations::BlockAuthorResponse.new(
1602
+ status_code: http_response.status,
1603
+ content_type: content_type,
1604
+ raw_response: http_response,
1605
+ object: T.unsafe(obj)
1606
+ )
1607
+
1608
+ return response
1609
+ else
1610
+ raise(
1611
+ ::ModerationApi::Models::Errors::APIError.new(
1612
+ status_code: http_response.status,
1613
+ body: http_response.env.response_body,
1614
+ raw_response: http_response
1615
+ ),
1616
+ "Unknown content type received"
1617
+ )
1618
+ end
1619
+ elsif Utils.match_status_code(http_response.status, ["400"])
1620
+ if Utils.match_content_type(content_type, "application/json")
1621
+ http_response = @sdk_configuration.hooks.after_success(
1622
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
1623
+ hook_ctx: hook_ctx
1624
+ ),
1625
+ response: http_response
1626
+ )
1627
+ response_data = http_response.env.response_body
1628
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::BadRequestError)
1629
+ obj.raw_response = http_response
1630
+ raise obj
1631
+ else
1632
+ raise(
1633
+ ::ModerationApi::Models::Errors::APIError.new(
1634
+ status_code: http_response.status,
1635
+ body: http_response.env.response_body,
1636
+ raw_response: http_response
1637
+ ),
1638
+ "Unknown content type received"
1639
+ )
1640
+ end
1641
+ elsif Utils.match_status_code(http_response.status, ["401"])
1642
+ if Utils.match_content_type(content_type, "application/json")
1643
+ http_response = @sdk_configuration.hooks.after_success(
1644
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
1645
+ hook_ctx: hook_ctx
1646
+ ),
1647
+ response: http_response
1648
+ )
1649
+ response_data = http_response.env.response_body
1650
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::AuthenticationError)
1651
+ obj.raw_response = http_response
1652
+ raise obj
1653
+ else
1654
+ raise(
1655
+ ::ModerationApi::Models::Errors::APIError.new(
1656
+ status_code: http_response.status,
1657
+ body: http_response.env.response_body,
1658
+ raw_response: http_response
1659
+ ),
1660
+ "Unknown content type received"
1661
+ )
1662
+ end
1663
+ elsif Utils.match_status_code(http_response.status, ["404"])
1664
+ if Utils.match_content_type(content_type, "application/json")
1665
+ http_response = @sdk_configuration.hooks.after_success(
1666
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
1667
+ hook_ctx: hook_ctx
1668
+ ),
1669
+ response: http_response
1670
+ )
1671
+ response_data = http_response.env.response_body
1672
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::NotFoundError)
1673
+ obj.raw_response = http_response
1674
+ raise obj
1675
+ else
1676
+ raise(
1677
+ ::ModerationApi::Models::Errors::APIError.new(
1678
+ status_code: http_response.status,
1679
+ body: http_response.env.response_body,
1680
+ raw_response: http_response
1681
+ ),
1682
+ "Unknown content type received"
1683
+ )
1684
+ end
1685
+ elsif Utils.match_status_code(http_response.status, ["429"])
1686
+ if Utils.match_content_type(content_type, "application/json")
1687
+ http_response = @sdk_configuration.hooks.after_success(
1688
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
1689
+ hook_ctx: hook_ctx
1690
+ ),
1691
+ response: http_response
1692
+ )
1693
+ response_data = http_response.env.response_body
1694
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::RateLimitError)
1695
+ obj.raw_response = http_response
1696
+ raise obj
1697
+ else
1698
+ raise(
1699
+ ::ModerationApi::Models::Errors::APIError.new(
1700
+ status_code: http_response.status,
1701
+ body: http_response.env.response_body,
1702
+ raw_response: http_response
1703
+ ),
1704
+ "Unknown content type received"
1705
+ )
1706
+ end
1707
+ elsif Utils.match_status_code(http_response.status, ["4XX"])
1708
+ raise(
1709
+ ::ModerationApi::Models::Errors::APIError.new(
1710
+ status_code: http_response.status,
1711
+ body: http_response.env.response_body,
1712
+ raw_response: http_response
1713
+ ),
1714
+ "API error occurred"
1715
+ )
1716
+ elsif Utils.match_status_code(http_response.status, ["5XX"])
1717
+ raise(
1718
+ ::ModerationApi::Models::Errors::APIError.new(
1719
+ status_code: http_response.status,
1720
+ body: http_response.env.response_body,
1721
+ raw_response: http_response
1722
+ ),
1723
+ "API error occurred"
1724
+ )
1725
+ else
1726
+ raise(
1727
+ ::ModerationApi::Models::Errors::APIError.new(
1728
+ status_code: http_response.status,
1729
+ body: http_response.env.response_body,
1730
+ raw_response: http_response
1731
+ ),
1732
+ "Unknown status code received"
1733
+ )
1734
+
1735
+ end
1736
+ end
1737
+
1738
+ sig {
1739
+ params(
1740
+ body: Models::Operations::SuspendAuthorRequestBody,
1741
+ id: ::String,
1742
+ project_id: T.nilable(::String),
1743
+ timeout_ms: T.nilable(Integer),
1744
+ http_headers: T.nilable(T::Hash[T.any(String, Symbol), String])
1745
+ )
1746
+ .returns(Models::Operations::SuspendAuthorResponse)
1747
+ }
1748
+ def suspend(body:, id:, project_id: nil, timeout_ms: nil, http_headers: nil)
1749
+ # suspend - Suspend author
1750
+ # Block an author for a limited time with the built-in suspend action.
1751
+ request = Models::Operations::SuspendAuthorRequest.new(
1752
+ id: id,
1753
+ body: body,
1754
+ project_id: project_id
1755
+ )
1756
+ url, params = @sdk_configuration.get_server_details
1757
+ base_url = Utils.template_url(url, params)
1758
+ url = Utils.generate_url(
1759
+ Models::Operations::SuspendAuthorRequest,
1760
+ base_url,
1761
+ "/authors/{id}/suspend",
1762
+ request
1763
+ )
1764
+ headers = Utils.get_headers(request)
1765
+ headers = T.cast(headers, T::Hash[String, String])
1766
+ req_content_type, data, form = Utils.serialize_request_body(request, false, false, :body, :json)
1767
+ headers["content-type"] = req_content_type
1768
+ raise StandardError, "request body is required" if data.nil? && form.nil?
1769
+
1770
+ if form && !form.empty?
1771
+ body = Utils.encode_form(form)
1772
+ elsif Utils.match_content_type(req_content_type, "application/x-www-form-urlencoded")
1773
+ body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
1774
+ else
1775
+ body = data
1776
+ end
1777
+
1778
+ headers["Accept"] = "application/json"
1779
+ headers["user-agent"] = @sdk_configuration.user_agent
1780
+
1781
+ security = @sdk_configuration.security_source&.call
1782
+
1783
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
1784
+ timeout ||= @sdk_configuration.timeout
1785
+
1786
+ connection = @sdk_configuration.client
1787
+
1788
+ hook_ctx = SDKHooks::HookContext.new(
1789
+ config: @sdk_configuration,
1790
+ base_url: base_url,
1791
+ oauth2_scopes: nil,
1792
+ operation_id: "suspendAuthor",
1793
+ security_source: @sdk_configuration.security_source
1794
+ )
1795
+
1796
+ error = T.let(nil, T.nilable(StandardError))
1797
+ http_response = T.let(nil, T.nilable(Faraday::Response))
1798
+
1799
+ begin
1800
+ http_response = T.must(connection).post(url) do |req|
1801
+ req.body = body
1802
+ req.headers.merge!(headers)
1803
+ req.options.timeout = timeout unless timeout.nil?
1804
+ Utils.configure_request_security(req, security)
1805
+ http_headers&.each do |key, value|
1806
+ req.headers[key.to_s] = value
1807
+ end
1808
+
1809
+ @sdk_configuration.hooks.before_request(
1810
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
1811
+ hook_ctx: hook_ctx
1812
+ ),
1813
+ request: req
1814
+ )
1815
+ end
1816
+
1817
+ rescue StandardError => e
1818
+ error = e
1819
+ ensure
1820
+ if http_response.nil? || Utils.error_status?(http_response.status)
1821
+ http_response = @sdk_configuration.hooks.after_error(
1822
+ error: error,
1823
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
1824
+ hook_ctx: hook_ctx
1825
+ ),
1826
+ response: http_response
1827
+ )
1828
+ else
1829
+ http_response = @sdk_configuration.hooks.after_success(
1830
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
1831
+ hook_ctx: hook_ctx
1832
+ ),
1833
+ response: http_response
1834
+ )
1835
+ end
1836
+
1837
+ if http_response.nil?
1838
+ raise error if !error.nil?
1839
+ raise "no response"
1840
+ end
1841
+ end
1842
+
1843
+ content_type = http_response.headers.fetch("Content-Type", "application/octet-stream")
1844
+ if Utils.match_status_code(http_response.status, ["200"])
1845
+ if Utils.match_content_type(content_type, "application/json")
1846
+ http_response = @sdk_configuration.hooks.after_success(
1847
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
1848
+ hook_ctx: hook_ctx
1849
+ ),
1850
+ response: http_response
1851
+ )
1852
+ response_data = http_response.env.response_body
1853
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Operations::SuspendAuthorResponseBody)
1854
+ response = Models::Operations::SuspendAuthorResponse.new(
1855
+ status_code: http_response.status,
1856
+ content_type: content_type,
1857
+ raw_response: http_response,
1858
+ object: T.unsafe(obj)
1859
+ )
1860
+
1861
+ return response
1862
+ else
1863
+ raise(
1864
+ ::ModerationApi::Models::Errors::APIError.new(
1865
+ status_code: http_response.status,
1866
+ body: http_response.env.response_body,
1867
+ raw_response: http_response
1868
+ ),
1869
+ "Unknown content type received"
1870
+ )
1871
+ end
1872
+ elsif Utils.match_status_code(http_response.status, ["400"])
1873
+ if Utils.match_content_type(content_type, "application/json")
1874
+ http_response = @sdk_configuration.hooks.after_success(
1875
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
1876
+ hook_ctx: hook_ctx
1877
+ ),
1878
+ response: http_response
1879
+ )
1880
+ response_data = http_response.env.response_body
1881
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::BadRequestError)
1882
+ obj.raw_response = http_response
1883
+ raise obj
1884
+ else
1885
+ raise(
1886
+ ::ModerationApi::Models::Errors::APIError.new(
1887
+ status_code: http_response.status,
1888
+ body: http_response.env.response_body,
1889
+ raw_response: http_response
1890
+ ),
1891
+ "Unknown content type received"
1892
+ )
1893
+ end
1894
+ elsif Utils.match_status_code(http_response.status, ["401"])
1895
+ if Utils.match_content_type(content_type, "application/json")
1896
+ http_response = @sdk_configuration.hooks.after_success(
1897
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
1898
+ hook_ctx: hook_ctx
1899
+ ),
1900
+ response: http_response
1901
+ )
1902
+ response_data = http_response.env.response_body
1903
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::AuthenticationError)
1904
+ obj.raw_response = http_response
1905
+ raise obj
1906
+ else
1907
+ raise(
1908
+ ::ModerationApi::Models::Errors::APIError.new(
1909
+ status_code: http_response.status,
1910
+ body: http_response.env.response_body,
1911
+ raw_response: http_response
1912
+ ),
1913
+ "Unknown content type received"
1914
+ )
1915
+ end
1916
+ elsif Utils.match_status_code(http_response.status, ["404"])
1917
+ if Utils.match_content_type(content_type, "application/json")
1918
+ http_response = @sdk_configuration.hooks.after_success(
1919
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
1920
+ hook_ctx: hook_ctx
1921
+ ),
1922
+ response: http_response
1923
+ )
1924
+ response_data = http_response.env.response_body
1925
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::NotFoundError)
1926
+ obj.raw_response = http_response
1927
+ raise obj
1928
+ else
1929
+ raise(
1930
+ ::ModerationApi::Models::Errors::APIError.new(
1931
+ status_code: http_response.status,
1932
+ body: http_response.env.response_body,
1933
+ raw_response: http_response
1934
+ ),
1935
+ "Unknown content type received"
1936
+ )
1937
+ end
1938
+ elsif Utils.match_status_code(http_response.status, ["429"])
1939
+ if Utils.match_content_type(content_type, "application/json")
1940
+ http_response = @sdk_configuration.hooks.after_success(
1941
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
1942
+ hook_ctx: hook_ctx
1943
+ ),
1944
+ response: http_response
1945
+ )
1946
+ response_data = http_response.env.response_body
1947
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::RateLimitError)
1948
+ obj.raw_response = http_response
1949
+ raise obj
1950
+ else
1951
+ raise(
1952
+ ::ModerationApi::Models::Errors::APIError.new(
1953
+ status_code: http_response.status,
1954
+ body: http_response.env.response_body,
1955
+ raw_response: http_response
1956
+ ),
1957
+ "Unknown content type received"
1958
+ )
1959
+ end
1960
+ elsif Utils.match_status_code(http_response.status, ["4XX"])
1961
+ raise(
1962
+ ::ModerationApi::Models::Errors::APIError.new(
1963
+ status_code: http_response.status,
1964
+ body: http_response.env.response_body,
1965
+ raw_response: http_response
1966
+ ),
1967
+ "API error occurred"
1968
+ )
1969
+ elsif Utils.match_status_code(http_response.status, ["5XX"])
1970
+ raise(
1971
+ ::ModerationApi::Models::Errors::APIError.new(
1972
+ status_code: http_response.status,
1973
+ body: http_response.env.response_body,
1974
+ raw_response: http_response
1975
+ ),
1976
+ "API error occurred"
1977
+ )
1978
+ else
1979
+ raise(
1980
+ ::ModerationApi::Models::Errors::APIError.new(
1981
+ status_code: http_response.status,
1982
+ body: http_response.env.response_body,
1983
+ raw_response: http_response
1984
+ ),
1985
+ "Unknown status code received"
1986
+ )
1987
+
1988
+ end
1989
+ end
1990
+
1991
+ sig {
1992
+ params(
1993
+ body: Models::Operations::UnblockAuthorRequestBody,
1994
+ id: ::String,
1995
+ project_id: T.nilable(::String),
1996
+ timeout_ms: T.nilable(Integer),
1997
+ http_headers: T.nilable(T::Hash[T.any(String, Symbol), String])
1998
+ )
1999
+ .returns(Models::Operations::UnblockAuthorResponse)
2000
+ }
2001
+ def unblock(body:, id:, project_id: nil, timeout_ms: nil, http_headers: nil)
2002
+ # unblock - Unblock author
2003
+ # Unblock a blocked or suspended author with the built-in unblock action, so they can post new content again.
2004
+ request = Models::Operations::UnblockAuthorRequest.new(
2005
+ id: id,
2006
+ body: body,
2007
+ project_id: project_id
2008
+ )
2009
+ url, params = @sdk_configuration.get_server_details
2010
+ base_url = Utils.template_url(url, params)
2011
+ url = Utils.generate_url(
2012
+ Models::Operations::UnblockAuthorRequest,
2013
+ base_url,
2014
+ "/authors/{id}/unblock",
2015
+ request
2016
+ )
2017
+ headers = Utils.get_headers(request)
2018
+ headers = T.cast(headers, T::Hash[String, String])
2019
+ req_content_type, data, form = Utils.serialize_request_body(request, false, false, :body, :json)
2020
+ headers["content-type"] = req_content_type
2021
+ raise StandardError, "request body is required" if data.nil? && form.nil?
2022
+
2023
+ if form && !form.empty?
2024
+ body = Utils.encode_form(form)
2025
+ elsif Utils.match_content_type(req_content_type, "application/x-www-form-urlencoded")
2026
+ body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
2027
+ else
2028
+ body = data
2029
+ end
2030
+
2031
+ headers["Accept"] = "application/json"
2032
+ headers["user-agent"] = @sdk_configuration.user_agent
2033
+
2034
+ security = @sdk_configuration.security_source&.call
2035
+
2036
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
2037
+ timeout ||= @sdk_configuration.timeout
2038
+
2039
+ connection = @sdk_configuration.client
2040
+
2041
+ hook_ctx = SDKHooks::HookContext.new(
2042
+ config: @sdk_configuration,
2043
+ base_url: base_url,
2044
+ oauth2_scopes: nil,
2045
+ operation_id: "unblockAuthor",
2046
+ security_source: @sdk_configuration.security_source
2047
+ )
2048
+
2049
+ error = T.let(nil, T.nilable(StandardError))
2050
+ http_response = T.let(nil, T.nilable(Faraday::Response))
2051
+
2052
+ begin
2053
+ http_response = T.must(connection).post(url) do |req|
2054
+ req.body = body
2055
+ req.headers.merge!(headers)
2056
+ req.options.timeout = timeout unless timeout.nil?
2057
+ Utils.configure_request_security(req, security)
2058
+ http_headers&.each do |key, value|
2059
+ req.headers[key.to_s] = value
2060
+ end
2061
+
2062
+ @sdk_configuration.hooks.before_request(
2063
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
2064
+ hook_ctx: hook_ctx
2065
+ ),
2066
+ request: req
2067
+ )
2068
+ end
2069
+
2070
+ rescue StandardError => e
2071
+ error = e
2072
+ ensure
2073
+ if http_response.nil? || Utils.error_status?(http_response.status)
2074
+ http_response = @sdk_configuration.hooks.after_error(
2075
+ error: error,
2076
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
2077
+ hook_ctx: hook_ctx
2078
+ ),
2079
+ response: http_response
2080
+ )
2081
+ else
2082
+ http_response = @sdk_configuration.hooks.after_success(
2083
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
2084
+ hook_ctx: hook_ctx
2085
+ ),
2086
+ response: http_response
2087
+ )
2088
+ end
2089
+
2090
+ if http_response.nil?
2091
+ raise error if !error.nil?
2092
+ raise "no response"
2093
+ end
2094
+ end
2095
+
2096
+ content_type = http_response.headers.fetch("Content-Type", "application/octet-stream")
2097
+ if Utils.match_status_code(http_response.status, ["200"])
2098
+ if Utils.match_content_type(content_type, "application/json")
2099
+ http_response = @sdk_configuration.hooks.after_success(
2100
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
2101
+ hook_ctx: hook_ctx
2102
+ ),
2103
+ response: http_response
2104
+ )
2105
+ response_data = http_response.env.response_body
2106
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Operations::UnblockAuthorResponseBody)
2107
+ response = Models::Operations::UnblockAuthorResponse.new(
2108
+ status_code: http_response.status,
2109
+ content_type: content_type,
2110
+ raw_response: http_response,
2111
+ object: T.unsafe(obj)
2112
+ )
2113
+
2114
+ return response
2115
+ else
2116
+ raise(
2117
+ ::ModerationApi::Models::Errors::APIError.new(
2118
+ status_code: http_response.status,
2119
+ body: http_response.env.response_body,
2120
+ raw_response: http_response
2121
+ ),
2122
+ "Unknown content type received"
2123
+ )
2124
+ end
2125
+ elsif Utils.match_status_code(http_response.status, ["400"])
2126
+ if Utils.match_content_type(content_type, "application/json")
2127
+ http_response = @sdk_configuration.hooks.after_success(
2128
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
2129
+ hook_ctx: hook_ctx
2130
+ ),
2131
+ response: http_response
2132
+ )
2133
+ response_data = http_response.env.response_body
2134
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::BadRequestError)
2135
+ obj.raw_response = http_response
2136
+ raise obj
2137
+ else
2138
+ raise(
2139
+ ::ModerationApi::Models::Errors::APIError.new(
2140
+ status_code: http_response.status,
2141
+ body: http_response.env.response_body,
2142
+ raw_response: http_response
2143
+ ),
2144
+ "Unknown content type received"
2145
+ )
2146
+ end
2147
+ elsif Utils.match_status_code(http_response.status, ["401"])
2148
+ if Utils.match_content_type(content_type, "application/json")
2149
+ http_response = @sdk_configuration.hooks.after_success(
2150
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
2151
+ hook_ctx: hook_ctx
2152
+ ),
2153
+ response: http_response
2154
+ )
2155
+ response_data = http_response.env.response_body
2156
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::AuthenticationError)
2157
+ obj.raw_response = http_response
2158
+ raise obj
2159
+ else
2160
+ raise(
2161
+ ::ModerationApi::Models::Errors::APIError.new(
2162
+ status_code: http_response.status,
2163
+ body: http_response.env.response_body,
2164
+ raw_response: http_response
2165
+ ),
2166
+ "Unknown content type received"
2167
+ )
2168
+ end
2169
+ elsif Utils.match_status_code(http_response.status, ["404"])
2170
+ if Utils.match_content_type(content_type, "application/json")
2171
+ http_response = @sdk_configuration.hooks.after_success(
2172
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
2173
+ hook_ctx: hook_ctx
2174
+ ),
2175
+ response: http_response
2176
+ )
2177
+ response_data = http_response.env.response_body
2178
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::NotFoundError)
2179
+ obj.raw_response = http_response
2180
+ raise obj
2181
+ else
2182
+ raise(
2183
+ ::ModerationApi::Models::Errors::APIError.new(
2184
+ status_code: http_response.status,
2185
+ body: http_response.env.response_body,
2186
+ raw_response: http_response
2187
+ ),
2188
+ "Unknown content type received"
2189
+ )
2190
+ end
2191
+ elsif Utils.match_status_code(http_response.status, ["429"])
2192
+ if Utils.match_content_type(content_type, "application/json")
2193
+ http_response = @sdk_configuration.hooks.after_success(
2194
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
2195
+ hook_ctx: hook_ctx
2196
+ ),
2197
+ response: http_response
2198
+ )
2199
+ response_data = http_response.env.response_body
2200
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::RateLimitError)
2201
+ obj.raw_response = http_response
2202
+ raise obj
2203
+ else
2204
+ raise(
2205
+ ::ModerationApi::Models::Errors::APIError.new(
2206
+ status_code: http_response.status,
2207
+ body: http_response.env.response_body,
2208
+ raw_response: http_response
2209
+ ),
2210
+ "Unknown content type received"
2211
+ )
2212
+ end
2213
+ elsif Utils.match_status_code(http_response.status, ["4XX"])
2214
+ raise(
2215
+ ::ModerationApi::Models::Errors::APIError.new(
2216
+ status_code: http_response.status,
2217
+ body: http_response.env.response_body,
2218
+ raw_response: http_response
2219
+ ),
2220
+ "API error occurred"
2221
+ )
2222
+ elsif Utils.match_status_code(http_response.status, ["5XX"])
2223
+ raise(
2224
+ ::ModerationApi::Models::Errors::APIError.new(
2225
+ status_code: http_response.status,
2226
+ body: http_response.env.response_body,
2227
+ raw_response: http_response
2228
+ ),
2229
+ "API error occurred"
2230
+ )
2231
+ else
2232
+ raise(
2233
+ ::ModerationApi::Models::Errors::APIError.new(
2234
+ status_code: http_response.status,
2235
+ body: http_response.env.response_body,
2236
+ raw_response: http_response
2237
+ ),
2238
+ "Unknown status code received"
2239
+ )
2240
+
2241
+ end
2242
+ end
1484
2243
  end
1485
2244
  end