sourcescrub 0.0.2 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +3 -0
- data/CHANGELOG.md +16 -2
- data/Gemfile.lock +1 -4
- data/README.md +96 -4
- data/lib/sourcescrub.rb +5 -1
- data/lib/sourcescrub/apis/companies.rb +1 -1
- data/lib/sourcescrub/apis/sources.rb +37 -0
- data/lib/sourcescrub/client.rb +69 -3
- data/lib/sourcescrub/models.rb +11 -4
- data/lib/sourcescrub/models/concerns/company_items.rb +56 -0
- data/lib/sourcescrub/models/concerns/source_items.rb +33 -0
- data/lib/sourcescrub/models/employee.rb +18 -0
- data/lib/sourcescrub/models/employee_range.rb +18 -0
- data/lib/sourcescrub/models/financial.rb +20 -0
- data/lib/sourcescrub/models/investment.rb +21 -0
- data/lib/sourcescrub/models/person.rb +27 -0
- data/lib/sourcescrub/models/source.rb +3 -0
- data/lib/sourcescrub/utils/request.rb +52 -41
- data/lib/sourcescrub/utils/response.rb +19 -0
- data/lib/sourcescrub/utils/veriables.rb +17 -0
- data/lib/sourcescrub/version.rb +1 -1
- data/sourcescrub.gemspec +0 -1
- metadata +14 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c425f778c050e471a59f52d8101bc7d5b2bd926e333292525ebe9ad67d4dce65
|
4
|
+
data.tar.gz: b98238083a2c65ec56cf6d45e82141c2b2f70a9ffde7eaa6be46a989f0c30a01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5b33a6b315e789588f09039cd5b62d1e038833019f2ada2b31b9eff4f99e967745db6a65698a5f4226e6bdaa3d47a62492d916e990f6ba3815a926da5526418
|
7
|
+
data.tar.gz: 17be5421cb1d3008de1248befc059f9e481424b966106a80afc4622f375e594ca65e98b071522b970955b2692d9634efd4f53e4d14db028bc6827b5aa3b042ec
|
data/.rubocop_todo.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [0.0.
|
3
|
+
## [0.0.3] - 2020-06-20
|
4
4
|
|
5
5
|
- Implement API to request token by user certificate
|
6
|
-
- Get company data by domain
|
6
|
+
- Get company data by domain - `client.company(ekohe.com)`
|
7
|
+
- Get company's relationship data by domain - `client.company(ekohe.com, {card_id: 'people'})`
|
8
|
+
- Retrieve request limit data from header
|
9
|
+
|
10
|
+
```
|
11
|
+
# .date
|
12
|
+
# .content_type
|
13
|
+
# .server
|
14
|
+
# .content_length
|
15
|
+
# .request_context
|
16
|
+
# .strict_transport_security
|
17
|
+
# .x_ratelimit_limit
|
18
|
+
# .x_ratelimit_remaining
|
19
|
+
# .x_ratelimit_reset
|
20
|
+
```
|
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.7)
|
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/README.md
CHANGED
@@ -4,6 +4,9 @@ Sourcescrub is a ruby wrapper based on Source Scrub API, Here is API documentati
|
|
4
4
|
|
5
5
|
However, we need to request an access account from Sourcescrub.
|
6
6
|
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/sourcescrub.svg)](https://badge.fury.io/rb/sourcescrub)
|
8
|
+
[![Build Status](https://travis-ci.org/ekohe/sourcescrub.svg?branch=master)](https://travis-ci.org/ekohe/sourcescrub)
|
9
|
+
|
7
10
|
## Installation
|
8
11
|
|
9
12
|
Add this line to your application's Gemfile:
|
@@ -58,7 +61,7 @@ pry(main)> client.headers
|
|
58
61
|
|
59
62
|
```ruby
|
60
63
|
<!-- Company -->
|
61
|
-
response = client.
|
64
|
+
response = client.company('ekohe.com')
|
62
65
|
|
63
66
|
<!-- Get the JSON response of Company -->
|
64
67
|
|
@@ -70,11 +73,100 @@ response.as_json
|
|
70
73
|
#### Get the company data
|
71
74
|
|
72
75
|
```ruby
|
73
|
-
pry(main)> response = client.
|
76
|
+
pry(main)> response = client.company('ekohe.com')
|
77
|
+
=> #<Sourcescrub::Models::Company:0x00007f9e915161c0
|
78
|
+
@city="Xinzhuang",
|
79
|
+
@companyType="Private",
|
80
|
+
@country="China",
|
81
|
+
@crunchbase=nil,
|
82
|
+
@currentEmployeeCount=41,
|
83
|
+
@currentEmployeeRange="11-50",
|
84
|
+
@currentJobOpenings=0,
|
85
|
+
@description=
|
86
|
+
"Ekohe, Ltd. is a cutting-edge web and mobile design and development agency. It specialize in digital strategy, innovative technology and user-centered design experiences from conceptualization to market launch.",
|
87
|
+
@domain="ekohe.com",
|
88
|
+
@facebook=nil,
|
89
|
+
=> #<Sourcescrub::Models::Company:0x00007f9e915161c0
|
90
|
+
@city="Xinzhuang",
|
91
|
+
@companyType="Private",
|
92
|
+
@country="China",
|
93
|
+
@crunchbase=nil,
|
94
|
+
@currentEmployeeCount=41,
|
95
|
+
@currentEmployeeRange="11-50",
|
96
|
+
@currentJobOpenings=0,
|
97
|
+
@description=
|
98
|
+
"Ekohe, Ltd. is a cutting-edge web and mobile design and development agency. It specialize in digital strategy, innovative technology and user-centered design experiences from conceptualization to market la
|
99
|
+
unch.",
|
100
|
+
@domain="ekohe.com",
|
101
|
+
@facebook=nil,
|
102
|
+
@firmTags=[],
|
103
|
+
@foundingYear=2007,
|
104
|
+
@id="LZ281NVD",
|
105
|
+
@informalName="Ekohe",
|
106
|
+
@investors="",
|
107
|
+
@linkedIn="https://www.linkedin.com/company/ekohe",
|
108
|
+
@location="Xinzhuang, Shanghai Shi, China",
|
109
|
+
@name="Ekohe, Ltd.",
|
110
|
+
@parentCompanyDomain=nil,
|
111
|
+
@personalTags=[],
|
112
|
+
@phoneNumber="",
|
113
|
+
@postalCode=nil,
|
114
|
+
@specialties=
|
115
|
+
["IT & Startup Consulting",
|
116
|
+
"Ruby on Rails leaders",
|
117
|
+
"Intelligent Web & Mobile Development",
|
118
|
+
"Usable Web & Mobile design",
|
119
|
+
"UX or UI Design",
|
120
|
+
"Artificial Intelligence",
|
121
|
+
"Machine Learning",
|
122
|
+
"Data Sourcing",
|
123
|
+
"FinTech Tools"],
|
124
|
+
@state="Shanghai Shi",
|
125
|
+
@totalAmountInvested=0,
|
126
|
+
@twitter=nil,
|
127
|
+
@website="https://ekohe.com">
|
74
128
|
pry(main)> response.name
|
75
129
|
=> "Ekohe, Ltd."
|
76
130
|
pry(main)> response.domain
|
77
131
|
=> "ekohe.com"
|
132
|
+
pry(main)> response.as_json
|
133
|
+
=> {:id=>"LZ281NVD",
|
134
|
+
:companyType=>"Private",
|
135
|
+
:name=>"Ekohe, Ltd.",
|
136
|
+
:informalName=>"Ekohe",
|
137
|
+
:website=>"https://ekohe.com",
|
138
|
+
:domain=>"ekohe.com",
|
139
|
+
:description=>
|
140
|
+
"Ekohe, Ltd. is a cutting-edge web and mobile design and development agency. It specialize in digital strategy, innovative technology and user-centered design experiences from conceptualization to market launch.",
|
141
|
+
:foundingYear=>2007,
|
142
|
+
:location=>"Xinzhuang, Shanghai Shi, China",
|
143
|
+
:city=>"Xinzhuang",
|
144
|
+
:state=>"Shanghai Shi",
|
145
|
+
:postalCode=>nil,
|
146
|
+
:country=>"China",
|
147
|
+
:parentCompanyDomain=>nil,
|
148
|
+
:phoneNumber=>"",
|
149
|
+
:specialties=>
|
150
|
+
["IT & Startup Consulting",
|
151
|
+
"Ruby on Rails leaders",
|
152
|
+
"Intelligent Web & Mobile Development",
|
153
|
+
"Usable Web & Mobile design",
|
154
|
+
"UX or UI Design",
|
155
|
+
"Artificial Intelligence",
|
156
|
+
"Machine Learning",
|
157
|
+
"Data Sourcing",
|
158
|
+
"FinTech Tools"],
|
159
|
+
:facebook=>nil,
|
160
|
+
:twitter=>nil,
|
161
|
+
:crunchbase=>nil,
|
162
|
+
:linkedIn=>"https://www.linkedin.com/company/ekohe",
|
163
|
+
:totalAmountInvested=>0,
|
164
|
+
:currentEmployeeCount=>41,
|
165
|
+
:currentEmployeeRange=>"11-50",
|
166
|
+
:currentJobOpenings=>0,
|
167
|
+
:investors=>"",
|
168
|
+
:personalTags=>[],
|
169
|
+
:firmTags=>[]}
|
78
170
|
```
|
79
171
|
|
80
172
|
### Searches
|
@@ -85,7 +177,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
85
177
|
|
86
178
|
## Contributing
|
87
179
|
|
88
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
180
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ekohe/sourcescrub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ekohe/sourcescrub/blob/master/CODE_OF_CONDUCT.md).
|
89
181
|
|
90
182
|
|
91
183
|
## License
|
@@ -94,4 +186,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
94
186
|
|
95
187
|
## Code of Conduct
|
96
188
|
|
97
|
-
Everyone interacting in the Sourcescrub project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
189
|
+
Everyone interacting in the Sourcescrub project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ekohe/sourcescrub/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/sourcescrub.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'json'
|
3
4
|
require 'sourcescrub/version'
|
4
5
|
|
5
6
|
require 'sourcescrub/account'
|
6
7
|
require 'sourcescrub/client'
|
7
8
|
require 'sourcescrub/models'
|
9
|
+
require 'sourcescrub/utils/veriables'
|
8
10
|
|
11
|
+
# Sourcescrub
|
9
12
|
module Sourcescrub
|
10
13
|
TOKEN_URL = 'https://identity.sourcescrub.com'
|
11
14
|
TOKEN_URI = '/connect/token'
|
@@ -14,5 +17,6 @@ module Sourcescrub
|
|
14
17
|
API_URI = 'https://api.sourcescrub.com/'
|
15
18
|
|
16
19
|
class Error < StandardError; end
|
17
|
-
|
20
|
+
|
21
|
+
include Utils::Veriables
|
18
22
|
end
|
@@ -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
|
@@ -12,21 +13,86 @@ module Sourcescrub
|
|
12
13
|
attr_accessor :token
|
13
14
|
|
14
15
|
def headers
|
15
|
-
@token
|
16
|
+
authenticate if @token.nil?
|
16
17
|
|
17
18
|
{ 'Authorization' => "Bearer #{@token}" }
|
18
19
|
end
|
19
20
|
|
20
|
-
def
|
21
|
+
def company(domain, args = {})
|
21
22
|
api = companies_api(domain, args)
|
22
23
|
|
23
24
|
api.sobject.parse_response get(api.request_url, api.args)
|
24
25
|
end
|
25
26
|
|
27
|
+
def company_cards(domain, args = {})
|
28
|
+
api = companies_api(domain, args.merge(model_type: company_card_mappings[args[:card_id]]))
|
29
|
+
|
30
|
+
Models::CompanyItems.new.parse_response_items(
|
31
|
+
domain,
|
32
|
+
api.kclass_name,
|
33
|
+
get(api.request_url, api.args)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
# The max limit range is 0 - 100
|
38
|
+
def all_sources(args = { sourceStatus: 'None', limit: 100, offset: 0 })
|
39
|
+
api = source_api('sources', args)
|
40
|
+
|
41
|
+
Models::SourceItems.new.parse_response_items(
|
42
|
+
api.kclass_name,
|
43
|
+
get(api.request_url, api.args)
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def sources(source_id, args = {})
|
48
|
+
api = source_api(source_id, args)
|
49
|
+
|
50
|
+
api.sobject.parse_response get(api.request_url, api.args)
|
51
|
+
end
|
52
|
+
|
53
|
+
def source_companies(source_id, args = {})
|
54
|
+
api = source_companies_api(source_id, args)
|
55
|
+
|
56
|
+
Models::CompanyItems.new.parse_response_items(
|
57
|
+
source_id,
|
58
|
+
api.kclass_name,
|
59
|
+
get(api.companies_url, api.args)
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
26
63
|
private
|
27
64
|
|
28
65
|
def companies_api(domain, args)
|
29
|
-
@companies_api
|
66
|
+
@companies_api ||= Apis::Companies.new(
|
67
|
+
domain,
|
68
|
+
{ model_type: 'company' }.merge(args)
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
def source_api(source_id, args)
|
73
|
+
@source_api ||= Apis::Sources.new(
|
74
|
+
source_id,
|
75
|
+
{ model_type: 'source' }.merge(args)
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
def source_companies_api(source_id, args)
|
80
|
+
@source_companies_api ||= Apis::Sources.new(
|
81
|
+
source_id,
|
82
|
+
{ model_type: 'company' }.merge(args)
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
def company_card_mappings
|
87
|
+
{
|
88
|
+
'sources' => 'source',
|
89
|
+
'people' => 'person',
|
90
|
+
'financials' => 'financial',
|
91
|
+
'investments' => 'investment',
|
92
|
+
'employees' => 'employee',
|
93
|
+
'tags' => 'tag',
|
94
|
+
'employeerange' => 'employee_range'
|
95
|
+
}
|
30
96
|
end
|
31
97
|
end
|
32
98
|
end
|
data/lib/sourcescrub/models.rb
CHANGED
@@ -3,9 +3,16 @@
|
|
3
3
|
module Sourcescrub
|
4
4
|
# Models
|
5
5
|
module Models
|
6
|
-
autoload :Entity,
|
7
|
-
autoload :Company,
|
8
|
-
autoload :
|
9
|
-
autoload :
|
6
|
+
autoload :Entity, 'sourcescrub/models/concerns/entity'
|
7
|
+
autoload :Company, 'sourcescrub/models/company'
|
8
|
+
autoload :CompanyItems, 'sourcescrub/models/concerns/company_items'
|
9
|
+
autoload :SourceItems, 'sourcescrub/models/concerns/source_items'
|
10
|
+
autoload :Source, 'sourcescrub/models/source'
|
11
|
+
autoload :Tag, 'sourcescrub/models/tag'
|
12
|
+
autoload :Person, 'sourcescrub/models/person'
|
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'
|
10
17
|
end
|
11
18
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sourcescrub
|
4
|
+
# Models
|
5
|
+
module Models
|
6
|
+
# Tag
|
7
|
+
class CompanyItems < Entity
|
8
|
+
attr_accessor :domain, :total, :items, :type
|
9
|
+
|
10
|
+
def parse_response_items(domain, 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, 'domain', domain)
|
19
|
+
dynamic_define_method(self, 'type', kclass_name)
|
20
|
+
dynamic_define_method(self, 'total', response.dig(total_key) || 0)
|
21
|
+
dynamic_define_method(self, 'items', company_items(kclass_name, response.dig(items_key) || []))
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def company_items(kclass_name, items)
|
28
|
+
items.each_with_object([]) do |item, results|
|
29
|
+
results << kclass_name.new.parse_response(item)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def total_key
|
34
|
+
case type_name
|
35
|
+
when 'Person'
|
36
|
+
'totalPeople'
|
37
|
+
else
|
38
|
+
'total'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def items_key
|
43
|
+
case type_name
|
44
|
+
when 'Person'
|
45
|
+
'peopleAllocations'
|
46
|
+
else
|
47
|
+
'items'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def type_name
|
52
|
+
type.name.split('::')[-1]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
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
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sourcescrub
|
4
|
+
# Models
|
5
|
+
module Models
|
6
|
+
# Financial
|
7
|
+
class Financial < Entity
|
8
|
+
ENDPOINT = 'financials'
|
9
|
+
|
10
|
+
def field_ids
|
11
|
+
%w[
|
12
|
+
year
|
13
|
+
revenue
|
14
|
+
growth
|
15
|
+
growthTimePeriod
|
16
|
+
]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sourcescrub
|
4
|
+
# Models
|
5
|
+
module Models
|
6
|
+
# Investment
|
7
|
+
class Investment < Entity
|
8
|
+
ENDPOINT = 'investments'
|
9
|
+
|
10
|
+
def field_ids
|
11
|
+
%w[
|
12
|
+
amount
|
13
|
+
dateOfRaise
|
14
|
+
round
|
15
|
+
investors
|
16
|
+
valuation
|
17
|
+
]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sourcescrub
|
4
|
+
# Models
|
5
|
+
module Models
|
6
|
+
# Person
|
7
|
+
class Person < Entity
|
8
|
+
ENDPOINT = 'people'
|
9
|
+
|
10
|
+
def field_ids
|
11
|
+
%w[
|
12
|
+
personId
|
13
|
+
firstName
|
14
|
+
firstName
|
15
|
+
lastName
|
16
|
+
linkedIn
|
17
|
+
startDate
|
18
|
+
endDate
|
19
|
+
email
|
20
|
+
emailConfirmed
|
21
|
+
title
|
22
|
+
role
|
23
|
+
]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
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
|
@@ -21,43 +19,59 @@ module Sourcescrub
|
|
21
19
|
#
|
22
20
|
#
|
23
21
|
def get(uri, *args)
|
24
|
-
response = Faraday.new(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
22
|
+
response = Faraday.new(
|
23
|
+
url: API_URI,
|
24
|
+
headers: headers,
|
25
|
+
request: {
|
26
|
+
timeout: 10,
|
27
|
+
open_timeout: 5
|
28
|
+
}
|
29
|
+
).get(uri, *args)
|
30
|
+
|
31
|
+
response_body = response.body
|
32
|
+
raise Error, response_body unless response.status == 200
|
33
|
+
|
34
|
+
response_body = JSON.parse(response_body)
|
35
|
+
# Processing different cases for investments
|
36
|
+
if response_body.is_a?(Array)
|
37
|
+
response_body = if response_body.empty?
|
38
|
+
{}
|
39
|
+
else
|
40
|
+
{
|
41
|
+
'total' => response_body.size,
|
42
|
+
'items' => response_body
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
response_body.merge('headers' => response.headers)
|
34
48
|
end
|
35
49
|
|
36
|
-
def put(uri, args)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
50
|
+
# def put(uri, args)
|
51
|
+
# response = Faraday.new(url: API_URI) do |faraday|
|
52
|
+
# faraday.headers = headers
|
53
|
+
# faraday.request :json
|
54
|
+
# faraday.response :json
|
55
|
+
# faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
|
56
|
+
# end.put(uri, args)
|
43
57
|
|
44
|
-
|
58
|
+
# return response.body if response.status == 200
|
45
59
|
|
46
|
-
|
47
|
-
end
|
60
|
+
# raise Error, response.body
|
61
|
+
# end
|
48
62
|
|
49
|
-
def delete(uri, args)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
63
|
+
# def delete(uri, args)
|
64
|
+
# response = Faraday.new(url: API_URI) do |faraday|
|
65
|
+
# faraday.headers = headers
|
66
|
+
# faraday.request :json
|
67
|
+
# faraday.response :json
|
68
|
+
# faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
|
69
|
+
# end.delete(uri, args)
|
56
70
|
|
57
|
-
|
71
|
+
# return response.body if response.status == 200
|
58
72
|
|
59
|
-
|
60
|
-
end
|
73
|
+
# raise Error, response.body
|
74
|
+
# end
|
61
75
|
|
62
76
|
# Authentication Token
|
63
77
|
#
|
@@ -73,20 +87,17 @@ module Sourcescrub
|
|
73
87
|
def authenticate
|
74
88
|
body = "grant_type=password&username=#{Sourcescrub.account.username}&password=#{Sourcescrub.account.password}&scope=client_api"
|
75
89
|
|
76
|
-
response = Faraday.new(
|
77
|
-
|
90
|
+
response = Faraday.new(
|
91
|
+
url: TOKEN_URL,
|
92
|
+
headers: {
|
78
93
|
'Content-Type' => 'application/x-www-form-urlencoded',
|
79
94
|
'Authorization' => Sourcescrub.account.basic
|
80
95
|
}
|
81
|
-
|
82
|
-
faraday.request :json
|
83
|
-
faraday.response :json
|
84
|
-
faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
|
85
|
-
end.post(TOKEN_URI, body)
|
96
|
+
).post(TOKEN_URI, body)
|
86
97
|
|
87
|
-
raise '
|
98
|
+
raise 'Sourcescrub error: Service Unavailable' unless response.status == 200
|
88
99
|
|
89
|
-
@token = response.body['access_token']
|
100
|
+
@token = JSON.parse(response.body)['access_token']
|
90
101
|
end
|
91
102
|
|
92
103
|
private
|
@@ -8,6 +8,25 @@ module Sourcescrub
|
|
8
8
|
module_function
|
9
9
|
|
10
10
|
def dynamic_attributes(object, attribute_names, response)
|
11
|
+
# Retrieve request limit data from header
|
12
|
+
#
|
13
|
+
# .date
|
14
|
+
# .content_type
|
15
|
+
# .server
|
16
|
+
# .content_length
|
17
|
+
# .request_context
|
18
|
+
# .strict_transport_security
|
19
|
+
# .x_ratelimit_limit
|
20
|
+
# .x_ratelimit_remaining
|
21
|
+
# .x_ratelimit_reset
|
22
|
+
headers = response.dig('headers')
|
23
|
+
headers&.keys&.each do |attr_name|
|
24
|
+
object.class.send(:define_method, attr_name.gsub('-', '_').to_sym) do
|
25
|
+
headers[attr_name]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Setup attributes
|
11
30
|
attribute_names.each do |attr_name|
|
12
31
|
attr_value = response.dig(attr_name)
|
13
32
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sourcescrub
|
4
|
+
# Utils
|
5
|
+
module Utils
|
6
|
+
# Veriables
|
7
|
+
module Veriables
|
8
|
+
# Description of operators
|
9
|
+
PEOPLE_ROLES = {
|
10
|
+
'founder' => 'Founder',
|
11
|
+
'employee' => 'Employee',
|
12
|
+
'board_member' => 'Board Member',
|
13
|
+
'advisor' => 'Advisor'
|
14
|
+
}.freeze
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Encore Shao
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-12 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,15 +104,24 @@ 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
|
111
|
+
- lib/sourcescrub/models/concerns/company_items.rb
|
124
112
|
- lib/sourcescrub/models/concerns/entity.rb
|
113
|
+
- lib/sourcescrub/models/concerns/source_items.rb
|
114
|
+
- lib/sourcescrub/models/employee.rb
|
115
|
+
- lib/sourcescrub/models/employee_range.rb
|
116
|
+
- lib/sourcescrub/models/financial.rb
|
117
|
+
- lib/sourcescrub/models/investment.rb
|
118
|
+
- lib/sourcescrub/models/person.rb
|
125
119
|
- lib/sourcescrub/models/source.rb
|
126
120
|
- lib/sourcescrub/models/tag.rb
|
127
121
|
- lib/sourcescrub/utils/request.rb
|
128
122
|
- lib/sourcescrub/utils/response.rb
|
129
123
|
- lib/sourcescrub/utils/ss_model.rb
|
124
|
+
- lib/sourcescrub/utils/veriables.rb
|
130
125
|
- lib/sourcescrub/version.rb
|
131
126
|
- sourcescrub.gemspec
|
132
127
|
homepage: https://github.com/ekohe/sourcescrub
|
@@ -137,7 +132,7 @@ metadata:
|
|
137
132
|
homepage_uri: https://github.com/ekohe/sourcescrub
|
138
133
|
source_code_uri: https://github.com/ekohe/sourcescrub
|
139
134
|
changelog_uri: https://github.com/ekohe/sourcescrub/blob/master/CHANGELOG.md
|
140
|
-
post_install_message:
|
135
|
+
post_install_message:
|
141
136
|
rdoc_options: []
|
142
137
|
require_paths:
|
143
138
|
- lib
|
@@ -153,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
148
|
version: '0'
|
154
149
|
requirements: []
|
155
150
|
rubygems_version: 3.0.3
|
156
|
-
signing_key:
|
151
|
+
signing_key:
|
157
152
|
specification_version: 4
|
158
153
|
summary: Sourcescrub is a ruby wrapper based on Source Scrub API.
|
159
154
|
test_files: []
|