horizon_client 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -0
- data/lib/horizon_client.rb +22 -7
- data/lib/horizon_client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7c21225a65811cbf379c2ffdc95cda48899ba9f
|
4
|
+
data.tar.gz: 5c7a368fb38adee65510e6e4201ddba0b028e11a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0791f4f98d51f6de68f063c4d5bd005efbf5523cd6195ca405440b054e86f19d9fed8c3f4db7c9de55419c965332e00ef9ea9f2aff61e503de1ccd17aa93a833
|
7
|
+
data.tar.gz: 89a9973737c804a89ae4c34c2f1cee1016190ed4293ea175c242884f1e829ba64829df6b1f43975f46832287f6954f91d5e70e51136c5830cff64b04c4b6e435
|
data/README.md
CHANGED
@@ -2,10 +2,31 @@
|
|
2
2
|
|
3
3
|
Client to use with Horizon REST xml API.
|
4
4
|
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'horizon_client'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ gem install horizon_client
|
23
|
+
```
|
24
|
+
|
5
25
|
## Usage
|
6
26
|
|
7
27
|
```ruby
|
8
28
|
client = HorizonClient.new
|
29
|
+
client.logger = Logger.new(STDOUT)
|
9
30
|
|
10
31
|
# incoming xml:
|
11
32
|
# <?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
data/lib/horizon_client.rb
CHANGED
@@ -15,6 +15,8 @@ module HorizonClient
|
|
15
15
|
end
|
16
16
|
|
17
17
|
class Connection
|
18
|
+
attr_accessor :logger
|
19
|
+
|
18
20
|
def initialize(url = nil)
|
19
21
|
url ||= ENV['HORIZON_REST_URL']
|
20
22
|
|
@@ -32,18 +34,31 @@ module HorizonClient
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def get(path = '', params = {})
|
35
|
-
|
36
|
-
|
37
|
+
log "GET #{path}", params do
|
38
|
+
response = @connection.get path, params
|
39
|
+
response.body
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
def post(path = '', body)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
+
log "GET #{path}", {body: body} do
|
45
|
+
response = @connection.post do |req|
|
46
|
+
req.url path
|
47
|
+
req.headers['Content-Type'] = 'application/xml;charset=UTF-8'
|
48
|
+
req.body = body
|
49
|
+
end
|
50
|
+
|
51
|
+
response.body
|
44
52
|
end
|
53
|
+
end
|
45
54
|
|
46
|
-
|
55
|
+
def log(message, params = {})
|
56
|
+
t1 = Time.now
|
57
|
+
yield
|
58
|
+
ensure
|
59
|
+
t2 = Time.now
|
60
|
+
duration = (t2 - t1) / 1000
|
61
|
+
logger.info "Horizon (#{duration}ms) #{message} #{params.inspect}" if logger
|
47
62
|
end
|
48
63
|
end
|
49
64
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: horizon_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MAK IT
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|