rpc-json 0.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.
Files changed (5) hide show
  1. data.tar.gz.sig +1 -0
  2. data/UNLICENSE +24 -0
  3. data/lib/rpc-json.rb +54 -0
  4. metadata +100 -0
  5. metadata.gz.sig +2 -0
data.tar.gz.sig ADDED
@@ -0,0 +1 @@
1
+ ��_D\|��{�,�ymǍ�_G��Ij���g�@����0}���H �-����?K���\J�>�����]��>&C^��9�}ժ��+���ɞ�\Ѿ���Xʤ�Z���'%X���n���4�y/���Ƴz�໤ԭ���ɻ@ޢT �à�q��O�~���E�Ŀ��|�!"�;�������
data/UNLICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
data/lib/rpc-json.rb ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ require 'uri'
3
+ require 'json'
4
+ require 'rest_client'
5
+
6
+ class RPCJSONError < Exception
7
+ end
8
+
9
+ # Communicate with a JSON RPC server.
10
+ class RPCJSON
11
+ def initialize(url)
12
+ @url = url
13
+ end
14
+
15
+ # Call the remote method meth with args. We raise NoMethodError if meth
16
+ # doesn't exist on the remote side, and RPCJSONError if an error occured on
17
+ # the server.
18
+ def call(meth, *args)
19
+ begin
20
+ resp = RestClient.post(@url, {method: meth, params: args,
21
+ id: :jsonrpc}.to_json)
22
+ rescue RestClient::ResourceNotFound => ex
23
+ if ex.http_code == 404
24
+ raise(NoMethodError, "undefined method `#{meth}' for #{self}")
25
+ else
26
+ raise
27
+ end
28
+ rescue RestClient::InternalServerError => ex
29
+ if ex.http_code == 500
30
+ raise(RPCJSONError, JSON.parse(ex.http_body)['error']['message'])
31
+ else
32
+ raise
33
+ end
34
+ end
35
+
36
+ parsed = JSON.parse(resp)
37
+ raise(RPCJSONError, parsed['error']) if parsed['error']
38
+
39
+ parsed['result']
40
+ end
41
+
42
+ # Call call(meth, *args). If no error is raised, define_singleton_method(meth)
43
+ # to do the same.
44
+ def method_missing(meth, *args)
45
+ ret = call(meth, *args)
46
+
47
+ # Make it so meth shows up in our methods list.
48
+ unless methods.include?(meth.to_sym)
49
+ define_singleton_method(meth) { |*args_| call(meth, *args_) }
50
+ end
51
+
52
+ ret
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rpc-json
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - katmagic
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - ! '-----BEGIN CERTIFICATE-----
13
+
14
+ MIIDQDCCAiigAwIBAgIBADANBgkqhkiG9w0BAQUFADBGMRgwFgYDVQQDDA90aGUu
15
+
16
+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M2ijzwsVNUMUr7R58LoCnQZrZ/YaRW
45
+
46
+ ob6QnVgwqu5SUAKQxlFJ/aKlPMj735z8EogaZC1ZHgg3vkgGGyu57N/8BDDG0TzC
47
+
48
+ Zn3u2leVae/fJ03zYGArhuJKPgc=
49
+
50
+ -----END CERTIFICATE-----
51
+
52
+ '
53
+ date: 2011-12-03 00:00:00.000000000 Z
54
+ dependencies:
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest_client
57
+ requirement: &79528650 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: *79528650
66
+ description:
67
+ email: the.magical.kat@gmail.com
68
+ executables: []
69
+ extensions: []
70
+ extra_rdoc_files: []
71
+ files:
72
+ - lib/rpc-json.rb
73
+ - UNLICENSE
74
+ homepage: https://github.com/katmagic/rpc-json
75
+ licenses:
76
+ - Public Domain
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.10
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Communicate with a JSON RPC server.
99
+ test_files: []
100
+ has_rdoc:
metadata.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ q�S�Է���Ҁ�rm,��0�ܚ�m����N.1��w�`2颼>�vN"�<o�jEyB?q!uw?�m@���}�0hw��xJ�4
2
+ ��{�� 87B��@�B���n1��Oa��fA/\�I��W�L����Jd����6�P�h�@%]����6�]�ԤI�I����E���)�C�'Bj�YK��f���lc����6�!qNzk�ڝ)\Gpg!���