sourcescrub 0.0.7 → 0.1.2

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: c425f778c050e471a59f52d8101bc7d5b2bd926e333292525ebe9ad67d4dce65
4
- data.tar.gz: b98238083a2c65ec56cf6d45e82141c2b2f70a9ffde7eaa6be46a989f0c30a01
3
+ metadata.gz: 8631fba58663ed2b6340e63ac4dcbfdd387a07aa1192bb0ab911412071bf25f7
4
+ data.tar.gz: 446f9ebbbbe9fe5acf1eaef967c2b10983e3f5ce9c2362799e1071af34dcf9dd
5
5
  SHA512:
6
- metadata.gz: b5b33a6b315e789588f09039cd5b62d1e038833019f2ada2b31b9eff4f99e967745db6a65698a5f4226e6bdaa3d47a62492d916e990f6ba3815a926da5526418
7
- data.tar.gz: 17be5421cb1d3008de1248befc059f9e481424b966106a80afc4622f375e594ca65e98b071522b970955b2692d9634efd4f53e4d14db028bc6827b5aa3b042ec
6
+ metadata.gz: 54577a01f056d9414ffe17e72ff651e1bda42c4776ca9d820d672943a3e4f866fff933f80447feb96131932f8dadc28c132fb8a5da7149aee57bf893ee7c7d0b
7
+ data.tar.gz: 726091a74644fbf1f0b09dcd5b70f8a1d5f542796ea9f756a969487362b85744165dcf823b25f2f47c8f6385c53368a582fdcf8da1f58d29fc959fe19020e249
@@ -1,5 +1,23 @@
1
1
  # Change Log
2
2
 
3
+ ## [0.1.2] - 2021-01-14
4
+
5
+ - Implement search source endpoint to allow use filters to get matched sources - `client.source_search({limit: 10, offset: 0})`
6
+
7
+ ## [0.1.1] - 2020-11-03
8
+
9
+ - Fixing wrong data issue of `currentEmployeeRange` in Company
10
+
11
+ ## [0.0.8] - 2020-08-13
12
+
13
+ - Implement API to request all compnies - `client.companies`
14
+
15
+ ## [0.0.7] - 2020-08-04
16
+
17
+ - Get source data and source compaines - `client.source_companies(source_id)`
18
+ - Get company's employeerange data by domain - `client.company_cards('monday.com', { card_id: 'employeerange' })`
19
+ - Get company's employees data by domain - `client.company_cards('monday.com', { card_id: 'employees' })`
20
+
3
21
  ## [0.0.3] - 2020-06-20
4
22
 
5
23
  - Implement API to request token by user certificate
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sourcescrub (0.0.7)
4
+ sourcescrub (0.1.2)
5
5
  faraday
6
6
 
7
7
  GEM
@@ -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
@@ -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
 
@@ -18,14 +20,24 @@ module Sourcescrub
18
20
  { 'Authorization' => "Bearer #{@token}" }
19
21
  end
20
22
 
23
+ def companies(args = { limit: 100, offset: 0 })
24
+ api = companies_api(args)
25
+
26
+ Models::CompanyItems.new.parse_response_items(
27
+ nil,
28
+ api.kclass_name,
29
+ get(api.search_url, api.args)
30
+ )
31
+ end
32
+
21
33
  def company(domain, args = {})
22
- api = companies_api(domain, args)
34
+ api = company_api(domain, args)
23
35
 
24
36
  api.sobject.parse_response get(api.request_url, api.args)
25
37
  end
26
38
 
27
39
  def company_cards(domain, args = {})
28
- api = companies_api(domain, args.merge(model_type: company_card_mappings[args[:card_id]]))
40
+ api = company_api(domain, args.merge(model_type: company_card_mappings[args[:card_id]]))
29
41
 
30
42
  Models::CompanyItems.new.parse_response_items(
31
43
  domain,
@@ -44,6 +56,15 @@ module Sourcescrub
44
56
  )
45
57
  end
46
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
+
47
68
  def sources(source_id, args = {})
48
69
  api = source_api(source_id, args)
49
70
 
@@ -62,22 +83,36 @@ module Sourcescrub
62
83
 
63
84
  private
64
85
 
65
- def companies_api(domain, args)
66
- @companies_api ||= Apis::Companies.new(
86
+ def companies_api(args)
87
+ Apis::Companies.new(
88
+ nil,
89
+ { model_type: 'company' }.merge(args)
90
+ )
91
+ end
92
+
93
+ def company_api(domain, args)
94
+ Apis::Companies.new(
67
95
  domain,
68
96
  { model_type: 'company' }.merge(args)
69
97
  )
70
98
  end
71
99
 
72
100
  def source_api(source_id, args)
73
- @source_api ||= Apis::Sources.new(
101
+ Apis::Sources.new(
74
102
  source_id,
75
103
  { model_type: 'source' }.merge(args)
76
104
  )
77
105
  end
78
106
 
107
+ def source_search_api(args)
108
+ Apis::Sources.new(
109
+ nil,
110
+ { model_type: 'source' }.merge(args)
111
+ )
112
+ end
113
+
79
114
  def source_companies_api(source_id, args)
80
- @source_companies_api ||= Apis::Sources.new(
115
+ Apis::Sources.new(
81
116
  source_id,
82
117
  { model_type: 'company' }.merge(args)
83
118
  )
@@ -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,32 +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
- ).get(uri, *args)
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)
30
28
 
31
- response_body = response.body
32
- raise Error, response_body unless response.status == 200
29
+ raise Error, response.body unless response.status == 200
33
30
 
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)
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)
48
45
  end
49
46
 
50
47
  # def put(uri, args)
@@ -102,6 +99,31 @@ module Sourcescrub
102
99
 
103
100
  private
104
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
+
105
127
  def debug_mode?
106
128
  Sourcescrub.account.debug || false
107
129
  end
@@ -29,6 +29,7 @@ module Sourcescrub
29
29
  # Setup attributes
30
30
  attribute_names.each do |attr_name|
31
31
  attr_value = response.dig(attr_name)
32
+ attr_value = nil if attr_name == 'currentEmployeeRange' && attr_value.is_a?(Integer)
32
33
 
33
34
  dynamic_define_method(object, attr_name, attr_value)
34
35
  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.0.7'
4
+ VERSION = '0.1.2'
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.0.7
4
+ version: 0.1.2
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-08-12 00:00:00.000000000 Z
11
+ date: 2021-01-14 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