sourcescrub 0.0.2 → 0.0.3
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/.rubocop_todo.yml +3 -0
- data/CHANGELOG.md +16 -2
- data/Gemfile.lock +1 -1
- data/README.md +27 -2
- data/lib/sourcescrub.rb +4 -1
- data/lib/sourcescrub/apis/companies.rb +1 -1
- data/lib/sourcescrub/client.rb +20 -2
- data/lib/sourcescrub/models.rb +6 -4
- data/lib/sourcescrub/models/concerns/company_items.rb +56 -0
- data/lib/sourcescrub/models/employee.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 +38 -32
- data/lib/sourcescrub/utils/response.rb +19 -0
- data/lib/sourcescrub/utils/veriables.rb +17 -0
- data/lib/sourcescrub/version.rb +1 -1
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 545d2b8b334ea07bbe2685f9a3b6d272aac07d1bf844b5193cd8253359365ba6
|
4
|
+
data.tar.gz: 49b57da12028f5755a3339451eda02029f65e66b5adb594d2b097434d526fa5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d75bb44c81093c2d4ce1a757a5c83741c8b7f0699625cb7551d17fb87b4828aec2e7515ccfc1a771d38de96c78aaa88f7d860c7782c051dd5f4185f3247a0f5
|
7
|
+
data.tar.gz: 8d2bf71686def7d5743d537babfab8eba380584aa0654dd33f92cbaac424b6e559df15e352da1aaae5856404b39335165e25a689b366631ddb328443f3dcc83d
|
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
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
|
+
[](https://badge.fury.io/rb/sourcescrub)
|
8
|
+
[](https://travis-ci.org/ekohe/sourcescrub)
|
9
|
+
|
7
10
|
## Installation
|
8
11
|
|
9
12
|
Add this line to your application's Gemfile:
|
@@ -59,6 +62,7 @@ pry(main)> client.headers
|
|
59
62
|
```ruby
|
60
63
|
<!-- Company -->
|
61
64
|
response = client.companies('ekohe.com')
|
65
|
+
response = client.company_cards('ekohe.com', { card_id: 'sources' })
|
62
66
|
|
63
67
|
<!-- Get the JSON response of Company -->
|
64
68
|
|
@@ -71,6 +75,27 @@ response.as_json
|
|
71
75
|
|
72
76
|
```ruby
|
73
77
|
pry(main)> response = client.companies('ekohe.com')
|
78
|
+
pry(main)> #<Sourcescrub::Models::Company:0x00007fcd31bcd238
|
79
|
+
@city="Xinzhuang",
|
80
|
+
@companyType="Private",
|
81
|
+
@country="China",
|
82
|
+
@crunchbase=nil,
|
83
|
+
@currentEmployeeCount=41,
|
84
|
+
@currentEmployeeRange="11-50",
|
85
|
+
@currentJobOpenings=0,
|
86
|
+
@description=
|
87
|
+
"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.",
|
88
|
+
@domain="ekohe.com",
|
89
|
+
@facebook=nil,
|
90
|
+
@firmTags=[],
|
91
|
+
@foundingYear=2007,
|
92
|
+
@id="LZ281NVD",
|
93
|
+
@informalName="Ekohe",
|
94
|
+
@investors=nil,
|
95
|
+
@linkedIn="https://www.linkedin.com/company/ekohe",
|
96
|
+
@location="Xinzhuang, Shanghai Shi, China",
|
97
|
+
@name="Ekohe, Ltd.",
|
98
|
+
.....>
|
74
99
|
pry(main)> response.name
|
75
100
|
=> "Ekohe, Ltd."
|
76
101
|
pry(main)> response.domain
|
@@ -85,7 +110,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
85
110
|
|
86
111
|
## Contributing
|
87
112
|
|
88
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
113
|
+
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
114
|
|
90
115
|
|
91
116
|
## License
|
@@ -94,4 +119,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
94
119
|
|
95
120
|
## Code of Conduct
|
96
121
|
|
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/
|
122
|
+
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
@@ -5,7 +5,9 @@ require 'sourcescrub/version'
|
|
5
5
|
require 'sourcescrub/account'
|
6
6
|
require 'sourcescrub/client'
|
7
7
|
require 'sourcescrub/models'
|
8
|
+
require 'sourcescrub/utils/veriables'
|
8
9
|
|
10
|
+
# Sourcescrub
|
9
11
|
module Sourcescrub
|
10
12
|
TOKEN_URL = 'https://identity.sourcescrub.com'
|
11
13
|
TOKEN_URI = '/connect/token'
|
@@ -14,5 +16,6 @@ module Sourcescrub
|
|
14
16
|
API_URI = 'https://api.sourcescrub.com/'
|
15
17
|
|
16
18
|
class Error < StandardError; end
|
17
|
-
|
19
|
+
|
20
|
+
include Utils::Veriables
|
18
21
|
end
|
data/lib/sourcescrub/client.rb
CHANGED
@@ -17,16 +17,34 @@ module Sourcescrub
|
|
17
17
|
{ 'Authorization' => "Bearer #{@token}" }
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def company(domain, args = {})
|
21
21
|
api = companies_api(domain, args)
|
22
22
|
|
23
23
|
api.sobject.parse_response get(api.request_url, api.args)
|
24
24
|
end
|
25
25
|
|
26
|
+
def company_cards(domain, args = {})
|
27
|
+
api = companies_api(domain, args.merge(model_type: card_mappings[args[:card_id]]))
|
28
|
+
|
29
|
+
Models::CompanyItems.new.parse_response_items(domain, api.kclass_name, get(api.request_url, api.args))
|
30
|
+
end
|
31
|
+
|
26
32
|
private
|
27
33
|
|
28
34
|
def companies_api(domain, args)
|
29
|
-
@companies_api || Apis::Companies.new(domain,
|
35
|
+
@companies_api || Apis::Companies.new(domain,
|
36
|
+
{ model_type: 'company' }.merge(args))
|
37
|
+
end
|
38
|
+
|
39
|
+
def card_mappings
|
40
|
+
{
|
41
|
+
'sources' => 'source',
|
42
|
+
'people' => 'person',
|
43
|
+
'financials' => 'financial',
|
44
|
+
'investments' => 'investment',
|
45
|
+
'employees' => 'employee',
|
46
|
+
'tags' => 'tag'
|
47
|
+
}
|
30
48
|
end
|
31
49
|
end
|
32
50
|
end
|
data/lib/sourcescrub/models.rb
CHANGED
@@ -3,9 +3,11 @@
|
|
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 :Source, 'sourcescrub/models/source'
|
10
|
+
autoload :Tag, 'sourcescrub/models/tag'
|
11
|
+
autoload :Person, 'sourcescrub/models/person'
|
10
12
|
end
|
11
13
|
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))
|
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,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
|
@@ -21,43 +21,48 @@ module Sourcescrub
|
|
21
21
|
#
|
22
22
|
#
|
23
23
|
def get(uri, *args)
|
24
|
-
response = Faraday.new(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
response = Faraday.new(
|
25
|
+
url: API_URI,
|
26
|
+
headers: headers,
|
27
|
+
request: {
|
28
|
+
timeout: 10,
|
29
|
+
open_timeout: 5
|
30
|
+
}
|
31
|
+
) do |faraday|
|
32
|
+
faraday.response :json
|
33
|
+
faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
|
29
34
|
end.get(uri, *args)
|
30
35
|
|
31
|
-
return response.body if response.status == 200
|
36
|
+
return response.body.merge('headers' => response.headers) if response.status == 200
|
32
37
|
|
33
38
|
raise Error, response.body
|
34
39
|
end
|
35
40
|
|
36
|
-
def put(uri, args)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
# def put(uri, args)
|
42
|
+
# response = Faraday.new(url: API_URI) do |faraday|
|
43
|
+
# faraday.headers = headers
|
44
|
+
# faraday.request :json
|
45
|
+
# faraday.response :json
|
46
|
+
# faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
|
47
|
+
# end.put(uri, args)
|
43
48
|
|
44
|
-
|
49
|
+
# return response.body if response.status == 200
|
45
50
|
|
46
|
-
|
47
|
-
end
|
51
|
+
# raise Error, response.body
|
52
|
+
# end
|
48
53
|
|
49
|
-
def delete(uri, args)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
# def delete(uri, args)
|
55
|
+
# response = Faraday.new(url: API_URI) do |faraday|
|
56
|
+
# faraday.headers = headers
|
57
|
+
# faraday.request :json
|
58
|
+
# faraday.response :json
|
59
|
+
# faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
|
60
|
+
# end.delete(uri, args)
|
56
61
|
|
57
|
-
|
62
|
+
# return response.body if response.status == 200
|
58
63
|
|
59
|
-
|
60
|
-
end
|
64
|
+
# raise Error, response.body
|
65
|
+
# end
|
61
66
|
|
62
67
|
# Authentication Token
|
63
68
|
#
|
@@ -73,18 +78,19 @@ module Sourcescrub
|
|
73
78
|
def authenticate
|
74
79
|
body = "grant_type=password&username=#{Sourcescrub.account.username}&password=#{Sourcescrub.account.password}&scope=client_api"
|
75
80
|
|
76
|
-
response = Faraday.new(
|
77
|
-
|
81
|
+
response = Faraday.new(
|
82
|
+
url: TOKEN_URL,
|
83
|
+
headers: {
|
78
84
|
'Content-Type' => 'application/x-www-form-urlencoded',
|
79
85
|
'Authorization' => Sourcescrub.account.basic
|
80
86
|
}
|
81
|
-
|
82
|
-
faraday.
|
83
|
-
faraday.response
|
87
|
+
) do |faraday|
|
88
|
+
faraday.adapter Faraday.default_adapter
|
89
|
+
faraday.response :json
|
84
90
|
faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
|
85
91
|
end.post(TOKEN_URI, body)
|
86
92
|
|
87
|
-
raise '
|
93
|
+
raise 'Sourcescrub error: Service Unavailable' unless response.status == 200
|
88
94
|
|
89
95
|
@token = response.body['access_token']
|
90
96
|
end
|
@@ -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
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Encore Shao
|
@@ -121,12 +121,18 @@ files:
|
|
121
121
|
- lib/sourcescrub/client.rb
|
122
122
|
- lib/sourcescrub/models.rb
|
123
123
|
- lib/sourcescrub/models/company.rb
|
124
|
+
- lib/sourcescrub/models/concerns/company_items.rb
|
124
125
|
- lib/sourcescrub/models/concerns/entity.rb
|
126
|
+
- lib/sourcescrub/models/employee.rb
|
127
|
+
- lib/sourcescrub/models/financial.rb
|
128
|
+
- lib/sourcescrub/models/investment.rb
|
129
|
+
- lib/sourcescrub/models/person.rb
|
125
130
|
- lib/sourcescrub/models/source.rb
|
126
131
|
- lib/sourcescrub/models/tag.rb
|
127
132
|
- lib/sourcescrub/utils/request.rb
|
128
133
|
- lib/sourcescrub/utils/response.rb
|
129
134
|
- lib/sourcescrub/utils/ss_model.rb
|
135
|
+
- lib/sourcescrub/utils/veriables.rb
|
130
136
|
- lib/sourcescrub/version.rb
|
131
137
|
- sourcescrub.gemspec
|
132
138
|
homepage: https://github.com/ekohe/sourcescrub
|