shep 0.1.0.pre.alpha0 → 0.2.0.pre.alpha0

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -1
  3. data/Rakefile +1 -0
  4. data/doc/Shep/Entity/Account.html +22 -37
  5. data/doc/Shep/Entity/Context.html +8 -9
  6. data/doc/Shep/Entity/CustomEmoji.html +11 -15
  7. data/doc/Shep/Entity/MediaAttachment.html +13 -19
  8. data/doc/Shep/Entity/Notification.html +11 -15
  9. data/doc/Shep/Entity/Status.html +34 -61
  10. data/doc/Shep/Entity/StatusSource.html +9 -11
  11. data/doc/Shep/Entity/Status_Application.html +11 -10
  12. data/doc/Shep/Entity/Status_Mention.html +10 -13
  13. data/doc/Shep/Entity/Status_Tag.html +8 -9
  14. data/doc/Shep/Entity.html +156 -141
  15. data/doc/Shep/Error/Caller.html +4 -4
  16. data/doc/Shep/Error/Http.html +13 -13
  17. data/doc/Shep/Error/RateLimit.html +176 -0
  18. data/doc/Shep/Error/Remote.html +3 -4
  19. data/doc/Shep/Error/Server.html +5 -4
  20. data/doc/Shep/Error/Type.html +6 -8
  21. data/doc/Shep/Error.html +5 -5
  22. data/doc/Shep/Session.html +895 -570
  23. data/doc/Shep.html +20 -5
  24. data/doc/_index.html +10 -3
  25. data/doc/class_list.html +1 -1
  26. data/doc/file.README.html +52 -33
  27. data/doc/file_list.html +1 -1
  28. data/doc/index.html +117 -239
  29. data/doc/method_list.html +9 -1
  30. data/doc/top-level-namespace.html +2 -2
  31. data/lib/shep/entity_base.rb +6 -1
  32. data/lib/shep/exceptions.rb +5 -0
  33. data/lib/shep/session.rb +292 -146
  34. data/lib/shep/version.rb +4 -0
  35. data/lib/shep.rb +1 -1
  36. data/run_rake_test.example.sh +12 -5
  37. data/shep.gemspec +4 -2
  38. data/spec/session_reader_1_unauth_spec.rb +20 -17
  39. data/spec/session_reader_2_auth_spec.rb +17 -19
  40. data/spec/session_writer_spec.rb +4 -11
  41. data/spec/session_zzz_tricky_spec.rb +136 -0
  42. data/spec/spec_helper.rb +12 -3
  43. metadata +12 -9
data/doc/index.html CHANGED
@@ -1,10 +1,12 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <meta charset="utf-8">
4
+ <meta charset="UTF-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>
7
- Documentation by YARD 0.9.34
7
+ File: README
8
+
9
+ &mdash; Documentation by YARD 0.9.34
8
10
 
9
11
  </title>
10
12
 
@@ -13,7 +15,7 @@
13
15
  <link rel="stylesheet" href="css/common.css" type="text/css" />
14
16
 
15
17
  <script type="text/javascript">
16
- pathId = null;
18
+ pathId = "README";
17
19
  relpath = '';
18
20
  </script>
19
21
 
@@ -34,6 +36,9 @@
34
36
  <div id="header">
35
37
  <div id="menu">
36
38
 
39
+ <a href="_index.html">Index</a> &raquo;
40
+ <span class="title">File: README</span>
41
+
37
42
  </div>
38
43
 
39
44
  <div id="search">
@@ -52,247 +57,120 @@
52
57
  <div class="clear"></div>
53
58
  </div>
54
59
 
55
- <div id="content"><h1 class="noborder title">Documentation by YARD 0.9.34</h1>
56
- <div id="listing">
57
- <h1 class="alphaindex">Alphabetic Index</h1>
58
-
59
- <h2>File Listing</h2>
60
- <ul id="files" class="index_inline_list">
61
-
62
-
63
- <li class="r1"><a href="file.README.html" title="README">README</a></li>
64
-
65
-
66
- </ul>
67
-
68
- <div class="clear"></div>
69
- <h2>Namespace Listing A-Z</h2>
70
-
71
-
72
-
73
-
74
- <table>
75
- <tr>
76
- <td valign='top' width="33%">
77
-
78
-
79
- <ul id="alpha_A" class="alpha">
80
- <li class="letter">A</li>
81
- <ul>
82
-
83
- <li>
84
- <span class='object_link'><a href="Shep/Entity/Account.html" title="Shep::Entity::Account (class)">Account</a></span>
85
-
86
- <small>(Shep::Entity)</small>
87
-
88
- </li>
89
-
90
- </ul>
91
- </ul>
92
-
93
-
94
- <ul id="alpha_C" class="alpha">
95
- <li class="letter">C</li>
96
- <ul>
97
-
98
- <li>
99
- <span class='object_link'><a href="Shep/Error/Caller.html" title="Shep::Error::Caller (class)">Caller</a></span>
100
-
101
- <small>(Shep::Error)</small>
102
-
103
- </li>
104
-
105
- <li>
106
- <span class='object_link'><a href="Shep/Entity/Context.html" title="Shep::Entity::Context (class)">Context</a></span>
107
-
108
- <small>(Shep::Entity)</small>
109
-
110
- </li>
111
-
112
- <li>
113
- <span class='object_link'><a href="Shep/Entity/CustomEmoji.html" title="Shep::Entity::CustomEmoji (class)">CustomEmoji</a></span>
114
-
115
- <small>(Shep::Entity)</small>
116
-
117
- </li>
118
-
119
- </ul>
120
- </ul>
121
-
122
-
123
- <ul id="alpha_E" class="alpha">
124
- <li class="letter">E</li>
125
- <ul>
126
-
127
- <li>
128
- <span class='object_link'><a href="Shep/Entity.html" title="Shep::Entity (class)">Entity</a></span>
129
-
130
- <small>(Shep)</small>
131
-
132
- </li>
133
-
134
- <li>
135
- <span class='object_link'><a href="Shep/Error.html" title="Shep::Error (class)">Error</a></span>
136
-
137
- <small>(Shep)</small>
138
-
139
- </li>
140
-
141
- </ul>
142
- </ul>
143
-
144
-
145
- <ul id="alpha_H" class="alpha">
146
- <li class="letter">H</li>
147
- <ul>
148
-
149
- <li>
150
- <span class='object_link'><a href="Shep/Error/Http.html" title="Shep::Error::Http (class)">Http</a></span>
151
-
152
- <small>(Shep::Error)</small>
153
-
154
- </li>
155
-
156
- </ul>
157
- </ul>
158
-
159
-
160
- <ul id="alpha_M" class="alpha">
161
- <li class="letter">M</li>
162
- <ul>
163
-
164
- <li>
165
- <span class='object_link'><a href="Shep/Entity/MediaAttachment.html" title="Shep::Entity::MediaAttachment (class)">MediaAttachment</a></span>
166
-
167
- <small>(Shep::Entity)</small>
168
-
169
- </li>
170
-
171
- </ul>
172
- </ul>
173
-
174
-
175
- <ul id="alpha_N" class="alpha">
176
- <li class="letter">N</li>
177
- <ul>
178
-
179
- <li>
180
- <span class='object_link'><a href="Shep/Entity/Notification.html" title="Shep::Entity::Notification (class)">Notification</a></span>
181
-
182
- <small>(Shep::Entity)</small>
183
-
184
- </li>
185
-
186
- </ul>
187
- </ul>
188
-
189
-
190
- <ul id="alpha_R" class="alpha">
191
- <li class="letter">R</li>
192
- <ul>
193
-
194
- <li>
195
- <span class='object_link'><a href="Shep/Error/Remote.html" title="Shep::Error::Remote (class)">Remote</a></span>
196
-
197
- <small>(Shep::Error)</small>
198
-
199
- </li>
200
-
201
- </ul>
202
- </ul>
203
-
204
-
205
- </td><td valign='top' width="33%">
206
-
207
-
208
- <ul id="alpha_S" class="alpha">
209
- <li class="letter">S</li>
210
- <ul>
211
-
212
- <li>
213
- <span class='object_link'><a href="Shep/Error/Server.html" title="Shep::Error::Server (class)">Server</a></span>
214
-
215
- <small>(Shep::Error)</small>
216
-
217
- </li>
218
-
219
- <li>
220
- <span class='object_link'><a href="Shep/Session.html" title="Shep::Session (class)">Session</a></span>
221
-
222
- <small>(Shep)</small>
223
-
224
- </li>
225
-
226
- <li>
227
- <span class='object_link'><a href="Shep.html" title="Shep (module)">Shep</a></span>
228
-
229
- </li>
230
-
231
- <li>
232
- <span class='object_link'><a href="Shep/Entity/Status.html" title="Shep::Entity::Status (class)">Status</a></span>
233
-
234
- <small>(Shep::Entity)</small>
235
-
236
- </li>
237
-
238
- <li>
239
- <span class='object_link'><a href="Shep/Entity/StatusSource.html" title="Shep::Entity::StatusSource (class)">StatusSource</a></span>
240
-
241
- <small>(Shep::Entity)</small>
242
-
243
- </li>
244
-
245
- <li>
246
- <span class='object_link'><a href="Shep/Entity/Status_Application.html" title="Shep::Entity::Status_Application (class)">Status_Application</a></span>
247
-
248
- <small>(Shep::Entity)</small>
249
-
250
- </li>
251
-
252
- <li>
253
- <span class='object_link'><a href="Shep/Entity/Status_Mention.html" title="Shep::Entity::Status_Mention (class)">Status_Mention</a></span>
254
-
255
- <small>(Shep::Entity)</small>
256
-
257
- </li>
258
-
259
- <li>
260
- <span class='object_link'><a href="Shep/Entity/Status_Tag.html" title="Shep::Entity::Status_Tag (class)">Status_Tag</a></span>
261
-
262
- <small>(Shep::Entity)</small>
263
-
264
- </li>
265
-
266
- </ul>
267
- </ul>
268
-
269
-
270
- <ul id="alpha_T" class="alpha">
271
- <li class="letter">T</li>
272
- <ul>
273
-
274
- <li>
275
- <span class='object_link'><a href="Shep/Error/Type.html" title="Shep::Error::Type (class)">Type</a></span>
276
-
277
- <small>(Shep::Error)</small>
278
-
279
- </li>
280
-
281
- </ul>
282
- </ul>
283
-
284
- </td>
285
- </tr>
286
- </table>
60
+ <div id="content"><div id='filecontents'><h1 id="shep-simple-http-interface-to-pmastodon">Shep: Simple Http intErface to Pmastodon</h1>
287
61
 
288
- </div>
62
+ <p>Shep is a library that provides access to the Mastodon web API. It is
63
+ an alternative to the
64
+ <a href="https://rubygems.org/gems/mastodon-api/versions/2.0.0">official Mastodon API Gem</a>.</p>
289
65
 
290
- </div>
66
+ <p>Pros:</p>
67
+
68
+ <ul>
69
+ <li>It has no dependencies other than stock Ruby 3.0.x or later. (It&#39;s
70
+ also been seen to work on JRuby-9.4.2.0.)</li>
71
+ <li>Its unit tests do not require a dedicated Mastodon instance and will
72
+ work with just a scratch user account (and partially without even
73
+ that).</li>
74
+ <li>It&#39;s a bit more &quot;batteries included&quot; than the official gem tries to
75
+ do more for you.</li>
76
+ <li>It supports <a href="https://docs.joinmastodon.org/methods/statuses/#context">Contexts</a>.</li>
77
+ </ul>
78
+
79
+ <p>Cons:</p>
80
+
81
+ <ul>
82
+ <li>It supports much less of the API than the offical gem.</li>
83
+ <li>Its author thinks metaprogramming is cool.</li>
84
+ </ul>
85
+
86
+ <h2 id="some-quick-examples">Some Quick Examples:</h2>
87
+
88
+ <p>Here&#39;s the canonical use case, retrieving cat pictures:</p>
89
+
90
+ <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'>shep</span><span class='tstring_end'>&#39;</span></span>
91
+
92
+ <span class='const'>HOST</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>... name of mastodon host goes here...</span><span class='tstring_end'>&quot;</span></span>
93
+
94
+ <span class='id identifier rubyid_ss'>ss</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Shep.html" title="Shep (module)">Shep</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Shep/Session.html" title="Shep::Session (class)">Session</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Shep/Session.html#initialize-instance_method" title="Shep::Session#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>host:</span> <span class='const'>HOST</span><span class='rparen'>)</span>
95
+
96
+ <span class='id identifier rubyid_ss'>ss</span><span class='period'>.</span><span class='id identifier rubyid_each_tag_status'>each_tag_status</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>caturday</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>only_media:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>limit:</span> <span class='int'>10</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_status'>status</span><span class='op'>|</span>
97
+ <span class='id identifier rubyid_ss'>ss</span><span class='period'>.</span><span class='id identifier rubyid_fetch_status_with_media'>fetch_status_with_media</span><span class='lparen'>(</span><span class='id identifier rubyid_status'>status</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span><span class='comma'>,</span> <span class='id identifier rubyid_media_dir'>media_dir</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>cat_pix</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
98
+ <span class='rbrace'>}</span>
99
+ </code></pre>
100
+
101
+ <p>And, of course, uploading cat pictures:</p>
102
+
103
+ <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'>shep</span><span class='tstring_end'>&#39;</span></span>
104
+
105
+ <span class='const'>HOST</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>... name of mastodon host goes here...</span><span class='tstring_end'>&quot;</span></span>
106
+ <span class='const'>TOKEN</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>...token goes here...</span><span class='tstring_end'>&quot;</span></span>
107
+
108
+ <span class='id identifier rubyid_ss'>ss</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Shep.html" title="Shep (module)">Shep</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Shep/Session.html" title="Shep::Session (class)">Session</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Shep/Session.html#initialize-instance_method" title="Shep::Session#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>host:</span> <span class='const'>HOST</span><span class='comma'>,</span> <span class='label'>token:</span> <span class='const'>TOKEN</span><span class='rparen'>)</span>
109
+
110
+ <span class='id identifier rubyid_img_obj'>img_obj</span> <span class='op'>=</span> <span class='id identifier rubyid_ss'>ss</span><span class='period'>.</span><span class='id identifier rubyid_upload_media'>upload_media</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>cat.jpg</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span>
111
+ <span class='label'>content_type:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>image/jpeg</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
112
+ <span class='label'>description:</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>A cat.</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
113
+
114
+ <span class='id identifier rubyid_post'>post</span> <span class='op'>=</span> <span class='id identifier rubyid_ss'>ss</span><span class='period'>.</span><span class='id identifier rubyid_post_status'>post_status</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Here is a picture of a cat.</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span>
115
+ <span class='label'>spoiler_text:</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>cat pic</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span>
116
+ <span class='label'>visibility:</span> <span class='symbol'>:public</span><span class='comma'>,</span>
117
+ <span class='label'>media_ids:</span> <span class='lbracket'>[</span><span class='id identifier rubyid_img_obj'>img_obj</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span><span class='rbracket'>]</span><span class='rparen'>)</span>
118
+
119
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Cat picture posted: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_post'>post</span><span class='period'>.</span><span class='id identifier rubyid_url'>url</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
120
+ </code></pre>
121
+
122
+ <p>It can also be used for other things.</p>
123
+
124
+ <h2 id="installation">Installation</h2>
125
+
126
+ <p>The usual way to install Shep is via gem:</p>
127
+
128
+ <pre class="code ruby"><code class="ruby">$ gem install shep --pre
129
+ </code></pre>
130
+
131
+ <p>Alternately, you can fetch this repo and add it to your Ruby path.</p>
132
+
133
+ <p>If you wish to develop Shep, you&#39;ll also need Rake, YARD, and RSpec.</p>
134
+
135
+ <h2 id="testing">Testing</h2>
136
+
137
+ <p>The tests are somewhat clever in that if there isn&#39;t a Mastodon
138
+ instance available or if you don&#39;t have a writable account on it, it
139
+ will still try to run tests that don&#39;t need those things.</p>
140
+
141
+ <p>On they other hand, some of the tests will fail if (e.g.) an account
142
+ doesn&#39;t have enough statuses with attached pictures. I&#39;ve tried to
143
+ document this when it happens. Usually, a test will fail rather than
144
+ let a part of the code go untested.</p>
145
+
146
+ <p>The tests get credentials from the environment. Normally, I run
147
+ <code>rake test</code> from a script that first sets those variables to useful
148
+ values.</p>
149
+
150
+ <p>The file <code>run_rake_test.example.sh</code> documents these variables and what
151
+ they do.</p>
152
+
153
+ <p>There are also a number of tricky tests (e.g. for rate-limit-reached
154
+ cases) that need to be explicitly invoked using rspec tags. See
155
+ <code>spec/session_zzz_tricky.rb</code> for details.</p>
156
+
157
+ <h2 id="license-and-warranty">License and Warranty</h2>
158
+
159
+ <p>Shep is available under the terms of the GNU Affero GPL Version 3 plus
160
+ an exemption that allows you to release programs that use it under
161
+ your own terms.</p>
162
+
163
+ <p>It is offered <strong>WITHOUT WARRANTY OF ANY KIND</strong>. If it breaks, you get to keep
164
+ the pieces.</p>
165
+
166
+ <p>While it is not legally required or enforcable, you are nontheless
167
+ honour-bound to use Shep only for good and never for evil.</p>
168
+ </div></div>
291
169
 
292
170
  <div id="footer">
293
- Generated on Sun Jun 4 13:40:28 2023 by
171
+ Generated on Sat Jun 10 19:16:28 2023 by
294
172
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
295
- 0.9.34 (ruby-3.1.0).
173
+ 0.9.34 (ruby-3.0.3).
296
174
  </div>
297
175
 
298
176
  </div>
data/doc/method_list.html CHANGED
@@ -366,13 +366,21 @@
366
366
 
367
367
  <li class="odd ">
368
368
  <div class="item">
369
- <span class='object_link'><a href="Shep/Session.html#verify_credentials-instance_method" title="Shep::Session#verify_credentials (method)">#verify_credentials</a></span>
369
+ <span class='object_link'><a href="Shep/Session.html#user_agent-instance_method" title="Shep::Session#user_agent (method)">#user_agent</a></span>
370
370
  <small>Shep::Session</small>
371
371
  </div>
372
372
  </li>
373
373
 
374
374
 
375
375
  <li class="even ">
376
+ <div class="item">
377
+ <span class='object_link'><a href="Shep/Session.html#verify_credentials-instance_method" title="Shep::Session#verify_credentials (method)">#verify_credentials</a></span>
378
+ <small>Shep::Session</small>
379
+ </div>
380
+ </li>
381
+
382
+
383
+ <li class="odd ">
376
384
  <div class="item">
377
385
  <span class='object_link'><a href="Shep/Entity.html#with-class_method" title="Shep::Entity.with (method)">with</a></span>
378
386
  <small>Shep::Entity</small>
@@ -100,9 +100,9 @@
100
100
  </div>
101
101
 
102
102
  <div id="footer">
103
- Generated on Sun Jun 4 13:40:29 2023 by
103
+ Generated on Sat Jun 10 19:16:28 2023 by
104
104
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
- 0.9.34 (ruby-3.1.0).
105
+ 0.9.34 (ruby-3.0.3).
106
106
  </div>
107
107
 
108
108
  </div>
@@ -128,9 +128,14 @@ module Shep
128
128
  #
129
129
  # @return [String]
130
130
  def to_s
131
+ maxlen = 20
131
132
  notable = self.disp_fields()
132
133
  .reject{|fld| getbox(fld).get_for_json.to_s.empty? }
133
- .map{|fld| "#{fld}=#{getbox(fld).get}"}
134
+ .map{|fld|
135
+ valtxt = getbox(fld).get
136
+ valtxt = valtxt[0..maxlen] + '...' unless valtxt.size < maxlen+3
137
+ "#{fld}=#{valtxt}"
138
+ }
134
139
  .join(",")
135
140
  notable = "0x#{self.object_id.to_s(16)}" if notable.empty?
136
141
 
@@ -58,6 +58,11 @@ module Shep
58
58
  end
59
59
  end
60
60
 
61
+ # Thrown when the HTTP operation fails because a rate limit was
62
+ # reached. `Session.rate_limit` will **probably** return the
63
+ # correct reset time, but no promises at this time.
64
+ class Error::RateLimit < Error::Http ; end
65
+
61
66
 
62
67
  private
63
68