sourcescrub 0.0.4 → 0.0.9
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 +11 -0
- data/Gemfile.lock +1 -4
- 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 -18
- data/lib/sourcescrub/version.rb +1 -1
- data/sourcescrub.gemspec +0 -1
- metadata +5 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c19a7a8e7554d1092ccc61b24d0086edccd0f6a88d6eb506b6bafc47e18bc404
|
4
|
+
data.tar.gz: 503a99966317d3237531c12ccbd8b2d5e608f874c20d3ffc476f661ccf61acab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 163d4b20774715805eec30672711c96a5aa0b412faa3431c1fb9668faa9c98b83f8d21d3b6044c8f184a22f62da0bf75993df5db4d0d1e16c6670f2ec125eaef
|
7
|
+
data.tar.gz: 072a4fbf9921d199c4006bd6535e9cb5e61d784db8003d9e9bb7ff1a443ef0fcf07be1102392c67db380a792454054525c7a71fbb09139000562d75dc3dc0aea
|
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
@@ -1,9 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sourcescrub (0.0.
|
4
|
+
sourcescrub (0.0.9)
|
5
5
|
faraday
|
6
|
-
faraday_middleware
|
7
6
|
|
8
7
|
GEM
|
9
8
|
remote: https://rubygems.org/
|
@@ -17,8 +16,6 @@ GEM
|
|
17
16
|
diff-lcs (1.3)
|
18
17
|
faraday (1.0.1)
|
19
18
|
multipart-post (>= 1.2, < 3)
|
20
|
-
faraday_middleware (1.0.0)
|
21
|
-
faraday (~> 1.0)
|
22
19
|
hashdiff (1.0.1)
|
23
20
|
method_source (1.0.0)
|
24
21
|
multipart-post (2.1.1)
|
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
|
-
@companies_api
|
36
|
-
|
75
|
+
def companies_api(args)
|
76
|
+
@companies_api ||= Apis::Companies.new(
|
77
|
+
nil,
|
78
|
+
{ model_type: 'company' }.merge(args)
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
def company_api(domain, args)
|
83
|
+
@company_api ||= Apis::Companies.new(
|
84
|
+
domain,
|
85
|
+
{ model_type: 'company' }.merge(args)
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
def source_api(source_id, args)
|
90
|
+
@source_api ||= 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
|
+
@source_companies_api ||= 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
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'faraday'
|
4
|
-
require 'faraday_middleware'
|
5
|
-
require 'logger'
|
6
4
|
|
7
5
|
module Sourcescrub
|
8
6
|
# Utils
|
@@ -27,20 +25,27 @@ module Sourcescrub
|
|
27
25
|
request: {
|
28
26
|
timeout: 10,
|
29
27
|
open_timeout: 5
|
30
|
-
}
|
31
|
-
|
32
|
-
|
33
|
-
faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
|
34
|
-
end.get(uri, *args)
|
28
|
+
},
|
29
|
+
params: args[0] || {}
|
30
|
+
).get(uri)
|
35
31
|
|
36
32
|
response_body = response.body
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
41
46
|
end
|
42
47
|
|
43
|
-
|
48
|
+
response_body.merge('headers' => response.headers)
|
44
49
|
end
|
45
50
|
|
46
51
|
# def put(uri, args)
|
@@ -89,15 +94,11 @@ module Sourcescrub
|
|
89
94
|
'Content-Type' => 'application/x-www-form-urlencoded',
|
90
95
|
'Authorization' => Sourcescrub.account.basic
|
91
96
|
}
|
92
|
-
)
|
93
|
-
faraday.adapter Faraday.default_adapter
|
94
|
-
faraday.response :json
|
95
|
-
faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
|
96
|
-
end.post(TOKEN_URI, body)
|
97
|
+
).post(TOKEN_URI, body)
|
97
98
|
|
98
99
|
raise 'Sourcescrub error: Service Unavailable' unless response.status == 200
|
99
100
|
|
100
|
-
@token = response.body['access_token']
|
101
|
+
@token = JSON.parse(response.body)['access_token']
|
101
102
|
end
|
102
103
|
|
103
104
|
private
|
data/lib/sourcescrub/version.rb
CHANGED
data/sourcescrub.gemspec
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.0.9
|
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
|
+
date: 2020-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: faraday_middleware
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: vcr
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,12 +104,15 @@ files:
|
|
118
104
|
- lib/sourcescrub.rb
|
119
105
|
- lib/sourcescrub/account.rb
|
120
106
|
- lib/sourcescrub/apis/companies.rb
|
107
|
+
- lib/sourcescrub/apis/sources.rb
|
121
108
|
- lib/sourcescrub/client.rb
|
122
109
|
- lib/sourcescrub/models.rb
|
123
110
|
- lib/sourcescrub/models/company.rb
|
124
111
|
- lib/sourcescrub/models/concerns/company_items.rb
|
125
112
|
- lib/sourcescrub/models/concerns/entity.rb
|
113
|
+
- lib/sourcescrub/models/concerns/source_items.rb
|
126
114
|
- lib/sourcescrub/models/employee.rb
|
115
|
+
- lib/sourcescrub/models/employee_range.rb
|
127
116
|
- lib/sourcescrub/models/financial.rb
|
128
117
|
- lib/sourcescrub/models/investment.rb
|
129
118
|
- lib/sourcescrub/models/person.rb
|