algolia 2.0.0 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +11 -2
  3. data/.dockerignore +38 -0
  4. data/.gitignore +1 -0
  5. data/CHANGELOG.md +80 -1
  6. data/CONTRIBUTING.MD +184 -0
  7. data/DOCKER_README.MD +89 -0
  8. data/Dockerfile +7 -0
  9. data/README.md +4 -4
  10. data/SECURITY.md +1 -1
  11. data/algolia.gemspec +3 -1
  12. data/lib/algolia/analytics_client.rb +1 -1
  13. data/lib/algolia/config/personalization_config.rb +20 -0
  14. data/lib/algolia/config/recommend_config.rb +6 -0
  15. data/lib/algolia/config/recommendation_config.rb +2 -15
  16. data/lib/algolia/helpers.rb +51 -1
  17. data/lib/algolia/http/http_requester.rb +4 -4
  18. data/lib/algolia/insights_client.rb +1 -1
  19. data/lib/algolia/logger_helper.rb +1 -1
  20. data/lib/algolia/personalization_client.rb +60 -0
  21. data/lib/algolia/recommend_client.rb +134 -0
  22. data/lib/algolia/recommendation_client.rb +2 -55
  23. data/lib/algolia/responses/add_api_key_response.rb +1 -1
  24. data/lib/algolia/responses/delete_api_key_response.rb +1 -1
  25. data/lib/algolia/responses/dictionary_response.rb +33 -0
  26. data/lib/algolia/responses/restore_api_key_response.rb +1 -1
  27. data/lib/algolia/responses/update_api_key_response.rb +1 -1
  28. data/lib/algolia/search_client.rb +185 -8
  29. data/lib/algolia/search_index.rb +21 -56
  30. data/lib/algolia/transport/request_options.rb +1 -1
  31. data/lib/algolia/transport/transport.rb +11 -10
  32. data/lib/algolia/version.rb +1 -1
  33. data/lib/algolia.rb +5 -0
  34. data/renovate.json +5 -0
  35. data/test/algolia/integration/account_client_test.rb +2 -2
  36. data/test/algolia/integration/analytics_client_test.rb +6 -2
  37. data/test/algolia/integration/mocks/mock_requester.rb +13 -11
  38. data/test/algolia/integration/personalization_client_test.rb +30 -0
  39. data/test/algolia/integration/recommend_client_test.rb +70 -0
  40. data/test/algolia/integration/search_client_test.rb +108 -13
  41. data/test/algolia/integration/search_index_test.rb +31 -0
  42. data/test/algolia/unit/helpers_test.rb +4 -2
  43. data/test/test_helper.rb +32 -0
  44. metadata +45 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 555e432d41a84d3031f58dc7c74acf5297df48fe693fadf977c6b15547a82d6b
4
- data.tar.gz: a3fbbc9ba6552b0b432a20e34cd5cf7a311f339c2df7f7a3c549ced84f409ba0
3
+ metadata.gz: 1dfdc9659fd559dda96a6bac3df7d81f455fba723f835ee62213928bb2e1ba03
4
+ data.tar.gz: fd2abb719cc40db045c976e1183083986ebc13fff45a979bd6a0da4bb1cf68c1
5
5
  SHA512:
6
- metadata.gz: 757d57c2723f3f036bfb7faa38615fd751311e99b0a3f5e1b3c13087c53a9010af88c99a5412e31bb3e6d3cdb9201478d7100c71080b3fe948004170a870f875
7
- data.tar.gz: ede51228b6bc2498b65434102f8b25b17d7db74ae74cd2b50a1ec7184f42692e4b24d94de8c621ec91a8192c924e71ac1067bfdde038a03936407f12147b6175
6
+ metadata.gz: ed0f1ba2efdb129534b30ec41f381d9288685aa9f88beeaea813426ba40831c3c3691727fcfd52002a6db35a0f2c3218687b2687fb3e7b71e8ccfc655b27b920
7
+ data.tar.gz: 8df23199078a71911b108864b74e0c9431790fdb28cfd5cafdd811ecc31d9a860a53e9031b050b969ba73aaa49ac96555c564162fb766425c86683cc2dcfb74a
data/.circleci/config.yml CHANGED
@@ -23,6 +23,13 @@ aliases:
23
23
  name: Run linting tool
24
24
  command: bundle exec rake rubocop
25
25
 
26
+ - &credentials
27
+ name: Retrieve temporary Algolia credentials if needed
28
+ command: |
29
+ if [ "$CIRCLE_PR_REPONAME" ]; then
30
+ curl -s https://algoliasearch-client-keygen.herokuapp.com | sh >> $BASH_ENV
31
+ fi
32
+
26
33
  - &run_tests
27
34
  name: Run unit and integration tests
28
35
  command: |
@@ -73,6 +80,7 @@ jobs:
73
80
  - restore_cache: *restore_cache
74
81
  - run: *install_bundler
75
82
  - save_cache: *save_cache
83
+ - run: *credentials
76
84
  - run: *run_tests
77
85
 
78
86
  test_jruby:
@@ -88,6 +96,7 @@ jobs:
88
96
  - restore_cache: *restore_cache
89
97
  - run: *install_bundler
90
98
  - save_cache: *save_cache
99
+ - run: *credentials
91
100
  - run: *run_tests
92
101
 
93
102
  release:
@@ -122,14 +131,14 @@ workflows:
122
131
  - test_ruby:
123
132
  matrix:
124
133
  parameters:
125
- version: ['2.2', '2.3', '2.4', '2.5', '2.6', '2.7']
134
+ version: ['2.4', '2.5', '2.6', '2.7', '3.0']
126
135
  filters:
127
136
  tags:
128
137
  only: /.*/
129
138
  - test_jruby:
130
139
  matrix:
131
140
  parameters:
132
- version: ['9.1', '9.2']
141
+ version: ['9.2']
133
142
  filters:
134
143
  tags:
135
144
  only: /.*/
data/.dockerignore ADDED
@@ -0,0 +1,38 @@
1
+ # rspec failure tracking
2
+ .rspec_status
3
+
4
+ ## MAC OS
5
+ .DS_Store
6
+ .idea/
7
+
8
+ ## TEXTMATE
9
+ *.tmproj
10
+ tmtags
11
+
12
+ ## EMACS
13
+ *~
14
+ \#*
15
+ .\#*
16
+
17
+ ## VIM
18
+ *.swp
19
+
20
+ ## PROJECT::GENERAL
21
+ coverage
22
+ rdoc
23
+ pkg
24
+ .rvmrc
25
+ /.bundle/
26
+ /.yardoc
27
+ /_yardoc/
28
+ /coverage/
29
+ /doc/
30
+ /pkg/
31
+ /spec/reports/
32
+ /tmp/
33
+
34
+ ## PROJECT::SPECIFIC
35
+ spec/integration_spec_conf.rb
36
+ data.sqlite3
37
+
38
+ debug.log
data/.gitignore CHANGED
@@ -37,3 +37,4 @@ spec/integration_spec_conf.rb
37
37
  data.sqlite3
38
38
 
39
39
  debug.log
40
+ .ruby-version
data/CHANGELOG.md CHANGED
@@ -1,6 +1,85 @@
1
1
  # ChangeLog
2
2
 
3
- ## Unreleased
3
+ ## [Unreleased](https://github.com/algolia/algoliasearch-client-ruby/compare/2.3.2..master)
4
+
5
+ ## [2.3.2](https://github.com/algolia/algoliasearch-client-ruby/compare/2.3.1...2.3.2) (2023-06-07)
6
+ ### Fixed
7
+ - Fixed issue with Request not taking timeouts into account ([`#493`](https://github.com/algolia/algoliasearch-client-ruby/pull/493))
8
+
9
+ ## [2.3.1](https://github.com/algolia/algoliasearch-client-ruby/compare/2.3.0...2.3.1) (2022-09-26)
10
+ ### Fixed
11
+ - Fixed issue when project uses Faraday <1 ([`#485`](https://github.com/algolia/algoliasearch-client-ruby/pull/485))
12
+
13
+ ## [2.3.0](https://github.com/algolia/algoliasearch-client-ruby/compare/2.2.5...2.3.0) (2022-09-26)
14
+ ### Changed
15
+ - Dropped support for Ruby < 2.4 ([`#483`](https://github.com/algolia/algoliasearch-client-ruby/pull/483))
16
+ - Updated Faraday dependency range ([`#471`](https://github.com/algolia/algoliasearch-client-ruby/pull/471))
17
+ - Fixed bug with `createIfNotExists` ([`#458`](https://github.com/algolia/algoliasearch-client-ruby/pull/458))
18
+ - Use user-configured logger to temp client ([`#480`](https://github.com/algolia/algoliasearch-client-ruby/pull/480))
19
+
20
+ ## [2.2.5](https://github.com/algolia/algoliasearch-client-ruby/compare/2.2.4...2.2.5) (2022-05-24)
21
+ ### Fixed
22
+ - multiple_queries: allow params to be `nil` ([`#478`](https://github.com/algolia/algoliasearch-client-ruby/pull/478))
23
+
24
+ ## [2.2.4](https://github.com/algolia/algoliasearch-client-ruby/compare/2.2.3...2.2.4) (2022-05-24)
25
+ ### Fixed
26
+ - API endpoint URL mishandling in get_settings method ([`#473`](https://github.com/algolia/algoliasearch-client-ruby/pull/473))
27
+ - Confusing empty debug.log generation in gem users root ([`#474`](https://github.com/algolia/algoliasearch-client-ruby/pull/474))
28
+
29
+ ## [2.2.3](https://github.com/algolia/algoliasearch-client-ruby/compare/2.2.2...2.2.3) (2022-04-21)
30
+ ### Fixed
31
+ - API polling flood issue due to msec sleep time mishandling ([`#472`](https://github.com/algolia/algoliasearch-client-ruby/pull/472))
32
+ - mailto link in SECURITY.md ([`#463`](https://github.com/algolia/algoliasearch-client-ruby/pull/463))
33
+
34
+ ### Added
35
+ - allow hash in multiple queries ([`#468`](https://github.com/algolia/algoliasearch-client-ruby/pull/468))
36
+
37
+ ## [2.2.2](https://github.com/algolia/algoliasearch-client-ruby/compare/2.2.1...2.2.2) (2021-12-08)
38
+ ### Fixed
39
+ - Added a `status` field to the `MockRequester` ([`#467`](https://github.com/algolia/algoliasearch-client-ruby/pull/467))
40
+
41
+ ## [2.2.1](https://github.com/algolia/algoliasearch-client-ruby/compare/2.2.0...2.2.1) (2021-11-12)
42
+ ### Chore
43
+ - Deprecated `RecommendationClient` in favor of `PersonalizationClient` ([`#461`](https://github.com/algolia/algoliasearch-client-ruby/pull/461))
44
+
45
+ ## [2.2.0](https://github.com/algolia/algoliasearch-client-ruby/compare/2.1.1...2.2.0) (2021-11-08)
46
+ ### Added
47
+ - Added RecommendClient ([`#466`](https://github.com/algolia/algoliasearch-client-ruby/pull/466))
48
+ - Added `search` alias for `multiple_queries` ([`#457`](https://github.com/algolia/algoliasearch-client-ruby/pull/457))
49
+
50
+ ## [2.1.1](https://github.com/algolia/algoliasearch-client-ruby/compare/2.1.0...2.1.1) (2021-05-27)
51
+
52
+ ### Fix
53
+ - Bug with read/write nodes caching ([`#455`](https://github.com/algolia/algoliasearch-client-ruby/pull/455))
54
+
55
+ ## [2.1.0](https://github.com/algolia/algoliasearch-client-ruby/compare/2.0.4...2.1.0) (2021-03-30)
56
+
57
+ ### Feat
58
+ - Custom dictionaries methods
59
+
60
+ ### Fix
61
+ - The parameter `forwardToReplicas` should be handled independently in the `set_settings` method
62
+
63
+ ## [2.0.4](https://github.com/algolia/algoliasearch-client-ruby/compare/2.0.3...2.0.4) (2021-01-05)
64
+
65
+ ### Fix
66
+ - `app_api_key`: send opts with waitable method
67
+
68
+ ## [2.0.3](https://github.com/algolia/algoliasearch-client-ruby/compare/2.0.2...2.0.3) (2020-11-24)
69
+
70
+ ### Chore
71
+ - Containerize the repo
72
+
73
+ ## [2.0.2](https://github.com/algolia/algoliasearch-client-ruby/compare/2.0.1...2.0.2) (2020-11-09)
74
+
75
+ ### Fix
76
+ - Don't mutate index name on stripping
77
+
78
+ ## [2.0.1](https://github.com/algolia/algoliasearch-client-ruby/compare/2.0.0...2.0.1) (2020-11-02)
79
+
80
+ ### Fix
81
+ - Simplify merge of headers in `Transport` class
82
+ - `deserialize_settings` function to take into account `symbolize_keys` parameter
4
83
 
5
84
  ## [2.0.0](https://github.com/algolia/algoliasearch-client-ruby/releases/tag/2.0.0) (2020-10-27)
6
85
 
data/CONTRIBUTING.MD ADDED
@@ -0,0 +1,184 @@
1
+ <p align="center">
2
+ <a href="https://www.algolia.com">
3
+ <img alt="Algolia for Ruby" src="https://raw.githubusercontent.com/algolia/algoliasearch-client-common/master/banners/ruby.png" >
4
+ </a>
5
+ </p>
6
+
7
+ Hello and welcome to the contributing guide for algolia gem. Thanks for considering participating in our project 🙇
8
+
9
+ If this guide does not contain what you are looking for and thus prevents you from contributing, don't hesitate to leave a message on the [community forum](https://discourse.algolia.com/) or to [open an issue](https://github.com/algolia/algoliasearch-client-ruby/issues).
10
+
11
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN TocDown TO UPDATE -->
12
+ <!-- TocDown Begin -->
13
+ * [Reporting an issue](#reporting-an-issue)
14
+ * [The code contribution process](#the-code-contribution-process)
15
+ * [Commit conventions](#commit-conventions)
16
+ * [Branch organization](#branch-organization)
17
+ * [Requirements](#requirements)
18
+ * [Code structure](#code-structure)
19
+ * [The source algolia folder](#the-source-algolia-folder)
20
+ * [Tests](#tests)
21
+ * [Linting](#linting)
22
+ <!-- TocDown End -->
23
+
24
+ ## Reporting an issue
25
+
26
+ Opening an issue is very effective way to contribute because other users might also be impacted. We'll make sure to fix it quickly if it's technically feasible and doesn't have important side effects for other users.
27
+
28
+ Before reporting an issue, first check that there is not an already open issue for the same topic using the [issues page](https://github.com/algolia/algoliasearch-client-ruby/issues). Don't hesitate to thumb up an issue that corresponds to the problem you have.
29
+
30
+ It would be very helpful if you're able to add a test case that reproduces the issue. This could help us solve the issue faster.
31
+
32
+ ## The code contribution process
33
+
34
+ The algolia gem is developed in Ruby ≥ 2.2.
35
+
36
+ For any code contribution, you need to:
37
+
38
+ - Fork and clone the project
39
+ - Create a new branch for what you want to solve (fix/_issue-number_, feat/_name-of-the-feature_)
40
+ - Make your changes
41
+ - Open a pull request
42
+
43
+ Depending on what you're working on, you might consider different [base branches](#branch-organization).
44
+
45
+ Then:
46
+
47
+ - Peer review of the pull request (by at least one of the core contributors)
48
+ - Automatic checks ([tests](#tests), [commits](#commit-conventions), [linters](#linting))
49
+ - When everything is green, one of the core contributors will merge your contribution 🚀
50
+
51
+ ## Commit conventions
52
+
53
+ This project follows the [conventional changelog](https://conventionalcommits.org/) approach. This means that all commit messages should be formatted using the following scheme:
54
+
55
+ ```
56
+ type(scope): description
57
+ ```
58
+
59
+ In most cases, we use the following types:
60
+
61
+ - `fix`: for any resolution of an issue (identified or not)
62
+ - `feat`: for any new feature
63
+ - `refactor`: for any code change that neither adds a feature nor fixes an issue
64
+ - `docs`: for any documentation change or addition
65
+ - `chore`: for anything that is not related to the library itself (doc, tooling)
66
+
67
+ Even though the scope is optional, we try to fill it in as it helps us better understand the impact of a change. We either use the name of the widget/connector/component impacted or we use impact topic (e.g. `docs`, `tooling`, `deps`, `ci`).
68
+
69
+ Finally, if your work is based on an issue on GitHub, please fill in the dedicated line in the PR template (read "[Closing issues using keywords](https://help.github.com/en/articles/closing-issues-using-keywords)").
70
+
71
+ Some examples of valid commit messages (used as first lines):
72
+
73
+ > - feat(account-client): add method XXX
74
+ > - chore(deps): update dependency XXX to v3.0.7
75
+ > - fix(search_user_ids): rename parameter clusterName
76
+ > - chore: reword contributions guides
77
+
78
+ ## Branch organization
79
+
80
+ The project is based on the classic GitHub flow:
81
+
82
+ - `master` for the current version being worked on – Pull requests for bugs and feature related to the current major version should be created against this branch
83
+ - `vX` for each major version (`X` being a number) – Pull requests for critical bug fixes should be created against this branch
84
+
85
+ Most of the time, your pull requests should target the `master` branch.
86
+
87
+ _Note that no new features will be developed or backported for the `vX` branches._
88
+
89
+ ## Requirements
90
+
91
+ To run this project, you will need:
92
+
93
+ - Ruby ≥ 2.2
94
+ - [Bundler](https://bundler.io/)
95
+
96
+ ## Use the Dockerfile
97
+
98
+ If you want to contribute to this project without installing all its dependencies, you can use our Docker image.
99
+ Please check our [dedicated guide](DOCKER_README.MD) to learn more.
100
+
101
+ ## Code structure
102
+
103
+ Here are the main files and folders of the project
104
+
105
+ ```
106
+ ▸ lib/algolia/ << standalone clients and helpers classes
107
+ ▸ lib/test/ << gathers the unit and integration tests
108
+ .rubocop.yml << contains the rule used for the linter
109
+ algolia.gemspec << gemspec file
110
+ CHANGELOG.md << changelog file
111
+ CONTRIBUTING.md << this file
112
+ Gemfile << dependencies needed to run the project locally
113
+ Rakefile << defines the different tasks to lint/test the project
114
+ README.md << the introduction of the project
115
+ ```
116
+
117
+ ### The lib/algolia folder
118
+
119
+ ```
120
+ ▸ lib/algolia/
121
+ ▸ config/ << the configurations associated with each clients
122
+ ▸ enums/ << enumerables used accross the lib
123
+ ▸ http/ << the http layer logic
124
+ ▸ iterators/ << the iterators used for the browsing methods
125
+ ▸ responses/ << the waitable responses
126
+ ▸ transport/ << the transport layer logic
127
+ ```
128
+
129
+ ## Tests
130
+
131
+ Our unit and integration tests are written with [Minitest](https://github.com/seattlerb/minitest), in the `test` syntax.
132
+
133
+ To run all the tests at once:
134
+
135
+ ```sh
136
+ bundle exec rake test:all
137
+ ```
138
+
139
+ To run only the unit tests:
140
+
141
+ ```sh
142
+ bundle exec rake test:unit
143
+ ```
144
+
145
+ To run only the integration tests:
146
+
147
+ ```sh
148
+ bundle exec rake test:integration
149
+ ```
150
+
151
+ We ask that for each fix or feature submitted, you add at least one test demonstrating its behaviour. As you will need to use your own Algolia credentials to run them, we advise you to keep them short and use a small dataset, as well as using a mock requester anytime it's possible. If you encounter huge data overload because of testing, please reach out to [our support team](support@algolia.com).
152
+
153
+ ## Linting
154
+
155
+ Linters help us maintain a consistent code base.
156
+
157
+ If your editor support them, then you will see the errors directly there. You can also run them using your command line:
158
+
159
+ ```sh
160
+ rake rubocop
161
+ ```
162
+
163
+ However, we recommend that you use in your workflow pre-commit hooks, to avoid submitting code that might not pass the linting task setup in the CI. To use them,
164
+ first download the gem `git-precommit`
165
+
166
+ ```sh
167
+ gem install git-precommit
168
+ ```
169
+
170
+ Then copy-paste the following content in a file called `pre-commit` in `.git/hooks/`
171
+
172
+ ```sh
173
+ #!/usr/bin/env sh
174
+
175
+ function unstaged_changes {
176
+ ! git diff --quiet
177
+ }
178
+
179
+ if unstaged_changes; then
180
+ git stash save --keep-index "Performing partial commit against `git rev-parse HEAD`"
181
+ fi
182
+
183
+ exec time bundle exec rake precommit
184
+ ```
data/DOCKER_README.MD ADDED
@@ -0,0 +1,89 @@
1
+ In this page you will find our recommended way of installing Docker on your machine.
2
+ This guide is made for OSX users.
3
+
4
+ ## Install docker
5
+
6
+ First install Docker using [Homebrew](https://brew.sh/)
7
+ ```
8
+ $ brew install docker
9
+ ```
10
+
11
+ You can then install [Docker Desktop](https://docs.docker.com/get-docker/) if you wish, or use `docker-machine`. As we prefer the second option, we will only document this one.
12
+
13
+ ## Setup your docker
14
+
15
+ Install `docker-machine`
16
+ ```
17
+ $ brew install docker-machine
18
+ ```
19
+
20
+ Then install [VirtualBox](https://www.virtualbox.org/) with [Homebrew Cask](https://github.com/Homebrew/homebrew-cask) to get a driver for your Docker machine
21
+ ```
22
+ $ brew cask install virtualbox
23
+ ```
24
+
25
+ You may need to enter your password and authorize the application in your `System Settings` > `Security & Privacy`.
26
+
27
+ Create now a new machine, set it up as default and connect your shell to it (here we use zsh. The commands should anyway be displayed in each steps' output)
28
+
29
+ ```
30
+ $ docker-machine create --driver virtualbox default
31
+ $ docker-machine env default
32
+ $ eval "$(docker-machine env default)"
33
+ ```
34
+
35
+ Now you're all setup to use our provided Docker image!
36
+
37
+ ## Build the image
38
+
39
+ ```bash
40
+ docker build -t algolia-ruby .
41
+ ```
42
+
43
+ ## Run the image
44
+
45
+ You need to provide few environment variables at runtime to be able to run the [Common Test Suite](https://github.com/algolia/algoliasearch-client-specs/tree/master/common-test-suite).
46
+ You can set them up directly in the command:
47
+
48
+ ```bash
49
+ docker run -it --rm --env ALGOLIA_APP_ID=XXXXXX [...] -v $PWD:/app -w /app algolia-ruby bash
50
+ ```
51
+
52
+ However, we advise you to export them in your `.bashrc` or `.zshrc`. That way, you can use [Docker's shorten syntax](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file) to set your variables.
53
+
54
+ ```bash
55
+ ### For external contributors, only the following env variables should be enough
56
+ docker run -it --rm --env ALGOLIA_APPLICATION_ID_1 \
57
+ --env ALGOLIA_ADMIN_KEY_1 \
58
+ --env ALGOLIA_SEARCH_KEY_1 \
59
+ -v $PWD:/app -w /app algolia-ruby bash
60
+
61
+ ### This is needed only to run the full test suite
62
+ docker run -it --rm --env ALGOLIA_APPLICATION_ID_1 \
63
+ --env ALGOLIA_ADMIN_KEY_1 \
64
+ --env ALGOLIA_SEARCH_KEY_1 \
65
+ --env ALGOLIA_APPLICATION_ID_2 \
66
+ --env ALGOLIA_ADMIN_KEY_2 \
67
+ --env ALGOLIA_APPLICATION_ID_MCM \
68
+ --env ALGOLIA_ADMIN_KEY_MCM \
69
+ -v $PWD:/app -w /app algolia-ruby bash
70
+ ```
71
+
72
+ Once your container is running, any changes you make in your IDE are directly reflected in the container.
73
+
74
+ To launch the tests, you can use one of the following commands
75
+ ```shell script
76
+ # run only the unit tests
77
+ bundle exec rake test:unit
78
+
79
+ # run only the integration tests
80
+ bundle exec rake test:integration
81
+
82
+ # run the whole test suite
83
+ bundle exec rake test:all
84
+
85
+ # run a single test
86
+ bundle exec rake test TEST=/full/path/to/test.rb TESTOPTS="--name=test_name"
87
+ ```
88
+
89
+ Feel free to contact us if you have any questions.
data/Dockerfile ADDED
@@ -0,0 +1,7 @@
1
+ FROM ruby:2.6.3
2
+
3
+ RUN gem install bundler
4
+
5
+ WORKDIR /app
6
+ COPY . /app/
7
+ RUN bundle install
data/README.md CHANGED
@@ -6,8 +6,8 @@
6
6
  <h4 align="center">The perfect starting point to integrate <a href="https://algolia.com" target="_blank">Algolia</a> within your Ruby project</h4>
7
7
 
8
8
  <p align="center">
9
- <a href="https://circleci.com/gh/algolia/algoliasearch-client-ruby"><img src="https://circleci.com/gh/algolia/algoliasearch-client-ruby/tree/release%2Fv2.svg?style=shield" alt="CircleCI" /></a>
10
- <a href="https://rubygems.org/gems/algolia"><img src="https://badge.fury.io/rb/algoliasearch.svg" alt="Gem Version"></a>
9
+ <a href="https://circleci.com/gh/algolia/algoliasearch-client-ruby"><img src="https://circleci.com/gh/algolia/algoliasearch-client-ruby.svg?style=shield" alt="CircleCI" /></a>
10
+ <a href="https://rubygems.org/gems/algolia"><img src="https://badge.fury.io/rb/algolia.svg" alt="Gem Version"></a>
11
11
  <a href="https://rubygems.org/gems/algolia"><img src="https://img.shields.io/badge/licence-MIT-blue.svg" alt="License"></a>
12
12
  </p>
13
13
  </p>
@@ -25,7 +25,7 @@
25
25
  ## ✨ Features
26
26
 
27
27
  - Thin & minimal low-level HTTP client to interact with Algolia's API
28
- - Supports Ruby `^2.2`.
28
+ - Supports Ruby `^2.4`.
29
29
 
30
30
  ## 💡 Getting Started
31
31
 
@@ -41,7 +41,7 @@ Then, create objects on your index:
41
41
  client = Algolia::Search::Client.create('YourApplicationID', 'YourAPIKey')
42
42
  index = client.init_index('your_index_name')
43
43
 
44
- index.save_objects([objectID: 1, name: 'Foo'])
44
+ index.save_objects([{objectID: 1, name: 'Foo'}])
45
45
  ```
46
46
 
47
47
  Finally, you may begin searching a object using the `search` method:
data/SECURITY.md CHANGED
@@ -1,3 +1,3 @@
1
1
  ## Reporting a Vulnerability
2
2
 
3
- To report a security vulnerability, please use the [Algolia security email](security@algolia.com). Algolia will coordinate the fix and disclosure.
3
+ To report a security vulnerability, please use the [Algolia security email](mailto:security@algolia.com). Algolia will coordinate the fix and disclosure.
data/algolia.gemspec CHANGED
@@ -35,7 +35,9 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'rake'
36
36
  spec.add_development_dependency 'rubocop', '<= 0.82.0'
37
37
 
38
- spec.add_dependency 'faraday', '~> 0.15'
38
+ spec.add_dependency 'faraday', ['>= 0.15', '< 3']
39
+ spec.add_dependency 'faraday-net_http_persistent', ['>= 0.15', '< 3']
40
+
39
41
  spec.add_dependency 'multi_json', '~> 1.0'
40
42
  spec.add_dependency 'net-http-persistent'
41
43
 
@@ -13,7 +13,7 @@ module Algolia
13
13
  def initialize(analytics_config, opts = {})
14
14
  @config = analytics_config
15
15
  adapter = opts[:adapter] || Defaults::ADAPTER
16
- logger = opts[:logger] || LoggerHelper.create('debug.log')
16
+ logger = opts[:logger] || LoggerHelper.create
17
17
  requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter, logger)
18
18
  @transporter = Transport::Transport.new(@config, requester)
19
19
  end
@@ -0,0 +1,20 @@
1
+ module Algolia
2
+ module Personalization
3
+ class Config < BaseConfig
4
+ attr_accessor :region, :default_hosts
5
+
6
+ # Initialize a config
7
+ #
8
+ # @option options [String] :application_id
9
+ # @option options [String] :api_key
10
+ # @option options [String] :region
11
+ #
12
+ def initialize(opts = {})
13
+ super(opts)
14
+
15
+ @region = opts[:region] || 'us'
16
+ @default_hosts = [Transport::StatefulHost.new("personalization.#{region}.algolia.com")]
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ module Algolia
2
+ module Recommend
3
+ class Config < Algolia::Search::Config
4
+ end
5
+ end
6
+ end
@@ -1,20 +1,7 @@
1
1
  module Algolia
2
2
  module Recommendation
3
- class Config < BaseConfig
4
- attr_accessor :region, :default_hosts
5
-
6
- # Initialize a config
7
- #
8
- # @option options [String] :application_id
9
- # @option options [String] :api_key
10
- # @option options [String] :region
11
- #
12
- def initialize(opts = {})
13
- super(opts)
14
-
15
- @region = opts[:region] || 'us'
16
- @default_hosts = [Transport::StatefulHost.new("recommendation.#{region}.algolia.com")]
17
- end
3
+ # <b>DEPRECATED:</b> Please use <tt>Algolia::Personalization::Config</tt> instead.
4
+ class Config < Algolia::Personalization::Config
18
5
  end
19
6
  end
20
7
  end
@@ -53,7 +53,7 @@ module Helpers
53
53
  # Support to convert old settings to their new names
54
54
  #
55
55
  def deserialize_settings(data, symbolize_keys)
56
- settings = symbolize_hash(data)
56
+ settings = data
57
57
  keys = {
58
58
  attributesToIndex: 'searchableAttributes',
59
59
  numericAttributesToIndex: 'numericAttributesForFiltering',
@@ -61,6 +61,7 @@ module Helpers
61
61
  }
62
62
 
63
63
  keys.each do |deprecated_key, current_key|
64
+ deprecated_key = symbolize_keys ? deprecated_key : deprecated_key.to_s
64
65
  if settings.has_key?(deprecated_key)
65
66
  key = symbolize_keys ? current_key.to_sym : current_key.to_s
66
67
  settings[key] = settings.delete(deprecated_key)
@@ -81,4 +82,53 @@ module Helpers
81
82
  end
82
83
  res
83
84
  end
85
+
86
+ # Check the passed object to determine if it's an array
87
+ #
88
+ # @param object [Object]
89
+ #
90
+ def check_array(object)
91
+ raise Algolia::AlgoliaError, 'argument must be an array of objects' unless object.is_a?(Array)
92
+ end
93
+
94
+ # Check the passed object
95
+ #
96
+ # @param object [Object]
97
+ # @param in_array [Boolean] whether the object is an array or not
98
+ #
99
+ def check_object(object, in_array = false)
100
+ case object
101
+ when Array
102
+ raise Algolia::AlgoliaError, in_array ? 'argument must be an array of objects' : 'argument must not be an array'
103
+ when String, Integer, Float, TrueClass, FalseClass, NilClass
104
+ raise Algolia::AlgoliaError, "argument must be an #{'array of' if in_array} object, got: #{object.inspect}"
105
+ end
106
+ end
107
+
108
+ # Check if passed object has a objectID
109
+ #
110
+ # @param object [Object]
111
+ # @param object_id [String]
112
+ #
113
+ def get_object_id(object, object_id = nil)
114
+ check_object(object)
115
+ object_id ||= object[:objectID] || object['objectID']
116
+ raise Algolia::AlgoliaError, "Missing 'objectID'" if object_id.nil?
117
+ object_id
118
+ end
119
+
120
+ # Build a batch request
121
+ #
122
+ # @param action [String] action to perform on the engine
123
+ # @param objects [Array] objects on which build the action
124
+ # @param with_object_id [Boolean] if set to true, check if each object has an objectID set
125
+ #
126
+ def chunk(action, objects, with_object_id = false)
127
+ objects.map do |object|
128
+ check_object(object, true)
129
+ request = { action: action, body: object }
130
+ request[:objectID] = get_object_id(object).to_s if with_object_id
131
+ request
132
+ end
133
+ end
84
134
  end
@@ -9,9 +9,9 @@ module Algolia
9
9
  # @param logger [Object] logger used to log requests. Defaults to Algolia::LoggerHelper
10
10
  #
11
11
  def initialize(adapter, logger)
12
- @adapter = adapter
13
- @logger = logger
14
- @connection = nil
12
+ @adapter = adapter
13
+ @logger = logger
14
+ @connections = {}
15
15
  end
16
16
 
17
17
  # Sends request to the engine
@@ -65,7 +65,7 @@ module Algolia
65
65
  # @return [Faraday::Connection]
66
66
  #
67
67
  def connection(host)
68
- @connection ||= Faraday.new(build_url(host)) do |f|
68
+ @connections[host.accept] ||= Faraday.new(build_url(host)) do |f|
69
69
  f.adapter @adapter.to_sym
70
70
  end
71
71
  end