sourcescrub 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: 2884125ab5a2d684096e4c2a1107ae6f561671f4122cc7cf34962b74f9e51b64
4
- data.tar.gz: d34e3f88743020e0eb49d4a7acadeb2fe0451d6742fcbcf1651b5eee08ad3494
3
+ metadata.gz: 8631fba58663ed2b6340e63ac4dcbfdd387a07aa1192bb0ab911412071bf25f7
4
+ data.tar.gz: 446f9ebbbbe9fe5acf1eaef967c2b10983e3f5ce9c2362799e1071af34dcf9dd
5
5
  SHA512:
6
- metadata.gz: a0e4aca28751dbaa64568bbe53ddfae988c538b117d059d66ce5b9c2f37a13119616f2ad6d8d6e3b99d0110796eac6f0a7515e5a43cc03f184fce33c618229f7
7
- data.tar.gz: 9c8b1e392af7cc0bbd09d81cd6421f115503deb2872a49a58ea9e1ac4efd30c0e0b6be4a439f67dcee80ef415508d9b0972b042e6edda09fa44695b2d4b021cf
6
+ metadata.gz: 54577a01f056d9414ffe17e72ff651e1bda42c4776ca9d820d672943a3e4f866fff933f80447feb96131932f8dadc28c132fb8a5da7149aee57bf893ee7c7d0b
7
+ data.tar.gz: 726091a74644fbf1f0b09dcd5b70f8a1d5f542796ea9f756a969487362b85744165dcf823b25f2f47c8f6385c53368a582fdcf8da1f58d29fc959fe19020e249
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## [0.1.2] - 2021-01-14
4
+
5
+ - Implement search source endpoint to allow use filters to get matched sources - `client.source_search({limit: 10, offset: 0})`
6
+
3
7
  ## [0.1.1] - 2020-11-03
4
8
 
5
9
  - Fixing wrong data issue of `currentEmployeeRange` in Company
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sourcescrub (0.1.1)
4
+ sourcescrub (0.1.2)
5
5
  faraday
6
6
 
7
7
  GEM
@@ -25,6 +25,13 @@ module Sourcescrub
25
25
  ].compact.join('/')
26
26
  end
27
27
 
28
+ def search_url
29
+ [
30
+ 'search',
31
+ Models::Source::ENDPOINT
32
+ ].compact.join('/')
33
+ end
34
+
28
35
  def companies_url
29
36
  [
30
37
  Models::Source::ENDPOINT,
@@ -3,12 +3,14 @@
3
3
  require_relative './utils/request'
4
4
  require_relative './apis/companies'
5
5
  require_relative './apis/sources'
6
+ require_relative './utils/search_params'
6
7
 
7
8
  # Root Sourcescrub
8
9
  module Sourcescrub
9
10
  # Client
10
11
  class Client
11
12
  include Utils::Request
13
+ include Utils::SearchParams
12
14
 
13
15
  attr_accessor :token
14
16
 
@@ -54,6 +56,15 @@ module Sourcescrub
54
56
  )
55
57
  end
56
58
 
59
+ def source_search(args = {})
60
+ api = source_search_api(source_params(args))
61
+
62
+ Models::SourceItems.new.parse_response_items(
63
+ api.kclass_name,
64
+ search(api.search_url, api.args)
65
+ )
66
+ end
67
+
57
68
  def sources(source_id, args = {})
58
69
  api = source_api(source_id, args)
59
70
 
@@ -93,6 +104,13 @@ module Sourcescrub
93
104
  )
94
105
  end
95
106
 
107
+ def source_search_api(args)
108
+ Apis::Sources.new(
109
+ nil,
110
+ { model_type: 'source' }.merge(args)
111
+ )
112
+ end
113
+
96
114
  def source_companies_api(source_id, args)
97
115
  Apis::Sources.new(
98
116
  source_id,
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'faraday'
4
+ require 'logger'
4
5
 
5
6
  module Sourcescrub
6
7
  # Utils
@@ -19,33 +20,28 @@ module Sourcescrub
19
20
  #
20
21
  #
21
22
  def get(uri, *args)
22
- response = Faraday.new(
23
- url: API_URI,
24
- headers: headers,
25
- request: {
26
- timeout: 10,
27
- open_timeout: 5
28
- },
29
- params: args[0] || {}
30
- ).get(uri)
23
+ response = Faraday.new(request_options(args)) do |faraday|
24
+ faraday.headers['Content-Type'] = 'application/json-patch+json'
25
+ faraday.adapter Faraday.default_adapter
26
+ faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
27
+ end.get(uri)
31
28
 
32
- response_body = response.body
33
- raise Error, response_body unless response.status == 200
29
+ raise Error, response.body unless response.status == 200
34
30
 
35
- response_body = JSON.parse(response_body)
36
- # Processing different cases for investments
37
- if response_body.is_a?(Array)
38
- response_body = if response_body.empty?
39
- {}
40
- else
41
- {
42
- 'total' => response_body.size,
43
- 'items' => response_body
44
- }
45
- end
46
- end
47
-
48
- response_body.merge('headers' => response.headers)
31
+ parse_api_response(response.body).merge('headers' => response.headers)
32
+ end
33
+
34
+ # Search endpoints
35
+ def search(uri, args)
36
+ response = Faraday.new(request_options(args)) do |faraday|
37
+ faraday.headers['Content-Type'] = 'application/json-patch+json'
38
+ faraday.adapter Faraday.default_adapter
39
+ faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
40
+ end.post(uri, args.to_json)
41
+
42
+ raise Error, response.body unless response.status == 200
43
+
44
+ parse_api_response(response.body).merge('headers' => response.headers)
49
45
  end
50
46
 
51
47
  # def put(uri, args)
@@ -103,6 +99,31 @@ module Sourcescrub
103
99
 
104
100
  private
105
101
 
102
+ def request_options(args)
103
+ {
104
+ url: API_URI,
105
+ headers: headers,
106
+ request: {
107
+ timeout: 10,
108
+ open_timeout: 5
109
+ },
110
+ params: args[0] || {}
111
+ }
112
+ end
113
+
114
+ def parse_api_response(response_body)
115
+ response_body = JSON.parse(response_body)
116
+
117
+ # Processing different cases for investments
118
+ return response_body unless response_body.is_a?(Array)
119
+ return {} if response_body.empty?
120
+
121
+ {
122
+ 'total' => response_body.size,
123
+ 'items' => response_body
124
+ }
125
+ end
126
+
106
127
  def debug_mode?
107
128
  Sourcescrub.account.debug || false
108
129
  end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sourcescrub
4
+ # Utilities
5
+ module Utils
6
+ # All Searches Parameters
7
+ module SearchParams
8
+ module_function
9
+
10
+ def source_params(args = {})
11
+ recursive_compact(build_args(args))
12
+ end
13
+
14
+ private
15
+
16
+ def build_args(args)
17
+ {
18
+ 'filters' => {
19
+ 'startDateRange' => {
20
+ 'from' => args.dig(:start_date, :from),
21
+ 'to' => args.dig(:start_date, :to)
22
+ },
23
+ 'endDateRange' => {
24
+ 'from' => args.dig(:end_date, :from),
25
+ 'to' => args.dig(:end_date, :to)
26
+ },
27
+ 'modifiedDateRange' => {
28
+ 'from' => args.dig(:modified, :from),
29
+ 'to' => args.dig(:modified, :to)
30
+ },
31
+ 'completedAtDateRange' => {
32
+ 'from' => args.dig(:completed_date, :from),
33
+ 'to' => args.dig(:completed_date, :to)
34
+ },
35
+ 'industries' => args.dig(:industries),
36
+ 'statuses' => args.dig(:statuses),
37
+ 'sourceTypes' => args.dig(:source_types),
38
+ 'clientStatuses' => args.dig(:client_statuses),
39
+ 'completedAt' => args.dig(:completed_at)
40
+ },
41
+ 'searchText' => args.dig(:search_text),
42
+ 'limit' => args.dig(:limit) || 100,
43
+ 'offset' => args.dig(:offset) || 0,
44
+ 'orderBy' => args.dig(:order_by) || 'endDate DESC'
45
+ }
46
+ end
47
+
48
+ def recursive_compact(hash_or_array)
49
+ block = proc do |*args|
50
+ v = args.last
51
+ v.delete_if(&block) if v.respond_to? :delete_if
52
+ v.nil? || v.respond_to?(:"empty?") && v.empty?
53
+ end
54
+
55
+ hash_or_array.delete_if(&block)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sourcescrub
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sourcescrub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Encore Shao
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-03 00:00:00.000000000 Z
11
+ date: 2021-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -120,6 +120,7 @@ files:
120
120
  - lib/sourcescrub/models/tag.rb
121
121
  - lib/sourcescrub/utils/request.rb
122
122
  - lib/sourcescrub/utils/response.rb
123
+ - lib/sourcescrub/utils/search_params.rb
123
124
  - lib/sourcescrub/utils/ss_model.rb
124
125
  - lib/sourcescrub/utils/veriables.rb
125
126
  - lib/sourcescrub/version.rb