simple_http_service 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,220 @@
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
+ <h1 id="label-SimpleHttpService+rdoc-image-3Ahttps-3A-2F-2Fbadge.fury.io-2Frb-2Fsimple_http_service.svg">SimpleHttpService <a href="https://badge.fury.io/rb/simple_http_service"><img src="https://badge.fury.io/rb/simple_http_service.svg"></a></h1>
62
+
63
+ <p>SimpleHttpService is a simple Ruby library to make HTTP requests with customizable options for headers, timeouts, and retries. It provides a convenient way to create and send HTTP requests using a clean and simple interface.</p>
64
+
65
+ <h2 id="label-Installation">Installation</h2>
66
+
67
+ <p>Add this line to your application’s Gemfile:</p>
68
+
69
+ <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'>simple_http_service</span><span class='tstring_end'>&#39;</span></span>
70
+ </code></pre>
71
+
72
+ <p>And then execute:</p>
73
+
74
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_install'>install</span>
75
+ </code></pre>
76
+
77
+ <p>Or install it yourself as:</p>
78
+
79
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_install'>install</span> <span class='id identifier rubyid_simple_http_service'>simple_http_service</span>
80
+ </code></pre>
81
+
82
+ <h2 id="label-Usage">Usage</h2>
83
+
84
+ <h3 id="label-Creating+a+Client">Creating a Client</h3>
85
+
86
+ <p>You can create a new HTTP client using the SimpleHttpService.new method, which initializes an instance of SimpleHttpService::Client.</p>
87
+
88
+ <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'>simple_http_service</span><span class='tstring_end'>&#39;</span></span>
89
+
90
+ <span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="SimpleHttpService.html" title="SimpleHttpService (module)">SimpleHttpService</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="SimpleHttpService.html#new-class_method" title="SimpleHttpService.new (method)">new</a></span></span><span class='lparen'>(</span>
91
+ <span class='label'>url:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>https://api.example.com/endpoint</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
92
+ <span class='label'>http_method:</span> <span class='symbol'>:get</span><span class='comma'>,</span>
93
+ <span class='label'>headers:</span> <span class='lbrace'>{</span>
94
+ <span class='label'>accept:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>application/json</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
95
+ <span class='label'>authorization:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Bearer your_token</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
96
+ <span class='label'>content_type:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>application/json</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
97
+ <span class='label'>cookie:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>your cookie</span><span class='tstring_end'>&#39;</span></span>
98
+ <span class='rbrace'>}</span><span class='comma'>,</span>
99
+ <span class='label'>open_timeout:</span> <span class='int'>5</span><span class='comma'>,</span>
100
+ <span class='label'>read_timeout:</span> <span class='int'>10</span><span class='comma'>,</span>
101
+ <span class='label'>write_timeout:</span> <span class='int'>5</span><span class='comma'>,</span>
102
+ <span class='label'>max_retries:</span> <span class='int'>3</span><span class='comma'>,</span>
103
+ <span class='label'>additional_headers:</span> <span class='lbrace'>{</span>
104
+ <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>X-Request-Id</span><span class='label_end'>&#39;:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>12345</span><span class='tstring_end'>&#39;</span></span>
105
+ <span class='rbrace'>}</span>
106
+ <span class='rparen'>)</span>
107
+ </code></pre>
108
+
109
+ <h3 id="label-Making+a+Request">Making a Request</h3>
110
+
111
+ <p>After creating the client, you can call the call method to make the HTTP request:</p>
112
+
113
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span>
114
+ <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>
115
+ </code></pre>
116
+
117
+ <h3 id="label-Options">Options</h3>
118
+ <ul><li>
119
+ <p><code>url</code> (required): The URL for the HTTP request.</p>
120
+ </li><li>
121
+ <p><code>http_method</code> (required): The HTTP method to use (:get, :post, :put).</p>
122
+ </li><li>
123
+ <p><code>headers</code>: A hash of headers to include in the request.</p>
124
+ </li><li>
125
+ <p><code>open_timeout</code>: Timeout for opening the connection (default is false).</p>
126
+ </li><li>
127
+ <p><code>read_timeout</code>: Timeout for reading the response (default is false).</p>
128
+ </li><li>
129
+ <p><code>write_timeout</code>: Timeout for writing the request (default is false).</p>
130
+ </li><li>
131
+ <p><code>max_retries</code>: The number of times to retry the request in case of failure.</p>
132
+ </li><li>
133
+ <p><code>request_body</code>: The body of the request (used for POST and PUT requests).</p>
134
+ </li><li>
135
+ <p><code>additional_headers</code>: Additional headers to include in the request.</p>
136
+ </li></ul>
137
+
138
+ <h3 id="label-Example">Example</h3>
139
+
140
+ <p>Here’s a complete example of using <code>SimpleHttpService</code> to make a <code>GET</code> request:</p>
141
+
142
+ <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'>simple_http_service</span><span class='tstring_end'>&#39;</span></span>
143
+
144
+ <span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="SimpleHttpService.html" title="SimpleHttpService (module)">SimpleHttpService</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="SimpleHttpService.html#new-class_method" title="SimpleHttpService.new (method)">new</a></span></span><span class='lparen'>(</span>
145
+ <span class='label'>url:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>https://api.example.com/endpoint</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
146
+ <span class='label'>http_method:</span> <span class='symbol'>:get</span><span class='comma'>,</span>
147
+ <span class='label'>headers:</span> <span class='lbrace'>{</span>
148
+ <span class='label'>accept:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>application/json</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
149
+ <span class='label'>authorization:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Bearer your_token</span><span class='tstring_end'>&#39;</span></span>
150
+ <span class='rbrace'>}</span><span class='comma'>,</span>
151
+ <span class='label'>open_timeout:</span> <span class='int'>5</span><span class='comma'>,</span>
152
+ <span class='label'>read_timeout:</span> <span class='int'>10</span>
153
+ <span class='rparen'>)</span>
154
+
155
+ <span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span>
156
+ <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>
157
+ </code></pre>
158
+
159
+ <p>For a POST request with a request body:</p>
160
+
161
+ <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'>simple_http_service</span><span class='tstring_end'>&#39;</span></span>
162
+
163
+ <span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="SimpleHttpService.html" title="SimpleHttpService (module)">SimpleHttpService</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="SimpleHttpService.html#new-class_method" title="SimpleHttpService.new (method)">new</a></span></span><span class='lparen'>(</span>
164
+ <span class='label'>url:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>https://api.example.com/endpoint</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
165
+ <span class='label'>http_method:</span> <span class='symbol'>:post</span><span class='comma'>,</span>
166
+ <span class='label'>headers:</span> <span class='lbrace'>{</span>
167
+ <span class='label'>accept:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>application/json</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
168
+ <span class='label'>authorization:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Bearer your_token</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
169
+ <span class='label'>content_type:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>application/json</span><span class='tstring_end'>&#39;</span></span>
170
+ <span class='rbrace'>}</span><span class='comma'>,</span>
171
+ <span class='label'>request_body:</span> <span class='lbrace'>{</span> <span class='label'>key:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>value</span><span class='tstring_end'>&#39;</span></span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='comma'>,</span>
172
+ <span class='label'>open_timeout:</span> <span class='int'>5</span><span class='comma'>,</span>
173
+ <span class='label'>read_timeout:</span> <span class='int'>10</span><span class='comma'>,</span>
174
+ <span class='label'>write_timeout:</span> <span class='int'>5</span>
175
+ <span class='rparen'>)</span>
176
+
177
+ <span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span>
178
+ <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>
179
+ </code></pre>
180
+
181
+ <h3 id="label-Error+Handling">Error Handling</h3>
182
+
183
+ <p>The library defines a custom error class SimpleHttpService::Error that you can use to handle exceptions:</p>
184
+
185
+ <pre class="code ruby"><code class="ruby"><span class='kw'>begin</span>
186
+ <span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span>
187
+ <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>
188
+ <span class='kw'>rescue</span> <span class='const'><span class='object_link'><a href="SimpleHttpService.html" title="SimpleHttpService (module)">SimpleHttpService</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="SimpleHttpService/Error.html" title="SimpleHttpService::Error (class)">Error</a></span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
189
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>An error occurred: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
190
+ <span class='kw'>end</span>
191
+ </code></pre>
192
+
193
+ <h2 id="label-Development">Development</h2>
194
+
195
+ <p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>rspec</code> to run the tests. You can also run <code>bin/console</code> for an interactive prompt that will allow you to experiment.</p>
196
+
197
+ <p>To install this gem onto your local machine, run <code>bundle install</code>. To release a new version, update the version number in <code>version.rb</code>.</p>
198
+
199
+ <h2 id="label-Contributing">Contributing</h2>
200
+
201
+ <p>Bug reports and pull requests are welcome on GitHub at <a href="https://github.com/gklsan/simple_http_service">github.com/gklsan/simple_http_service</a>.</p>
202
+
203
+ <h2 id="label-License">License</h2>
204
+
205
+ <p>The gem is available as open source under the terms of the <a href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
206
+
207
+ <h2 id="label-Code+of+Conduct">Code of Conduct</h2>
208
+
209
+ <p>Everyone interacting in the SimpleHttpService project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.</p>
210
+ </div></div>
211
+
212
+ <div id="footer">
213
+ Generated on Sun Jan 19 17:15:39 2025 by
214
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
215
+ 0.9.37 (ruby-3.2.2).
216
+ </div>
217
+
218
+ </div>
219
+ </body>
220
+ </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,220 @@
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
+ <h1 id="label-SimpleHttpService+rdoc-image-3Ahttps-3A-2F-2Fbadge.fury.io-2Frb-2Fsimple_http_service.svg">SimpleHttpService <a href="https://badge.fury.io/rb/simple_http_service"><img src="https://badge.fury.io/rb/simple_http_service.svg"></a></h1>
62
+
63
+ <p>SimpleHttpService is a simple Ruby library to make HTTP requests with customizable options for headers, timeouts, and retries. It provides a convenient way to create and send HTTP requests using a clean and simple interface.</p>
64
+
65
+ <h2 id="label-Installation">Installation</h2>
66
+
67
+ <p>Add this line to your application’s Gemfile:</p>
68
+
69
+ <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'>simple_http_service</span><span class='tstring_end'>&#39;</span></span>
70
+ </code></pre>
71
+
72
+ <p>And then execute:</p>
73
+
74
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_install'>install</span>
75
+ </code></pre>
76
+
77
+ <p>Or install it yourself as:</p>
78
+
79
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_install'>install</span> <span class='id identifier rubyid_simple_http_service'>simple_http_service</span>
80
+ </code></pre>
81
+
82
+ <h2 id="label-Usage">Usage</h2>
83
+
84
+ <h3 id="label-Creating+a+Client">Creating a Client</h3>
85
+
86
+ <p>You can create a new HTTP client using the SimpleHttpService.new method, which initializes an instance of SimpleHttpService::Client.</p>
87
+
88
+ <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'>simple_http_service</span><span class='tstring_end'>&#39;</span></span>
89
+
90
+ <span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="SimpleHttpService.html" title="SimpleHttpService (module)">SimpleHttpService</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="SimpleHttpService.html#new-class_method" title="SimpleHttpService.new (method)">new</a></span></span><span class='lparen'>(</span>
91
+ <span class='label'>url:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>https://api.example.com/endpoint</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
92
+ <span class='label'>http_method:</span> <span class='symbol'>:get</span><span class='comma'>,</span>
93
+ <span class='label'>headers:</span> <span class='lbrace'>{</span>
94
+ <span class='label'>accept:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>application/json</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
95
+ <span class='label'>authorization:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Bearer your_token</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
96
+ <span class='label'>content_type:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>application/json</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
97
+ <span class='label'>cookie:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>your cookie</span><span class='tstring_end'>&#39;</span></span>
98
+ <span class='rbrace'>}</span><span class='comma'>,</span>
99
+ <span class='label'>open_timeout:</span> <span class='int'>5</span><span class='comma'>,</span>
100
+ <span class='label'>read_timeout:</span> <span class='int'>10</span><span class='comma'>,</span>
101
+ <span class='label'>write_timeout:</span> <span class='int'>5</span><span class='comma'>,</span>
102
+ <span class='label'>max_retries:</span> <span class='int'>3</span><span class='comma'>,</span>
103
+ <span class='label'>additional_headers:</span> <span class='lbrace'>{</span>
104
+ <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>X-Request-Id</span><span class='label_end'>&#39;:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>12345</span><span class='tstring_end'>&#39;</span></span>
105
+ <span class='rbrace'>}</span>
106
+ <span class='rparen'>)</span>
107
+ </code></pre>
108
+
109
+ <h3 id="label-Making+a+Request">Making a Request</h3>
110
+
111
+ <p>After creating the client, you can call the call method to make the HTTP request:</p>
112
+
113
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span>
114
+ <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>
115
+ </code></pre>
116
+
117
+ <h3 id="label-Options">Options</h3>
118
+ <ul><li>
119
+ <p><code>url</code> (required): The URL for the HTTP request.</p>
120
+ </li><li>
121
+ <p><code>http_method</code> (required): The HTTP method to use (:get, :post, :put).</p>
122
+ </li><li>
123
+ <p><code>headers</code>: A hash of headers to include in the request.</p>
124
+ </li><li>
125
+ <p><code>open_timeout</code>: Timeout for opening the connection (default is false).</p>
126
+ </li><li>
127
+ <p><code>read_timeout</code>: Timeout for reading the response (default is false).</p>
128
+ </li><li>
129
+ <p><code>write_timeout</code>: Timeout for writing the request (default is false).</p>
130
+ </li><li>
131
+ <p><code>max_retries</code>: The number of times to retry the request in case of failure.</p>
132
+ </li><li>
133
+ <p><code>request_body</code>: The body of the request (used for POST and PUT requests).</p>
134
+ </li><li>
135
+ <p><code>additional_headers</code>: Additional headers to include in the request.</p>
136
+ </li></ul>
137
+
138
+ <h3 id="label-Example">Example</h3>
139
+
140
+ <p>Here’s a complete example of using <code>SimpleHttpService</code> to make a <code>GET</code> request:</p>
141
+
142
+ <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'>simple_http_service</span><span class='tstring_end'>&#39;</span></span>
143
+
144
+ <span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="SimpleHttpService.html" title="SimpleHttpService (module)">SimpleHttpService</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="SimpleHttpService.html#new-class_method" title="SimpleHttpService.new (method)">new</a></span></span><span class='lparen'>(</span>
145
+ <span class='label'>url:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>https://api.example.com/endpoint</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
146
+ <span class='label'>http_method:</span> <span class='symbol'>:get</span><span class='comma'>,</span>
147
+ <span class='label'>headers:</span> <span class='lbrace'>{</span>
148
+ <span class='label'>accept:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>application/json</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
149
+ <span class='label'>authorization:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Bearer your_token</span><span class='tstring_end'>&#39;</span></span>
150
+ <span class='rbrace'>}</span><span class='comma'>,</span>
151
+ <span class='label'>open_timeout:</span> <span class='int'>5</span><span class='comma'>,</span>
152
+ <span class='label'>read_timeout:</span> <span class='int'>10</span>
153
+ <span class='rparen'>)</span>
154
+
155
+ <span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span>
156
+ <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>
157
+ </code></pre>
158
+
159
+ <p>For a POST request with a request body:</p>
160
+
161
+ <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'>simple_http_service</span><span class='tstring_end'>&#39;</span></span>
162
+
163
+ <span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="SimpleHttpService.html" title="SimpleHttpService (module)">SimpleHttpService</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="SimpleHttpService.html#new-class_method" title="SimpleHttpService.new (method)">new</a></span></span><span class='lparen'>(</span>
164
+ <span class='label'>url:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>https://api.example.com/endpoint</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
165
+ <span class='label'>http_method:</span> <span class='symbol'>:post</span><span class='comma'>,</span>
166
+ <span class='label'>headers:</span> <span class='lbrace'>{</span>
167
+ <span class='label'>accept:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>application/json</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
168
+ <span class='label'>authorization:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Bearer your_token</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
169
+ <span class='label'>content_type:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>application/json</span><span class='tstring_end'>&#39;</span></span>
170
+ <span class='rbrace'>}</span><span class='comma'>,</span>
171
+ <span class='label'>request_body:</span> <span class='lbrace'>{</span> <span class='label'>key:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>value</span><span class='tstring_end'>&#39;</span></span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='comma'>,</span>
172
+ <span class='label'>open_timeout:</span> <span class='int'>5</span><span class='comma'>,</span>
173
+ <span class='label'>read_timeout:</span> <span class='int'>10</span><span class='comma'>,</span>
174
+ <span class='label'>write_timeout:</span> <span class='int'>5</span>
175
+ <span class='rparen'>)</span>
176
+
177
+ <span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span>
178
+ <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>
179
+ </code></pre>
180
+
181
+ <h3 id="label-Error+Handling">Error Handling</h3>
182
+
183
+ <p>The library defines a custom error class SimpleHttpService::Error that you can use to handle exceptions:</p>
184
+
185
+ <pre class="code ruby"><code class="ruby"><span class='kw'>begin</span>
186
+ <span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span>
187
+ <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>
188
+ <span class='kw'>rescue</span> <span class='const'><span class='object_link'><a href="SimpleHttpService.html" title="SimpleHttpService (module)">SimpleHttpService</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="SimpleHttpService/Error.html" title="SimpleHttpService::Error (class)">Error</a></span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
189
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>An error occurred: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
190
+ <span class='kw'>end</span>
191
+ </code></pre>
192
+
193
+ <h2 id="label-Development">Development</h2>
194
+
195
+ <p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>rspec</code> to run the tests. You can also run <code>bin/console</code> for an interactive prompt that will allow you to experiment.</p>
196
+
197
+ <p>To install this gem onto your local machine, run <code>bundle install</code>. To release a new version, update the version number in <code>version.rb</code>.</p>
198
+
199
+ <h2 id="label-Contributing">Contributing</h2>
200
+
201
+ <p>Bug reports and pull requests are welcome on GitHub at <a href="https://github.com/gklsan/simple_http_service">github.com/gklsan/simple_http_service</a>.</p>
202
+
203
+ <h2 id="label-License">License</h2>
204
+
205
+ <p>The gem is available as open source under the terms of the <a href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
206
+
207
+ <h2 id="label-Code+of+Conduct">Code of Conduct</h2>
208
+
209
+ <p>Everyone interacting in the SimpleHttpService project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.</p>
210
+ </div></div>
211
+
212
+ <div id="footer">
213
+ Generated on Sun Jan 19 17:15:39 2025 by
214
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
215
+ 0.9.37 (ruby-3.2.2).
216
+ </div>
217
+
218
+ </div>
219
+ </body>
220
+ </html>