api_wrapper 0.1.6

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 (42) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +7 -0
  3. data/CHANGELOG.md +18 -0
  4. data/CODE_OF_CONDUCT.md +84 -0
  5. data/Gemfile +22 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +153 -0
  8. data/Rakefile +31 -0
  9. data/api_wrapper.gemspec +34 -0
  10. data/doc/ApiWrapper/ApiManager.html +807 -0
  11. data/doc/ApiWrapper/Cache/CachePolicy.html +907 -0
  12. data/doc/ApiWrapper/Cache/CacheStore.html +674 -0
  13. data/doc/ApiWrapper/Cache.html +117 -0
  14. data/doc/ApiWrapper/Configuration.html +366 -0
  15. data/doc/ApiWrapper/HttpClient/BaseClient.html +349 -0
  16. data/doc/ApiWrapper/HttpClient/FaradayClient.html +299 -0
  17. data/doc/ApiWrapper/HttpClient.html +117 -0
  18. data/doc/ApiWrapper.html +543 -0
  19. data/doc/_index.html +195 -0
  20. data/doc/class_list.html +54 -0
  21. data/doc/css/common.css +1 -0
  22. data/doc/css/full_list.css +58 -0
  23. data/doc/css/style.css +503 -0
  24. data/doc/file.README.html +248 -0
  25. data/doc/file_list.html +59 -0
  26. data/doc/frames.html +22 -0
  27. data/doc/index.html +248 -0
  28. data/doc/js/app.js +344 -0
  29. data/doc/js/full_list.js +242 -0
  30. data/doc/js/jquery.js +4 -0
  31. data/doc/method_list.html +286 -0
  32. data/doc/top-level-namespace.html +110 -0
  33. data/lib/api_wrapper/api_manager.rb +86 -0
  34. data/lib/api_wrapper/cache/README.md +78 -0
  35. data/lib/api_wrapper/cache/cache_policy.rb +115 -0
  36. data/lib/api_wrapper/cache/cache_store.rb +84 -0
  37. data/lib/api_wrapper/cache/redis_cache_store.rb +3 -0
  38. data/lib/api_wrapper/http_client/base_client.rb +26 -0
  39. data/lib/api_wrapper/http_client/faraday_client.rb +81 -0
  40. data/lib/api_wrapper/version.rb +5 -0
  41. data/lib/api_wrapper.rb +83 -0
  42. metadata +121 -0
@@ -0,0 +1,248 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ File: README
8
+
9
+ &mdash; Documentation by YARD 0.9.37
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
18
+ pathId = "README";
19
+ relpath = '';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="file_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="_index.html">Index</a> &raquo;
40
+ <span class="title">File: README</span>
41
+
42
+ </div>
43
+
44
+ <div id="search">
45
+
46
+ <a class="full_list_link" id="class_list_link"
47
+ href="class_list.html">
48
+
49
+ <svg width="24" height="24">
50
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
51
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
52
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
53
+ </svg>
54
+ </a>
55
+
56
+ </div>
57
+ <div class="clear"></div>
58
+ </div>
59
+
60
+ <div id="content"><div id='filecontents'>
61
+ <p><code>ApiWrapper</code> is a Ruby gem that offers an easy and flexible way to handle API interactions.</p>
62
+
63
+ <h2 id="label-Table+of+Contents">Table of Contents</h2>
64
+ <ul><li>
65
+ <p><a href="#installation">Installation</a></p>
66
+ </li><li>
67
+ <p><a href="#usage">Usage</a></p>
68
+ </li><li>
69
+ <p><a href="#basic-usage">Basic Usage</a></p>
70
+ </li><li>
71
+ <p><a href="#custom-configuration">Custom Configuration</a></p>
72
+ </li><li>
73
+ <p><a href="#resetting-the-api-manager">Resetting the API Manager</a></p>
74
+ </li><li>
75
+ <p><a href="#configuration">Configuration</a></p>
76
+ </li><li>
77
+ <p><a href="#api-configuration-file">API Configuration File</a></p>
78
+ </li><li>
79
+ <p><a href="#key-methods">Key Methods</a></p>
80
+ </li><li>
81
+ <p><a href="#development">Development</a></p>
82
+ </li><li>
83
+ <p><a href="#running-tests">Running Tests</a></p>
84
+ </li><li>
85
+ <p><a href="#code-style-and-linting">Code Style and Linting</a></p>
86
+ </li><li>
87
+ <p><a href="#contributing">Contributing</a></p>
88
+ </li><li>
89
+ <p><a href="#license">License</a></p>
90
+ </li><li>
91
+ <p><a href="#code-of-conduct">Code of Conduct</a></p>
92
+ </li></ul>
93
+
94
+ <h2 id="label-Installation">Installation</h2>
95
+
96
+ <p>Add this to your Gemfile:</p>
97
+
98
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>api_wrapper</span><span class='tstring_end'>&#39;</span></span>
99
+ </code></pre>
100
+
101
+ <p>Then run</p>
102
+
103
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_install'>install</span>
104
+ </code></pre>
105
+
106
+ <h2 id="label-Usage">Usage</h2>
107
+
108
+ <h3 id="label-Basic+Usage">Basic Usage</h3>
109
+
110
+ <p>By default, ApiWrapper looks for an API configuration file at <code>config/api_endpoints.yml</code> (see <a href="#api-configuration-file">API Configuration File</a>) in your root directory of your application and uses in-memory caching. You can fetch data from an API endpoint like this:</p>
111
+
112
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>api_wrapper</span><span class='tstring_end'>&#39;</span></span>
113
+
114
+ <span class='comment'># Fetch data from an API endpoint using the default settings
115
+ </span><span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="ApiWrapper.html" title="ApiWrapper (module)">ApiWrapper</a></span></span><span class='period'>.</span><span class='id identifier rubyid_fetch_data'><span class='object_link'><a href="ApiWrapper.html#fetch_data-class_method" title="ApiWrapper.fetch_data (method)">fetch_data</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>endpoint_key</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
116
+ <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_response'>response</span><span class='period'>.</span><span class='id identifier rubyid_body'>body</span>
117
+ </code></pre>
118
+
119
+ <h3 id="label-Custom+Configuration">Custom Configuration</h3>
120
+
121
+ <p>You can customize the API configuration path and cache store by configuring ApiWrapper:</p>
122
+
123
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>api_wrapper</span><span class='tstring_end'>&#39;</span></span>
124
+
125
+ <span class='comment'># Configure ApiWrapper with custom settings
126
+ </span><span class='const'><span class='object_link'><a href="ApiWrapper.html" title="ApiWrapper (module)">ApiWrapper</a></span></span><span class='period'>.</span><span class='id identifier rubyid_configure'><span class='object_link'><a href="ApiWrapper.html#configure-class_method" title="ApiWrapper.configure (method)">configure</a></span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_config'>config</span><span class='op'>|</span>
127
+ <span class='id identifier rubyid_config'>config</span><span class='period'>.</span><span class='id identifier rubyid_api_configuration_path'>api_configuration_path</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>custom/path/to/api_configuration.yml</span><span class='tstring_end'>&#39;</span></span>
128
+ <span class='id identifier rubyid_config'>config</span><span class='period'>.</span><span class='id identifier rubyid_cache_store'>cache_store</span> <span class='op'>=</span> <span class='const'>CustomCacheStore</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='comment'># TODO: Update details on CustomCacheStore later
129
+ </span><span class='kw'>end</span>
130
+
131
+ <span class='comment'># Fetch data with the custom configuration
132
+ </span><span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="ApiWrapper.html" title="ApiWrapper (module)">ApiWrapper</a></span></span><span class='period'>.</span><span class='id identifier rubyid_fetch_data'><span class='object_link'><a href="ApiWrapper.html#fetch_data-class_method" title="ApiWrapper.fetch_data (method)">fetch_data</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>endpoint_key</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
133
+ <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_response'>response</span><span class='period'>.</span><span class='id identifier rubyid_body'>body</span>
134
+ </code></pre>
135
+
136
+ <h3 id="label-Resetting+the+API+Manager">Resetting the API Manager</h3>
137
+
138
+ <p>If you change the configuration and want to reset the API manager, call:</p>
139
+
140
+ <pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="ApiWrapper.html" title="ApiWrapper (module)">ApiWrapper</a></span></span><span class='period'>.</span><span class='id identifier rubyid_reset_api_manager!'><span class='object_link'><a href="ApiWrapper.html#reset_api_manager!-class_method" title="ApiWrapper.reset_api_manager! (method)">reset_api_manager!</a></span></span>
141
+ </code></pre>
142
+
143
+ <p>This will create a new instance of ApiManager with the updated settings.</p>
144
+
145
+ <h2 id="label-Configuration">Configuration</h2>
146
+
147
+ <p>You can adjust two main settings:</p>
148
+ <ol><li>
149
+ <p><strong>API Configuration Path</strong>: This is the path to the YAML file that defines your API endpoints. By default, it’s set to config/api_endpoints.yml. You can also set it through the environment variable <a href="&#39;API_CONFIGURATION_PATH&#39;">ENV</a>.</p>
150
+ </li><li>
151
+ <p><strong>Cache Store</strong>: This is where API responses are stored. By default, ApiWrapper uses an in-memory cache. You can customize this to use a different cache store, such as Redis. You can also set the cache type through <a href="&#39;CACHE_STORE_TYPE&#39;">ENV</a>.</p>
152
+ </li></ol>
153
+
154
+ <h3 id="label-API+Configuration+File">API Configuration File</h3>
155
+
156
+ <p>Your configuration file (api_endpoints.yml) defines the base URL for the API and the available endpoints. Here’s an example:</p>
157
+
158
+ <pre class="code ruby"><code class="ruby">base_url: https://api.example.com/
159
+ apis:
160
+ endpoint1:
161
+ path: &#39;path/to/endpoint1&#39;
162
+ description: &#39;Endpoint 1 description&#39;
163
+ no_cache: true
164
+ endpoint2:
165
+ path: &#39;path/to/endpoint2&#39;
166
+ description: &#39;Endpoint 2 description&#39;
167
+ ttl: 600
168
+ </code></pre>
169
+ <ul><li>
170
+ <p>base_url: The base URL for all API requests.</p>
171
+ </li><li>
172
+ <p>apis: A list of API endpoints.</p>
173
+ <ul><li>
174
+ <p>path: The path to the API endpoint.</p>
175
+ </li><li>
176
+ <p>description: (Optional) The description about the endpoint</p>
177
+ </li><li>
178
+ <p>ttl: (Optional) The time (in seconds) that data should be cached.</p>
179
+ </li><li>
180
+ <p>no_cache: (Optional) Whether to bypass caching for this endpoint.</p>
181
+ </li></ul>
182
+ </li></ul>
183
+
184
+ <h2 id="label-Key+Methods">Key Methods</h2>
185
+ <ul><li>
186
+ <p><code>ApiWrapper.fetch_data(endpoint_key, force_refresh: false)</code>: Fetches data from the specified API endpoint.</p>
187
+ </li><li>
188
+ <p><code>ApiWrapper.configure { |config| ... }</code>: Allows you to configure the gem with custom settings.</p>
189
+ </li><li>
190
+ <p><code>ApiWrapper.reset_api_manager!</code>: Resets the ApiManager instance, which will use any new settings.</p>
191
+ </li></ul>
192
+
193
+ <h2 id="label-Development">Development</h2>
194
+
195
+ <p>To get started with contributing to <strong>ApiWrapper</strong>, follow these steps:</p>
196
+ <ol><li>
197
+ <p><strong>Clone the repository</strong>:</p>
198
+ </li></ol>
199
+
200
+ <p>First, clone the repository to your local machine and navigate to the project directory:</p>
201
+
202
+ <p>“‘bash git clone <a href="https://github.com/ahasunos/api_wrapper.git">github.com/ahasunos/api_wrapper.git</a> cd api_wrapper</p>
203
+ <ol><li>
204
+ <p><strong>Install dependencies</strong>:</p>
205
+ </li></ol>
206
+
207
+ <p>After navigating to the project directory, install the required gems using Bundler:</p>
208
+
209
+ <p><code>bash bundle install </code></p>
210
+
211
+ <h3 id="label-Running+Tests">Running Tests</h3>
212
+
213
+ <p>The project uses RSpec for testing. Before submitting any changes, make sure to run the test suite to ensure that everything works as expected:</p>
214
+
215
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_rspec'>rspec</span>
216
+ </code></pre>
217
+
218
+ <h3 id="label-Code+Style+and+Linting">Code Style and Linting</h3>
219
+
220
+ <p>To maintain consistent code quality and style, the project uses RuboCop for linting. Before submitting a pull request, ensure that your code adheres to the project’s style guidelines by running RuboCop:</p>
221
+
222
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_rubocop'>rubocop</span>
223
+ </code></pre>
224
+
225
+ <p>If RuboCop identifies any issues, it will provide suggestions for how to fix them.</p>
226
+
227
+ <h2 id="label-Contributing">Contributing</h2>
228
+
229
+ <p>Bug reports and pull requests are welcome on GitHub at <a href="https://github.com/ahasunos/api_wrapper">github.com/ahasunos/api_wrapper</a>. For major changes, please open an issue first to discuss what you would like to change.</p>
230
+
231
+ <h2 id="label-License">License</h2>
232
+
233
+ <p>The gem is available as open source under the terms of the <a href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
234
+
235
+ <h2 id="label-Code+of+Conduct">Code of Conduct</h2>
236
+
237
+ <p>Everyone interacting in the NseData project’s codebases, issue trackers, chat rooms, and mailing lists is expected to follow the <a href="https://github.com/ahasunos/api_wrapper/blob/master/CODE_OF_CONDUCT.md">code of conduct</a>.</p>
238
+ </div></div>
239
+
240
+ <div id="footer">
241
+ Generated on Mon Sep 16 23:22:30 2024 by
242
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
243
+ 0.9.37 (ruby-3.2.2).
244
+ </div>
245
+
246
+ </div>
247
+ </body>
248
+ </html>
@@ -0,0 +1,59 @@
1
+ <!DOCTYPE html>
2
+ <html >
3
+ <head>
4
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
5
+ <meta charset="utf-8" />
6
+
7
+ <link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" />
8
+
9
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" />
10
+
11
+
12
+
13
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
16
+
17
+
18
+ <title>File List</title>
19
+ <base id="base_target" target="_parent" />
20
+ </head>
21
+ <body>
22
+ <div id="content">
23
+ <div class="fixed_header">
24
+ <h1 id="full_list_header">File List</h1>
25
+ <div id="full_list_nav">
26
+
27
+ <span><a target="_self" href="class_list.html">
28
+ Classes
29
+ </a></span>
30
+
31
+ <span><a target="_self" href="method_list.html">
32
+ Methods
33
+ </a></span>
34
+
35
+ <span><a target="_self" href="file_list.html">
36
+ Files
37
+ </a></span>
38
+
39
+ </div>
40
+
41
+ <div id="search">
42
+ <label for="search-class">Search:</label>
43
+ <input id="search-class" type="text" />
44
+ </div>
45
+ </div>
46
+
47
+ <ul id="full_list" class="file">
48
+
49
+
50
+ <li id="object_README" class="odd">
51
+ <div class="item"><span class="object_link"><a href="index.html" title="README">README</a></span></div>
52
+ </li>
53
+
54
+
55
+
56
+ </ul>
57
+ </div>
58
+ </body>
59
+ </html>
data/doc/frames.html ADDED
@@ -0,0 +1,22 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Documentation by YARD 0.9.37</title>
6
+ </head>
7
+ <script type="text/javascript">
8
+ var mainUrl = 'index.html';
9
+ try {
10
+ var match = decodeURIComponent(window.location.hash).match(/^#!(.+)/);
11
+ var name = match ? match[1] : mainUrl;
12
+ var url = new URL(name, location.href);
13
+ window.top.location.replace(url.origin === location.origin ? name : mainUrl);
14
+ } catch (e) {
15
+ window.top.location.replace(mainUrl);
16
+ }
17
+ </script>
18
+ <noscript>
19
+ <h1>Oops!</h1>
20
+ <h2>YARD requires JavaScript!</h2>
21
+ </noscript>
22
+ </html>
data/doc/index.html ADDED
@@ -0,0 +1,248 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ File: README
8
+
9
+ &mdash; Documentation by YARD 0.9.37
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
18
+ pathId = "README";
19
+ relpath = '';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="_index.html">Index</a> &raquo;
40
+ <span class="title">File: README</span>
41
+
42
+ </div>
43
+
44
+ <div id="search">
45
+
46
+ <a class="full_list_link" id="class_list_link"
47
+ href="class_list.html">
48
+
49
+ <svg width="24" height="24">
50
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
51
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
52
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
53
+ </svg>
54
+ </a>
55
+
56
+ </div>
57
+ <div class="clear"></div>
58
+ </div>
59
+
60
+ <div id="content"><div id='filecontents'>
61
+ <p><code>ApiWrapper</code> is a Ruby gem that offers an easy and flexible way to handle API interactions.</p>
62
+
63
+ <h2 id="label-Table+of+Contents">Table of Contents</h2>
64
+ <ul><li>
65
+ <p><a href="#installation">Installation</a></p>
66
+ </li><li>
67
+ <p><a href="#usage">Usage</a></p>
68
+ </li><li>
69
+ <p><a href="#basic-usage">Basic Usage</a></p>
70
+ </li><li>
71
+ <p><a href="#custom-configuration">Custom Configuration</a></p>
72
+ </li><li>
73
+ <p><a href="#resetting-the-api-manager">Resetting the API Manager</a></p>
74
+ </li><li>
75
+ <p><a href="#configuration">Configuration</a></p>
76
+ </li><li>
77
+ <p><a href="#api-configuration-file">API Configuration File</a></p>
78
+ </li><li>
79
+ <p><a href="#key-methods">Key Methods</a></p>
80
+ </li><li>
81
+ <p><a href="#development">Development</a></p>
82
+ </li><li>
83
+ <p><a href="#running-tests">Running Tests</a></p>
84
+ </li><li>
85
+ <p><a href="#code-style-and-linting">Code Style and Linting</a></p>
86
+ </li><li>
87
+ <p><a href="#contributing">Contributing</a></p>
88
+ </li><li>
89
+ <p><a href="#license">License</a></p>
90
+ </li><li>
91
+ <p><a href="#code-of-conduct">Code of Conduct</a></p>
92
+ </li></ul>
93
+
94
+ <h2 id="label-Installation">Installation</h2>
95
+
96
+ <p>Add this to your Gemfile:</p>
97
+
98
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>api_wrapper</span><span class='tstring_end'>&#39;</span></span>
99
+ </code></pre>
100
+
101
+ <p>Then run</p>
102
+
103
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_install'>install</span>
104
+ </code></pre>
105
+
106
+ <h2 id="label-Usage">Usage</h2>
107
+
108
+ <h3 id="label-Basic+Usage">Basic Usage</h3>
109
+
110
+ <p>By default, ApiWrapper looks for an API configuration file at <code>config/api_endpoints.yml</code> (see <a href="#api-configuration-file">API Configuration File</a>) in your root directory of your application and uses in-memory caching. You can fetch data from an API endpoint like this:</p>
111
+
112
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>api_wrapper</span><span class='tstring_end'>&#39;</span></span>
113
+
114
+ <span class='comment'># Fetch data from an API endpoint using the default settings
115
+ </span><span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="ApiWrapper.html" title="ApiWrapper (module)">ApiWrapper</a></span></span><span class='period'>.</span><span class='id identifier rubyid_fetch_data'><span class='object_link'><a href="ApiWrapper.html#fetch_data-class_method" title="ApiWrapper.fetch_data (method)">fetch_data</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>endpoint_key</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
116
+ <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_response'>response</span><span class='period'>.</span><span class='id identifier rubyid_body'>body</span>
117
+ </code></pre>
118
+
119
+ <h3 id="label-Custom+Configuration">Custom Configuration</h3>
120
+
121
+ <p>You can customize the API configuration path and cache store by configuring ApiWrapper:</p>
122
+
123
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>api_wrapper</span><span class='tstring_end'>&#39;</span></span>
124
+
125
+ <span class='comment'># Configure ApiWrapper with custom settings
126
+ </span><span class='const'><span class='object_link'><a href="ApiWrapper.html" title="ApiWrapper (module)">ApiWrapper</a></span></span><span class='period'>.</span><span class='id identifier rubyid_configure'><span class='object_link'><a href="ApiWrapper.html#configure-class_method" title="ApiWrapper.configure (method)">configure</a></span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_config'>config</span><span class='op'>|</span>
127
+ <span class='id identifier rubyid_config'>config</span><span class='period'>.</span><span class='id identifier rubyid_api_configuration_path'>api_configuration_path</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>custom/path/to/api_configuration.yml</span><span class='tstring_end'>&#39;</span></span>
128
+ <span class='id identifier rubyid_config'>config</span><span class='period'>.</span><span class='id identifier rubyid_cache_store'>cache_store</span> <span class='op'>=</span> <span class='const'>CustomCacheStore</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='comment'># TODO: Update details on CustomCacheStore later
129
+ </span><span class='kw'>end</span>
130
+
131
+ <span class='comment'># Fetch data with the custom configuration
132
+ </span><span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="ApiWrapper.html" title="ApiWrapper (module)">ApiWrapper</a></span></span><span class='period'>.</span><span class='id identifier rubyid_fetch_data'><span class='object_link'><a href="ApiWrapper.html#fetch_data-class_method" title="ApiWrapper.fetch_data (method)">fetch_data</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>endpoint_key</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
133
+ <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_response'>response</span><span class='period'>.</span><span class='id identifier rubyid_body'>body</span>
134
+ </code></pre>
135
+
136
+ <h3 id="label-Resetting+the+API+Manager">Resetting the API Manager</h3>
137
+
138
+ <p>If you change the configuration and want to reset the API manager, call:</p>
139
+
140
+ <pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="ApiWrapper.html" title="ApiWrapper (module)">ApiWrapper</a></span></span><span class='period'>.</span><span class='id identifier rubyid_reset_api_manager!'><span class='object_link'><a href="ApiWrapper.html#reset_api_manager!-class_method" title="ApiWrapper.reset_api_manager! (method)">reset_api_manager!</a></span></span>
141
+ </code></pre>
142
+
143
+ <p>This will create a new instance of ApiManager with the updated settings.</p>
144
+
145
+ <h2 id="label-Configuration">Configuration</h2>
146
+
147
+ <p>You can adjust two main settings:</p>
148
+ <ol><li>
149
+ <p><strong>API Configuration Path</strong>: This is the path to the YAML file that defines your API endpoints. By default, it’s set to config/api_endpoints.yml. You can also set it through the environment variable <a href="&#39;API_CONFIGURATION_PATH&#39;">ENV</a>.</p>
150
+ </li><li>
151
+ <p><strong>Cache Store</strong>: This is where API responses are stored. By default, ApiWrapper uses an in-memory cache. You can customize this to use a different cache store, such as Redis. You can also set the cache type through <a href="&#39;CACHE_STORE_TYPE&#39;">ENV</a>.</p>
152
+ </li></ol>
153
+
154
+ <h3 id="label-API+Configuration+File">API Configuration File</h3>
155
+
156
+ <p>Your configuration file (api_endpoints.yml) defines the base URL for the API and the available endpoints. Here’s an example:</p>
157
+
158
+ <pre class="code ruby"><code class="ruby">base_url: https://api.example.com/
159
+ apis:
160
+ endpoint1:
161
+ path: &#39;path/to/endpoint1&#39;
162
+ description: &#39;Endpoint 1 description&#39;
163
+ no_cache: true
164
+ endpoint2:
165
+ path: &#39;path/to/endpoint2&#39;
166
+ description: &#39;Endpoint 2 description&#39;
167
+ ttl: 600
168
+ </code></pre>
169
+ <ul><li>
170
+ <p>base_url: The base URL for all API requests.</p>
171
+ </li><li>
172
+ <p>apis: A list of API endpoints.</p>
173
+ <ul><li>
174
+ <p>path: The path to the API endpoint.</p>
175
+ </li><li>
176
+ <p>description: (Optional) The description about the endpoint</p>
177
+ </li><li>
178
+ <p>ttl: (Optional) The time (in seconds) that data should be cached.</p>
179
+ </li><li>
180
+ <p>no_cache: (Optional) Whether to bypass caching for this endpoint.</p>
181
+ </li></ul>
182
+ </li></ul>
183
+
184
+ <h2 id="label-Key+Methods">Key Methods</h2>
185
+ <ul><li>
186
+ <p><code>ApiWrapper.fetch_data(endpoint_key, force_refresh: false)</code>: Fetches data from the specified API endpoint.</p>
187
+ </li><li>
188
+ <p><code>ApiWrapper.configure { |config| ... }</code>: Allows you to configure the gem with custom settings.</p>
189
+ </li><li>
190
+ <p><code>ApiWrapper.reset_api_manager!</code>: Resets the ApiManager instance, which will use any new settings.</p>
191
+ </li></ul>
192
+
193
+ <h2 id="label-Development">Development</h2>
194
+
195
+ <p>To get started with contributing to <strong>ApiWrapper</strong>, follow these steps:</p>
196
+ <ol><li>
197
+ <p><strong>Clone the repository</strong>:</p>
198
+ </li></ol>
199
+
200
+ <p>First, clone the repository to your local machine and navigate to the project directory:</p>
201
+
202
+ <p>“‘bash git clone <a href="https://github.com/ahasunos/api_wrapper.git">github.com/ahasunos/api_wrapper.git</a> cd api_wrapper</p>
203
+ <ol><li>
204
+ <p><strong>Install dependencies</strong>:</p>
205
+ </li></ol>
206
+
207
+ <p>After navigating to the project directory, install the required gems using Bundler:</p>
208
+
209
+ <p><code>bash bundle install </code></p>
210
+
211
+ <h3 id="label-Running+Tests">Running Tests</h3>
212
+
213
+ <p>The project uses RSpec for testing. Before submitting any changes, make sure to run the test suite to ensure that everything works as expected:</p>
214
+
215
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_rspec'>rspec</span>
216
+ </code></pre>
217
+
218
+ <h3 id="label-Code+Style+and+Linting">Code Style and Linting</h3>
219
+
220
+ <p>To maintain consistent code quality and style, the project uses RuboCop for linting. Before submitting a pull request, ensure that your code adheres to the project’s style guidelines by running RuboCop:</p>
221
+
222
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_rubocop'>rubocop</span>
223
+ </code></pre>
224
+
225
+ <p>If RuboCop identifies any issues, it will provide suggestions for how to fix them.</p>
226
+
227
+ <h2 id="label-Contributing">Contributing</h2>
228
+
229
+ <p>Bug reports and pull requests are welcome on GitHub at <a href="https://github.com/ahasunos/api_wrapper">github.com/ahasunos/api_wrapper</a>. For major changes, please open an issue first to discuss what you would like to change.</p>
230
+
231
+ <h2 id="label-License">License</h2>
232
+
233
+ <p>The gem is available as open source under the terms of the <a href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
234
+
235
+ <h2 id="label-Code+of+Conduct">Code of Conduct</h2>
236
+
237
+ <p>Everyone interacting in the NseData project’s codebases, issue trackers, chat rooms, and mailing lists is expected to follow the <a href="https://github.com/ahasunos/api_wrapper/blob/master/CODE_OF_CONDUCT.md">code of conduct</a>.</p>
238
+ </div></div>
239
+
240
+ <div id="footer">
241
+ Generated on Mon Sep 16 23:22:30 2024 by
242
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
243
+ 0.9.37 (ruby-3.2.2).
244
+ </div>
245
+
246
+ </div>
247
+ </body>
248
+ </html>