joshua 0.1.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.
Binary file
@@ -0,0 +1,52 @@
1
+ # api = JoshuaRemote.new 'http://localhost:4567/api', debug: true
2
+ # api.company(1).index
3
+ # api.call 'company/1/index'
4
+ # api.call [:company, 1, :index]
5
+ # api.call :company, 1, :index
6
+ # api.success?
7
+ # api.response
8
+
9
+ require 'awesome_print'
10
+ require 'http'
11
+
12
+ class JoshuaRemote
13
+ attr_reader :response
14
+
15
+ def initialize root, debug: false
16
+ @debug = debug
17
+ @root = root
18
+ @path = []
19
+ end
20
+
21
+ def method_missing name, *args
22
+ @path.push name
23
+ return call if @path[1]
24
+ @path.push args.first if args.first
25
+ self
26
+ end
27
+
28
+ def call *args
29
+ path =
30
+ if args.first
31
+ args = args.flatten
32
+ args[1] ? args.join('/') : args.first
33
+ else
34
+ '/' + @path.join('/')
35
+ end
36
+
37
+ path = [@root, path].join('/')
38
+ puts 'Joshua: %s' % path if @debug
39
+
40
+ @path = []
41
+ @response = JSON.parse HTTP.get(path).to_s
42
+ end
43
+
44
+ def success?
45
+ @response['success'] == true
46
+ end
47
+
48
+ def error?
49
+ !success?
50
+ end
51
+ end
52
+
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: joshua
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dino Reic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-inflector
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Ruby language based, framework agnostic API request/response lib
42
+ email: rejotl@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - "./.version"
48
+ - "./lib/.DS_Store"
49
+ - "./lib/doc/doc.rb"
50
+ - "./lib/doc/special.rb"
51
+ - "./lib/joshua.rb"
52
+ - "./lib/joshua/base.rb"
53
+ - "./lib/joshua/error.rb"
54
+ - "./lib/joshua/opts.rb"
55
+ - "./lib/joshua/params/define.rb"
56
+ - "./lib/joshua/params/parse.rb"
57
+ - "./lib/joshua/params/types.rb"
58
+ - "./lib/joshua/params/types_errors.rb"
59
+ - "./lib/joshua/response.rb"
60
+ - "./lib/misc/api_example.coffee"
61
+ - "./lib/misc/doc.css"
62
+ - "./lib/misc/doc.js"
63
+ - "./lib/misc/favicon.png"
64
+ - "./lib/misc/ruby_client.rb"
65
+ homepage: http://github.com/dux/joshua
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.0.6
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Joshua
88
+ test_files: []