clamo 0.4.0 → 0.5.0

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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +140 -2
  3. data/lib/clamo/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50a648eb843f70c35499806bb4f53736046560d333af184759917ff10f321dbe
4
- data.tar.gz: ce450a2e07864e7908ec0321f1f1f116168dbe6fd7ae7cc054bffc84442f33d5
3
+ metadata.gz: 93acbb6067140d2268cec5379f519ab6e693949f36f76e3933f8a93c246dbd96
4
+ data.tar.gz: 6811ac69e7b7b405991d2b1ce73e7138f4fb0709101e482da7f3744826dec592
5
5
  SHA512:
6
- metadata.gz: 242c0a8d44b69ada88887001943213ab8a6cd074eecfec4482e08de60b39d505df2fd58b4e34a7f00b2266250e3d54f07bc187b036dc08d47889ec1fe55d6140
7
- data.tar.gz: 4c72e3384fd958d1e9fe2a5a5b0ae607c4a667fbb9bc69eb04b1c8a10889ced46fd7caa47e8cc8f413dc5aec1746104c509c83165ec70863b4e02cc717090845
6
+ metadata.gz: 1c83b16bd8e702714fca22d0277206538f22c560f795ed01f8ae76268304209b2ae0669e988e3897725a62856fe286832ffe3f3993cdd99040659a4178373efb
7
+ data.tar.gz: bed60d4e01db858ea8875c420258c5754efdaa21a34cdb35b337c13168c811f6c2f7945f0510680fb872644ddf9d872a9a30f7ecbd164010d4eddf3d8dac7edc
data/README.md CHANGED
@@ -14,15 +14,153 @@ If bundler is not being used to manage dependencies, install the gem by executin
14
14
 
15
15
  $ gem install clamo
16
16
 
17
+
18
+ ## Development
19
+
20
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
21
+
22
+ To install this gem onto your local machi# Clamo
23
+
24
+ A Ruby implementation of [JSON-RPC 2.0](https://www.jsonrpc.org/specification) designed for simplicity and compliance with the specification.
25
+
26
+
17
27
  ## Usage
18
28
 
19
- TODO: Write usage instructions here
29
+ ### Basic Usage
30
+
31
+ ```ruby
32
+ require 'clamo'
33
+
34
+ # Define a service object with methods you want to expose
35
+ module MyService
36
+ def self.add(a, b)
37
+ a + b
38
+ end
39
+
40
+ def self.subtract(a:, b:)
41
+ a - b
42
+ end
43
+
44
+ # Private methods won't be accessible via JSON-RPC
45
+ private_class_method def self.internal_method
46
+ # This won't be exposed
47
+ end
48
+ end
49
+
50
+ # Handle a JSON-RPC request
51
+ request_body = '{"jsonrpc": "2.0", "method": "add", "params": [1, 2], "id": 1}'
52
+ response = Clamo::Server.unparsed_dispatch_to_object(
53
+ request: request_body,
54
+ object: MyService
55
+ )
56
+
57
+ puts response
58
+ # => {"jsonrpc":"2.0","result":3,"id":1}
59
+ ```
60
+
61
+ ### Handling Different Parameter Types
62
+
63
+ Clamo supports both positional (array) and named (object/hash) parameters:
64
+
65
+ ```ruby
66
+ # Positional parameters
67
+ request = '{"jsonrpc": "2.0", "method": "add", "params": [1, 2], "id": 1}'
68
+
69
+ # Named parameters
70
+ request = '{"jsonrpc": "2.0", "method": "subtract", "params": {"a": 5, "b": 3}, "id": 2}'
71
+ ```
72
+
73
+ ### Batch Requests
74
+
75
+ Clamo handles batch requests automatically:
76
+
77
+ ```ruby
78
+ batch_request = <<~JSON
79
+ [
80
+ {"jsonrpc": "2.0", "method": "add", "params": [1, 2], "id": 1},
81
+ {"jsonrpc": "2.0", "method": "subtract", "params": {"a": 5, "b": 3}, "id": 2}
82
+ ]
83
+ JSON
84
+
85
+ batch_response = Clamo::Server.unparsed_dispatch_to_object(
86
+ request: batch_request,
87
+ object: MyService
88
+ )
89
+
90
+ puts batch_response
91
+ # => [{"jsonrpc":"2.0","result":3,"id":1},{"jsonrpc":"2.0","result":2,"id":2}]
92
+ ```
93
+
94
+ ### Notifications
95
+
96
+ Notifications are requests without an ID field. They don't produce a response:
97
+
98
+ ```ruby
99
+ notification = '{"jsonrpc": "2.0", "method": "add", "params": [1, 2]}'
100
+ response = Clamo::Server.unparsed_dispatch_to_object(
101
+ request: notification,
102
+ object: MyService
103
+ )
104
+
105
+ puts response
106
+ # => nil
107
+ ```
108
+
109
+ ### Building JSON-RPC Requests
110
+
111
+ Clamo provides utilities for building JSON-RPC requests:
112
+
113
+ ```ruby
114
+ request = Clamo::JSONRPC.build_request(
115
+ method: "add",
116
+ params: [1, 2],
117
+ id: 1
118
+ )
119
+
120
+ puts request
121
+ # => {:jsonrpc=>"2.0", :method=>"add", :params=>[1, 2], :id=>1}
122
+ ```
123
+
124
+ ## Error Handling
125
+
126
+ Clamo follows the JSON-RPC 2.0 specification for error handling:
127
+
128
+ | Error Code | Message | Description |
129
+ |------------|------------------|------------------------------------------------------|
130
+ | -32700 | Parse error | Invalid JSON was received |
131
+ | -32600 | Invalid request | The JSON sent is not a valid Request object |
132
+ | -32601 | Method not found | The method does not exist / is not available |
133
+ | -32602 | Invalid params | Invalid method parameter(s) |
134
+ | -32603 | Internal error | Internal JSON-RPC error |
135
+ | -32000 | Server error | Reserved for implementation-defined server errors |
136
+
137
+ ## Advanced Features
138
+
139
+ ### Parallel Processing
140
+
141
+ Batch requests are processed in parallel using the [parallel](https://github.com/grosser/parallel) gem. You can pass options to `Parallel.map` via the `parsed_dispatch_to_object` method:
142
+
143
+ ```ruby
144
+ Clamo::Server.parsed_dispatch_to_object(
145
+ request: batch_request,
146
+ object: MyService,
147
+ in_processes: 4 # Parallel processing option
148
+ )
149
+ ```
20
150
 
21
151
  ## Development
22
152
 
23
153
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
154
 
25
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
155
+ To install this gem onto your local machine, run `bundle exec rake install`.
156
+
157
+ ## Contributing
158
+
159
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/clamo.
160
+
161
+ ## License
162
+
163
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).ne, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
164
 
27
165
  ## Contributing
28
166
 
data/lib/clamo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Clamo
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clamo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andriy Tyurnikov