sourcescrub 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +1 -1
- data/lib/sourcescrub.rb +1 -0
- data/lib/sourcescrub/apis/companies.rb +7 -0
- data/lib/sourcescrub/apis/sources.rb +37 -0
- data/lib/sourcescrub/client.rb +73 -8
- data/lib/sourcescrub/models.rb +4 -0
- data/lib/sourcescrub/models/concerns/source_items.rb +33 -0
- data/lib/sourcescrub/models/employee_range.rb +18 -0
- data/lib/sourcescrub/utils/request.rb +19 -9
- data/lib/sourcescrub/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4980e44a9b4c4a87dec3bd316dc8de553db7a6d51290660ecf6c186ad28b4b6f
|
4
|
+
data.tar.gz: 8f919568a28e03bfa1256e1582581d4631b89b8d51395e6468e5d546683d5155
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0dd2c6d24b3ba995ae93a327b42b80f2cad1bf94b7a1aefbecf8c6b96be0163ad78dd447f1686ee66409f4c2209b1374ed63310e54c67fcb0377e2769f287de
|
7
|
+
data.tar.gz: 32c0d749fbd12014cb60a9f98ca35a78b63a13045483f265ec3cf9cf0b8966ab214f4089de855f2bce868cb036d8866865dc26f23c121eb851aa4613db1ee097
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
|
4
|
+
## [0.0.8] - 2020-08-13
|
5
|
+
|
6
|
+
- Implement API to request all compnies - `client.companies`
|
7
|
+
|
8
|
+
## [0.0.7] - 2020-08-04
|
9
|
+
|
10
|
+
- Get source data and source compaines - `client.source_companies(source_id)`
|
11
|
+
- Get company's employeerange data by domain - `client.company_cards('monday.com', { card_id: 'employeerange' })`
|
12
|
+
- Get company's employees data by domain - `client.company_cards('monday.com', { card_id: 'employees' })`
|
13
|
+
|
3
14
|
## [0.0.3] - 2020-06-20
|
4
15
|
|
5
16
|
- Implement API to request token by user certificate
|
data/Gemfile.lock
CHANGED
data/lib/sourcescrub.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './../utils/ss_model'
|
4
|
+
|
5
|
+
# Root Sourcescrub
|
6
|
+
module Sourcescrub
|
7
|
+
# Apis
|
8
|
+
module Apis
|
9
|
+
# Companies endpoint
|
10
|
+
class Sources
|
11
|
+
include ::Sourcescrub::Utils::SsModel
|
12
|
+
|
13
|
+
attr_accessor :args
|
14
|
+
|
15
|
+
def initialize(source_id, args)
|
16
|
+
@source_id = source_id
|
17
|
+
@model_type = args.delete(:model_type)
|
18
|
+
@args = args
|
19
|
+
end
|
20
|
+
|
21
|
+
def request_url
|
22
|
+
[
|
23
|
+
Models::Source::ENDPOINT,
|
24
|
+
@source_id
|
25
|
+
].compact.join('/')
|
26
|
+
end
|
27
|
+
|
28
|
+
def companies_url
|
29
|
+
[
|
30
|
+
Models::Source::ENDPOINT,
|
31
|
+
@source_id,
|
32
|
+
'companies'
|
33
|
+
].compact.join('/')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/sourcescrub/client.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative './utils/request'
|
4
4
|
require_relative './apis/companies'
|
5
|
+
require_relative './apis/sources'
|
5
6
|
|
6
7
|
# Root Sourcescrub
|
7
8
|
module Sourcescrub
|
@@ -17,33 +18,97 @@ module Sourcescrub
|
|
17
18
|
{ 'Authorization' => "Bearer #{@token}" }
|
18
19
|
end
|
19
20
|
|
21
|
+
def companies(args = { limit: 100, offset: 0 })
|
22
|
+
api = companies_api(args)
|
23
|
+
|
24
|
+
Models::CompanyItems.new.parse_response_items(
|
25
|
+
nil,
|
26
|
+
api.kclass_name,
|
27
|
+
get(api.search_url, api.args)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
20
31
|
def company(domain, args = {})
|
21
|
-
api =
|
32
|
+
api = company_api(domain, args)
|
22
33
|
|
23
34
|
api.sobject.parse_response get(api.request_url, api.args)
|
24
35
|
end
|
25
36
|
|
26
37
|
def company_cards(domain, args = {})
|
27
|
-
api =
|
38
|
+
api = company_api(domain, args.merge(model_type: company_card_mappings[args[:card_id]]))
|
39
|
+
|
40
|
+
Models::CompanyItems.new.parse_response_items(
|
41
|
+
domain,
|
42
|
+
api.kclass_name,
|
43
|
+
get(api.request_url, api.args)
|
44
|
+
)
|
45
|
+
end
|
28
46
|
|
29
|
-
|
47
|
+
# The max limit range is 0 - 100
|
48
|
+
def all_sources(args = { sourceStatus: 'None', limit: 100, offset: 0 })
|
49
|
+
api = source_api('sources', args)
|
50
|
+
|
51
|
+
Models::SourceItems.new.parse_response_items(
|
52
|
+
api.kclass_name,
|
53
|
+
get(api.request_url, api.args)
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def sources(source_id, args = {})
|
58
|
+
api = source_api(source_id, args)
|
59
|
+
|
60
|
+
api.sobject.parse_response get(api.request_url, api.args)
|
61
|
+
end
|
62
|
+
|
63
|
+
def source_companies(source_id, args = {})
|
64
|
+
api = source_companies_api(source_id, args)
|
65
|
+
|
66
|
+
Models::CompanyItems.new.parse_response_items(
|
67
|
+
source_id,
|
68
|
+
api.kclass_name,
|
69
|
+
get(api.companies_url, api.args)
|
70
|
+
)
|
30
71
|
end
|
31
72
|
|
32
73
|
private
|
33
74
|
|
34
|
-
def companies_api(
|
35
|
-
|
36
|
-
|
75
|
+
def companies_api(args)
|
76
|
+
Apis::Companies.new(
|
77
|
+
nil,
|
78
|
+
{ model_type: 'company' }.merge(args)
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
def company_api(domain, args)
|
83
|
+
Apis::Companies.new(
|
84
|
+
domain,
|
85
|
+
{ model_type: 'company' }.merge(args)
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
def source_api(source_id, args)
|
90
|
+
Apis::Sources.new(
|
91
|
+
source_id,
|
92
|
+
{ model_type: 'source' }.merge(args)
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
def source_companies_api(source_id, args)
|
97
|
+
Apis::Sources.new(
|
98
|
+
source_id,
|
99
|
+
{ model_type: 'company' }.merge(args)
|
100
|
+
)
|
37
101
|
end
|
38
102
|
|
39
|
-
def
|
103
|
+
def company_card_mappings
|
40
104
|
{
|
41
105
|
'sources' => 'source',
|
42
106
|
'people' => 'person',
|
43
107
|
'financials' => 'financial',
|
44
108
|
'investments' => 'investment',
|
45
109
|
'employees' => 'employee',
|
46
|
-
'tags' => 'tag'
|
110
|
+
'tags' => 'tag',
|
111
|
+
'employeerange' => 'employee_range'
|
47
112
|
}
|
48
113
|
end
|
49
114
|
end
|
data/lib/sourcescrub/models.rb
CHANGED
@@ -6,9 +6,13 @@ module Sourcescrub
|
|
6
6
|
autoload :Entity, 'sourcescrub/models/concerns/entity'
|
7
7
|
autoload :Company, 'sourcescrub/models/company'
|
8
8
|
autoload :CompanyItems, 'sourcescrub/models/concerns/company_items'
|
9
|
+
autoload :SourceItems, 'sourcescrub/models/concerns/source_items'
|
9
10
|
autoload :Source, 'sourcescrub/models/source'
|
10
11
|
autoload :Tag, 'sourcescrub/models/tag'
|
11
12
|
autoload :Person, 'sourcescrub/models/person'
|
12
13
|
autoload :Financial, 'sourcescrub/models/financial'
|
14
|
+
autoload :Investment, 'sourcescrub/models/investment'
|
15
|
+
autoload :Employee, 'sourcescrub/models/employee'
|
16
|
+
autoload :EmployeeRange, 'sourcescrub/models/employee_range'
|
13
17
|
end
|
14
18
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sourcescrub
|
4
|
+
# Models
|
5
|
+
module Models
|
6
|
+
# Tag
|
7
|
+
class SourceItems < Entity
|
8
|
+
attr_accessor :total, :items, :type
|
9
|
+
|
10
|
+
def parse_response_items(kclass_name, response)
|
11
|
+
headers = response.dig('headers')
|
12
|
+
headers&.keys&.each do |attr_name|
|
13
|
+
self.class.send(:define_method, attr_name.gsub('-', '_').to_sym) do
|
14
|
+
headers[attr_name]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
dynamic_define_method(self, 'type', kclass_name)
|
19
|
+
dynamic_define_method(self, 'total', response.dig('total') || 0)
|
20
|
+
dynamic_define_method(self, 'items', source_items(kclass_name, response.dig('items') || []))
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def source_items(kclass_name, items)
|
27
|
+
items.each_with_object([]) do |item, results|
|
28
|
+
results << kclass_name.new.parse_response(item)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -25,17 +25,27 @@ module Sourcescrub
|
|
25
25
|
request: {
|
26
26
|
timeout: 10,
|
27
27
|
open_timeout: 5
|
28
|
-
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
},
|
29
|
+
params: args[0] || {}
|
30
|
+
).get(uri)
|
31
|
+
|
32
|
+
response_body = response.body
|
33
|
+
raise Error, response_body unless response.status == 200
|
34
|
+
|
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
|
36
46
|
end
|
37
47
|
|
38
|
-
|
48
|
+
response_body.merge('headers' => response.headers)
|
39
49
|
end
|
40
50
|
|
41
51
|
# def put(uri, args)
|
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.0
|
4
|
+
version: 0.1.0
|
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-08-
|
11
|
+
date: 2020-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -104,12 +104,15 @@ files:
|
|
104
104
|
- lib/sourcescrub.rb
|
105
105
|
- lib/sourcescrub/account.rb
|
106
106
|
- lib/sourcescrub/apis/companies.rb
|
107
|
+
- lib/sourcescrub/apis/sources.rb
|
107
108
|
- lib/sourcescrub/client.rb
|
108
109
|
- lib/sourcescrub/models.rb
|
109
110
|
- lib/sourcescrub/models/company.rb
|
110
111
|
- lib/sourcescrub/models/concerns/company_items.rb
|
111
112
|
- lib/sourcescrub/models/concerns/entity.rb
|
113
|
+
- lib/sourcescrub/models/concerns/source_items.rb
|
112
114
|
- lib/sourcescrub/models/employee.rb
|
115
|
+
- lib/sourcescrub/models/employee_range.rb
|
113
116
|
- lib/sourcescrub/models/financial.rb
|
114
117
|
- lib/sourcescrub/models/investment.rb
|
115
118
|
- lib/sourcescrub/models/person.rb
|