crapi 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +5 -4
- data/.gitignore +3 -0
- data/.ruby-version +1 -1
- data/Gemfile.lock +120 -49
- data/README.md +2 -2
- data/crapi.gemspec +6 -6
- data/docs/CrAPI/ArgumentError.html +11 -8
- data/docs/CrAPI/BadHttpResponseError.html +11 -8
- data/docs/CrAPI/Client.html +53 -95
- data/docs/CrAPI/Error.html +10 -8
- data/docs/CrAPI/Proxy.html +30 -49
- data/docs/CrAPI.html +12 -12
- data/docs/Net/HTTP.html +12 -12
- data/docs/_index.html +9 -7
- data/docs/class_list.html +10 -7
- data/docs/css/common.css +1 -1
- data/docs/css/full_list.css +201 -53
- data/docs/css/style.css +991 -399
- data/docs/file.README.html +62 -86
- data/docs/file_list.html +9 -6
- data/docs/frames.html +10 -5
- data/docs/index.html +62 -86
- data/docs/js/app.js +799 -312
- data/docs/js/full_list.js +332 -214
- data/docs/method_list.html +9 -6
- data/docs/top-level-namespace.html +8 -6
- data/lib/crapi/version.rb +1 -1
- metadata +12 -25
- data/spec/crapi_client_spec.rb +0 -121
- data/spec/crapi_errors_spec.rb +0 -17
- data/spec/crapi_proxy_spec.rb +0 -121
- data/spec/crapi_spec.rb +0 -5
- data/spec/spec_helper.rb +0 -19
data/docs/file.README.html
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
<title>
|
|
7
7
|
File: README
|
|
8
8
|
|
|
9
|
-
— Documentation by YARD 0.9.
|
|
9
|
+
— Documentation by YARD 0.9.44
|
|
10
10
|
|
|
11
11
|
</title>
|
|
12
12
|
|
|
13
|
-
<link rel="stylesheet" href="css/style.css" type="text/css"
|
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css">
|
|
14
14
|
|
|
15
|
-
<link rel="stylesheet" href="css/common.css" type="text/css"
|
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css">
|
|
16
16
|
|
|
17
17
|
<script type="text/javascript">
|
|
18
18
|
pathId = "README";
|
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
|
|
28
28
|
</head>
|
|
29
29
|
<body>
|
|
30
|
+
<div id="main_progress" aria-hidden="true"></div>
|
|
31
|
+
|
|
30
32
|
<div class="nav_wrap">
|
|
31
33
|
<iframe id="nav" src="file_list.html?1"></iframe>
|
|
32
34
|
<div id="resizer"></div>
|
|
@@ -59,114 +61,88 @@
|
|
|
59
61
|
|
|
60
62
|
<div id="content"><div id='filecontents'><p><a href="https://rubygems.org/gems/crapi"><img src="https://img.shields.io/github/v/release/nestor-custodio/crapi?color=green&label=gem%20version" alt="Gem Version" /></a>
|
|
61
63
|
<a href="https://tldrlegal.com/license/mit-license"><img src="https://img.shields.io/github/license/nestor-custodio/crapi" alt="MIT License" /></a></p>
|
|
62
|
-
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
<h2 id="installation">Installation</h2>
|
|
70
|
-
|
|
71
|
-
<p>Add this line to your application’s Gemfile:</p>
|
|
72
|
-
|
|
73
|
-
<p><code>ruby
|
|
74
|
-
gem 'crapi'
|
|
75
|
-
</code></p>
|
|
76
|
-
|
|
64
|
+
<h1 id="CrAPI">CrAPI</h1>
|
|
65
|
+
<p>CrAPI is yet another <strong>Cr</strong>ud <strong>API</strong> client wrapper. Yes, there is no shortage of these out there, but no other API wrapper gem (that I could find) provided the kind of functionality you get from the CrAPI::Proxy class, which is really the biggest benefit here.</p>
|
|
66
|
+
<p><strong>CrAPI::Client</strong> will connect to the target system and handily provides a base path for you (because some APIs and services have a path that is always part of every request), <strong>CrAPI::Proxy</strong> lets you add to the root client's base path or default set of headers without having to create any new connections.</p>
|
|
67
|
+
<h2 id="Installation">Installation</h2>
|
|
68
|
+
<p>Add this line to your application's Gemfile:</p>
|
|
69
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>crapi</span><span class='tstring_end'>'</span></span>
|
|
70
|
+
</code></pre>
|
|
77
71
|
<p>And then execute:</p>
|
|
78
|
-
|
|
79
72
|
<pre class="code ruby"><code class="ruby">$ bundle
|
|
80
73
|
</code></pre>
|
|
81
|
-
|
|
82
74
|
<p>Or install it yourself as:</p>
|
|
83
|
-
|
|
84
75
|
<pre class="code ruby"><code class="ruby">$ gem install crapi
|
|
85
76
|
</code></pre>
|
|
86
|
-
|
|
87
|
-
<
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
<p>mew_comment = { user: ‘megapwner’, text: ‘FRIST!!1!’ }
|
|
103
|
-
api.post(‘comments’, payload: new_comment) # POSTs to /comments; returns a Hash.
|
|
104
|
-
```</p>
|
|
105
|
-
|
|
77
|
+
<h2 id="Using_The_CrAPI_Tools">Using The CrAPI Tools</h2>
|
|
78
|
+
<h3 id="Client_Usage">Client Usage</h3>
|
|
79
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># Connect to an API.
|
|
80
|
+
</span>
|
|
81
|
+
<span class='id identifier rubyid_api'>api</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="CrAPI.html" title="CrAPI (module)">CrAPI</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CrAPI/Client.html" title="CrAPI::Client (class)">Client</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="CrAPI/Client.html#initialize-instance_method" title="CrAPI::Client#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>https://jsonplaceholder.typicode.com/</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
<span class='comment'># Issue requests against the API.
|
|
85
|
+
</span>
|
|
86
|
+
<span class='id identifier rubyid_api'>api</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>users/1</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># GETs /users/1; returns a Hash.
|
|
87
|
+
</span>
|
|
88
|
+
<span class='id identifier rubyid_api'>api</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>posts</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>query:</span> <span class='lbrace'>{</span> <span class='label'>userId:</span> <span class='int'>2</span> <span class='rbrace'>}</span><span class='rparen'>)</span> <span class='comment'># GETs /posts?userId=2; returns an Array.
|
|
89
|
+
</span>
|
|
90
|
+
<span class='id identifier rubyid_mew_comment'>mew_comment</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='label'>user:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>megapwner</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>text:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>FRIST!!1!</span><span class='tstring_end'>'</span></span> <span class='rbrace'>}</span>
|
|
91
|
+
<span class='id identifier rubyid_api'>api</span><span class='period'>.</span><span class='id identifier rubyid_post'>post</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>comments</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>payload:</span> <span class='id identifier rubyid_new_comment'>new_comment</span><span class='rparen'>)</span> <span class='comment'># POSTs to /comments; returns a Hash.
|
|
92
|
+
</span></code></pre>
|
|
106
93
|
<hr />
|
|
94
|
+
<h3 id="Proxy_Usage">Proxy Usage</h3>
|
|
95
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># Connect to an API.
|
|
96
|
+
</span>
|
|
97
|
+
<span class='id identifier rubyid_api'>api</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="CrAPI.html" title="CrAPI (module)">CrAPI</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CrAPI/Client.html" title="CrAPI::Client (class)">Client</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="CrAPI/Client.html#initialize-instance_method" title="CrAPI::Client#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>https://versioned.fake-api.com/api/</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
107
98
|
|
|
108
|
-
<h3 id="proxy-usage">Proxy Usage</h3>
|
|
109
|
-
|
|
110
|
-
<p>```ruby
|
|
111
|
-
# Connect to an API.</p>
|
|
112
|
-
|
|
113
|
-
<p>api = CrAPI::Client.new(‘https://versioned.fake-api.com/api/’)</p>
|
|
114
|
-
|
|
115
|
-
<h1 id="back-in-the-v1-days-versioning-of-this-api-was-via-the-url-">Back in the v1 days, versioning of this API was via the URL …</h1>
|
|
116
99
|
|
|
117
|
-
<
|
|
100
|
+
<span class='comment'># Back in the v1 days, versioning of this API was via the URL ...
|
|
101
|
+
</span>
|
|
102
|
+
<span class='id identifier rubyid_v1'>v1</span> <span class='op'>=</span> <span class='id identifier rubyid_api'>api</span><span class='period'>.</span><span class='id identifier rubyid_new_proxy'>new_proxy</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>/v1</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
118
103
|
|
|
119
|
-
<
|
|
120
|
-
v1
|
|
104
|
+
<span class='id identifier rubyid_v1'>v1</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>data</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># GETs /api/v1/data; pretty straight-forward.
|
|
105
|
+
</span><span class='id identifier rubyid_v1'>v1</span><span class='period'>.</span><span class='id identifier rubyid_post'>post</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>data</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>payload:</span> <span class='id identifier rubyid_values'>values</span><span class='rparen'>)</span> <span class='comment'># POSTs *values* to /api/v1/data.
|
|
106
|
+
</span>
|
|
121
107
|
|
|
122
|
-
<
|
|
108
|
+
<span class='comment'># For API v2, they switched to an Accept header approach ...
|
|
109
|
+
</span>
|
|
110
|
+
<span class='id identifier rubyid_v2'>v2</span> <span class='op'>=</span> <span class='id identifier rubyid_api'>api</span><span class='period'>.</span><span class='id identifier rubyid_new_proxy'>new_proxy</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>/</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>headers:</span> <span class='lbrace'>{</span> <span class='label'>Accept:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>application/vnd.fake-api.v2+json</span><span class='tstring_end'>'</span></span> <span class='rbrace'>}</span><span class='rparen'>)</span>
|
|
123
111
|
|
|
124
|
-
<
|
|
112
|
+
<span class='id identifier rubyid_v2'>v2</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>data</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># GETs /api/data with the v2 header.
|
|
113
|
+
</span>
|
|
125
114
|
|
|
126
|
-
<
|
|
115
|
+
<span class='comment'># API v3 keeps the Accept header approach ...
|
|
116
|
+
</span>
|
|
117
|
+
<span class='id identifier rubyid_v3'>v3</span> <span class='op'>=</span> <span class='id identifier rubyid_api'>api</span><span class='period'>.</span><span class='id identifier rubyid_new_proxy'>new_proxy</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>/</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>headers:</span> <span class='lbrace'>{</span> <span class='label'>Accept:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>application/vnd.fake-api.v3+json</span><span class='tstring_end'>'</span></span> <span class='rbrace'>}</span><span class='rparen'>)</span>
|
|
127
118
|
|
|
128
|
-
<
|
|
129
|
-
|
|
130
|
-
<p>v3 = api.new_proxy(‘/’, headers: { Accept: ‘application/vnd.fake-api.v3+json’ })</p>
|
|
131
|
-
|
|
132
|
-
<p>v3.get(‘data’) # GETs /api/data with the v3 header.</p>
|
|
133
|
-
|
|
134
|
-
<h1 id="note-that-only-one-connection-to-the-client-is-made-and-you-can-easily-make">Note that only one connection to the client is made and you can easily make</h1>
|
|
135
|
-
<p># v1, v2, and v3 API calls ad hoc without having to juggle paths/headers yourself.
|
|
136
|
-
```</p>
|
|
119
|
+
<span class='id identifier rubyid_v3'>v3</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>data</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># GETs /api/data with the v3 header.
|
|
120
|
+
</span>
|
|
137
121
|
|
|
122
|
+
<span class='comment'># Note that only one connection to the client is made and you can easily make
|
|
123
|
+
</span><span class='comment'># v1, v2, and v3 API calls ad hoc without having to juggle paths/headers yourself.
|
|
124
|
+
</span></code></pre>
|
|
138
125
|
<hr />
|
|
139
|
-
|
|
140
|
-
<
|
|
141
|
-
|
|
142
|
-
<h2 id="feature-roadmap--future-development">Feature Roadmap / Future Development</h2>
|
|
143
|
-
|
|
126
|
+
<p><a href="https://nestor-custodio.github.io/crapi/CrAPI.html">Consult the repo docs for the full CrAPI documentation.</a></p>
|
|
127
|
+
<h2 id="Feature_Roadmap___Future_Development">Feature Roadmap / Future Development</h2>
|
|
144
128
|
<p>Additional features/options coming in the future:</p>
|
|
145
|
-
|
|
146
129
|
<ul>
|
|
147
|
-
|
|
148
|
-
|
|
130
|
+
<li>Cleaner handling of non-body-returning calls.</li>
|
|
131
|
+
<li>More resilient serializing of non-String paylods when using custom Content-Type headers.</li>
|
|
149
132
|
</ul>
|
|
150
|
-
|
|
151
|
-
<
|
|
152
|
-
|
|
153
|
-
<p>Bug reports and pull requests are welcome at: <a href="https://github.com/nestor-custodio/crapi">https://github.com/nestor-custodio/crapi</a></p>
|
|
154
|
-
|
|
133
|
+
<h2 id="Contribution___Development">Contribution / Development</h2>
|
|
134
|
+
<p>Bug reports and pull requests are welcome at: <a href="https://github.com/nestor-custodio/crapi"><a href="https://github.com/nestor-custodio/crapi">https://github.com/nestor-custodio/crapi</a></a></p>
|
|
155
135
|
<p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>bundle exec 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>
|
|
156
|
-
|
|
157
136
|
<p>Linting is courtesy of <a href="https://docs.rubocop.org/">Rubocop</a> (<code>bundle exec rubocop</code>) and documentation is built using <a href="https://yardoc.org/">Yard</a> (<code>bundle exec yard</code>). Please ensure you have a clean bill of health from Rubocop and that any new features and/or changes to behaviour are reflected in the documentation before submitting a pull request.</p>
|
|
158
|
-
|
|
159
|
-
<
|
|
160
|
-
|
|
161
|
-
<p>CrAPI is available as open source under the terms of the <a href="https://tldrlegal.com/license/mit-license">MIT License</a>.</p>
|
|
162
|
-
</div></div>
|
|
137
|
+
<h2 id="License">License</h2>
|
|
138
|
+
<p>CrAPI is available as open source under the terms of the <a href="https://tldrlegal.com/license/mit-license">MIT License</a>.</p></div></div>
|
|
163
139
|
|
|
164
140
|
<div id="footer">
|
|
165
|
-
Generated on
|
|
141
|
+
Generated on Sun Jul 5 14:46:38 2026 by
|
|
166
142
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
167
|
-
0.9.
|
|
143
|
+
0.9.44 (ruby-3.4.8).
|
|
168
144
|
</div>
|
|
169
145
|
|
|
170
146
|
</div>
|
|
171
147
|
</body>
|
|
172
|
-
</html>
|
|
148
|
+
</html>
|
data/docs/file_list.html
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
2
|
+
<html >
|
|
3
3
|
<head>
|
|
4
4
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
5
|
-
<meta charset="utf-8"
|
|
5
|
+
<meta charset="utf-8">
|
|
6
6
|
|
|
7
|
-
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen"
|
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen">
|
|
8
8
|
|
|
9
|
-
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen"
|
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen">
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
<title>File List</title>
|
|
19
|
-
<base id="base_target" target="_parent"
|
|
19
|
+
<base id="base_target" target="_parent">
|
|
20
20
|
</head>
|
|
21
21
|
<body>
|
|
22
22
|
<div id="content">
|
|
@@ -38,7 +38,10 @@
|
|
|
38
38
|
|
|
39
39
|
</div>
|
|
40
40
|
|
|
41
|
-
<div id="search">
|
|
41
|
+
<div id="search">
|
|
42
|
+
<label for="search-class">Search:</label>
|
|
43
|
+
<input id="search-class" type="text">
|
|
44
|
+
</div>
|
|
42
45
|
</div>
|
|
43
46
|
|
|
44
47
|
<ul id="full_list" class="file">
|
data/docs/frames.html
CHANGED
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
<html>
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
|
-
<title>Documentation by YARD 0.9.
|
|
5
|
+
<title>Documentation by YARD 0.9.44</title>
|
|
6
6
|
</head>
|
|
7
7
|
<script type="text/javascript">
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
}
|
|
12
17
|
</script>
|
|
13
18
|
<noscript>
|
|
14
19
|
<h1>Oops!</h1>
|
data/docs/index.html
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
<title>
|
|
7
7
|
File: README
|
|
8
8
|
|
|
9
|
-
— Documentation by YARD 0.9.
|
|
9
|
+
— Documentation by YARD 0.9.44
|
|
10
10
|
|
|
11
11
|
</title>
|
|
12
12
|
|
|
13
|
-
<link rel="stylesheet" href="css/style.css" type="text/css"
|
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css">
|
|
14
14
|
|
|
15
|
-
<link rel="stylesheet" href="css/common.css" type="text/css"
|
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css">
|
|
16
16
|
|
|
17
17
|
<script type="text/javascript">
|
|
18
18
|
pathId = "README";
|
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
|
|
28
28
|
</head>
|
|
29
29
|
<body>
|
|
30
|
+
<div id="main_progress" aria-hidden="true"></div>
|
|
31
|
+
|
|
30
32
|
<div class="nav_wrap">
|
|
31
33
|
<iframe id="nav" src="class_list.html?1"></iframe>
|
|
32
34
|
<div id="resizer"></div>
|
|
@@ -59,114 +61,88 @@
|
|
|
59
61
|
|
|
60
62
|
<div id="content"><div id='filecontents'><p><a href="https://rubygems.org/gems/crapi"><img src="https://img.shields.io/github/v/release/nestor-custodio/crapi?color=green&label=gem%20version" alt="Gem Version" /></a>
|
|
61
63
|
<a href="https://tldrlegal.com/license/mit-license"><img src="https://img.shields.io/github/license/nestor-custodio/crapi" alt="MIT License" /></a></p>
|
|
62
|
-
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
<h2 id="installation">Installation</h2>
|
|
70
|
-
|
|
71
|
-
<p>Add this line to your application’s Gemfile:</p>
|
|
72
|
-
|
|
73
|
-
<p><code>ruby
|
|
74
|
-
gem 'crapi'
|
|
75
|
-
</code></p>
|
|
76
|
-
|
|
64
|
+
<h1 id="CrAPI">CrAPI</h1>
|
|
65
|
+
<p>CrAPI is yet another <strong>Cr</strong>ud <strong>API</strong> client wrapper. Yes, there is no shortage of these out there, but no other API wrapper gem (that I could find) provided the kind of functionality you get from the CrAPI::Proxy class, which is really the biggest benefit here.</p>
|
|
66
|
+
<p><strong>CrAPI::Client</strong> will connect to the target system and handily provides a base path for you (because some APIs and services have a path that is always part of every request), <strong>CrAPI::Proxy</strong> lets you add to the root client's base path or default set of headers without having to create any new connections.</p>
|
|
67
|
+
<h2 id="Installation">Installation</h2>
|
|
68
|
+
<p>Add this line to your application's Gemfile:</p>
|
|
69
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>crapi</span><span class='tstring_end'>'</span></span>
|
|
70
|
+
</code></pre>
|
|
77
71
|
<p>And then execute:</p>
|
|
78
|
-
|
|
79
72
|
<pre class="code ruby"><code class="ruby">$ bundle
|
|
80
73
|
</code></pre>
|
|
81
|
-
|
|
82
74
|
<p>Or install it yourself as:</p>
|
|
83
|
-
|
|
84
75
|
<pre class="code ruby"><code class="ruby">$ gem install crapi
|
|
85
76
|
</code></pre>
|
|
86
|
-
|
|
87
|
-
<
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
<p>mew_comment = { user: ‘megapwner’, text: ‘FRIST!!1!’ }
|
|
103
|
-
api.post(‘comments’, payload: new_comment) # POSTs to /comments; returns a Hash.
|
|
104
|
-
```</p>
|
|
105
|
-
|
|
77
|
+
<h2 id="Using_The_CrAPI_Tools">Using The CrAPI Tools</h2>
|
|
78
|
+
<h3 id="Client_Usage">Client Usage</h3>
|
|
79
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># Connect to an API.
|
|
80
|
+
</span>
|
|
81
|
+
<span class='id identifier rubyid_api'>api</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="CrAPI.html" title="CrAPI (module)">CrAPI</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CrAPI/Client.html" title="CrAPI::Client (class)">Client</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="CrAPI/Client.html#initialize-instance_method" title="CrAPI::Client#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>https://jsonplaceholder.typicode.com/</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
<span class='comment'># Issue requests against the API.
|
|
85
|
+
</span>
|
|
86
|
+
<span class='id identifier rubyid_api'>api</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>users/1</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># GETs /users/1; returns a Hash.
|
|
87
|
+
</span>
|
|
88
|
+
<span class='id identifier rubyid_api'>api</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>posts</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>query:</span> <span class='lbrace'>{</span> <span class='label'>userId:</span> <span class='int'>2</span> <span class='rbrace'>}</span><span class='rparen'>)</span> <span class='comment'># GETs /posts?userId=2; returns an Array.
|
|
89
|
+
</span>
|
|
90
|
+
<span class='id identifier rubyid_mew_comment'>mew_comment</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='label'>user:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>megapwner</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>text:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>FRIST!!1!</span><span class='tstring_end'>'</span></span> <span class='rbrace'>}</span>
|
|
91
|
+
<span class='id identifier rubyid_api'>api</span><span class='period'>.</span><span class='id identifier rubyid_post'>post</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>comments</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>payload:</span> <span class='id identifier rubyid_new_comment'>new_comment</span><span class='rparen'>)</span> <span class='comment'># POSTs to /comments; returns a Hash.
|
|
92
|
+
</span></code></pre>
|
|
106
93
|
<hr />
|
|
94
|
+
<h3 id="Proxy_Usage">Proxy Usage</h3>
|
|
95
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># Connect to an API.
|
|
96
|
+
</span>
|
|
97
|
+
<span class='id identifier rubyid_api'>api</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="CrAPI.html" title="CrAPI (module)">CrAPI</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CrAPI/Client.html" title="CrAPI::Client (class)">Client</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="CrAPI/Client.html#initialize-instance_method" title="CrAPI::Client#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>https://versioned.fake-api.com/api/</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
107
98
|
|
|
108
|
-
<h3 id="proxy-usage">Proxy Usage</h3>
|
|
109
|
-
|
|
110
|
-
<p>```ruby
|
|
111
|
-
# Connect to an API.</p>
|
|
112
|
-
|
|
113
|
-
<p>api = CrAPI::Client.new(‘https://versioned.fake-api.com/api/’)</p>
|
|
114
|
-
|
|
115
|
-
<h1 id="back-in-the-v1-days-versioning-of-this-api-was-via-the-url-">Back in the v1 days, versioning of this API was via the URL …</h1>
|
|
116
99
|
|
|
117
|
-
<
|
|
100
|
+
<span class='comment'># Back in the v1 days, versioning of this API was via the URL ...
|
|
101
|
+
</span>
|
|
102
|
+
<span class='id identifier rubyid_v1'>v1</span> <span class='op'>=</span> <span class='id identifier rubyid_api'>api</span><span class='period'>.</span><span class='id identifier rubyid_new_proxy'>new_proxy</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>/v1</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
118
103
|
|
|
119
|
-
<
|
|
120
|
-
v1
|
|
104
|
+
<span class='id identifier rubyid_v1'>v1</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>data</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># GETs /api/v1/data; pretty straight-forward.
|
|
105
|
+
</span><span class='id identifier rubyid_v1'>v1</span><span class='period'>.</span><span class='id identifier rubyid_post'>post</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>data</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>payload:</span> <span class='id identifier rubyid_values'>values</span><span class='rparen'>)</span> <span class='comment'># POSTs *values* to /api/v1/data.
|
|
106
|
+
</span>
|
|
121
107
|
|
|
122
|
-
<
|
|
108
|
+
<span class='comment'># For API v2, they switched to an Accept header approach ...
|
|
109
|
+
</span>
|
|
110
|
+
<span class='id identifier rubyid_v2'>v2</span> <span class='op'>=</span> <span class='id identifier rubyid_api'>api</span><span class='period'>.</span><span class='id identifier rubyid_new_proxy'>new_proxy</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>/</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>headers:</span> <span class='lbrace'>{</span> <span class='label'>Accept:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>application/vnd.fake-api.v2+json</span><span class='tstring_end'>'</span></span> <span class='rbrace'>}</span><span class='rparen'>)</span>
|
|
123
111
|
|
|
124
|
-
<
|
|
112
|
+
<span class='id identifier rubyid_v2'>v2</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>data</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># GETs /api/data with the v2 header.
|
|
113
|
+
</span>
|
|
125
114
|
|
|
126
|
-
<
|
|
115
|
+
<span class='comment'># API v3 keeps the Accept header approach ...
|
|
116
|
+
</span>
|
|
117
|
+
<span class='id identifier rubyid_v3'>v3</span> <span class='op'>=</span> <span class='id identifier rubyid_api'>api</span><span class='period'>.</span><span class='id identifier rubyid_new_proxy'>new_proxy</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>/</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>headers:</span> <span class='lbrace'>{</span> <span class='label'>Accept:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>application/vnd.fake-api.v3+json</span><span class='tstring_end'>'</span></span> <span class='rbrace'>}</span><span class='rparen'>)</span>
|
|
127
118
|
|
|
128
|
-
<
|
|
129
|
-
|
|
130
|
-
<p>v3 = api.new_proxy(‘/’, headers: { Accept: ‘application/vnd.fake-api.v3+json’ })</p>
|
|
131
|
-
|
|
132
|
-
<p>v3.get(‘data’) # GETs /api/data with the v3 header.</p>
|
|
133
|
-
|
|
134
|
-
<h1 id="note-that-only-one-connection-to-the-client-is-made-and-you-can-easily-make">Note that only one connection to the client is made and you can easily make</h1>
|
|
135
|
-
<p># v1, v2, and v3 API calls ad hoc without having to juggle paths/headers yourself.
|
|
136
|
-
```</p>
|
|
119
|
+
<span class='id identifier rubyid_v3'>v3</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>data</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># GETs /api/data with the v3 header.
|
|
120
|
+
</span>
|
|
137
121
|
|
|
122
|
+
<span class='comment'># Note that only one connection to the client is made and you can easily make
|
|
123
|
+
</span><span class='comment'># v1, v2, and v3 API calls ad hoc without having to juggle paths/headers yourself.
|
|
124
|
+
</span></code></pre>
|
|
138
125
|
<hr />
|
|
139
|
-
|
|
140
|
-
<
|
|
141
|
-
|
|
142
|
-
<h2 id="feature-roadmap--future-development">Feature Roadmap / Future Development</h2>
|
|
143
|
-
|
|
126
|
+
<p><a href="https://nestor-custodio.github.io/crapi/CrAPI.html">Consult the repo docs for the full CrAPI documentation.</a></p>
|
|
127
|
+
<h2 id="Feature_Roadmap___Future_Development">Feature Roadmap / Future Development</h2>
|
|
144
128
|
<p>Additional features/options coming in the future:</p>
|
|
145
|
-
|
|
146
129
|
<ul>
|
|
147
|
-
|
|
148
|
-
|
|
130
|
+
<li>Cleaner handling of non-body-returning calls.</li>
|
|
131
|
+
<li>More resilient serializing of non-String paylods when using custom Content-Type headers.</li>
|
|
149
132
|
</ul>
|
|
150
|
-
|
|
151
|
-
<
|
|
152
|
-
|
|
153
|
-
<p>Bug reports and pull requests are welcome at: <a href="https://github.com/nestor-custodio/crapi">https://github.com/nestor-custodio/crapi</a></p>
|
|
154
|
-
|
|
133
|
+
<h2 id="Contribution___Development">Contribution / Development</h2>
|
|
134
|
+
<p>Bug reports and pull requests are welcome at: <a href="https://github.com/nestor-custodio/crapi"><a href="https://github.com/nestor-custodio/crapi">https://github.com/nestor-custodio/crapi</a></a></p>
|
|
155
135
|
<p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>bundle exec 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>
|
|
156
|
-
|
|
157
136
|
<p>Linting is courtesy of <a href="https://docs.rubocop.org/">Rubocop</a> (<code>bundle exec rubocop</code>) and documentation is built using <a href="https://yardoc.org/">Yard</a> (<code>bundle exec yard</code>). Please ensure you have a clean bill of health from Rubocop and that any new features and/or changes to behaviour are reflected in the documentation before submitting a pull request.</p>
|
|
158
|
-
|
|
159
|
-
<
|
|
160
|
-
|
|
161
|
-
<p>CrAPI is available as open source under the terms of the <a href="https://tldrlegal.com/license/mit-license">MIT License</a>.</p>
|
|
162
|
-
</div></div>
|
|
137
|
+
<h2 id="License">License</h2>
|
|
138
|
+
<p>CrAPI is available as open source under the terms of the <a href="https://tldrlegal.com/license/mit-license">MIT License</a>.</p></div></div>
|
|
163
139
|
|
|
164
140
|
<div id="footer">
|
|
165
|
-
Generated on
|
|
141
|
+
Generated on Sun Jul 5 14:46:38 2026 by
|
|
166
142
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
167
|
-
0.9.
|
|
143
|
+
0.9.44 (ruby-3.4.8).
|
|
168
144
|
</div>
|
|
169
145
|
|
|
170
146
|
</div>
|
|
171
147
|
</body>
|
|
172
|
-
</html>
|
|
148
|
+
</html>
|