tightknit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.env.example +3 -0
- data/.standard.yml +3 -0
- data/.yardopts +11 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +123 -0
- data/Rakefile +30 -0
- data/lib/tightknit/client.rb +84 -0
- data/lib/tightknit/resources/calendar_events.rb +138 -0
- data/lib/tightknit/utils/html_formatter.rb +129 -0
- data/lib/tightknit/version.rb +5 -0
- data/lib/tightknit.rb +21 -0
- data/sig/tightknit.rbs +4 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2ff85345fef913fc9d8cbd8e23973d6e4550f2c85da56461b593b4ecabb159b2
|
4
|
+
data.tar.gz: 01c94f13fa480ddbf46208cb42b2182519559ab877ccd1437208a2c59c5e02d7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 55bd7d6dc26d4f849b21f41c196855628ca5bb5cec9fce2f09428a4a953fd4821fe689052c2db96b5c9cbf1e886db0fef80786380a1add8b9afadfd45050f5b3
|
7
|
+
data.tar.gz: 360d79cc1b04b06993fc51e4d3fae5ed825db6674693e4162e5ebe0702a3feaa33a792831e522274f4907e1a8a63d1c3be25639206d9d6d959e2f2373bcf8e44
|
data/.env.example
ADDED
data/.standard.yml
ADDED
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Saalik Lokhandwala
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# Tightknit
|
2
|
+
### 💎 + 🧶 = 🎉
|
3
|
+
|
4
|
+
A Ruby client for the [Tightknit](https://tightknit.ai) API.
|
5
|
+
|
6
|
+
[Official API docs](https://docs.tightknit.ai)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Install the gem and add to the application's Gemfile by executing:
|
11
|
+
|
12
|
+
```bash
|
13
|
+
bundle add tightknit
|
14
|
+
```
|
15
|
+
|
16
|
+
If bundler is not being used to manage dependencies, install the gem with:
|
17
|
+
|
18
|
+
```bash
|
19
|
+
gem install tightknit
|
20
|
+
```
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Creating a Client
|
25
|
+
|
26
|
+
Create a Tightknit client with your API key:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'tightknit'
|
30
|
+
|
31
|
+
# Create a client with your API key
|
32
|
+
client = Tightknit::Client.new(api_key: 'your_api_key')
|
33
|
+
```
|
34
|
+
|
35
|
+
### Calendar Events
|
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
|
+
#### List Events
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
# Get events with default parameters (page 0, per_page 10, status 'published')
|
44
|
+
events = client.calendar_events.list
|
45
|
+
|
46
|
+
# With custom parameters
|
47
|
+
events = client.calendar_events.list(
|
48
|
+
page: 1,
|
49
|
+
per_page: 20,
|
50
|
+
time_filter: 'upcoming',
|
51
|
+
status: 'published'
|
52
|
+
)
|
53
|
+
|
54
|
+
# Available time_filter values: 'upcoming', 'past'
|
55
|
+
# Available status values: 'published', 'draft', 'cancelled'
|
56
|
+
```
|
57
|
+
|
58
|
+
#### Get All Events (Both Past and Upcoming)
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
all_events = client.calendar_events.all(
|
62
|
+
page: 0,
|
63
|
+
per_page: 10,
|
64
|
+
status: 'published'
|
65
|
+
)
|
66
|
+
```
|
67
|
+
|
68
|
+
#### Get a Specific Event
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
event = client.calendar_events.get('event_id')
|
72
|
+
```
|
73
|
+
|
74
|
+
#### Format an Event for Display
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
event = client.calendar_events.get('event_id')
|
78
|
+
formatted_event = client.calendar_events.format_data(event[:data])
|
79
|
+
```
|
80
|
+
|
81
|
+
## Documentation
|
82
|
+
|
83
|
+
The gem includes comprehensive YARD documentation. To generate the documentation, first ensure you have the required dependencies:
|
84
|
+
|
85
|
+
```bash
|
86
|
+
bundle install
|
87
|
+
```
|
88
|
+
|
89
|
+
Then generate the documentation with:
|
90
|
+
|
91
|
+
```bash
|
92
|
+
bundle exec rake yard
|
93
|
+
```
|
94
|
+
|
95
|
+
This will generate the documentation in the `doc/yard` directory. To view the documentation in your browser, run:
|
96
|
+
|
97
|
+
```bash
|
98
|
+
bundle exec rake yard_open
|
99
|
+
```
|
100
|
+
|
101
|
+
## Development
|
102
|
+
|
103
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
104
|
+
|
105
|
+
Note that if you're adding new API routes, you'll need to add a `.env` file to test requests with your Tightknit API credentials. You can rely on our stubbed VCR cassettes for exisiting routes.
|
106
|
+
|
107
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
108
|
+
|
109
|
+
## Contributing
|
110
|
+
|
111
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Lok-Bros/tightknit.
|
112
|
+
|
113
|
+
Get in touch with us anytime: hello@lokbros.com
|
114
|
+
|
115
|
+
## License
|
116
|
+
|
117
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
118
|
+
|
119
|
+
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
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "minitest/test_task"
|
5
|
+
|
6
|
+
Minitest::TestTask.create
|
7
|
+
|
8
|
+
require "standard/rake"
|
9
|
+
|
10
|
+
begin
|
11
|
+
require "yard"
|
12
|
+
YARD::Rake::YardocTask.new do |t|
|
13
|
+
t.files = ["lib/**/*.rb"]
|
14
|
+
t.options = ["--output-dir", "doc/yard"]
|
15
|
+
t.stats_options = ["--list-undoc"]
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Generate YARD documentation and open in browser"
|
19
|
+
task :yard_open do
|
20
|
+
Rake::Task["yard"].invoke
|
21
|
+
`open doc/yard/index.html`
|
22
|
+
end
|
23
|
+
rescue LoadError
|
24
|
+
desc "Generate YARD documentation (YARD not available)"
|
25
|
+
task :yard do
|
26
|
+
abort "YARD is not available. Run `gem install yard` to install it."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
task default: %i[test standard]
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module Tightknit
|
7
|
+
# The Client class is the main entry point for interacting with the Tightknit API.
|
8
|
+
# It handles the HTTP connection and provides access to the various API resources.
|
9
|
+
#
|
10
|
+
# @example Creating a client
|
11
|
+
# client = Tightknit::Client.new(api_key: "your_api_key")
|
12
|
+
#
|
13
|
+
class Client
|
14
|
+
# @return [Faraday::Connection] The Faraday connection object used for HTTP requests
|
15
|
+
attr_reader :conn
|
16
|
+
|
17
|
+
# Initialize a new Tightknit API client
|
18
|
+
#
|
19
|
+
# @param api_key [String] The API key to use for authentication
|
20
|
+
# @raise [Tightknit::Error] If no API key is provided
|
21
|
+
def initialize(api_key:)
|
22
|
+
@api_key = api_key
|
23
|
+
|
24
|
+
raise Error, "API key is required" unless @api_key
|
25
|
+
|
26
|
+
@conn = Faraday.new(url: BASE_URL) do |faraday|
|
27
|
+
faraday.headers["Authorization"] = "Bearer #{@api_key}"
|
28
|
+
faraday.headers["Content-Type"] = "application/json"
|
29
|
+
faraday.adapter Faraday.default_adapter
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Access the calendar events resource
|
34
|
+
#
|
35
|
+
# @return [Tightknit::Resources::CalendarEvents] The calendar events resource
|
36
|
+
def calendar_events
|
37
|
+
@calendar_events ||= Resources::CalendarEvents.new(self)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Make a GET request to the API
|
41
|
+
#
|
42
|
+
# @param path [String] The path to request
|
43
|
+
# @param params [Hash] The query parameters to include
|
44
|
+
# @return [Hash] The parsed JSON response
|
45
|
+
# @raise [Tightknit::Error] If the request fails
|
46
|
+
def get(path, params = {})
|
47
|
+
response = @conn.get(path, params)
|
48
|
+
handle_response(response)
|
49
|
+
rescue Faraday::Error => e
|
50
|
+
handle_error(e)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
# Handle the API response
|
56
|
+
#
|
57
|
+
# @param response [Faraday::Response] The Faraday response object
|
58
|
+
# @return [Hash] The parsed JSON response
|
59
|
+
# @raise [Tightknit::Error] If the response status is not 2xx
|
60
|
+
def handle_response(response)
|
61
|
+
case response.status
|
62
|
+
when 200..299
|
63
|
+
JSON.parse(response.body, symbolize_names: true)
|
64
|
+
else
|
65
|
+
error_message = begin
|
66
|
+
error_data = JSON.parse(response.body, symbolize_names: true)
|
67
|
+
error_data[:message] || error_data[:error] || "Unknown error"
|
68
|
+
rescue JSON::ParserError
|
69
|
+
response.body || "Unknown error"
|
70
|
+
end
|
71
|
+
|
72
|
+
raise Error, "API Error (#{response.status}): #{error_message}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Handle Faraday errors
|
77
|
+
#
|
78
|
+
# @param error [Faraday::Error] The Faraday error
|
79
|
+
# @raise [Tightknit::Error] A wrapped error with more context
|
80
|
+
def handle_error(error)
|
81
|
+
raise Error, "Network Error: #{error.message}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "time"
|
4
|
+
|
5
|
+
module Tightknit
|
6
|
+
module Resources
|
7
|
+
# The CalendarEvents class provides methods for interacting with the calendar events API.
|
8
|
+
# It allows listing, creating, updating, and deleting calendar events.
|
9
|
+
#
|
10
|
+
# @example List upcoming events
|
11
|
+
# client = Tightknit.client
|
12
|
+
# events = client.calendar_events.list(time_filter: "upcoming")
|
13
|
+
#
|
14
|
+
# @example Get a specific event
|
15
|
+
# client = Tightknit.client
|
16
|
+
# event = client.calendar_events.get("event_id")
|
17
|
+
#
|
18
|
+
class CalendarEvents
|
19
|
+
# Initialize a new CalendarEvents resource
|
20
|
+
#
|
21
|
+
# @param client [Tightknit::Client] The client to use for API requests
|
22
|
+
def initialize(client)
|
23
|
+
@client = client
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get a list of calendar events
|
27
|
+
#
|
28
|
+
# @param options [Hash] Options for filtering events
|
29
|
+
# @option options [Integer] :page (0) Page number
|
30
|
+
# @option options [Integer] :per_page (10) Number of records per page
|
31
|
+
# @option options [String] :time_filter ('upcoming' or 'past') Filter events by time
|
32
|
+
# @option options [String] :status ('published') Filter events by status
|
33
|
+
# @return [Hash] Response containing events data
|
34
|
+
def list(options = {})
|
35
|
+
page = options[:page] || 0
|
36
|
+
per_page = options[:per_page] || 10
|
37
|
+
time_filter = options[:time_filter]
|
38
|
+
status = options[:status] || 'published'
|
39
|
+
|
40
|
+
params = {
|
41
|
+
page: page,
|
42
|
+
per_page: per_page,
|
43
|
+
status: status
|
44
|
+
}
|
45
|
+
|
46
|
+
# Only add time_filter to params if it's specified
|
47
|
+
params[:time_filter] = time_filter if time_filter
|
48
|
+
|
49
|
+
@client.get('calendar_events', params)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get both past and upcoming events
|
53
|
+
#
|
54
|
+
# @param options [Hash] Options for filtering events
|
55
|
+
# @option options [Integer] :page (0) Page number
|
56
|
+
# @option options [Integer] :per_page (10) Number of records per page
|
57
|
+
# @option options [String] :status ('published') Filter events by status
|
58
|
+
# @return [Hash] Combined response containing both past and upcoming events
|
59
|
+
def all(options = {})
|
60
|
+
# Get upcoming events
|
61
|
+
upcoming_options = options.dup
|
62
|
+
upcoming_options[:time_filter] = 'upcoming'
|
63
|
+
upcoming_response = list(upcoming_options)
|
64
|
+
|
65
|
+
# Get past events
|
66
|
+
past_options = options.dup
|
67
|
+
past_options[:time_filter] = 'past'
|
68
|
+
past_response = list(past_options)
|
69
|
+
|
70
|
+
# Combine the results
|
71
|
+
if upcoming_response[:success] && past_response[:success]
|
72
|
+
combined_records = []
|
73
|
+
|
74
|
+
if upcoming_response[:data] && upcoming_response[:data][:records]
|
75
|
+
combined_records += upcoming_response[:data][:records]
|
76
|
+
end
|
77
|
+
|
78
|
+
if past_response[:data] && past_response[:data][:records]
|
79
|
+
combined_records += past_response[:data][:records]
|
80
|
+
end
|
81
|
+
|
82
|
+
# Create a combined response with the same structure
|
83
|
+
{
|
84
|
+
success: true,
|
85
|
+
data: {
|
86
|
+
records: combined_records,
|
87
|
+
total: combined_records.length
|
88
|
+
}
|
89
|
+
}
|
90
|
+
else
|
91
|
+
# If either request failed, return the successful one or the first error
|
92
|
+
upcoming_response[:success] ? upcoming_response : past_response
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Get a specific calendar event
|
97
|
+
#
|
98
|
+
# @param event_id [String] The ID of the event to retrieve
|
99
|
+
# @return [Hash] Response containing event data
|
100
|
+
# @raise [Tightknit::Error] If the event is not found or another error occurs
|
101
|
+
def get(event_id)
|
102
|
+
@client.get("calendar_events/#{event_id}")
|
103
|
+
end
|
104
|
+
|
105
|
+
# Format event data for the API
|
106
|
+
#
|
107
|
+
# @param event_data [Hash] The raw event data
|
108
|
+
# @return [Hash] The formatted event data
|
109
|
+
# @private
|
110
|
+
def format_data(event_data)
|
111
|
+
# Create a new hash to avoid modifying the original
|
112
|
+
formatted = event_data.dup
|
113
|
+
|
114
|
+
# Format description if it's a string
|
115
|
+
if formatted[:description].is_a?(String)
|
116
|
+
formatted[:description] = { text: formatted[:description] }
|
117
|
+
end
|
118
|
+
|
119
|
+
# Format recap if it's a string
|
120
|
+
if formatted[:recap].is_a?(String)
|
121
|
+
formatted[:recap] = { text: formatted[:recap] }
|
122
|
+
end
|
123
|
+
|
124
|
+
# Format hosts if it's an array of IDs
|
125
|
+
if formatted[:hosts].is_a?(Array)
|
126
|
+
formatted[:hosts] = { slack_user_ids: formatted[:hosts] }
|
127
|
+
end
|
128
|
+
|
129
|
+
# Format speakers if it's an array of IDs
|
130
|
+
if formatted[:speakers].is_a?(Array)
|
131
|
+
formatted[:speakers] = { slack_user_ids: formatted[:speakers] }
|
132
|
+
end
|
133
|
+
|
134
|
+
formatted
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tightknit
|
4
|
+
module Utils
|
5
|
+
# The HtmlFormatter class provides utilities for converting Slack blocks to HTML.
|
6
|
+
# This is useful for displaying event descriptions that are stored in Slack block format.
|
7
|
+
#
|
8
|
+
# @example Convert Slack blocks to HTML
|
9
|
+
# blocks = [
|
10
|
+
# {
|
11
|
+
# type: "rich_text",
|
12
|
+
# elements: [
|
13
|
+
# {
|
14
|
+
# type: "rich_text_section",
|
15
|
+
# elements: [
|
16
|
+
# {
|
17
|
+
# type: "text",
|
18
|
+
# text: "Hello, world!"
|
19
|
+
# }
|
20
|
+
# ]
|
21
|
+
# }
|
22
|
+
# ]
|
23
|
+
# }
|
24
|
+
# ]
|
25
|
+
#
|
26
|
+
# html = Tightknit::Utils::HtmlFormatter.slack_blocks_to_html(blocks)
|
27
|
+
# # => "<p class='mb-4'>Hello, world!</p>"
|
28
|
+
#
|
29
|
+
class HtmlFormatter
|
30
|
+
class << self
|
31
|
+
# Convert Slack blocks to HTML
|
32
|
+
#
|
33
|
+
# This method takes an array of Slack blocks and converts them to HTML.
|
34
|
+
# It supports rich text sections, lists, and various text styles.
|
35
|
+
#
|
36
|
+
# @param blocks [Array] Slack blocks to convert
|
37
|
+
# @return [String] HTML representation of the Slack blocks
|
38
|
+
def slack_blocks_to_html(blocks)
|
39
|
+
return "" unless blocks.is_a?(Array)
|
40
|
+
|
41
|
+
html = ""
|
42
|
+
|
43
|
+
blocks.each do |block|
|
44
|
+
next unless block.is_a?(Hash) && block[:type] == "rich_text" && block[:elements].is_a?(Array)
|
45
|
+
|
46
|
+
block[:elements].each do |element|
|
47
|
+
if element[:type] == "rich_text_section" && element[:elements].is_a?(Array)
|
48
|
+
# Add a paragraph with margin for spacing
|
49
|
+
html += "<p class='mb-4'>"
|
50
|
+
element[:elements].each do |text_element|
|
51
|
+
processed_text = process_text_element(text_element)
|
52
|
+
# Replace newlines with <br> tags for proper line breaks
|
53
|
+
html += processed_text.to_s.gsub("\n", "<br>")
|
54
|
+
end
|
55
|
+
html += "</p>"
|
56
|
+
elsif element[:type] == "rich_text_list" && element[:elements].is_a?(Array)
|
57
|
+
# Add margin before and after lists
|
58
|
+
if element[:style] == "bullet"
|
59
|
+
html += "<ul class='list-disc pl-5 my-4'>"
|
60
|
+
element[:elements].each do |list_item|
|
61
|
+
html += "<li class='mb-2'>"
|
62
|
+
if list_item[:elements].is_a?(Array)
|
63
|
+
list_item[:elements].each do |item_element|
|
64
|
+
processed_text = process_text_element(item_element)
|
65
|
+
html += processed_text.to_s.gsub("\n", "<br>")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
html += "</li>"
|
69
|
+
end
|
70
|
+
html += "</ul>"
|
71
|
+
elsif element[:style] == "ordered"
|
72
|
+
html += "<ol class='list-decimal pl-5 my-4'>"
|
73
|
+
element[:elements].each do |list_item|
|
74
|
+
html += "<li class='mb-2'>"
|
75
|
+
if list_item[:elements].is_a?(Array)
|
76
|
+
list_item[:elements].each do |item_element|
|
77
|
+
processed_text = process_text_element(item_element)
|
78
|
+
html += processed_text.to_s.gsub("\n", "<br>")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
html += "</li>"
|
82
|
+
end
|
83
|
+
html += "</ol>"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
html
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
# Process a text element from Slack blocks
|
95
|
+
#
|
96
|
+
# This method takes a text element from Slack blocks and converts it to HTML.
|
97
|
+
# It supports various text styles like bold, italic, strikethrough, and code.
|
98
|
+
#
|
99
|
+
# @param element [Hash] Text element to process
|
100
|
+
# @return [String] HTML representation of the text element
|
101
|
+
def process_text_element(element)
|
102
|
+
return "" unless element.is_a?(Hash)
|
103
|
+
|
104
|
+
if element[:type] == "text"
|
105
|
+
text = element[:text].to_s
|
106
|
+
|
107
|
+
if element[:style]
|
108
|
+
if element[:style][:bold]
|
109
|
+
return "<strong>#{text}</strong>"
|
110
|
+
elsif element[:style][:italic]
|
111
|
+
return "<em>#{text}</em>"
|
112
|
+
elsif element[:style][:strike]
|
113
|
+
return "<del>#{text}</del>"
|
114
|
+
elsif element[:style][:code]
|
115
|
+
return "<code>#{text}</code>"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
return text
|
120
|
+
elsif element[:type] == "link"
|
121
|
+
return "<a href='#{element[:url]}' target='_blank' class='text-primary hover:underline'>#{element[:text]}</a>"
|
122
|
+
end
|
123
|
+
|
124
|
+
""
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
data/lib/tightknit.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "tightknit/version"
|
4
|
+
require_relative "tightknit/client"
|
5
|
+
require_relative "tightknit/resources/calendar_events"
|
6
|
+
require_relative "tightknit/utils/html_formatter"
|
7
|
+
|
8
|
+
# The Tightknit module is the main namespace for the Tightknit API client.
|
9
|
+
# It provides a simple way to interact with the Tightknit API.
|
10
|
+
#
|
11
|
+
# @example Create a client
|
12
|
+
# client = Tightknit::Client.new(api_key: "your_api_key")
|
13
|
+
# events = client.calendar_events.list
|
14
|
+
#
|
15
|
+
module Tightknit
|
16
|
+
# Error class for Tightknit-specific exceptions
|
17
|
+
class Error < StandardError; end
|
18
|
+
|
19
|
+
# Base URL for the Tightknit API
|
20
|
+
BASE_URL = "https://api.tightknit.dev/admin/v0/"
|
21
|
+
end
|
data/sig/tightknit.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tightknit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Saalik Lokhandwala
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-04-21 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: faraday
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '2.7'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '2.7'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: json
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.6'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.6'
|
40
|
+
description: A Ruby client for interacting with the Tightknit API to manage calendar
|
41
|
+
events and more.
|
42
|
+
email:
|
43
|
+
- saalikl111@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".env.example"
|
49
|
+
- ".standard.yml"
|
50
|
+
- ".yardopts"
|
51
|
+
- CHANGELOG.md
|
52
|
+
- CODE_OF_CONDUCT.md
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- lib/tightknit.rb
|
57
|
+
- lib/tightknit/client.rb
|
58
|
+
- lib/tightknit/resources/calendar_events.rb
|
59
|
+
- lib/tightknit/utils/html_formatter.rb
|
60
|
+
- lib/tightknit/version.rb
|
61
|
+
- sig/tightknit.rbs
|
62
|
+
homepage: https://github.com/saalik/tightknit
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata:
|
66
|
+
allowed_push_host: https://rubygems.org
|
67
|
+
homepage_uri: https://github.com/saalik/tightknit
|
68
|
+
source_code_uri: https://github.com/saalik/tightknit
|
69
|
+
changelog_uri: https://github.com/saalik/tightknit/blob/main/CHANGELOG.md
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 3.1.0
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubygems_version: 3.6.2
|
85
|
+
specification_version: 4
|
86
|
+
summary: Ruby client for the Tightknit API
|
87
|
+
test_files: []
|