sourcescrub 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2884125ab5a2d684096e4c2a1107ae6f561671f4122cc7cf34962b74f9e51b64
4
- data.tar.gz: d34e3f88743020e0eb49d4a7acadeb2fe0451d6742fcbcf1651b5eee08ad3494
3
+ metadata.gz: 7d8b09fea67b65e3ff5d2d8effb6d62a695a414b3b6f650561e2c261a0071d3f
4
+ data.tar.gz: 2746a0d58773997be22eab5c4b50bb01118bad06f9c149a7f4de86aa77f314af
5
5
  SHA512:
6
- metadata.gz: a0e4aca28751dbaa64568bbe53ddfae988c538b117d059d66ce5b9c2f37a13119616f2ad6d8d6e3b99d0110796eac6f0a7515e5a43cc03f184fce33c618229f7
7
- data.tar.gz: 9c8b1e392af7cc0bbd09d81cd6421f115503deb2872a49a58ea9e1ac4efd30c0e0b6be4a439f67dcee80ef415508d9b0972b042e6edda09fa44695b2d4b021cf
6
+ metadata.gz: e460c9f06ed36b2806d808d3360eaba605e3d43254699e0c284a210bde657e6e1f7c54e18e580fa7e9a1075b51510c3071a109af58e0807770f414dfbe868468
7
+ data.tar.gz: 45f1be48446d80daa3b11f4f15d604ea9b840d1c42d256bcbf6b7018f3d26ff720cfd820c9c8a20f5c5157ebd6dd9cfdceb17b3ab4ae1f1a67512a428c8da7c7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Change Log
2
2
 
3
+ ## [0.1.3] - 2024-06-17
4
+
5
+ - Get company data by SS ID - `client.company('XWO6N4OP')`
6
+ - Pull new fields of company
7
+ - threeMonthsGrowthRate
8
+ - sixMonthsGrowthRate
9
+ - nineMonthsGrowthRate
10
+ - twelveMonthsGrowthRate
11
+ - growthIntent
12
+ - customScore
13
+ - industries
14
+ - modifiedDate
15
+ - endMarkets
16
+ - productsAndServices
17
+
18
+ ## [0.1.2] - 2021-01-14
19
+
20
+ - Implement search source endpoint to allow use filters to get matched sources - `client.source_search({limit: 10, offset: 0})`
21
+
3
22
  ## [0.1.1] - 2020-11-03
4
23
 
5
24
  - Fixing wrong data issue of `currentEmployeeRange` in Company
@@ -17,8 +36,8 @@
17
36
  ## [0.0.3] - 2020-06-20
18
37
 
19
38
  - Implement API to request token by user certificate
20
- - Get company data by domain - `client.company(ekohe.com)`
21
- - Get company's relationship data by domain - `client.company(ekohe.com, {card_id: 'people'})`
39
+ - Get company data by domain - `client.company('ekohe.com')`
40
+ - Get company's relationship data by domain - `client.company('ekohe.com', {card_id: 'people'})`
22
41
  - Retrieve request limit data from header
23
42
 
24
43
  ```
data/Gemfile.lock CHANGED
@@ -1,35 +1,38 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sourcescrub (0.1.1)
4
+ sourcescrub (0.1.3)
5
5
  faraday
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.7.0)
10
+ addressable (2.8.0)
11
11
  public_suffix (>= 2.0.2, < 5.0)
12
12
  ast (2.4.1)
13
+ base64 (0.2.0)
13
14
  coderay (1.1.3)
14
15
  crack (0.4.3)
15
16
  safe_yaml (~> 1.0.0)
16
17
  diff-lcs (1.3)
17
- faraday (1.0.1)
18
- multipart-post (>= 1.2, < 3)
18
+ faraday (2.8.1)
19
+ base64
20
+ faraday-net_http (>= 2.0, < 3.1)
21
+ ruby2_keywords (>= 0.0.4)
22
+ faraday-net_http (3.0.2)
19
23
  hashdiff (1.0.1)
20
24
  method_source (1.0.0)
21
- multipart-post (2.1.1)
22
25
  parallel (1.19.2)
23
26
  parser (2.7.1.3)
24
27
  ast (~> 2.4.0)
25
28
  pry (0.13.1)
26
29
  coderay (~> 1.1)
27
30
  method_source (~> 1.0)
28
- public_suffix (4.0.5)
31
+ public_suffix (4.0.6)
29
32
  rainbow (3.0.0)
30
33
  rake (12.3.3)
31
34
  regexp_parser (1.7.1)
32
- rexml (3.2.4)
35
+ rexml (3.2.5)
33
36
  rspec (3.9.0)
34
37
  rspec-core (~> 3.9.0)
35
38
  rspec-expectations (~> 3.9.0)
@@ -55,6 +58,7 @@ GEM
55
58
  rubocop-ast (0.0.3)
56
59
  parser (>= 2.7.0.1)
57
60
  ruby-progressbar (1.10.1)
61
+ ruby2_keywords (0.0.5)
58
62
  safe_yaml (1.0.5)
59
63
  unicode-display_width (1.7.0)
60
64
  vcr (6.0.0)
data/README.md CHANGED
@@ -61,7 +61,8 @@ pry(main)> client.headers
61
61
 
62
62
  ```ruby
63
63
  <!-- Company -->
64
- response = client.company('ekohe.com')
64
+ response = client.company('ekohe.com') # get data by domain
65
+ response = client.company('LZ281NVD') # get data by SS ID
65
66
 
66
67
  <!-- Get the JSON response of Company -->
67
68
 
@@ -70,7 +71,7 @@ response.as_json
70
71
 
71
72
  ### Companies
72
73
 
73
- #### Get the company data
74
+ #### Get the company data by domain or Sourcescrub ID
74
75
 
75
76
  ```ruby
76
77
  pry(main)> response = client.company('ekohe.com')
@@ -179,6 +180,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
179
180
 
180
181
  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).
181
182
 
183
+ - [Encore](https://github.com/encoreshao)
182
184
 
183
185
  ## License
184
186
 
@@ -12,8 +12,8 @@ module Sourcescrub
12
12
 
13
13
  attr_accessor :args
14
14
 
15
- def initialize(domain, args)
16
- @domain = domain
15
+ def initialize(identifier, args)
16
+ @identifier = identifier
17
17
  @model_type = args.delete(:model_type)
18
18
  @card_id = args.delete(:card_id)
19
19
  @args = args
@@ -22,7 +22,7 @@ module Sourcescrub
22
22
  def request_url
23
23
  [
24
24
  Models::Company::ENDPOINT,
25
- @domain,
25
+ @identifier,
26
26
  @card_id
27
27
  ].compact.join('/')
28
28
  end
@@ -25,6 +25,13 @@ module Sourcescrub
25
25
  ].compact.join('/')
26
26
  end
27
27
 
28
+ def search_url
29
+ [
30
+ 'search',
31
+ Models::Source::ENDPOINT
32
+ ].compact.join('/')
33
+ end
34
+
28
35
  def companies_url
29
36
  [
30
37
  Models::Source::ENDPOINT,
@@ -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
 
@@ -28,17 +30,17 @@ module Sourcescrub
28
30
  )
29
31
  end
30
32
 
31
- def company(domain, args = {})
32
- api = company_api(domain, args)
33
+ def company(identifier, args = {})
34
+ api = company_api(identifier, args)
33
35
 
34
36
  api.sobject.parse_response get(api.request_url, api.args)
35
37
  end
36
38
 
37
- def company_cards(domain, args = {})
38
- api = company_api(domain, args.merge(model_type: company_card_mappings[args[:card_id]]))
39
+ def company_cards(identifier, args = {})
40
+ api = company_api(identifier, args.merge(model_type: company_card_mappings[args[:card_id]]))
39
41
 
40
42
  Models::CompanyItems.new.parse_response_items(
41
- domain,
43
+ identifier,
42
44
  api.kclass_name,
43
45
  get(api.request_url, api.args)
44
46
  )
@@ -54,6 +56,15 @@ module Sourcescrub
54
56
  )
55
57
  end
56
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
+
57
68
  def sources(source_id, args = {})
58
69
  api = source_api(source_id, args)
59
70
 
@@ -79,9 +90,9 @@ module Sourcescrub
79
90
  )
80
91
  end
81
92
 
82
- def company_api(domain, args)
93
+ def company_api(identifier, args)
83
94
  Apis::Companies.new(
84
- domain,
95
+ identifier,
85
96
  { model_type: 'company' }.merge(args)
86
97
  )
87
98
  end
@@ -93,6 +104,13 @@ module Sourcescrub
93
104
  )
94
105
  end
95
106
 
107
+ def source_search_api(args)
108
+ Apis::Sources.new(
109
+ nil,
110
+ { model_type: 'source' }.merge(args)
111
+ )
112
+ end
113
+
96
114
  def source_companies_api(source_id, args)
97
115
  Apis::Sources.new(
98
116
  source_id,
@@ -8,6 +8,7 @@ module Sourcescrub
8
8
  class Company < Entity
9
9
  ENDPOINT = 'companies'
10
10
 
11
+ # rubocop:disable Metrics/MethodLength
11
12
  def field_ids
12
13
  %w[
13
14
  id
@@ -32,13 +33,24 @@ module Sourcescrub
32
33
  linkedIn
33
34
  totalAmountInvested
34
35
  currentEmployeeCount
36
+ threeMonthsGrowthRate
37
+ sixMonthsGrowthRate
38
+ nineMonthsGrowthRate
39
+ twelveMonthsGrowthRate
35
40
  currentEmployeeRange
36
41
  currentJobOpenings
42
+ growthIntent
37
43
  investors
38
44
  personalTags
39
45
  firmTags
46
+ customScore
47
+ industries
48
+ modifiedDate
49
+ endMarkets
50
+ productsAndServices
40
51
  ]
41
52
  end
53
+ # rubocop:enable Metrics/MethodLength
42
54
  end
43
55
  end
44
56
  end
@@ -5,9 +5,10 @@ module Sourcescrub
5
5
  module Models
6
6
  # Tag
7
7
  class CompanyItems < Entity
8
- attr_accessor :domain, :total, :items, :type
8
+ attr_accessor :identifier, :total, :items, :type
9
9
 
10
- def parse_response_items(domain, kclass_name, response)
10
+ # the identifier can be domain or SS ID
11
+ def parse_response_items(identifier, kclass_name, response)
11
12
  headers = response.dig('headers')
12
13
  headers&.keys&.each do |attr_name|
13
14
  self.class.send(:define_method, attr_name.gsub('-', '_').to_sym) do
@@ -15,7 +16,7 @@ module Sourcescrub
15
16
  end
16
17
  end
17
18
 
18
- dynamic_define_method(self, 'domain', domain)
19
+ dynamic_define_method(self, 'identifier', identifier)
19
20
  dynamic_define_method(self, 'type', kclass_name)
20
21
  dynamic_define_method(self, 'total', response.dig(total_key) || 0)
21
22
  dynamic_define_method(self, 'items', company_items(kclass_name, response.dig(items_key) || []))
@@ -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,33 +20,28 @@ module Sourcescrub
19
20
  #
20
21
  #
21
22
  def get(uri, *args)
22
- response = Faraday.new(
23
- url: API_URI,
24
- headers: headers,
25
- request: {
26
- timeout: 10,
27
- open_timeout: 5
28
- },
29
- params: args[0] || {}
30
- ).get(uri)
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)
31
28
 
32
- response_body = response.body
33
- raise Error, response_body unless response.status == 200
29
+ raise Error, response.body unless response.status == 200
34
30
 
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
46
- end
47
-
48
- response_body.merge('headers' => response.headers)
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)
49
45
  end
50
46
 
51
47
  # def put(uri, args)
@@ -103,6 +99,31 @@ module Sourcescrub
103
99
 
104
100
  private
105
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
+
106
127
  def debug_mode?
107
128
  Sourcescrub.account.debug || false
108
129
  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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sourcescrub
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.3'
5
5
  end
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.1.1
4
+ version: 0.1.3
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-03 00:00:00.000000000 Z
11
+ date: 2024-06-17 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
@@ -147,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
148
  - !ruby/object:Gem::Version
148
149
  version: '0'
149
150
  requirements: []
150
- rubygems_version: 3.0.3
151
+ rubygems_version: 3.1.6
151
152
  signing_key:
152
153
  specification_version: 4
153
154
  summary: Sourcescrub is a ruby wrapper based on Source Scrub API.