bridge_api 0.0.14 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bridge_api/api_array.rb +23 -12
- data/lib/bridge_api/client.rb +2 -3
- data/lib/bridge_api/client/manager.rb +7 -2
- data/lib/bridge_api/version.rb +1 -1
- data/spec/bridge_api/client/manager_spec.rb +4 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32715294cbf0a4012da38a0664923ac8a5f9560e
|
4
|
+
data.tar.gz: 30dc2aacd810e8387cf3d1ad5354680219772970
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 450207f9fc4039e3740540a3f1076fa3a3eb5ff4b1688aa66470e2df6b9d1154dd9af2d8231f14e778b3a830c3e3cc7104ae79b78f644de77c8d0053b813ee9d
|
7
|
+
data.tar.gz: 3fcba14431b03b2ec2102d9d59c35741d93c564bc0c90841bb8eab56c59a8a877c2965abdd4295b4a64e07710af245053eb31110098eb7bd0d06fce961a676d0
|
data/lib/bridge_api/api_array.rb
CHANGED
@@ -6,18 +6,29 @@ module BridgeAPI
|
|
6
6
|
@next_page = nil
|
7
7
|
@prev_page = nil
|
8
8
|
|
9
|
-
META_FIELDS = %w(meta linked).freeze
|
10
|
-
|
11
9
|
attr_reader :status, :headers, :members
|
12
10
|
|
13
|
-
def self.process_response(response, api_client)
|
14
|
-
ApiArray.new(response, api_client)
|
11
|
+
def self.process_response(response, api_client, result_mapping)
|
12
|
+
ApiArray.new(response, api_client, result_mapping)
|
15
13
|
end
|
16
14
|
|
17
|
-
def initialize(response, api_client)
|
15
|
+
def initialize(response, api_client, result_mapping)
|
16
|
+
@meta_fields = %w(meta linked)
|
18
17
|
@api_client = api_client
|
19
18
|
@linked = {}
|
20
19
|
@meta = {}
|
20
|
+
@extra_meta_fields = []
|
21
|
+
pattern = /.*(\/api\/.*)/
|
22
|
+
path = response.env.url
|
23
|
+
matches = pattern.match(path.to_s)
|
24
|
+
mapping = nil
|
25
|
+
if matches
|
26
|
+
mapping_exists = result_mapping.key?(matches[1])
|
27
|
+
mapping = result_mapping[matches[1]] if mapping_exists
|
28
|
+
end
|
29
|
+
unless mapping.nil?
|
30
|
+
@extra_meta_fields.concat(mapping[:meta])
|
31
|
+
end
|
21
32
|
case response.status
|
22
33
|
when *((200..206).to_a + [302])
|
23
34
|
apply_response_metadata(response)
|
@@ -101,14 +112,11 @@ module BridgeAPI
|
|
101
112
|
|
102
113
|
def get_response_content(response)
|
103
114
|
return [] unless response.body.is_a?(Hash)
|
104
|
-
content = response.body.reject{|k, v|
|
105
|
-
if content.length >
|
106
|
-
content
|
107
|
-
elsif content.length == 1
|
108
|
-
content.values[0]
|
109
|
-
else
|
110
|
-
[]
|
115
|
+
content = response.body.reject{|k, v| @meta_fields.include?(k) || @extra_meta_fields.include?(k)}
|
116
|
+
if content.length > 0
|
117
|
+
return content.values[0]
|
111
118
|
end
|
119
|
+
[]
|
112
120
|
end
|
113
121
|
|
114
122
|
def apply_response_metadata(response, concat = true)
|
@@ -133,6 +141,9 @@ module BridgeAPI
|
|
133
141
|
def init_meta(response)
|
134
142
|
if response.body.is_a?(Hash) && response.body.key?('meta')
|
135
143
|
@meta = @meta.merge(response.body['meta']){|key,oldval,newval| [*oldval].to_a + [*newval].to_a }
|
144
|
+
@extra_meta_fields.each do |field|
|
145
|
+
@meta[field] = response.body[field]
|
146
|
+
end
|
136
147
|
end
|
137
148
|
end
|
138
149
|
|
data/lib/bridge_api/client.rb
CHANGED
@@ -7,7 +7,6 @@ require 'footrest/follow_redirects'
|
|
7
7
|
require 'footrest/parse_json'
|
8
8
|
require 'base64'
|
9
9
|
|
10
|
-
|
11
10
|
module BridgeAPI
|
12
11
|
class Client < Footrest::Client
|
13
12
|
|
@@ -26,6 +25,7 @@ module BridgeAPI
|
|
26
25
|
CUSTOM_FIELD_PATH = "/custom_fields"
|
27
26
|
API_VERSION = 1
|
28
27
|
API_PATH = '/api'
|
28
|
+
RESULT_MAPPING = {}
|
29
29
|
|
30
30
|
require 'bridge_api/api_array'
|
31
31
|
|
@@ -36,7 +36,7 @@ module BridgeAPI
|
|
36
36
|
|
37
37
|
# Override Footrest request for ApiArray support
|
38
38
|
def request(method, &block)
|
39
|
-
ApiArray::process_response(connection.send(method, &block), self)
|
39
|
+
ApiArray::process_response(connection.send(method, &block), self, RESULT_MAPPING)
|
40
40
|
end
|
41
41
|
|
42
42
|
def set_connection(config)
|
@@ -68,4 +68,3 @@ module BridgeAPI
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
@@ -7,9 +7,14 @@ module BridgeAPI
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def get_manager_direct_reports(manager_id, params = {})
|
10
|
-
|
10
|
+
path = "#{API_PATH}#{AUTHOR_PATH}#{MANAGER_PATH}/#{manager_id}/direct_reports"
|
11
|
+
RESULT_MAPPING[path] = {
|
12
|
+
primary: 'direct_reports',
|
13
|
+
meta: ['manager_id', 'direct_reports_count']
|
14
|
+
}
|
15
|
+
get(path, params)
|
11
16
|
end
|
12
17
|
|
13
18
|
end
|
14
19
|
end
|
15
|
-
end
|
20
|
+
end
|
data/lib/bridge_api/version.rb
CHANGED
@@ -13,9 +13,10 @@ describe BridgeAPI::Client::User do
|
|
13
13
|
|
14
14
|
it 'should get all the people who report to a manager' do
|
15
15
|
response = @client.get_manager_direct_reports(17)
|
16
|
-
expect(response
|
17
|
-
expect(response
|
16
|
+
expect(response.members.count).to(eq(2))
|
17
|
+
expect(response.members.first['id']).to(eq("3"))
|
18
|
+
expect(response.meta['direct_reports_count']).to(eq(2))
|
19
|
+
expect(response.meta['manager_id']).to(eq("17"))
|
18
20
|
end
|
19
21
|
|
20
22
|
end
|
21
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bridge_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jay Shaffer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -250,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
250
250
|
version: '0'
|
251
251
|
requirements: []
|
252
252
|
rubyforge_project:
|
253
|
-
rubygems_version: 2.
|
253
|
+
rubygems_version: 2.2.2
|
254
254
|
signing_key:
|
255
255
|
specification_version: 4
|
256
256
|
summary: Bridge API
|
@@ -284,3 +284,4 @@ test_files:
|
|
284
284
|
- spec/fixtures/users.json
|
285
285
|
- spec/support/fake_bridge.rb
|
286
286
|
- spec/test_helper.rb
|
287
|
+
has_rdoc:
|