sourcescrub 0.0.3 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 545d2b8b334ea07bbe2685f9a3b6d272aac07d1bf844b5193cd8253359365ba6
4
- data.tar.gz: 49b57da12028f5755a3339451eda02029f65e66b5adb594d2b097434d526fa5f
3
+ metadata.gz: 3f41dea3cdbae246c59a9d375d31d5eff2f1897b09140415efc832a25efe52c2
4
+ data.tar.gz: 3ac121521449233ecca410aed6a1a6f3d8071f60162c2d9edc727a39284d9855
5
5
  SHA512:
6
- metadata.gz: 1d75bb44c81093c2d4ce1a757a5c83741c8b7f0699625cb7551d17fb87b4828aec2e7515ccfc1a771d38de96c78aaa88f7d860c7782c051dd5f4185f3247a0f5
7
- data.tar.gz: 8d2bf71686def7d5743d537babfab8eba380584aa0654dd33f92cbaac424b6e559df15e352da1aaae5856404b39335165e25a689b366631ddb328443f3dcc83d
6
+ metadata.gz: 5a08fc46e8376a96db5e1d32d5697f9a3b34f8190e7be90d84d5f3fb196f45ccf063953a56efd73b087608a4d19477a907ce7e8f69a2f4ec52ddc4a8314bd1ac
7
+ data.tar.gz: 759e47f3afd856181b36d79f7cb37e9894c35eca866087ef0d1266b9616c262b86764ac64f1084e5f1dee61ece13a14f617d00fd0c2350843ee936986c65c00b
@@ -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
@@ -1,9 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sourcescrub (0.0.3)
4
+ sourcescrub (0.0.8)
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
@@ -61,8 +61,7 @@ pry(main)> client.headers
61
61
 
62
62
  ```ruby
63
63
  <!-- Company -->
64
- response = client.companies('ekohe.com')
65
- response = client.company_cards('ekohe.com', { card_id: 'sources' })
64
+ response = client.company('ekohe.com')
66
65
 
67
66
  <!-- Get the JSON response of Company -->
68
67
 
@@ -74,8 +73,8 @@ response.as_json
74
73
  #### Get the company data
75
74
 
76
75
  ```ruby
77
- pry(main)> response = client.companies('ekohe.com')
78
- pry(main)> #<Sourcescrub::Models::Company:0x00007fcd31bcd238
76
+ pry(main)> response = client.company('ekohe.com')
77
+ => #<Sourcescrub::Models::Company:0x00007f9e915161c0
79
78
  @city="Xinzhuang",
80
79
  @companyType="Private",
81
80
  @country="China",
@@ -87,19 +86,87 @@ pry(main)> #<Sourcescrub::Models::Company:0x00007fcd31bcd238
87
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.",
88
87
  @domain="ekohe.com",
89
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,
90
102
  @firmTags=[],
91
103
  @foundingYear=2007,
92
104
  @id="LZ281NVD",
93
105
  @informalName="Ekohe",
94
- @investors=nil,
106
+ @investors="",
95
107
  @linkedIn="https://www.linkedin.com/company/ekohe",
96
108
  @location="Xinzhuang, Shanghai Shi, China",
97
109
  @name="Ekohe, Ltd.",
98
- .....>
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">
99
128
  pry(main)> response.name
100
129
  => "Ekohe, Ltd."
101
130
  pry(main)> response.domain
102
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=>[]}
103
170
  ```
104
171
 
105
172
  ### Searches
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
3
4
  require 'sourcescrub/version'
4
5
 
5
6
  require 'sourcescrub/account'
@@ -26,6 +26,13 @@ module Sourcescrub
26
26
  @card_id
27
27
  ].compact.join('/')
28
28
  end
29
+
30
+ def search_url
31
+ [
32
+ 'search',
33
+ Models::Company::ENDPOINT
34
+ ].compact.join('/')
35
+ end
29
36
  end
30
37
  end
31
38
  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
@@ -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,38 +13,102 @@ module Sourcescrub
12
13
  attr_accessor :token
13
14
 
14
15
  def headers
15
- @token || authenticate
16
+ authenticate if @token.nil?
16
17
 
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 = companies_api(domain, args)
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 = companies_api(domain, args.merge(model_type: card_mappings[args[:card_id]]))
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
- Models::CompanyItems.new.parse_response_items(domain, api.kclass_name, get(api.request_url, api.args))
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(domain, args)
35
- @companies_api || Apis::Companies.new(domain,
36
- { model_type: 'company' }.merge(args))
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 card_mappings
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
@@ -6,8 +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'
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'
12
17
  end
13
18
  end
@@ -17,8 +17,8 @@ module Sourcescrub
17
17
 
18
18
  dynamic_define_method(self, 'domain', domain)
19
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)))
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
22
  self
23
23
  end
24
24
 
@@ -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,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sourcescrub
4
+ # Models
5
+ module Models
6
+ # Employee
7
+ class EmployeeRange < Entity
8
+ ENDPOINT = 'employeerange'
9
+
10
+ def field_ids
11
+ %w[
12
+ employeeRange
13
+ date
14
+ ]
15
+ end
16
+ end
17
+ end
18
+ 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
@@ -28,14 +26,25 @@ module Sourcescrub
28
26
  timeout: 10,
29
27
  open_timeout: 5
30
28
  }
31
- ) do |faraday|
32
- faraday.response :json
33
- faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
34
- end.get(uri, *args)
35
-
36
- return response.body.merge('headers' => response.headers) if response.status == 200
37
-
38
- raise Error, response.body
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)
39
48
  end
40
49
 
41
50
  # def put(uri, args)
@@ -84,15 +93,11 @@ module Sourcescrub
84
93
  'Content-Type' => 'application/x-www-form-urlencoded',
85
94
  'Authorization' => Sourcescrub.account.basic
86
95
  }
87
- ) do |faraday|
88
- faraday.adapter Faraday.default_adapter
89
- faraday.response :json
90
- faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
91
- end.post(TOKEN_URI, body)
96
+ ).post(TOKEN_URI, body)
92
97
 
93
98
  raise 'Sourcescrub error: Service Unavailable' unless response.status == 200
94
99
 
95
- @token = response.body['access_token']
100
+ @token = JSON.parse(response.body)['access_token']
96
101
  end
97
102
 
98
103
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sourcescrub
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.8'
5
5
  end
@@ -30,7 +30,6 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ['lib']
31
31
 
32
32
  spec.add_dependency 'faraday'
33
- spec.add_dependency 'faraday_middleware'
34
33
 
35
34
  # VCR for testing APIs
36
35
  spec.add_development_dependency 'vcr'
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.3
4
+ version: 0.0.8
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-06-20 00:00:00.000000000 Z
11
+ date: 2020-08-13 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
@@ -143,7 +132,7 @@ metadata:
143
132
  homepage_uri: https://github.com/ekohe/sourcescrub
144
133
  source_code_uri: https://github.com/ekohe/sourcescrub
145
134
  changelog_uri: https://github.com/ekohe/sourcescrub/blob/master/CHANGELOG.md
146
- post_install_message:
135
+ post_install_message:
147
136
  rdoc_options: []
148
137
  require_paths:
149
138
  - lib
@@ -159,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
148
  version: '0'
160
149
  requirements: []
161
150
  rubygems_version: 3.0.3
162
- signing_key:
151
+ signing_key:
163
152
  specification_version: 4
164
153
  summary: Sourcescrub is a ruby wrapper based on Source Scrub API.
165
154
  test_files: []