sourcescrub 0.0.7 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/Gemfile.lock +1 -1
- data/lib/sourcescrub/apis/companies.rb +7 -0
- data/lib/sourcescrub/apis/sources.rb +7 -0
- data/lib/sourcescrub/client.rb +41 -6
- data/lib/sourcescrub/utils/request.rb +46 -24
- data/lib/sourcescrub/utils/response.rb +1 -0
- 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,23 @@
|
|
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
|
+
|
7
|
+
## [0.1.1] - 2020-11-03
|
8
|
+
|
9
|
+
- Fixing wrong data issue of `currentEmployeeRange` in Company
|
10
|
+
|
11
|
+
## [0.0.8] - 2020-08-13
|
12
|
+
|
13
|
+
- Implement API to request all compnies - `client.companies`
|
14
|
+
|
15
|
+
## [0.0.7] - 2020-08-04
|
16
|
+
|
17
|
+
- Get source data and source compaines - `client.source_companies(source_id)`
|
18
|
+
- Get company's employeerange data by domain - `client.company_cards('monday.com', { card_id: 'employeerange' })`
|
19
|
+
- Get company's employees data by domain - `client.company_cards('monday.com', { card_id: 'employees' })`
|
20
|
+
|
3
21
|
## [0.0.3] - 2020-06-20
|
4
22
|
|
5
23
|
- Implement API to request token by user certificate
|
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
|
|
@@ -18,14 +20,24 @@ module Sourcescrub
|
|
18
20
|
{ 'Authorization' => "Bearer #{@token}" }
|
19
21
|
end
|
20
22
|
|
23
|
+
def companies(args = { limit: 100, offset: 0 })
|
24
|
+
api = companies_api(args)
|
25
|
+
|
26
|
+
Models::CompanyItems.new.parse_response_items(
|
27
|
+
nil,
|
28
|
+
api.kclass_name,
|
29
|
+
get(api.search_url, api.args)
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
21
33
|
def company(domain, args = {})
|
22
|
-
api =
|
34
|
+
api = company_api(domain, args)
|
23
35
|
|
24
36
|
api.sobject.parse_response get(api.request_url, api.args)
|
25
37
|
end
|
26
38
|
|
27
39
|
def company_cards(domain, args = {})
|
28
|
-
api =
|
40
|
+
api = company_api(domain, args.merge(model_type: company_card_mappings[args[:card_id]]))
|
29
41
|
|
30
42
|
Models::CompanyItems.new.parse_response_items(
|
31
43
|
domain,
|
@@ -44,6 +56,15 @@ module Sourcescrub
|
|
44
56
|
)
|
45
57
|
end
|
46
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
|
+
|
47
68
|
def sources(source_id, args = {})
|
48
69
|
api = source_api(source_id, args)
|
49
70
|
|
@@ -62,22 +83,36 @@ module Sourcescrub
|
|
62
83
|
|
63
84
|
private
|
64
85
|
|
65
|
-
def companies_api(
|
66
|
-
|
86
|
+
def companies_api(args)
|
87
|
+
Apis::Companies.new(
|
88
|
+
nil,
|
89
|
+
{ model_type: 'company' }.merge(args)
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
def company_api(domain, args)
|
94
|
+
Apis::Companies.new(
|
67
95
|
domain,
|
68
96
|
{ model_type: 'company' }.merge(args)
|
69
97
|
)
|
70
98
|
end
|
71
99
|
|
72
100
|
def source_api(source_id, args)
|
73
|
-
|
101
|
+
Apis::Sources.new(
|
74
102
|
source_id,
|
75
103
|
{ model_type: 'source' }.merge(args)
|
76
104
|
)
|
77
105
|
end
|
78
106
|
|
107
|
+
def source_search_api(args)
|
108
|
+
Apis::Sources.new(
|
109
|
+
nil,
|
110
|
+
{ model_type: 'source' }.merge(args)
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
79
114
|
def source_companies_api(source_id, args)
|
80
|
-
|
115
|
+
Apis::Sources.new(
|
81
116
|
source_id,
|
82
117
|
{ model_type: 'company' }.merge(args)
|
83
118
|
)
|
@@ -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,32 +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
|
-
).get(uri, *args)
|
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)
|
30
28
|
|
31
|
-
|
32
|
-
raise Error, response_body unless response.status == 200
|
29
|
+
raise Error, response.body unless response.status == 200
|
33
30
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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)
|
48
45
|
end
|
49
46
|
|
50
47
|
# def put(uri, args)
|
@@ -102,6 +99,31 @@ module Sourcescrub
|
|
102
99
|
|
103
100
|
private
|
104
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
|
+
|
105
127
|
def debug_mode?
|
106
128
|
Sourcescrub.account.debug || false
|
107
129
|
end
|
@@ -29,6 +29,7 @@ module Sourcescrub
|
|
29
29
|
# Setup attributes
|
30
30
|
attribute_names.each do |attr_name|
|
31
31
|
attr_value = response.dig(attr_name)
|
32
|
+
attr_value = nil if attr_name == 'currentEmployeeRange' && attr_value.is_a?(Integer)
|
32
33
|
|
33
34
|
dynamic_define_method(object, attr_name, attr_value)
|
34
35
|
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.
|
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
|