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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4461f7ecab786b3b2ca3b1a769d0878306e29cb2
4
- data.tar.gz: 165d25273ca8cebdcf14ec7c60331462d8b815e4
3
+ metadata.gz: 32715294cbf0a4012da38a0664923ac8a5f9560e
4
+ data.tar.gz: 30dc2aacd810e8387cf3d1ad5354680219772970
5
5
  SHA512:
6
- metadata.gz: 0254b6676cac32f5ff64cc1c211a7059e5f91ddecac4d5cba3c4fee08585648e61257b633e5fbcf9964e7fd2decd71070122965650936561491c870ff6aaf984
7
- data.tar.gz: a0668e249527635573b8b7b4afd6d17f082c1d28f52325c4c2775ee19db151ba650ba714b50764c82616d165ad58d173811c979a82d03523841409a01145b792
6
+ metadata.gz: 450207f9fc4039e3740540a3f1076fa3a3eb5ff4b1688aa66470e2df6b9d1154dd9af2d8231f14e778b3a830c3e3cc7104ae79b78f644de77c8d0053b813ee9d
7
+ data.tar.gz: 3fcba14431b03b2ec2102d9d59c35741d93c564bc0c90841bb8eab56c59a8a877c2965abdd4295b4a64e07710af245053eb31110098eb7bd0d06fce961a676d0
@@ -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| META_FIELDS.include?(k)}
105
- if content.length > 1
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
 
@@ -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
- get("#{API_PATH}#{AUTHOR_PATH}#{MANAGER_PATH}/#{manager_id}/direct_reports", params)
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
@@ -1,3 +1,3 @@
1
1
  module BridgeAPI
2
- VERSION = '0.0.14' unless defined?(BridgeAPI::VERSION)
2
+ VERSION = '0.1.14' unless defined?(BridgeAPI::VERSION)
3
3
  end
@@ -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['direct_reports'].count).to(eq(2))
17
- expect(response['direct_reports'].first['id']).to(eq("3"))
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.0.14
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-18 00:00:00.000000000 Z
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.5.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: