Skip to content

Commit 41cd83f

Browse files
authored
Merge pull request #63 from tharropoulos/yardoc
docs: add yardoc for client resources and resource class methods
2 parents 7faa0cd + 4e4ea7d commit 41cd83f

42 files changed

Lines changed: 979 additions & 3 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎flake.lock‎

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flake.nix‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
description = "Nix development environment for the Typesense Ruby client";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils }:
10+
flake-utils.lib.eachDefaultSystem (system:
11+
let
12+
pkgs = import nixpkgs {
13+
inherit system;
14+
};
15+
16+
ruby = pkgs.ruby_3_4;
17+
in
18+
{
19+
devShells.default = pkgs.mkShell {
20+
packages = with pkgs; [
21+
ruby
22+
bundler
23+
git
24+
curl
25+
pkg-config
26+
openssl
27+
libyaml
28+
zlib
29+
libffi
30+
docker
31+
docker-compose
32+
];
33+
34+
shellHook = ''
35+
export BUNDLE_PATH="$PWD/.bundle"
36+
export BUNDLE_BIN="$PWD/.bundle/bin"
37+
export BUNDLE_APP_CONFIG="$PWD/.bundle/config"
38+
export GEM_HOME="$PWD/.bundle/ruby"
39+
export PATH="$BUNDLE_BIN:$GEM_HOME/bin:$PATH"
40+
41+
cat <<'EOF'
42+
Typesense Ruby dev shell
43+
44+
First-time setup:
45+
bundle install
46+
47+
Common commands:
48+
bundle exec rubocop
49+
bundle exec rspec --format documentation
50+
51+
Integration tests expect Docker to be running.
52+
EOF
53+
'';
54+
};
55+
});
56+
}

‎lib/typesense/alias.rb‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,22 @@ def initialize(name, api_call)
77
@api_call = api_call
88
end
99

10+
# Find out which collection an alias points to by fetching it
11+
#
12+
# @example
13+
# client.aliases['my-alias'].retrieve
14+
#
15+
# @see https://typesense.org/docs/latest/api/collection-alias.html#retrieve-an-alias
1016
def retrieve
1117
@api_call.get(endpoint_path)
1218
end
1319

20+
# Delete an alias
21+
#
22+
# @example
23+
# client.aliases['my-alias'].delete
24+
#
25+
# @see https://typesense.org/docs/latest/api/collection-alias.html#delete-an-alias
1426
def delete
1527
@api_call.delete(endpoint_path)
1628
end

‎lib/typesense/aliases.rb‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,34 @@ def initialize(api_call)
99
@aliases = {}
1010
end
1111

12+
# Create or update a collection alias.
13+
#
14+
# @example
15+
# client.aliases.upsert('my-alias', 'collection_name' => 'products')
16+
#
17+
# @see https://typesense.org/docs/latest/api/collection-alias.html#create-or-update-an-alias
1218
def upsert(alias_name, mapping)
1319
@api_call.put(endpoint_path(alias_name), mapping)
1420
end
1521

22+
# List all aliases and the corresponding collections that they map to.
23+
#
24+
# @example
25+
# client.aliases.retrieve
26+
#
27+
# @see https://typesense.org/docs/latest/api/collection-alias.html#list-all-aliases
1628
def retrieve
1729
@api_call.get(RESOURCE_PATH)
1830
end
1931

32+
# Access an individual collection alias by name.
33+
#
34+
# @example
35+
# client.aliases['my-alias'].retrieve
36+
#
37+
# @see https://typesense.org/docs/latest/api/collection-alias.html
38+
#
39+
# @return [Alias]
2040
def [](alias_name)
2141
@aliases[alias_name] ||= Alias.new(alias_name, @api_call)
2242
end

‎lib/typesense/analytics.rb‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,29 @@ def initialize(api_call)
88
@api_call = api_call
99
end
1010

11+
# Access the analytics rules resource. Use it to list or create rules, or as an array
12+
# to access a single rule by ID.
13+
#
14+
# @example
15+
# client.analytics.rules.retrieve
16+
# @example
17+
# client.analytics.rules['rule-1'].retrieve
18+
#
19+
# @see https://typesense.org/docs/latest/api/analytics-query-suggestions.html
20+
#
21+
# @return [AnalyticsRules]
1122
def rules
1223
@rules ||= AnalyticsRules.new(@api_call)
1324
end
1425

26+
# Access the analytics events resource to send analytics events.
27+
#
28+
# @example
29+
# client.analytics.events.create('type' => 'click', 'name' => 'products_click', 'data' => {})
30+
#
31+
# @see https://typesense.org/docs/latest/api/analytics-query-suggestions.html
32+
#
33+
# @return [AnalyticsEvents]
1534
def events
1635
@events ||= AnalyticsEvents.new(@api_call)
1736
end

‎lib/typesense/analytics_events.rb‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,22 @@ def initialize(api_call)
88
@api_call = api_call
99
end
1010

11+
# Submit a single analytics event. The event must correspond to an existing analytics rule by name.
12+
#
13+
# @example
14+
# client.analytics.events.create('type' => 'click', 'name' => 'products_click', 'data' => {})
15+
#
16+
# @see https://typesense.org/docs/latest/api/analytics-query-suggestions.html
1117
def create(params)
1218
@api_call.post(self.class::RESOURCE_PATH, params)
1319
end
1420

21+
# Retrieve the most recent events for a user and rule.
22+
#
23+
# @example
24+
# client.analytics.events.retrieve('user_id' => 'u1', 'name' => 'products_click', 'n' => 10)
25+
#
26+
# @see https://typesense.org/docs/latest/api/analytics-query-suggestions.html
1527
def retrieve(params = {})
1628
@api_call.get(self.class::RESOURCE_PATH, params)
1729
end

‎lib/typesense/analytics_events_v1.rb‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ def initialize(api_call)
88
@api_call = api_call
99
end
1010

11+
# Submit a single legacy v1 analytics event. The event must correspond to an existing analytics rule by name.
12+
#
13+
# @example
14+
# client.analytics_v1.events.create('type' => 'click', 'name' => 'products_click', 'data' => {})
15+
#
16+
# @see https://typesense.org/docs/29.0/api/analytics-query-suggestions.html
1117
def create(params)
1218
@api_call.post(endpoint_path, params)
1319
end

‎lib/typesense/analytics_rule.rb‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,32 @@ def initialize(rule_name, api_call)
77
@api_call = api_call
88
end
99

10+
# Retrieve the details of an analytics rule, given it's name
11+
#
12+
# @example
13+
# client.analytics.rules['rule-1'].retrieve
14+
#
15+
# @see https://typesense.org/docs/latest/api/analytics-query-suggestions.html
1016
def retrieve
1117
@api_call.get(endpoint_path)
1218
end
1319

20+
# Permanently deletes an analytics rule, given it's name
21+
#
22+
# @example
23+
# client.analytics.rules['rule-1'].delete
24+
#
25+
# @see https://typesense.org/docs/latest/api/analytics-query-suggestions.html
1426
def delete
1527
@api_call.delete(endpoint_path)
1628
end
1729

30+
# Upserts an analytics rule with the given name.
31+
#
32+
# @example
33+
# client.analytics.rules['products_query_hits'].update('type' => 'popular_queries', 'params' => {})
34+
#
35+
# @see https://typesense.org/docs/latest/api/analytics-query-suggestions.html
1836
def update(params)
1937
@api_call.put(endpoint_path, params)
2038
end

‎lib/typesense/analytics_rule_v1.rb‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,22 @@ def initialize(rule_name, api_call)
77
@api_call = api_call
88
end
99

10+
# Retrieve a legacy v1 analytics rule by name.
11+
#
12+
# @example
13+
# client.analytics_v1.rules['rule-1'].retrieve
14+
#
15+
# @see https://typesense.org/docs/29.0/api/analytics-query-suggestions.html
1016
def retrieve
1117
@api_call.get(endpoint_path)
1218
end
1319

20+
# Delete a legacy v1 analytics rule by name.
21+
#
22+
# @example
23+
# client.analytics_v1.rules['rule-1'].delete
24+
#
25+
# @see https://typesense.org/docs/29.0/api/analytics-query-suggestions.html
1426
def delete
1527
@api_call.delete(endpoint_path)
1628
end

‎lib/typesense/analytics_rules.rb‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,34 @@ def initialize(api_call)
88
@api_call = api_call
99
end
1010

11+
# Create one or more analytics rules. You can send a single rule object or an array of rule objects.
12+
#
13+
# @example
14+
# client.analytics.rules.create('name' => 'products_query_hits', 'type' => 'popular_queries', 'params' => {})
15+
#
16+
# @see https://typesense.org/docs/latest/api/analytics-query-suggestions.html
1117
def create(rules)
1218
@api_call.post(self.class::RESOURCE_PATH, rules)
1319
end
1420

21+
# Retrieve all analytics rules.
22+
#
23+
# @example
24+
# client.analytics.rules.retrieve
25+
#
26+
# @see https://typesense.org/docs/latest/api/analytics-query-suggestions.html
1527
def retrieve
1628
@api_call.get(self.class::RESOURCE_PATH)
1729
end
1830

31+
# Access an individual analytics rule by name.
32+
#
33+
# @example
34+
# client.analytics.rules['rule-1'].retrieve
35+
#
36+
# @see https://typesense.org/docs/latest/api/analytics-query-suggestions.html
37+
#
38+
# @return [AnalyticsRule]
1939
def [](rule_name)
2040
AnalyticsRule.new(rule_name, @api_call)
2141
end

0 commit comments

Comments
 (0)