horizon_client 0.2.4 → 0.2.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a09ff2207ac1aa1126e230bb2ee830eaf14a2e6
4
- data.tar.gz: 1724912405629ad741618a8540fbfcd4d2d46291
3
+ metadata.gz: aa6fb3b22042245289db4e5443406ad15cbf576f
4
+ data.tar.gz: 2d510a56cf7537485ebefb8127be6ca880a16683
5
5
  SHA512:
6
- metadata.gz: 6ef53c0b0b7c6be9205b38050a7c1e219a04539325ddcc6abbab73c02c1b804f895f931a89df943b5f73e18675f22c0d40f63b2f9ec5ef16a04ea7e50cd95ceb
7
- data.tar.gz: 6e39897251b8e72dee64c7fc00c6349a03b70b4378435ba5f20625899ed1a5db08eb5ef72f2b87b6c90e7ee69c7368ab57ac48bf30738ff0b9dc012c8ce73ea1
6
+ metadata.gz: 7b91a02d168edade641969f3a54e78508ac434273fe45b544b3fab71fcd3648001426a8a61dd9cfd9668567f2c22f211800aecec08ad5c60d1b9e8c3d7915b29
7
+ data.tar.gz: dc916a151fc23030dec5daec7b74026140a878dc4cfcde01a899fd2e591dde99e5543173387077595aa54c01cdefa8f17d1d2b3364aa05134229cb1781cc4a55
data/README.md CHANGED
@@ -41,6 +41,12 @@ client.logger = Logger.new(STDOUT)
41
41
  # <row>
42
42
  # </row>
43
43
  # </collection>
44
+ # <group>
45
+ # <link>
46
+ # </link>
47
+ # <link>
48
+ # </link>
49
+ # </group>
44
50
  # </resource>
45
51
 
46
52
  # returns and expects HorizonClient::Resource object
@@ -77,6 +83,9 @@ entity_array.each do |entity|
77
83
  entity['foo'] = 'test'
78
84
  end
79
85
 
86
+ # get group with links, it behaves just like collection
87
+ group = resource.group
88
+
80
89
  ```
81
90
 
82
91
 
@@ -6,13 +6,13 @@ module HorizonClient
6
6
 
7
7
  def initialize(node)
8
8
  @node = node
9
- @rows = @node.locate('row').map do |row|
9
+ @rows = @node.locate(row_element_name).map do |row|
10
10
  Entity.new(row)
11
11
  end
12
12
  end
13
13
 
14
14
  def build
15
- row = Ox::Element.new('row')
15
+ row = Ox::Element.new(row_element_name)
16
16
  node << row
17
17
  entity = Entity.new(row)
18
18
  @rows.push(entity)
@@ -26,5 +26,11 @@ module HorizonClient
26
26
  def each(&block)
27
27
  @rows.each(&block)
28
28
  end
29
+
30
+ private
31
+
32
+ def row_element_name
33
+ 'row'
34
+ end
29
35
  end
30
36
  end
@@ -0,0 +1,49 @@
1
+ module HorizonClient
2
+ class Connection
3
+ attr_accessor :logger
4
+
5
+ def initialize(url = nil)
6
+ url ||= ENV['HORIZON_REST_URL']
7
+
8
+ @connection = Faraday.new url do |conn|
9
+ conn.response :raise_error
10
+ conn.use HorizonClient::Response::ParseXml
11
+ conn.use HorizonClient::Request::EncodeXml
12
+
13
+ conn.adapter Faraday.default_adapter
14
+ end
15
+ end
16
+
17
+ def url_prefix
18
+ @connection.url_prefix
19
+ end
20
+
21
+ def get(path = '', params = {})
22
+ log "GET #{path}", params do
23
+ response = @connection.get path, params
24
+ response.body
25
+ end
26
+ end
27
+
28
+ def post(path = '', body)
29
+ log "GET #{path}", {body: body} do
30
+ response = @connection.post do |req|
31
+ req.url path
32
+ req.headers['Content-Type'] = 'application/xml;charset=UTF-8'
33
+ req.body = body
34
+ end
35
+
36
+ response.body
37
+ end
38
+ end
39
+
40
+ def log(message, params = {})
41
+ t1 = Time.now
42
+ yield
43
+ ensure
44
+ t2 = Time.now
45
+ duration = (t2 - t1) / 1000
46
+ logger.info "Horizon (#{duration}ms) #{message} #{params.inspect}" if logger
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,10 @@
1
+ module HorizonClient
2
+ class Group < Collection
3
+
4
+ private
5
+
6
+ def row_element_name
7
+ 'link'
8
+ end
9
+ end
10
+ end
@@ -21,6 +21,11 @@ module HorizonClient
21
21
  @collection ||= Collection.new(node)
22
22
  end
23
23
 
24
+ def group
25
+ node = @document.resource.group
26
+ @group ||= Group.new(node)
27
+ end
28
+
24
29
  def error
25
30
  if document.respond_to?('error')
26
31
  document.error.message.text
@@ -1,3 +1,3 @@
1
1
  module HorizonClient
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -2,63 +2,18 @@ require "horizon_client/version"
2
2
  require "faraday"
3
3
  require "ox"
4
4
 
5
+ require 'horizon_client/connection'
6
+
5
7
  require 'horizon_client/response/parse_xml'
6
8
  require 'horizon_client/request/encode_xml'
7
9
 
8
10
  require "horizon_client/resource"
9
11
  require "horizon_client/collection"
12
+ require "horizon_client/group"
10
13
  require "horizon_client/entity"
11
14
 
12
15
  module HorizonClient
13
16
  def self.new(*args)
14
17
  Connection.new(*args)
15
18
  end
16
-
17
- class Connection
18
- attr_accessor :logger
19
-
20
- def initialize(url = nil)
21
- url ||= ENV['HORIZON_REST_URL']
22
-
23
- @connection = Faraday.new url do |conn|
24
- conn.response :raise_error
25
- conn.use HorizonClient::Response::ParseXml
26
- conn.use HorizonClient::Request::EncodeXml
27
-
28
- conn.adapter Faraday.default_adapter
29
- end
30
- end
31
-
32
- def url_prefix
33
- @connection.url_prefix
34
- end
35
-
36
- def get(path = '', params = {})
37
- log "GET #{path}", params do
38
- response = @connection.get path, params
39
- response.body
40
- end
41
- end
42
-
43
- def post(path = '', body)
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
52
- end
53
- end
54
-
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
62
- end
63
- end
64
19
  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
4
+ version: 0.2.5
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-24 00:00:00.000000000 Z
11
+ date: 2017-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,7 +112,9 @@ files:
112
112
  - horizon_client.gemspec
113
113
  - lib/horizon_client.rb
114
114
  - lib/horizon_client/collection.rb
115
+ - lib/horizon_client/connection.rb
115
116
  - lib/horizon_client/entity.rb
117
+ - lib/horizon_client/group.rb
116
118
  - lib/horizon_client/request/encode_xml.rb
117
119
  - lib/horizon_client/resource.rb
118
120
  - lib/horizon_client/response/parse_xml.rb