sourcescrub 0.1.1 → 0.1.2
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/sourcescrub/apis/sources.rb +7 -0
- data/lib/sourcescrub/client.rb +18 -0
- data/lib/sourcescrub/utils/request.rb +46 -25
- data/lib/sourcescrub/utils/search_params.rb +59 -0
- data/lib/sourcescrub/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8631fba58663ed2b6340e63ac4dcbfdd387a07aa1192bb0ab911412071bf25f7
|
4
|
+
data.tar.gz: 446f9ebbbbe9fe5acf1eaef967c2b10983e3f5ce9c2362799e1071af34dcf9dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54577a01f056d9414ffe17e72ff651e1bda42c4776ca9d820d672943a3e4f866fff933f80447feb96131932f8dadc28c132fb8a5da7149aee57bf893ee7c7d0b
|
7
|
+
data.tar.gz: 726091a74644fbf1f0b09dcd5b70f8a1d5f542796ea9f756a969487362b85744165dcf823b25f2f47c8f6385c53368a582fdcf8da1f58d29fc959fe19020e249
|
data/CHANGELOG.md
CHANGED
@@ -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
|
data/Gemfile.lock
CHANGED
data/lib/sourcescrub/client.rb
CHANGED
@@ -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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
33
|
-
raise Error, response_body unless response.status == 200
|
29
|
+
raise Error, response.body unless response.status == 200
|
34
30
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
data/lib/sourcescrub/version.rb
CHANGED
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.
|
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:
|
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
|