sourcescrub 0.0.5 → 0.0.6

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: 8afd87f86978b44cc34f969d64732c9599feb55d374e30a6b8744df9cac9d59d
4
- data.tar.gz: f23474e047b16466cd1c70c86bc93d2e773f633f31acbd4100110ac10ee1f2e0
3
+ metadata.gz: 6de299d6fd6488b24f851914c38bf4a85dcd312a156445f2f357da4228a63c6f
4
+ data.tar.gz: 8f5a7c9a5208a689b5bc404d4b08f4745829ed4099b5335ba278823f2568b5b4
5
5
  SHA512:
6
- metadata.gz: 70c3bdf3d103542aa9e54e40ddff7058013823a3138a391356a1de7880f01ab0f0696a2184bf8b89ab722637c179556b604ea7e0fcbaf74c6006a90f2bbd2588
7
- data.tar.gz: '09a723173d5387952e8826d511d8ce9e76a63de200f165f4a3c592bd5d91724bbce9196e2f5447ddf30186f74dc742f34dc83e805fe6ca95e68b87fa2ad51c74'
6
+ metadata.gz: 832239e6396f1ddcfff488575bec81676d096e96e3b4b14d15edc5f5b92f9032b4e0d918759b59ddf36ed35672a4b275f8f46233745bce88d9fd829be6c30aa9
7
+ data.tar.gz: fbec2f0e813005424144a1f50591dd7057edf8f7bbe961571ee05fb8a4fb0afc4b6b299967aa58dc4849491ef07a3e8c22ef97bd38745c9234e66133e3e986b4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sourcescrub (0.0.5)
4
+ sourcescrub (0.0.6)
5
5
  faraday
6
6
 
7
7
  GEM
@@ -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'
@@ -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
@@ -24,19 +25,65 @@ module Sourcescrub
24
25
  end
25
26
 
26
27
  def company_cards(domain, args = {})
27
- api = companies_api(domain, args.merge(model_type: card_mappings[args[:card_id]]))
28
+ api = companies_api(domain, args.merge(model_type: company_card_mappings[args[:card_id]]))
28
29
 
29
- Models::CompanyItems.new.parse_response_items(domain, api.kclass_name, get(api.request_url, api.args))
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
+ )
30
61
  end
31
62
 
32
63
  private
33
64
 
34
65
  def companies_api(domain, args)
35
- @companies_api || Apis::Companies.new(domain,
36
- { model_type: 'company' }.merge(args))
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
+ )
37
84
  end
38
85
 
39
- def card_mappings
86
+ def company_card_mappings
40
87
  {
41
88
  'sources' => 'source',
42
89
  'people' => 'person',
@@ -6,6 +6,7 @@ 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'
@@ -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
@@ -28,14 +28,12 @@ module Sourcescrub
28
28
  }
29
29
  ).get(uri, *args)
30
30
 
31
- response_body = JSON.parse(response.body)
32
- if response.status == 200
33
- response_body = {} if response_body.is_a?(Array) && response_body.empty?
31
+ response_body = response.body
32
+ raise Error, response_body unless response.status == 200
34
33
 
35
- return response_body.merge('headers' => response.headers)
36
- end
37
-
38
- raise Error, response_body
34
+ response_body = JSON.parse(response_body)
35
+ response_body = {} if response_body.is_a?(Array) && response_body.empty?
36
+ response_body.merge('headers' => response.headers)
39
37
  end
40
38
 
41
39
  # def put(uri, args)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sourcescrub
4
- VERSION = '0.0.5'
4
+ VERSION = '0.0.6'
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.5
4
+ version: 0.0.6
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-03 00:00:00.000000000 Z
11
+ date: 2020-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -104,11 +104,13 @@ files:
104
104
  - lib/sourcescrub.rb
105
105
  - lib/sourcescrub/account.rb
106
106
  - lib/sourcescrub/apis/companies.rb
107
+ - lib/sourcescrub/apis/sources.rb
107
108
  - lib/sourcescrub/client.rb
108
109
  - lib/sourcescrub/models.rb
109
110
  - lib/sourcescrub/models/company.rb
110
111
  - lib/sourcescrub/models/concerns/company_items.rb
111
112
  - lib/sourcescrub/models/concerns/entity.rb
113
+ - lib/sourcescrub/models/concerns/source_items.rb
112
114
  - lib/sourcescrub/models/employee.rb
113
115
  - lib/sourcescrub/models/financial.rb
114
116
  - lib/sourcescrub/models/investment.rb