forem-ruby 0.1.0.beta1

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 (74) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/forem-ruby.gemspec +17 -0
  4. data/lib/forem/api_operations/create.rb +47 -0
  5. data/lib/forem/api_operations/delete.rb +88 -0
  6. data/lib/forem/api_operations/list.rb +70 -0
  7. data/lib/forem/api_operations/request.rb +83 -0
  8. data/lib/forem/api_operations/retrieve.rb +43 -0
  9. data/lib/forem/api_operations/save.rb +53 -0
  10. data/lib/forem/api_operations/update.rb +47 -0
  11. data/lib/forem/api_requestor.rb +283 -0
  12. data/lib/forem/api_resource.rb +77 -0
  13. data/lib/forem/client.rb +279 -0
  14. data/lib/forem/configuration.rb +74 -0
  15. data/lib/forem/connection_manager.rb +75 -0
  16. data/lib/forem/errors.rb +118 -0
  17. data/lib/forem/forem_object.rb +264 -0
  18. data/lib/forem/forem_response.rb +50 -0
  19. data/lib/forem/list_object.rb +171 -0
  20. data/lib/forem/resources/admin_concept.rb +169 -0
  21. data/lib/forem/resources/admin_user.rb +152 -0
  22. data/lib/forem/resources/agent_session.rb +110 -0
  23. data/lib/forem/resources/analytics.rb +151 -0
  24. data/lib/forem/resources/article.rb +256 -0
  25. data/lib/forem/resources/billboard.rb +76 -0
  26. data/lib/forem/resources/comment.rb +43 -0
  27. data/lib/forem/resources/concept.rb +192 -0
  28. data/lib/forem/resources/follow.rb +78 -0
  29. data/lib/forem/resources/follower.rb +56 -0
  30. data/lib/forem/resources/health_check.rb +70 -0
  31. data/lib/forem/resources/organization.rb +79 -0
  32. data/lib/forem/resources/page.rb +52 -0
  33. data/lib/forem/resources/podcast_episode.rb +36 -0
  34. data/lib/forem/resources/profile_image.rb +44 -0
  35. data/lib/forem/resources/reaction.rb +61 -0
  36. data/lib/forem/resources/reading_list.rb +29 -0
  37. data/lib/forem/resources/recommended_articles_list.rb +45 -0
  38. data/lib/forem/resources/request_redirect.rb +60 -0
  39. data/lib/forem/resources/segment.rb +103 -0
  40. data/lib/forem/resources/survey.rb +96 -0
  41. data/lib/forem/resources/tag.rb +27 -0
  42. data/lib/forem/resources/trend.rb +80 -0
  43. data/lib/forem/resources/user.rb +229 -0
  44. data/lib/forem/resources/video.rb +28 -0
  45. data/lib/forem/services/admin_concept_service.rb +138 -0
  46. data/lib/forem/services/admin_user_service.rb +114 -0
  47. data/lib/forem/services/agent_session_service.rb +87 -0
  48. data/lib/forem/services/analytics_service.rb +93 -0
  49. data/lib/forem/services/article_service.rb +233 -0
  50. data/lib/forem/services/base_service.rb +45 -0
  51. data/lib/forem/services/billboard_service.rb +91 -0
  52. data/lib/forem/services/comment_service.rb +51 -0
  53. data/lib/forem/services/concept_service.rb +143 -0
  54. data/lib/forem/services/follow_service.rb +61 -0
  55. data/lib/forem/services/follower_service.rb +34 -0
  56. data/lib/forem/services/health_check_service.rb +46 -0
  57. data/lib/forem/services/organization_service.rb +103 -0
  58. data/lib/forem/services/page_service.rb +107 -0
  59. data/lib/forem/services/podcast_episode_service.rb +34 -0
  60. data/lib/forem/services/profile_image_service.rb +32 -0
  61. data/lib/forem/services/reaction_service.rb +72 -0
  62. data/lib/forem/services/reading_list_service.rb +35 -0
  63. data/lib/forem/services/recommended_articles_list_service.rb +87 -0
  64. data/lib/forem/services/request_redirect_service.rb +118 -0
  65. data/lib/forem/services/segment_service.rb +83 -0
  66. data/lib/forem/services/survey_service.rb +48 -0
  67. data/lib/forem/services/tag_service.rb +32 -0
  68. data/lib/forem/services/trend_service.rb +70 -0
  69. data/lib/forem/services/user_service.rb +61 -0
  70. data/lib/forem/services/video_service.rb +33 -0
  71. data/lib/forem/util.rb +43 -0
  72. data/lib/forem/version.rb +4 -0
  73. data/lib/forem.rb +91 -0
  74. metadata +111 -0
@@ -0,0 +1,34 @@
1
+ module Forem
2
+ module Services
3
+ # Service for interacting with the Forem Podcast Episodes API.
4
+ #
5
+ # Access via {Client#podcast_episodes}. All methods inject the client's
6
+ # requestor automatically so no additional configuration is required.
7
+ #
8
+ # @example
9
+ # client = Forem::Client.new("your-api-key")
10
+ # episodes = client.podcast_episodes.list(username: "codenewbies")
11
+ #
12
+ # @see PodcastEpisode
13
+ # @see https://developers.forem.com/api/v1#/operations/getPodcastEpisodes
14
+ class PodcastEpisodeService < BaseService
15
+ # List podcast episodes.
16
+ #
17
+ # @param params [Hash] query parameters
18
+ # @option params [Integer] :page page number (default: 1)
19
+ # @option params [Integer] :per_page number of results per page (max: 1000)
20
+ # @option params [String] :username filter episodes by the podcast owner's
21
+ # username
22
+ # @param opts [Hash] per-request options
23
+ # @return [Array<PodcastEpisode>] list of podcast episodes
24
+ #
25
+ # @example
26
+ # client.podcast_episodes.list(username: "codenewbies", per_page: 20)
27
+ #
28
+ # @see https://developers.forem.com/api/v1#/operations/getPodcastEpisodes
29
+ def list(params = {}, opts = {})
30
+ PodcastEpisode.list(params, opts_with_requestor(opts))
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,32 @@
1
+ module Forem
2
+ module Services
3
+ # Service for interacting with the Forem Profile Images API.
4
+ #
5
+ # Retrieves profile image URLs for a given user or organization.
6
+ # Access via {Client#profile_images}. All methods inject the client's
7
+ # requestor automatically so no additional configuration is required.
8
+ #
9
+ # @example
10
+ # client = Forem::Client.new("your-api-key")
11
+ # image_info = client.profile_images.retrieve("jsmith")
12
+ #
13
+ # @see ProfileImage
14
+ # @see https://developers.forem.com/api/v1#/operations/getProfileImage
15
+ class ProfileImageService < BaseService
16
+ # Retrieve profile image details for a user or organization by username.
17
+ #
18
+ # @param username [String] the username of the user or organization
19
+ # @param opts [Hash] per-request options
20
+ # @return [ProfileImage] profile image data including the image URL
21
+ #
22
+ # @example
23
+ # image = client.profile_images.retrieve("jsmith")
24
+ # puts image.profile_image
25
+ #
26
+ # @see https://developers.forem.com/api/v1#/operations/getProfileImage
27
+ def retrieve(username, opts = {})
28
+ ProfileImage.retrieve(username, opts_with_requestor(opts))
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,72 @@
1
+ module Forem
2
+ module Services
3
+ # Service for interacting with the Forem Reactions API.
4
+ #
5
+ # Reactions are emoji-based responses to articles, comments, and other
6
+ # reactable content (likes, unicorns, bookmarks, etc.).
7
+ # Access via {Client#reactions}. All methods inject the client's requestor
8
+ # automatically so no additional configuration is required.
9
+ #
10
+ # @example
11
+ # client = Forem::Client.new("your-api-key")
12
+ # client.reactions.create(reactable_type: "Article", reactable_id: 1, category: "like")
13
+ # client.reactions.toggle(reactable_type: "Article", reactable_id: 1, category: "unicorn")
14
+ #
15
+ # @see Reaction
16
+ # @see https://developers.forem.com/api/v1
17
+ class ReactionService < BaseService
18
+ # Create a reaction on a reactable resource.
19
+ #
20
+ # @param params [Hash] reaction attributes
21
+ # @option params [String] :reactable_type the type of content to react to
22
+ # ("Article", "Comment", or "User")
23
+ # @option params [Integer] :reactable_id the ID of the content to react to
24
+ # @option params [String] :category the reaction type ("like", "unicorn",
25
+ # "exploding_head", "raised_hands", "fire", "thumbsdown", "vomit",
26
+ # "readinglist")
27
+ # @param opts [Hash] per-request options
28
+ # @return [Reaction] the newly created reaction
29
+ #
30
+ # @example
31
+ # client.reactions.create(
32
+ # reactable_type: "Article",
33
+ # reactable_id: 12345,
34
+ # category: "unicorn"
35
+ # )
36
+ #
37
+ # @see https://developers.forem.com/api/v1
38
+ def create(params = {}, opts = {})
39
+ Reaction.create(params, opts_with_requestor(opts))
40
+ end
41
+
42
+ # Toggle a reaction on a reactable resource.
43
+ #
44
+ # If the reaction already exists for the authenticated user it will be
45
+ # destroyed; otherwise a new reaction will be created.
46
+ #
47
+ # @param params [Hash] reaction attributes
48
+ # @option params [String] :reactable_type the type of content
49
+ # ("Article", "Comment", or "User")
50
+ # @option params [Integer] :reactable_id the ID of the content
51
+ # @option params [String] :category the reaction type ("like", "unicorn",
52
+ # "exploding_head", "raised_hands", "fire", "thumbsdown", "vomit",
53
+ # "readinglist")
54
+ # @param opts [Hash] per-request options
55
+ # @return [Hash] a hash with a +:result+ key indicating "create" or
56
+ # "destroy"
57
+ #
58
+ # @example
59
+ # result = client.reactions.toggle(
60
+ # reactable_type: "Article",
61
+ # reactable_id: 12345,
62
+ # category: "like"
63
+ # )
64
+ # puts result.result # => "create" or "destroy"
65
+ #
66
+ # @see https://developers.forem.com/api/v1
67
+ def toggle(params = {}, opts = {})
68
+ Reaction.toggle(params, opts_with_requestor(opts))
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,35 @@
1
+ module Forem
2
+ module Services
3
+ # Service for interacting with the Forem Reading List API.
4
+ #
5
+ # Lists articles the authenticated user has bookmarked for later reading.
6
+ # Access via {Client#reading_list}. All methods inject the client's
7
+ # requestor automatically so no additional configuration is required.
8
+ #
9
+ # @example
10
+ # client = Forem::Client.new("your-api-key")
11
+ # bookmarks = client.reading_list.list(page: 1, per_page: 20)
12
+ #
13
+ # @see ReadingList
14
+ # @see https://developers.forem.com/api/v1#/operations/getReadinglist
15
+ class ReadingListService < BaseService
16
+ # List articles in the authenticated user's reading list.
17
+ #
18
+ # @param params [Hash] query parameters
19
+ # @option params [Integer] :page page number (default: 1)
20
+ # @option params [Integer] :per_page number of results per page (max: 1000)
21
+ # @option params [String] :status filter by bookmark status ("valid",
22
+ # "invalid", "confirmed", "archived")
23
+ # @param opts [Hash] per-request options
24
+ # @return [Array<ReadingList>] bookmarked articles for the current user
25
+ #
26
+ # @example
27
+ # client.reading_list.list(per_page: 50)
28
+ #
29
+ # @see https://developers.forem.com/api/v1#/operations/getReadinglist
30
+ def list(params = {}, opts = {})
31
+ ReadingList.list(params, opts_with_requestor(opts))
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,87 @@
1
+ module Forem
2
+ module Services
3
+ # Service for interacting with the Forem Recommended Articles Lists API.
4
+ #
5
+ # Recommended articles lists are curated collections of articles surfaced
6
+ # to specific user segments.
7
+ # Access via {Client#recommended_articles_lists}. All methods inject the
8
+ # client's requestor automatically so no additional configuration is
9
+ # required.
10
+ #
11
+ # @example
12
+ # client = Forem::Client.new("your-api-key")
13
+ # lists = client.recommended_articles_lists.list
14
+ # list = client.recommended_articles_lists.retrieve(2)
15
+ #
16
+ # @see RecommendedArticlesList
17
+ # @see https://developers.forem.com/api/v1
18
+ class RecommendedArticlesListService < BaseService
19
+ # List all recommended articles lists.
20
+ #
21
+ # @param params [Hash] query parameters
22
+ # @option params [Integer] :page page number (default: 1)
23
+ # @option params [Integer] :per_page number of results per page
24
+ # @param opts [Hash] per-request options
25
+ # @return [Array<RecommendedArticlesList>] all recommended articles lists
26
+ #
27
+ # @example
28
+ # client.recommended_articles_lists.list
29
+ #
30
+ # @see https://developers.forem.com/api/v1
31
+ def list(params = {}, opts = {})
32
+ RecommendedArticlesList.list(params, opts_with_requestor(opts))
33
+ end
34
+
35
+ # Create a new recommended articles list.
36
+ #
37
+ # @param params [Hash] list attributes
38
+ # @option params [String] :name name of the list
39
+ # @option params [Integer] :segment_id the audience segment this list
40
+ # targets
41
+ # @param opts [Hash] per-request options
42
+ # @return [RecommendedArticlesList] the newly created list
43
+ #
44
+ # @example
45
+ # client.recommended_articles_lists.create(
46
+ # name: "Top Ruby Articles",
47
+ # segment_id: 5
48
+ # )
49
+ #
50
+ # @see https://developers.forem.com/api/v1
51
+ def create(params = {}, opts = {})
52
+ RecommendedArticlesList.create(params, opts_with_requestor(opts))
53
+ end
54
+
55
+ # Retrieve a single recommended articles list by its numeric ID.
56
+ #
57
+ # @param id [Integer, String] the list ID
58
+ # @param opts [Hash] per-request options
59
+ # @return [RecommendedArticlesList] the list with the given ID
60
+ #
61
+ # @example
62
+ # client.recommended_articles_lists.retrieve(2)
63
+ #
64
+ # @see https://developers.forem.com/api/v1
65
+ def retrieve(id, opts = {})
66
+ RecommendedArticlesList.retrieve(id, opts_with_requestor(opts))
67
+ end
68
+
69
+ # Update an existing recommended articles list.
70
+ #
71
+ # @param id [Integer, String] the list ID to update
72
+ # @param params [Hash] list attributes to change
73
+ # @option params [String] :name new name for the list
74
+ # @option params [Integer] :segment_id new target segment
75
+ # @param opts [Hash] per-request options
76
+ # @return [RecommendedArticlesList] the updated list
77
+ #
78
+ # @example
79
+ # client.recommended_articles_lists.update(2, name: "Best Ruby Content")
80
+ #
81
+ # @see https://developers.forem.com/api/v1
82
+ def update(id, params = {}, opts = {})
83
+ RecommendedArticlesList.update(id, params, opts_with_requestor(opts))
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,118 @@
1
+ module Forem
2
+ module Services
3
+ # Service for interacting with the Forem Admin Request Redirects API.
4
+ #
5
+ # Request redirects power organization custom domains: a request for
6
+ # +request_domain+ at path +original_url+ is redirected to
7
+ # +destination_url+. These endpoints require an API key with admin-level
8
+ # privileges. Access via {Client#request_redirects}. All methods inject
9
+ # the client's requestor automatically so no additional configuration is
10
+ # required.
11
+ #
12
+ # The underlying API requires create/update request bodies to be wrapped
13
+ # in a +request_redirect:+ key. This service accepts flat attribute
14
+ # hashes and wraps them for you, so callers never need to think about the
15
+ # wrapper.
16
+ #
17
+ # @example
18
+ # client = Forem::Client.new("admin-api-key")
19
+ # redirect = client.request_redirects.create(
20
+ # original_url: "/old",
21
+ # destination_url: "https://example.com/new",
22
+ # request_domain: "example.com"
23
+ # )
24
+ #
25
+ # @see RequestRedirect
26
+ # @see https://developers.forem.com/api/v1
27
+ class RequestRedirectService < BaseService
28
+ # List all request redirects, most recently created first.
29
+ #
30
+ # @param params [Hash] query parameters
31
+ # @option params [Integer] :page page number (default: 1)
32
+ # @option params [Integer] :per_page number of results per page
33
+ # (default: 50, maximum: 100)
34
+ # @param opts [Hash] per-request options
35
+ # @return [Forem::ListObject<RequestRedirect>] paginated list of request redirects
36
+ #
37
+ # @example
38
+ # client.request_redirects.list(per_page: 25)
39
+ #
40
+ # @see https://developers.forem.com/api/v1
41
+ def list(params = {}, opts = {})
42
+ RequestRedirect.list(params, opts_with_requestor(opts))
43
+ end
44
+
45
+ # Retrieve a single request redirect by its numeric ID.
46
+ #
47
+ # @param id [Integer, String] the request redirect ID
48
+ # @param opts [Hash] per-request options
49
+ # @return [RequestRedirect] the request redirect with the given ID
50
+ #
51
+ # @example
52
+ # client.request_redirects.retrieve(7)
53
+ #
54
+ # @see https://developers.forem.com/api/v1
55
+ def retrieve(id, opts = {})
56
+ RequestRedirect.retrieve(id, opts_with_requestor(opts))
57
+ end
58
+
59
+ # Create a new request redirect.
60
+ #
61
+ # @param params [Hash] request redirect attributes (flat — no
62
+ # +request_redirect:+ wrapper needed, this method adds it for you)
63
+ # @option params [String] :original_url the incoming request path;
64
+ # must start with +/+
65
+ # @option params [String] :destination_url the fully-qualified
66
+ # HTTP/HTTPS URL to redirect to
67
+ # @option params [String] :request_domain the domain the redirect
68
+ # applies to
69
+ # @param opts [Hash] per-request options
70
+ # @return [RequestRedirect] the newly created request redirect
71
+ #
72
+ # @example
73
+ # client.request_redirects.create(
74
+ # original_url: "/old",
75
+ # destination_url: "https://example.com/new",
76
+ # request_domain: "example.com"
77
+ # )
78
+ #
79
+ # @see https://developers.forem.com/api/v1
80
+ def create(params = {}, opts = {})
81
+ RequestRedirect.create({ request_redirect: params }, opts_with_requestor(opts))
82
+ end
83
+
84
+ # Update an existing request redirect.
85
+ #
86
+ # @param id [Integer, String] the request redirect ID to update
87
+ # @param params [Hash] request redirect attributes to change (flat —
88
+ # no +request_redirect:+ wrapper needed, this method adds it for you)
89
+ # @option params [String] :original_url new incoming request path
90
+ # @option params [String] :destination_url new destination URL
91
+ # @option params [String] :request_domain new request domain
92
+ # @param opts [Hash] per-request options
93
+ # @return [RequestRedirect] the updated request redirect
94
+ #
95
+ # @example
96
+ # client.request_redirects.update(7, destination_url: "https://example.com/newer")
97
+ #
98
+ # @see https://developers.forem.com/api/v1
99
+ def update(id, params = {}, opts = {})
100
+ RequestRedirect.update(id, { request_redirect: params }, opts_with_requestor(opts))
101
+ end
102
+
103
+ # Delete a request redirect.
104
+ #
105
+ # @param id [Integer, String] the request redirect ID to delete
106
+ # @param opts [Hash] per-request options
107
+ # @return [nil] returns nil on success (the API responds with 204 No Content)
108
+ #
109
+ # @example
110
+ # client.request_redirects.delete(7)
111
+ #
112
+ # @see https://developers.forem.com/api/v1
113
+ def delete(id, opts = {})
114
+ RequestRedirect.delete(id, opts_with_requestor(opts))
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,83 @@
1
+ module Forem
2
+ module Services
3
+ # Service for interacting with the Forem Segments API.
4
+ #
5
+ # Segments are user-defined audience groups used for targeted content
6
+ # and billboard campaigns.
7
+ # Access via {Client#segments}. All methods inject the client's requestor
8
+ # automatically so no additional configuration is required.
9
+ #
10
+ # @example
11
+ # client = Forem::Client.new("your-api-key")
12
+ # segments = client.segments.list
13
+ # segment = client.segments.retrieve(5)
14
+ #
15
+ # @see Segment
16
+ # @see https://developers.forem.com/api/v1#/operations/getSegments
17
+ class SegmentService < BaseService
18
+ # List all audience segments.
19
+ #
20
+ # @param params [Hash] query parameters
21
+ # @option params [Integer] :page page number (default: 1)
22
+ # @option params [Integer] :per_page number of results per page
23
+ # @param opts [Hash] per-request options
24
+ # @return [Forem::ListObject<Forem::Segment>] paginated list of segments
25
+ #
26
+ # @example
27
+ # client.segments.list
28
+ #
29
+ # @see https://developers.forem.com/api/v1#/operations/getSegments
30
+ def list(params = {}, opts = {})
31
+ Segment.list(params, opts_with_requestor(opts))
32
+ end
33
+
34
+ # Create a new audience segment.
35
+ #
36
+ # The Forem API does not accept any parameters on this endpoint —
37
+ # newly-created segments are always +type_of: "manual"+ and do not
38
+ # carry a name. Manage membership separately via {Segment#add_users}
39
+ # and {Segment#remove_users}.
40
+ #
41
+ # @param params [Hash] ignored by the API, kept for forward-compat
42
+ # @param opts [Hash] per-request options
43
+ # @return [Forem::Segment] the newly created (empty) segment
44
+ #
45
+ # @example
46
+ # segment = client.segments.create
47
+ # segment.add_users(user_ids: [101, 102])
48
+ #
49
+ # @see https://developers.forem.com/api/v1#/operations/createSegment
50
+ def create(params = {}, opts = {})
51
+ Segment.create(params, opts_with_requestor(opts))
52
+ end
53
+
54
+ # Retrieve a single audience segment by its numeric ID.
55
+ #
56
+ # @param id [Integer, String] the segment ID
57
+ # @param opts [Hash] per-request options
58
+ # @return [Segment] the segment with the given ID
59
+ #
60
+ # @example
61
+ # client.segments.retrieve(5)
62
+ #
63
+ # @see https://developers.forem.com/api/v1
64
+ def retrieve(id, opts = {})
65
+ Segment.retrieve(id, opts_with_requestor(opts))
66
+ end
67
+
68
+ # Delete an audience segment.
69
+ #
70
+ # @param id [Integer, String] the segment ID to delete
71
+ # @param opts [Hash] per-request options
72
+ # @return [nil] returns nil on success
73
+ #
74
+ # @example
75
+ # client.segments.delete(5)
76
+ #
77
+ # @see https://developers.forem.com/api/v1
78
+ def delete(id, opts = {})
79
+ Segment.delete(id, opts_with_requestor(opts))
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,48 @@
1
+ module Forem
2
+ module Services
3
+ # Service for interacting with the Forem Surveys API.
4
+ #
5
+ # Surveys are questionnaires presented to community members.
6
+ # Access via {Client#surveys}. All methods inject the client's requestor
7
+ # automatically so no additional configuration is required.
8
+ #
9
+ # @example
10
+ # client = Forem::Client.new("your-api-key")
11
+ # surveys = client.surveys.list
12
+ # survey = client.surveys.retrieve(8)
13
+ #
14
+ # @see Survey
15
+ # @see https://developers.forem.com/api/v1#/operations/getSurveyByIdOrSlug
16
+ class SurveyService < BaseService
17
+ # List all surveys.
18
+ #
19
+ # @param params [Hash] query parameters
20
+ # @option params [Integer] :page page number (default: 1)
21
+ # @option params [Integer] :per_page number of results per page
22
+ # @param opts [Hash] per-request options
23
+ # @return [Array<Survey>] list of surveys
24
+ #
25
+ # @example
26
+ # client.surveys.list
27
+ #
28
+ # @see https://developers.forem.com/api/v1
29
+ def list(params = {}, opts = {})
30
+ Survey.list(params, opts_with_requestor(opts))
31
+ end
32
+
33
+ # Retrieve a single survey by its numeric ID.
34
+ #
35
+ # @param id [Integer, String] the survey ID
36
+ # @param opts [Hash] per-request options
37
+ # @return [Survey] the survey with the given ID
38
+ #
39
+ # @example
40
+ # client.surveys.retrieve(8)
41
+ #
42
+ # @see https://developers.forem.com/api/v1#/operations/getSurveyByIdOrSlug
43
+ def retrieve(id, opts = {})
44
+ Survey.retrieve(id, opts_with_requestor(opts))
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,32 @@
1
+ module Forem
2
+ module Services
3
+ # Service for interacting with the Forem Tags API.
4
+ #
5
+ # Access via {Client#tags}. All methods inject the client's requestor
6
+ # automatically so no additional configuration is required.
7
+ #
8
+ # @example
9
+ # client = Forem::Client.new("your-api-key")
10
+ # tags = client.tags.list(per_page: 50)
11
+ #
12
+ # @see Tag
13
+ # @see https://developers.forem.com/api/v1#/operations/getTags
14
+ class TagService < BaseService
15
+ # List tags used on the Forem instance, ordered by popularity.
16
+ #
17
+ # @param params [Hash] query parameters
18
+ # @option params [Integer] :page page number (default: 1)
19
+ # @option params [Integer] :per_page number of results per page (max: 1000)
20
+ # @param opts [Hash] per-request options
21
+ # @return [Array<Tag>] list of tags ordered by article count
22
+ #
23
+ # @example
24
+ # client.tags.list(per_page: 100)
25
+ #
26
+ # @see https://developers.forem.com/api/v1#/operations/getTags
27
+ def list(params = {}, opts = {})
28
+ Tag.list(params, opts_with_requestor(opts))
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,70 @@
1
+ module Forem
2
+ module Services
3
+ # Service for interacting with the Forem Trends API.
4
+ #
5
+ # Trends are algorithmically-derived, "hot and recent" topic clusters made
6
+ # up of related articles. Access via {Client#trends}. All methods inject
7
+ # the client's requestor automatically so no additional configuration is
8
+ # required. Trends are read-only via the public API.
9
+ #
10
+ # @example
11
+ # client = Forem::Client.new("your-api-key")
12
+ # trends = client.trends.list
13
+ # trend = client.trends.retrieve("ai-agents")
14
+ # articles = client.trends.articles("ai-agents")
15
+ #
16
+ # @see Trend
17
+ # @see https://developers.forem.com/api/v1
18
+ class TrendService < BaseService
19
+ # List hot and recent trends.
20
+ #
21
+ # @param params [Hash] query parameters
22
+ # @option params [Integer] :page page number (default: 1)
23
+ # @option params [Integer] :per_page number of results per page (default: 10)
24
+ # @param opts [Hash] per-request options
25
+ # @return [Forem::ListObject<Trend>] paginated list of trends
26
+ #
27
+ # @example
28
+ # client.trends.list(per_page: 20)
29
+ #
30
+ # @see https://developers.forem.com/api/v1
31
+ def list(params = {}, opts = {})
32
+ Trend.list(params, opts_with_requestor(opts))
33
+ end
34
+
35
+ # Retrieve a single trend by its numeric ID or slug.
36
+ #
37
+ # @param id_or_slug [Integer, String] the trend's ID or slug
38
+ # @param opts [Hash] per-request options
39
+ # @return [Trend] the trend matching the given ID or slug
40
+ #
41
+ # @example
42
+ # client.trends.retrieve("ai-agents")
43
+ # client.trends.retrieve(3)
44
+ #
45
+ # @see https://developers.forem.com/api/v1
46
+ def retrieve(id_or_slug, opts = {})
47
+ Trend.retrieve(id_or_slug, opts_with_requestor(opts))
48
+ end
49
+
50
+ # List the articles belonging to a trend.
51
+ #
52
+ # @param id_or_slug [Integer, String] the trend's ID or slug
53
+ # @param params [Hash] query parameters
54
+ # @option params [Integer] :page page number (default: 1)
55
+ # @option params [Integer] :per_page number of results per page (default: 10)
56
+ # @option params [String] :sort +"score"+ to sort purely by article score;
57
+ # omit for the default ordering (trend membership distance, then score)
58
+ # @param opts [Hash] per-request options
59
+ # @return [Array<Forem::Article>] articles associated with the trend
60
+ #
61
+ # @example
62
+ # client.trends.articles("ai-agents", per_page: 5, sort: "score")
63
+ #
64
+ # @see https://developers.forem.com/api/v1
65
+ def articles(id_or_slug, params = {}, opts = {})
66
+ Trend.articles(id_or_slug, params, opts_with_requestor(opts))
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,61 @@
1
+ module Forem
2
+ module Services
3
+ # Service for interacting with the Forem Users API.
4
+ #
5
+ # Access via {Client#users}. All methods inject the client's requestor
6
+ # automatically so no additional configuration is required.
7
+ #
8
+ # @example
9
+ # client = Forem::Client.new("your-api-key")
10
+ # me = client.users.me
11
+ # user = client.users.retrieve(42)
12
+ #
13
+ # @see User
14
+ # @see https://developers.forem.com/api/v1#/operations/getUser
15
+ class UserService < BaseService
16
+ # Retrieve a single user by their numeric ID.
17
+ #
18
+ # @param id [Integer, String] the user ID, or the string "by_username"
19
+ # combined with the +:username+ param
20
+ # @param opts [Hash] per-request options
21
+ # @return [User] the user with the given ID
22
+ #
23
+ # @example
24
+ # client.users.retrieve(42)
25
+ #
26
+ # @see https://developers.forem.com/api/v1#/operations/getUser
27
+ def retrieve(id, opts = {})
28
+ User.retrieve(id, opts_with_requestor(opts))
29
+ end
30
+
31
+ # Retrieve the profile of the currently authenticated user.
32
+ #
33
+ # @param opts [Hash] per-request options
34
+ # @return [User] the authenticated user's profile
35
+ #
36
+ # @example
37
+ # me = client.users.me
38
+ # puts me.username
39
+ #
40
+ # @see https://developers.forem.com/api/v1#/operations/getUserMe
41
+ def me(opts = {})
42
+ User.me(opts_with_requestor(opts))
43
+ end
44
+
45
+ # Search for users by name or username.
46
+ #
47
+ # @param params [Hash] query parameters
48
+ # @option params [String] :term the search term
49
+ # @param opts [Hash] per-request options
50
+ # @return [Array<User>] users matching the search query
51
+ #
52
+ # @example
53
+ # client.users.search(term: "jane")
54
+ #
55
+ # @see https://developers.forem.com/api/v1#/operations/searchUser
56
+ def search(params = {}, opts = {})
57
+ User.search(params, opts_with_requestor(opts))
58
+ end
59
+ end
60
+ end
61
+ end