json_ffi_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +55 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/json_ffi_client.gemspec +30 -0
- data/lib/json_ffi_client.rb +58 -0
- data/lib/json_ffi_client/version.rb +3 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2d891b33e4b3cfbef290c60aa57d679259f73b0b
|
4
|
+
data.tar.gz: e7641bf8f69795b8c1aaccf460e36d25124976f5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75cee4998c85f2705c1bb5c69d4597ca025c6ceacea8c1e0ff642d1306f9065efcccc3aa50ecfe94f4c62e7d6c08cc3fde24f2ef1611eba179d28f2571c67a7b
|
7
|
+
data.tar.gz: 92841d410fcd6802aed11ac3333138f5e881b8753a6fc51cd1c3f8a4fb130c195ee0afb845eedf1388c91a5c7022eea5e6a5aae737dac67d03721b1b0175857a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 nubis
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# JsonFfiClient
|
2
|
+
|
3
|
+
[![Build
|
4
|
+
Status](https://travis-ci.org/bitex-la/json-ffi-client-ruby.svg?branch=master)](https://travis-ci.org/bitex-la/json-ffi-client-ruby)
|
5
|
+
|
6
|
+
JSON-FFI is an implementation of the [jsonapi.org](http://jsonapi.org)
|
7
|
+
protocol where instead of hitting a server your client communicates
|
8
|
+
with a local shared library.
|
9
|
+
|
10
|
+
It's a way to bridge the gap between native libraries and dynamic languages.
|
11
|
+
|
12
|
+
This gem provides a Connection class for the "json_api_client" gem.
|
13
|
+
(it does not explicitly depend on "json_api_client though)
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'json_ffi_client'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install json_ffi_client
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Assuming:
|
34
|
+
|
35
|
+
- You have a library called "funky" acting as the JSON FFI server for a 'person' resource.
|
36
|
+
- You have versions of your libraries for Linux, OS X and Windows called "libfunky.so", "libfunky.dylib" and "libfunky.dll".
|
37
|
+
- All three live in the same directory as the file defining your JsonApiclient::Resource subclass.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
class Person < JsonApiClient::Resource
|
41
|
+
self.connection_class =
|
42
|
+
JsonFfiClient::Connection.configured_for(:funky, __dir__)
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
## Development
|
47
|
+
|
48
|
+
This gem could be the reference implementation for JSON FFI clients.
|
49
|
+
|
50
|
+
The JSON FFI protocol is in early stages of development.
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
55
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "json_ffi_client"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'json_ffi_client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "json_ffi_client"
|
8
|
+
spec.version = JsonFfiClient::VERSION
|
9
|
+
spec.authors = ["nubis"]
|
10
|
+
spec.email = ["nb@bitex.la"]
|
11
|
+
|
12
|
+
spec.summary = "Build ruby JSON-FFI clients using ffi & json_api_client"
|
13
|
+
spec.homepage = "https://github.com/bitex-la/json_ffi_client"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "ffi", "~> 1.9"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
spec.add_development_dependency "json_api_client", "~> 1.5"
|
29
|
+
spec.add_development_dependency "byebug", "~> 9.0"
|
30
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "json_ffi_client/version"
|
2
|
+
require "json"
|
3
|
+
require "ffi"
|
4
|
+
|
5
|
+
module JsonFfiClient
|
6
|
+
class Response < FFI::AutoPointer
|
7
|
+
def self.release(ptr)
|
8
|
+
Connection.free(ptr)
|
9
|
+
end
|
10
|
+
|
11
|
+
def body
|
12
|
+
@body ||= JSON.parse(self.read_string).delete_if{|k,v| v.nil?}
|
13
|
+
end
|
14
|
+
|
15
|
+
def env
|
16
|
+
{}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Connection
|
21
|
+
extend FFI::Library
|
22
|
+
def initialize(*args); end
|
23
|
+
|
24
|
+
def self.configured_for(library_name, base_path)
|
25
|
+
@@library_name = library_name
|
26
|
+
|
27
|
+
lib_ext = if(FFI::Platform.mac?)
|
28
|
+
"dylib"
|
29
|
+
elsif(FFI::Platform.windows?)
|
30
|
+
"dll"
|
31
|
+
else
|
32
|
+
"so"
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
ffi_lib File.join(base_path, "lib#{library_name}.#{lib_ext}")
|
37
|
+
rescue LoadError => e
|
38
|
+
raise Error
|
39
|
+
.new("#{e.message}. Maybe '#{RUBY_PLATFORM}' is not supported.")
|
40
|
+
end
|
41
|
+
|
42
|
+
attach_function :free, "#{library_name}_free".to_sym, [Response], :void
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.method_missing(message, *args, &blk)
|
47
|
+
attach_function message, message, [:string], Response
|
48
|
+
send(message, *args)
|
49
|
+
end
|
50
|
+
|
51
|
+
def run(method, path, params = {}, headers = {})
|
52
|
+
raise JsonFfiError.new("Connection not configured") unless @@library_name
|
53
|
+
self.class.send([@@library_name, method, path].join("_"), params.to_json)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class Error < StandardError; end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: json_ffi_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nubis
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json_api_client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.5'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '9.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '9.0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- nb@bitex.la
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- json_ffi_client.gemspec
|
114
|
+
- lib/json_ffi_client.rb
|
115
|
+
- lib/json_ffi_client/version.rb
|
116
|
+
homepage: https://github.com/bitex-la/json_ffi_client
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.5.1
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Build ruby JSON-FFI clients using ffi & json_api_client
|
140
|
+
test_files: []
|