tightknit 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +34 -7
- data/Rakefile +1 -1
- data/lib/tightknit/client.rb +18 -11
- data/lib/tightknit/resources/calendar_events.rb +27 -27
- data/lib/tightknit/resources/feeds.rb +77 -0
- data/lib/tightknit/utils/html_formatter.rb +13 -12
- data/lib/tightknit/version.rb +2 -1
- data/lib/tightknit.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 930963313a29ee50d88f2d8e4f82630829a4595922271ef2a9754bc5778db604
|
4
|
+
data.tar.gz: e470f90293b160182439166009a60df6dda8d3be76da120f468ad0dc56652ef5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23ea56ffcd878838adfe54b0b564be1c56be899147248b30a82f9db064034473ae1fc77c3831324d5e8ab137e439154c44f5142cc7f1145436fbb51f59b0a951
|
7
|
+
data.tar.gz: 1fdb594e73c7eee8ec48dda0a5aefd2087213af31b753cc7f523a8a2c6e8d0ed2f6c2c9d51d51d7a06c2b6c3e58f68e2a405725629d9c8d73b4bb9114d54345f
|
data/README.md
CHANGED
@@ -34,9 +34,6 @@ client = Tightknit::Client.new(api_key: 'your_api_key')
|
|
34
34
|
|
35
35
|
### Calendar Events
|
36
36
|
|
37
|
-
Currently, listing all CalendarEvents and getting a single CalendarEvent is supported.
|
38
|
-
If you need more features here, feel free to contribute or chat with us: hello@lokbros.com
|
39
|
-
|
40
37
|
#### List Events
|
41
38
|
|
42
39
|
```ruby
|
@@ -78,6 +75,40 @@ event = client.calendar_events.get('event_id')
|
|
78
75
|
formatted_event = client.calendar_events.format_data(event[:data])
|
79
76
|
```
|
80
77
|
|
78
|
+
### Feeds
|
79
|
+
|
80
|
+
#### List Feeds
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
# Get feeds with default pagination (page 0, per_page 10)
|
84
|
+
feeds = client.feeds.list
|
85
|
+
|
86
|
+
# With custom pagination
|
87
|
+
feeds = client.feeds.list(
|
88
|
+
page: 1,
|
89
|
+
per_page: 20
|
90
|
+
)
|
91
|
+
```
|
92
|
+
|
93
|
+
#### Get a Specific Feed
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
feed = client.feeds.get('feed_id')
|
97
|
+
```
|
98
|
+
|
99
|
+
#### Get Posts from a Feed
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
# Get posts with default pagination (page 0, per_page 10)
|
103
|
+
posts = client.feeds.posts('feed_id')
|
104
|
+
|
105
|
+
# With custom pagination
|
106
|
+
posts = client.feeds.posts('feed_id',
|
107
|
+
page: 1,
|
108
|
+
per_page: 20
|
109
|
+
)
|
110
|
+
```
|
111
|
+
|
81
112
|
## Documentation
|
82
113
|
|
83
114
|
The gem includes comprehensive YARD documentation. To generate the documentation, first ensure you have the required dependencies:
|
@@ -117,7 +148,3 @@ Get in touch with us anytime: hello@lokbros.com
|
|
117
148
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
118
149
|
|
119
150
|
Maintained by [LokBros Studio](https://lokbros.com).
|
120
|
-
|
121
|
-
## Code of Conduct
|
122
|
-
|
123
|
-
Everyone interacting in the Tightknit project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tightknit/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
data/lib/tightknit/client.rb
CHANGED
@@ -9,34 +9,41 @@ module Tightknit
|
|
9
9
|
#
|
10
10
|
# @example Creating a client
|
11
11
|
# client = Tightknit::Client.new(api_key: "your_api_key")
|
12
|
-
#
|
12
|
+
#
|
13
13
|
class Client
|
14
14
|
# @return [Faraday::Connection] The Faraday connection object used for HTTP requests
|
15
15
|
attr_reader :conn
|
16
|
-
|
16
|
+
|
17
17
|
# Initialize a new Tightknit API client
|
18
18
|
#
|
19
19
|
# @param api_key [String] The API key to use for authentication
|
20
20
|
# @raise [Tightknit::Error] If no API key is provided
|
21
21
|
def initialize(api_key:)
|
22
22
|
@api_key = api_key
|
23
|
-
|
23
|
+
|
24
24
|
raise Error, "API key is required" unless @api_key
|
25
|
-
|
25
|
+
|
26
26
|
@conn = Faraday.new(url: BASE_URL) do |faraday|
|
27
27
|
faraday.headers["Authorization"] = "Bearer #{@api_key}"
|
28
28
|
faraday.headers["Content-Type"] = "application/json"
|
29
29
|
faraday.adapter Faraday.default_adapter
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
# Access the calendar events resource
|
34
34
|
#
|
35
35
|
# @return [Tightknit::Resources::CalendarEvents] The calendar events resource
|
36
36
|
def calendar_events
|
37
37
|
@calendar_events ||= Resources::CalendarEvents.new(self)
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
|
+
# Access the feeds resource
|
41
|
+
#
|
42
|
+
# @return [Tightknit::Resources::Feeds] The feeds resource
|
43
|
+
def feeds
|
44
|
+
@feeds ||= Resources::Feeds.new(self)
|
45
|
+
end
|
46
|
+
|
40
47
|
# Make a GET request to the API
|
41
48
|
#
|
42
49
|
# @param path [String] The path to request
|
@@ -49,9 +56,9 @@ module Tightknit
|
|
49
56
|
rescue Faraday::Error => e
|
50
57
|
handle_error(e)
|
51
58
|
end
|
52
|
-
|
59
|
+
|
53
60
|
private
|
54
|
-
|
61
|
+
|
55
62
|
# Handle the API response
|
56
63
|
#
|
57
64
|
# @param response [Faraday::Response] The Faraday response object
|
@@ -68,11 +75,11 @@ module Tightknit
|
|
68
75
|
rescue JSON::ParserError
|
69
76
|
response.body || "Unknown error"
|
70
77
|
end
|
71
|
-
|
78
|
+
|
72
79
|
raise Error, "API Error (#{response.status}): #{error_message}"
|
73
80
|
end
|
74
81
|
end
|
75
|
-
|
82
|
+
|
76
83
|
# Handle Faraday errors
|
77
84
|
#
|
78
85
|
# @param error [Faraday::Error] The Faraday error
|
@@ -81,4 +88,4 @@ module Tightknit
|
|
81
88
|
raise Error, "Network Error: #{error.message}"
|
82
89
|
end
|
83
90
|
end
|
84
|
-
end
|
91
|
+
end
|
@@ -22,7 +22,7 @@ module Tightknit
|
|
22
22
|
def initialize(client)
|
23
23
|
@client = client
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
# Get a list of calendar events
|
27
27
|
#
|
28
28
|
# @param options [Hash] Options for filtering events
|
@@ -35,20 +35,20 @@ module Tightknit
|
|
35
35
|
page = options[:page] || 0
|
36
36
|
per_page = options[:per_page] || 10
|
37
37
|
time_filter = options[:time_filter]
|
38
|
-
status = options[:status] ||
|
39
|
-
|
38
|
+
status = options[:status] || "published"
|
39
|
+
|
40
40
|
params = {
|
41
41
|
page: page,
|
42
42
|
per_page: per_page,
|
43
43
|
status: status
|
44
44
|
}
|
45
|
-
|
45
|
+
|
46
46
|
# Only add time_filter to params if it's specified
|
47
47
|
params[:time_filter] = time_filter if time_filter
|
48
|
-
|
49
|
-
@client.get(
|
48
|
+
|
49
|
+
@client.get("calendar_events", params)
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
# Get both past and upcoming events
|
53
53
|
#
|
54
54
|
# @param options [Hash] Options for filtering events
|
@@ -59,26 +59,26 @@ module Tightknit
|
|
59
59
|
def all(options = {})
|
60
60
|
# Get upcoming events
|
61
61
|
upcoming_options = options.dup
|
62
|
-
upcoming_options[:time_filter] =
|
62
|
+
upcoming_options[:time_filter] = "upcoming"
|
63
63
|
upcoming_response = list(upcoming_options)
|
64
|
-
|
64
|
+
|
65
65
|
# Get past events
|
66
66
|
past_options = options.dup
|
67
|
-
past_options[:time_filter] =
|
67
|
+
past_options[:time_filter] = "past"
|
68
68
|
past_response = list(past_options)
|
69
|
-
|
69
|
+
|
70
70
|
# Combine the results
|
71
71
|
if upcoming_response[:success] && past_response[:success]
|
72
72
|
combined_records = []
|
73
|
-
|
73
|
+
|
74
74
|
if upcoming_response[:data] && upcoming_response[:data][:records]
|
75
75
|
combined_records += upcoming_response[:data][:records]
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
if past_response[:data] && past_response[:data][:records]
|
79
79
|
combined_records += past_response[:data][:records]
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
# Create a combined response with the same structure
|
83
83
|
{
|
84
84
|
success: true,
|
@@ -92,7 +92,7 @@ module Tightknit
|
|
92
92
|
upcoming_response[:success] ? upcoming_response : past_response
|
93
93
|
end
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
# Get a specific calendar event
|
97
97
|
#
|
98
98
|
# @param event_id [String] The ID of the event to retrieve
|
@@ -101,7 +101,7 @@ module Tightknit
|
|
101
101
|
def get(event_id)
|
102
102
|
@client.get("calendar_events/#{event_id}")
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
# Format event data for the API
|
106
106
|
#
|
107
107
|
# @param event_data [Hash] The raw event data
|
@@ -110,29 +110,29 @@ module Tightknit
|
|
110
110
|
def format_data(event_data)
|
111
111
|
# Create a new hash to avoid modifying the original
|
112
112
|
formatted = event_data.dup
|
113
|
-
|
113
|
+
|
114
114
|
# Format description if it's a string
|
115
115
|
if formatted[:description].is_a?(String)
|
116
|
-
formatted[:description] = {
|
116
|
+
formatted[:description] = {text: formatted[:description]}
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
# Format recap if it's a string
|
120
120
|
if formatted[:recap].is_a?(String)
|
121
|
-
formatted[:recap] = {
|
121
|
+
formatted[:recap] = {text: formatted[:recap]}
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
# Format hosts if it's an array of IDs
|
125
125
|
if formatted[:hosts].is_a?(Array)
|
126
|
-
formatted[:hosts] = {
|
126
|
+
formatted[:hosts] = {slack_user_ids: formatted[:hosts]}
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
# Format speakers if it's an array of IDs
|
130
130
|
if formatted[:speakers].is_a?(Array)
|
131
|
-
formatted[:speakers] = {
|
131
|
+
formatted[:speakers] = {slack_user_ids: formatted[:speakers]}
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
formatted
|
135
|
-
end
|
135
|
+
end
|
136
136
|
end
|
137
137
|
end
|
138
|
-
end
|
138
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tightknit
|
4
|
+
# The Resources module contains classes for interacting with different API resources.
|
5
|
+
module Resources
|
6
|
+
# The Feeds class provides methods for interacting with the feeds API.
|
7
|
+
# It allows listing feeds and retrieving posts from feeds.
|
8
|
+
#
|
9
|
+
# @example List feeds
|
10
|
+
# client = Tightknit.client
|
11
|
+
# feeds = client.feeds.list
|
12
|
+
#
|
13
|
+
# @example Get a specific feed
|
14
|
+
# client = Tightknit.client
|
15
|
+
# feed = client.feeds.get("feed_id")
|
16
|
+
#
|
17
|
+
# @example Get posts from a feed
|
18
|
+
# client = Tightknit.client
|
19
|
+
# posts = client.feeds.posts("feed_id")
|
20
|
+
#
|
21
|
+
class Feeds
|
22
|
+
# Initialize a new Feeds resource
|
23
|
+
#
|
24
|
+
# @param client [Tightknit::Client] The client to use for API requests
|
25
|
+
def initialize(client)
|
26
|
+
@client = client
|
27
|
+
end
|
28
|
+
|
29
|
+
# Get a list of feeds in the community
|
30
|
+
#
|
31
|
+
# @param options [Hash] Options for pagination
|
32
|
+
# @option options [Integer] :page (0) Page number
|
33
|
+
# @option options [Integer] :per_page (10) Number of records per page
|
34
|
+
# @return [Hash] Response containing feeds data
|
35
|
+
def list(options = {})
|
36
|
+
page = options[:page] || 0
|
37
|
+
per_page = options[:per_page] || 10
|
38
|
+
|
39
|
+
params = {
|
40
|
+
page: page,
|
41
|
+
per_page: per_page
|
42
|
+
}
|
43
|
+
|
44
|
+
@client.get("feeds", params)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Get a specific feed
|
48
|
+
#
|
49
|
+
# @param feed_id [String] The ID of the feed to retrieve
|
50
|
+
# @return [Hash] Response containing feed data
|
51
|
+
# @raise [Tightknit::Error] If the feed is not found or another error occurs
|
52
|
+
def get(feed_id)
|
53
|
+
@client.get("feeds/#{feed_id}")
|
54
|
+
end
|
55
|
+
|
56
|
+
# Get posts from a specific feed
|
57
|
+
#
|
58
|
+
# @param feed_id [String] The ID of the feed to retrieve posts from
|
59
|
+
# @param options [Hash] Options for pagination
|
60
|
+
# @option options [Integer] :page (0) Page number
|
61
|
+
# @option options [Integer] :per_page (10) Number of records per page
|
62
|
+
# @return [Hash] Response containing posts data
|
63
|
+
# @raise [Tightknit::Error] If the feed is not found or another error occurs
|
64
|
+
def posts(feed_id, options = {})
|
65
|
+
page = options[:page] || 0
|
66
|
+
per_page = options[:per_page] || 10
|
67
|
+
|
68
|
+
params = {
|
69
|
+
page: page,
|
70
|
+
per_page: per_page
|
71
|
+
}
|
72
|
+
|
73
|
+
@client.get("feeds/#{feed_id}/posts", params)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Tightknit
|
4
|
+
# The Utils module contains utility classes for various helper functions.
|
4
5
|
module Utils
|
5
6
|
# The HtmlFormatter class provides utilities for converting Slack blocks to HTML.
|
6
7
|
# This is useful for displaying event descriptions that are stored in Slack block format.
|
@@ -22,7 +23,7 @@ module Tightknit
|
|
22
23
|
# ]
|
23
24
|
# }
|
24
25
|
# ]
|
25
|
-
#
|
26
|
+
#
|
26
27
|
# html = Tightknit::Utils::HtmlFormatter.slack_blocks_to_html(blocks)
|
27
28
|
# # => "<p class='mb-4'>Hello, world!</p>"
|
28
29
|
#
|
@@ -37,12 +38,12 @@ module Tightknit
|
|
37
38
|
# @return [String] HTML representation of the Slack blocks
|
38
39
|
def slack_blocks_to_html(blocks)
|
39
40
|
return "" unless blocks.is_a?(Array)
|
40
|
-
|
41
|
+
|
41
42
|
html = ""
|
42
|
-
|
43
|
+
|
43
44
|
blocks.each do |block|
|
44
45
|
next unless block.is_a?(Hash) && block[:type] == "rich_text" && block[:elements].is_a?(Array)
|
45
|
-
|
46
|
+
|
46
47
|
block[:elements].each do |element|
|
47
48
|
if element[:type] == "rich_text_section" && element[:elements].is_a?(Array)
|
48
49
|
# Add a paragraph with margin for spacing
|
@@ -85,12 +86,12 @@ module Tightknit
|
|
85
86
|
end
|
86
87
|
end
|
87
88
|
end
|
88
|
-
|
89
|
+
|
89
90
|
html
|
90
91
|
end
|
91
|
-
|
92
|
+
|
92
93
|
private
|
93
|
-
|
94
|
+
|
94
95
|
# Process a text element from Slack blocks
|
95
96
|
#
|
96
97
|
# This method takes a text element from Slack blocks and converts it to HTML.
|
@@ -100,10 +101,10 @@ module Tightknit
|
|
100
101
|
# @return [String] HTML representation of the text element
|
101
102
|
def process_text_element(element)
|
102
103
|
return "" unless element.is_a?(Hash)
|
103
|
-
|
104
|
+
|
104
105
|
if element[:type] == "text"
|
105
106
|
text = element[:text].to_s
|
106
|
-
|
107
|
+
|
107
108
|
if element[:style]
|
108
109
|
if element[:style][:bold]
|
109
110
|
return "<strong>#{text}</strong>"
|
@@ -115,15 +116,15 @@ module Tightknit
|
|
115
116
|
return "<code>#{text}</code>"
|
116
117
|
end
|
117
118
|
end
|
118
|
-
|
119
|
+
|
119
120
|
return text
|
120
121
|
elsif element[:type] == "link"
|
121
122
|
return "<a href='#{element[:url]}' target='_blank' class='text-primary hover:underline'>#{element[:text]}</a>"
|
122
123
|
end
|
123
|
-
|
124
|
+
|
124
125
|
""
|
125
126
|
end
|
126
127
|
end
|
127
128
|
end
|
128
129
|
end
|
129
|
-
end
|
130
|
+
end
|
data/lib/tightknit/version.rb
CHANGED
data/lib/tightknit.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative "tightknit/version"
|
4
4
|
require_relative "tightknit/client"
|
5
5
|
require_relative "tightknit/resources/calendar_events"
|
6
|
+
require_relative "tightknit/resources/feeds"
|
6
7
|
require_relative "tightknit/utils/html_formatter"
|
7
8
|
|
8
9
|
# The Tightknit module is the main namespace for the Tightknit API client.
|
@@ -15,7 +16,7 @@ require_relative "tightknit/utils/html_formatter"
|
|
15
16
|
module Tightknit
|
16
17
|
# Error class for Tightknit-specific exceptions
|
17
18
|
class Error < StandardError; end
|
18
|
-
|
19
|
+
|
19
20
|
# Base URL for the Tightknit API
|
20
21
|
BASE_URL = "https://api.tightknit.dev/admin/v0/"
|
21
22
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tightknit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Saalik Lokhandwala
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-05-14 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: faraday
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/tightknit.rb
|
57
57
|
- lib/tightknit/client.rb
|
58
58
|
- lib/tightknit/resources/calendar_events.rb
|
59
|
+
- lib/tightknit/resources/feeds.rb
|
59
60
|
- lib/tightknit/utils/html_formatter.rb
|
60
61
|
- lib/tightknit/version.rb
|
61
62
|
- sig/tightknit.rbs
|