machine-gun 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.
- checksums.yaml +7 -0
- data/lib/machine-gun.h +62 -0
- data/lib/machine-gun.rb +23 -0
- data/lib/machine-gun.so +0 -0
- data/lib/machine-gun/bridge.rb +28 -0
- data/lib/machine-gun/commands.rb +28 -0
- data/lib/machine-gun/request.rb +19 -0
- data/lib/machine-gun/response.rb +21 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fc41498deb5502dd39588f7a30fe6364cfefb1b8
|
4
|
+
data.tar.gz: 3f9e0c38485725896eaa056a567eec1a4b0bd4e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2221c00c3c828811de0b0490f31632b0cad4f2052daa73a286bfa88a9b7742dfb14e3a154dcc79427b6384c4deeee86e8671967362430db30699ab719d4ea5d5
|
7
|
+
data.tar.gz: c6b691f539e4666a5fb4b6e753457ca5100659973038dade409f6db153c03e24fe02e69e80a803e8694814469102bdc731903ead2ba96d2e6c757584c6060c36
|
data/lib/machine-gun.h
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
/* Created by "go tool cgo" - DO NOT EDIT. */
|
2
|
+
|
3
|
+
/* package command-line-arguments */
|
4
|
+
|
5
|
+
/* Start of preamble from import "C" comments. */
|
6
|
+
|
7
|
+
|
8
|
+
#line 3 "/Users/chakrit/Documents/machine-gun/src/bridge.go"
|
9
|
+
#include <stdlib.h>
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
/* End of preamble from import "C" comments. */
|
14
|
+
|
15
|
+
|
16
|
+
/* Start of boilerplate cgo prologue. */
|
17
|
+
|
18
|
+
#ifndef GO_CGO_PROLOGUE_H
|
19
|
+
#define GO_CGO_PROLOGUE_H
|
20
|
+
|
21
|
+
typedef signed char GoInt8;
|
22
|
+
typedef unsigned char GoUint8;
|
23
|
+
typedef short GoInt16;
|
24
|
+
typedef unsigned short GoUint16;
|
25
|
+
typedef int GoInt32;
|
26
|
+
typedef unsigned int GoUint32;
|
27
|
+
typedef long long GoInt64;
|
28
|
+
typedef unsigned long long GoUint64;
|
29
|
+
typedef GoInt64 GoInt;
|
30
|
+
typedef GoUint64 GoUint;
|
31
|
+
typedef __SIZE_TYPE__ GoUintptr;
|
32
|
+
typedef float GoFloat32;
|
33
|
+
typedef double GoFloat64;
|
34
|
+
typedef __complex float GoComplex64;
|
35
|
+
typedef __complex double GoComplex128;
|
36
|
+
|
37
|
+
// static assertion to make sure the file is being used on architecture
|
38
|
+
// at least with matching size of GoInt.
|
39
|
+
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
|
40
|
+
|
41
|
+
typedef struct { char *p; GoInt n; } GoString;
|
42
|
+
typedef void *GoMap;
|
43
|
+
typedef void *GoChan;
|
44
|
+
typedef struct { void *t; void *v; } GoInterface;
|
45
|
+
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
46
|
+
|
47
|
+
#endif
|
48
|
+
|
49
|
+
/* End of boilerplate cgo prologue. */
|
50
|
+
|
51
|
+
#ifdef __cplusplus
|
52
|
+
extern "C" {
|
53
|
+
#endif
|
54
|
+
|
55
|
+
|
56
|
+
extern GoInt Free(void* p0);
|
57
|
+
|
58
|
+
extern GoInt BridgeCommand(char* p0, char* p1, char** p2);
|
59
|
+
|
60
|
+
#ifdef __cplusplus
|
61
|
+
}
|
62
|
+
#endif
|
data/lib/machine-gun.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'machine-gun/bridge'
|
2
|
+
require 'machine-gun/commands'
|
3
|
+
require 'machine-gun/request'
|
4
|
+
require 'machine-gun/response'
|
5
|
+
|
6
|
+
module MachineGun
|
7
|
+
def self.start
|
8
|
+
Commands.start
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.stop
|
12
|
+
Commands.stop
|
13
|
+
end
|
14
|
+
|
15
|
+
class Error < StandardError
|
16
|
+
attr_accessor :code
|
17
|
+
|
18
|
+
def initialize(code, message)
|
19
|
+
super message
|
20
|
+
@code = code
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/machine-gun.so
ADDED
Binary file
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module MachineGun
|
5
|
+
module Bridge
|
6
|
+
extend FFI::Library
|
7
|
+
|
8
|
+
ffi_lib './lib/machine-gun.so'
|
9
|
+
attach_function :Free, [:pointer], :int
|
10
|
+
|
11
|
+
attach_function :BridgeCommand, [:string, :string, :pointer], :int
|
12
|
+
def self.command(cmd, in_hash)
|
13
|
+
input = JSON.generate(in_hash) rescue nil
|
14
|
+
|
15
|
+
out_ptr = FFI::MemoryPointer.new(:pointer, 1)
|
16
|
+
BridgeCommand(cmd, input, out_ptr)
|
17
|
+
out_json = out_ptr.read_pointer.read_string.force_encoding('UTF-8')
|
18
|
+
Free(out_ptr.read_pointer)
|
19
|
+
|
20
|
+
result = JSON.load(out_json)
|
21
|
+
if result && result["error"]
|
22
|
+
raise Error.new(result["code"], result["error"])
|
23
|
+
end
|
24
|
+
|
25
|
+
result
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module MachineGun
|
2
|
+
module Commands
|
3
|
+
def self.ping(input)
|
4
|
+
Bridge.command('ping', input)["pong"]
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.start
|
8
|
+
Bridge.command('start', { })
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.stop
|
12
|
+
Bridge.command('stop', { })
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.request(method, url, headers, payload=nil)
|
16
|
+
Bridge.command('request', {
|
17
|
+
method: method,
|
18
|
+
url: url,
|
19
|
+
headers: headers,
|
20
|
+
payload: payload
|
21
|
+
})["id"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.response(id)
|
25
|
+
Bridge.command('response', id: id)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MachineGun
|
2
|
+
class Request
|
3
|
+
attr_accessor :id
|
4
|
+
attr_accessor :method
|
5
|
+
attr_accessor :url
|
6
|
+
attr_accessor :headers
|
7
|
+
attr_accessor :payload
|
8
|
+
|
9
|
+
def initialize(method, url, headers, payload=nil)
|
10
|
+
@id = Commands.request(method, url, headers, payload)
|
11
|
+
@method = method
|
12
|
+
end
|
13
|
+
|
14
|
+
def response
|
15
|
+
Response.new(@id)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module MachineGun
|
2
|
+
class Response
|
3
|
+
attr_accessor :id
|
4
|
+
attr_accessor :status_code
|
5
|
+
attr_accessor :headers
|
6
|
+
attr_accessor :payload
|
7
|
+
|
8
|
+
def initialize(id)
|
9
|
+
response = Commands.response(id)
|
10
|
+
|
11
|
+
@id = id
|
12
|
+
@status_code = response["status_code"]
|
13
|
+
@headers = response["headers"]
|
14
|
+
@payload = response["payload"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def payload_as_json
|
18
|
+
JSON.load(@payload)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: machine-gun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chakrit Wichian
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-24 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: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: spy
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.11'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.11'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.8'
|
97
|
+
description: Send multiple HTTP requests simultaneously from a single ruby Thread,
|
98
|
+
powered by goroutines.
|
99
|
+
email: chakrit@omise.co
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- lib/machine-gun.h
|
105
|
+
- lib/machine-gun.rb
|
106
|
+
- lib/machine-gun.so
|
107
|
+
- lib/machine-gun/bridge.rb
|
108
|
+
- lib/machine-gun/commands.rb
|
109
|
+
- lib/machine-gun/request.rb
|
110
|
+
- lib/machine-gun/response.rb
|
111
|
+
homepage: https://www.omise.co
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.4.5.1
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Fire HTTP requests like a machine gun.
|
135
|
+
test_files: []
|