sourcescrub 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 107c70bcbc69c0b446ae0941bb148b73589cc8e1523d39e49a86db3747b6bf86
4
+ data.tar.gz: 1d8f9cd07245567aca8a939a337e0c9b5382ac2f818a35f289b9e4743b2d3e56
5
+ SHA512:
6
+ metadata.gz: 18acb6bd965321c23ff581d164bd155091675c3ba8ca1cf81d43a3e590477aa3c5c1cba0aaeaea17a5b077be811ce4474345ab75c513223e0845699718f5f829
7
+ data.tar.gz: df208a12a4ec65fae1372f4969321c0bff6ce859013989810095301d0c2fbc0927719db4dedaebe8efeadbe3019eb3c89771aaebc42703f24300f114548dcb08
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ /spec/sourcescrub.yml
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
@@ -0,0 +1,24 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2020-06-20 16:17:24 +0800 using RuboCop version 0.85.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: IgnoredMethods.
11
+ Metrics/AbcSize:
12
+ Max: 20
13
+
14
+ # Offense count: 3
15
+ # Configuration parameters: CountComments, ExcludedMethods.
16
+ Metrics/MethodLength:
17
+ Max: 29
18
+
19
+ # Offense count: 1
20
+ # Cop supports --auto-correct.
21
+ # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
22
+ # URISchemes: http, https
23
+ Layout/LineLength:
24
+ Max: 135
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.1
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,6 @@
1
+ # Change Log
2
+
3
+ ## [0.0.1] - 2020-06-20
4
+
5
+ - Implement API to request token by user certificate
6
+ - Get company data by domain
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at encore.shao@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in sourcescrub.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
@@ -0,0 +1,82 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sourcescrub (0.0.1)
5
+ faraday
6
+ faraday_middleware
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ ast (2.4.1)
14
+ coderay (1.1.3)
15
+ crack (0.4.3)
16
+ safe_yaml (~> 1.0.0)
17
+ diff-lcs (1.3)
18
+ faraday (1.0.1)
19
+ multipart-post (>= 1.2, < 3)
20
+ faraday_middleware (1.0.0)
21
+ faraday (~> 1.0)
22
+ hashdiff (1.0.1)
23
+ method_source (1.0.0)
24
+ multipart-post (2.1.1)
25
+ parallel (1.19.2)
26
+ parser (2.7.1.3)
27
+ ast (~> 2.4.0)
28
+ pry (0.13.1)
29
+ coderay (~> 1.1)
30
+ method_source (~> 1.0)
31
+ public_suffix (4.0.5)
32
+ rainbow (3.0.0)
33
+ rake (12.3.3)
34
+ regexp_parser (1.7.1)
35
+ rexml (3.2.4)
36
+ rspec (3.9.0)
37
+ rspec-core (~> 3.9.0)
38
+ rspec-expectations (~> 3.9.0)
39
+ rspec-mocks (~> 3.9.0)
40
+ rspec-core (3.9.2)
41
+ rspec-support (~> 3.9.3)
42
+ rspec-expectations (3.9.2)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.9.0)
45
+ rspec-mocks (3.9.1)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.9.0)
48
+ rspec-support (3.9.3)
49
+ rubocop (0.85.1)
50
+ parallel (~> 1.10)
51
+ parser (>= 2.7.0.1)
52
+ rainbow (>= 2.2.2, < 4.0)
53
+ regexp_parser (>= 1.7)
54
+ rexml
55
+ rubocop-ast (>= 0.0.3)
56
+ ruby-progressbar (~> 1.7)
57
+ unicode-display_width (>= 1.4.0, < 2.0)
58
+ rubocop-ast (0.0.3)
59
+ parser (>= 2.7.0.1)
60
+ ruby-progressbar (1.10.1)
61
+ safe_yaml (1.0.5)
62
+ unicode-display_width (1.7.0)
63
+ vcr (6.0.0)
64
+ webmock (3.8.3)
65
+ addressable (>= 2.3.6)
66
+ crack (>= 0.3.2)
67
+ hashdiff (>= 0.4.0, < 2.0.0)
68
+
69
+ PLATFORMS
70
+ ruby
71
+
72
+ DEPENDENCIES
73
+ pry
74
+ rake (~> 12.0)
75
+ rspec (~> 3.0)
76
+ rubocop
77
+ sourcescrub!
78
+ vcr
79
+ webmock
80
+
81
+ BUNDLED WITH
82
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Encore Shao
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,97 @@
1
+ # Sourcescrub
2
+
3
+ Sourcescrub is a ruby wrapper based on Source Scrub API, Here is API documentation: https://api.sourcescrub.com/index.html.
4
+
5
+ However, we need to request an access account from Sourcescrub.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sourcescrub'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sourcescrub
22
+
23
+ ## Getting Started
24
+
25
+ #### Configure your certificate for API
26
+
27
+ ```ruby
28
+ require 'sourcescrub'
29
+
30
+ account = YAML.load(File.read('sourcescrub.yml'))
31
+ Sourcescrub.account do |config|
32
+ config.username = account['username']
33
+ config.password = account['password']
34
+ config.basic = account['basic']
35
+ config.debug = false # Default is false, If you want to know the request information, can set the debug = true
36
+ end
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ #### Class: `Client` for API
42
+
43
+ ```
44
+ pry(main)> client = Sourcescrub::Client.new
45
+ ```
46
+
47
+ #### Request your token
48
+
49
+ ```
50
+ pry(main)> client.headers
51
+ => {"Authorization"=>"Bearer eyJhbGciOiJSUzI1NiIsImtpZCI........"}
52
+ ```
53
+
54
+ #### API request for endpoint we completed
55
+
56
+ - [Companies](https://github.com/ekohe/sourcescrub#companies)
57
+ - [Searches](https://github.com/ekohe/sourcescrub#searches)
58
+
59
+ ```ruby
60
+ <!-- Company -->
61
+ response = client.companies('ekohe.com')
62
+
63
+ <!-- Get the JSON response of Company -->
64
+
65
+ response.as_json
66
+ ```
67
+
68
+ ### Companies
69
+
70
+ #### Get the company data
71
+
72
+ ```ruby
73
+ pry(main)> response = client.companies('ekohe.com')
74
+ pry(main)> response.name
75
+ => "Ekohe, Ltd."
76
+ pry(main)> response.domain
77
+ => "ekohe.com"
78
+ ```
79
+
80
+ ### Searches
81
+
82
+ ## Development
83
+
84
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
85
+
86
+ ## Contributing
87
+
88
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/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/[USERNAME]/sourcescrub/blob/master/CODE_OF_CONDUCT.md).
89
+
90
+
91
+ ## License
92
+
93
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
94
+
95
+ ## Code of Conduct
96
+
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/[USERNAME]/sourcescrub/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'sourcescrub'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ require 'pry'
12
+ Pry.start
13
+
14
+ # require "irb"
15
+ # IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sourcescrub/version'
4
+
5
+ require 'sourcescrub/account'
6
+ require 'sourcescrub/client'
7
+ require 'sourcescrub/models'
8
+
9
+ module Sourcescrub
10
+ TOKEN_URL = 'https://identity.sourcescrub.com'
11
+ TOKEN_URI = '/connect/token'
12
+
13
+ # API URL
14
+ API_URI = 'https://api.sourcescrub.com/'
15
+
16
+ class Error < StandardError; end
17
+ # Your code goes here...
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+
5
+ # Root Sourcescrub
6
+ module Sourcescrub
7
+ # Account
8
+ class Account
9
+ include Singleton
10
+ attr_accessor :username, :password, :basic, :debug
11
+ end
12
+
13
+ def self.account
14
+ yield Account.instance if block_given?
15
+
16
+ Account.instance
17
+ end
18
+ end
@@ -0,0 +1,31 @@
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 Companies
11
+ include ::Sourcescrub::Utils::SsModel
12
+
13
+ attr_accessor :args
14
+
15
+ def initialize(domain, args)
16
+ @domain = domain
17
+ @model_type = args.delete(:model_type)
18
+ @card_id = args.delete(:card_id)
19
+ @args = args
20
+ end
21
+
22
+ def request_url
23
+ [
24
+ kclass_name::ENDPOINT,
25
+ @domain,
26
+ @card_id
27
+ ].compact.join('/')
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './utils/request'
4
+ require_relative './apis/companies'
5
+
6
+ # Root Sourcescrub
7
+ module Sourcescrub
8
+ # Client
9
+ class Client
10
+ include Utils::Request
11
+
12
+ attr_accessor :token
13
+
14
+ def headers
15
+ @token || authenticate
16
+
17
+ { 'Authorization' => "Bearer #{@token}" }
18
+ end
19
+
20
+ def companies(domain, args = {})
21
+ api = companies_api(domain, args)
22
+
23
+ api.sobject.parse_response get(api.request_url, api.args)
24
+ end
25
+
26
+ private
27
+
28
+ def companies_api(domain, args)
29
+ @companies_api || Apis::Companies.new(domain, args.merge(model_type: 'company'))
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sourcescrub
4
+ # Models
5
+ module Models
6
+ autoload :Entity, 'sourcescrub/models/concerns/entity'
7
+ autoload :Company, 'sourcescrub/models/company'
8
+ autoload :Source, 'sourcescrub/models/source'
9
+ autoload :Tag, 'sourcescrub/models/tag'
10
+ end
11
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Root Sourcescrub
4
+ module Sourcescrub
5
+ # Models
6
+ module Models
7
+ # Company
8
+ class Company < Entity
9
+ ENDPOINT = 'companies'
10
+
11
+ def field_ids
12
+ %w[
13
+ id
14
+ companyType
15
+ name
16
+ informalName
17
+ website
18
+ domain
19
+ description
20
+ foundingYear
21
+ location
22
+ city
23
+ state
24
+ postalCode
25
+ country
26
+ parentCompanyDomain
27
+ phoneNumber
28
+ specialties
29
+ facebook
30
+ twitter
31
+ crunchbase
32
+ linkedIn
33
+ totalAmountInvested
34
+ currentEmployeeCount
35
+ currentEmployeeRange
36
+ currentJobOpenings
37
+ investors
38
+ personalTags
39
+ firmTags
40
+ ]
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './../../utils/response'
4
+
5
+ module Sourcescrub
6
+ # Get the data from API
7
+ module Models
8
+ # Entity
9
+ class Entity
10
+ include ::Sourcescrub::Utils::Response
11
+
12
+ def fields
13
+ field_ids.map(&:to_sym)
14
+ end
15
+
16
+ def parse_response(response)
17
+ dynamic_attributes(self, field_ids, response)
18
+ self
19
+ end
20
+
21
+ def as_json
22
+ fields.each_with_object({}) { |item, hash| hash[item] = send(item) }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sourcescrub
4
+ # Models
5
+ module Models
6
+ # Source
7
+ class Source < Entity
8
+ ENDPOINT = 'sources'
9
+
10
+ def field_ids
11
+ %w[
12
+ id
13
+ officialTitle
14
+ nickname
15
+ sourceType
16
+ city
17
+ state
18
+ country
19
+ startDate
20
+ endDate
21
+ status
22
+ reviewStatus
23
+ companyCount
24
+ companiesCrmCount
25
+ companiesTaggedCount
26
+ ]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sourcescrub
4
+ # Models
5
+ module Models
6
+ # Tag
7
+ class Tag < Entity
8
+ ENDPOINT = 'tags'
9
+
10
+ def field_ids
11
+ %w[
12
+ id
13
+ name
14
+ firmScoped
15
+ createdDate
16
+ ]
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'faraday_middleware'
5
+ require 'logger'
6
+
7
+ module Sourcescrub
8
+ # Utils
9
+ module Utils
10
+ # Key Reminder
11
+ module Request
12
+ module_function
13
+
14
+ # SourceScrub API Response Headers
15
+ #
16
+ # X-RateLimit-Limit - Allowed number of requests for User Firm per month
17
+ # X-RateLimit-Remaining - Number of requests remaining for User Firm in current month
18
+ # X-RateLimit-Reset - Time until the request counter resets (1st of the month 00:00 UTC)
19
+
20
+ # Limit of requests per second: 30
21
+ #
22
+ #
23
+ def get(uri, *args)
24
+ response = Faraday.new(url: API_URI) do |faraday|
25
+ faraday.headers = headers
26
+ faraday.request :json
27
+ faraday.response :json
28
+ faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
29
+ end.get(uri, *args)
30
+
31
+ return response.body if response.status == 200
32
+
33
+ raise Error, response.body
34
+ end
35
+
36
+ def put(uri, args)
37
+ response = Faraday.new(url: API_URI) do |faraday|
38
+ faraday.headers = headers
39
+ faraday.request :json
40
+ faraday.response :json
41
+ faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
42
+ end.put(uri, args)
43
+
44
+ return response.body if response.status == 200
45
+
46
+ raise Error, response.body
47
+ end
48
+
49
+ def delete(uri, args)
50
+ response = Faraday.new(url: API_URI) do |faraday|
51
+ faraday.headers = headers
52
+ faraday.request :json
53
+ faraday.response :json
54
+ faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
55
+ end.delete(uri, args)
56
+
57
+ return response.body if response.status == 200
58
+
59
+ raise Error, response.body
60
+ end
61
+
62
+ # Authentication Token
63
+ #
64
+ # In order to obtain the authentication token that will be later used to request SourceScrub API:
65
+ # A POST request has to be made with following configuration:
66
+
67
+ # POST https://identity.sourcescrub.com/connect/token
68
+ # Content-Type: application/x-www-form-urlencoded
69
+ # Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxx
70
+
71
+ # Body:
72
+ # grant_type=password&username={username}&password={password}&scope=client_api
73
+ def authenticate
74
+ body = "grant_type=password&username=#{Sourcescrub.account.username}&password=#{Sourcescrub.account.password}&scope=client_api"
75
+
76
+ response = Faraday.new(url: TOKEN_URL) do |faraday|
77
+ faraday.headers = {
78
+ 'Content-Type' => 'application/x-www-form-urlencoded',
79
+ 'Authorization' => Sourcescrub.account.basic
80
+ }
81
+ faraday.adapter Faraday.default_adapter
82
+ faraday.request :json
83
+ faraday.response :json
84
+ faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
85
+ end.post(TOKEN_URI, body)
86
+
87
+ raise 'Apptopia error: Service Unavailable' unless response.status == 200
88
+
89
+ @token = response.body['access_token']
90
+ end
91
+
92
+ private
93
+
94
+ def debug_mode?
95
+ Sourcescrub.account.debug || false
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sourcescrub
4
+ # Utilities
5
+ module Utils
6
+ # Parse the response. build with object
7
+ module Response
8
+ module_function
9
+
10
+ def dynamic_attributes(object, attribute_names, response)
11
+ attribute_names.each do |attr_name|
12
+ attr_value = response.dig(attr_name)
13
+
14
+ dynamic_define_method(object, attr_name, attr_value)
15
+ end
16
+
17
+ object
18
+ end
19
+
20
+ private
21
+
22
+ def dynamic_define_method(object, attr_name, attr_value)
23
+ # Manually creates methods for both getter and setter and then
24
+ # sends a message to the new setter with the attr_value
25
+ object.class.send(:define_method, "#{attr_name}=".to_sym) do |value|
26
+ instance_variable_set('@' + attr_name, value)
27
+ end
28
+
29
+ object.class.send(:define_method, attr_name.to_sym) do
30
+ instance_variable_get('@' + attr_name.to_s)
31
+ end
32
+
33
+ object.send("#{attr_name}=".to_sym, attr_value)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sourcescrub
4
+ # Utils
5
+ module Utils
6
+ # API Request
7
+ module SsModel
8
+ attr_accessor :model_type
9
+
10
+ # module_function
11
+
12
+ def sobject
13
+ kclass_name.new
14
+ end
15
+
16
+ def kclass_name
17
+ @kclass_name ||= exact_kclass_object
18
+ end
19
+
20
+ def exact_kclass_object
21
+ return model_type if model_type.is_a?(Class)
22
+
23
+ ss_type = [
24
+ 'Sourcescrub',
25
+ 'Models',
26
+ model_type.split('_').map(&:capitalize).join
27
+ ].join('::')
28
+
29
+ Kernel.const_get("::#{ss_type}")
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sourcescrub
4
+ VERSION = '0.0.2'
5
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/sourcescrub/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'sourcescrub'
7
+ spec.version = Sourcescrub::VERSION
8
+ spec.authors = ['Encore Shao']
9
+ spec.email = ['encore@ekohe.com']
10
+
11
+ spec.summary = 'Sourcescrub is a ruby wrapper based on Source Scrub API.'
12
+ spec.description = 'Sourcescrub is a ruby wrapper based on Source Scrub API.'
13
+ spec.homepage = 'https://github.com/ekohe/sourcescrub'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
+
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/ekohe/sourcescrub'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/ekohe/sourcescrub/blob/master/CHANGELOG.md'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_dependency 'faraday'
33
+ spec.add_dependency 'faraday_middleware'
34
+
35
+ # VCR for testing APIs
36
+ spec.add_development_dependency 'vcr'
37
+ spec.add_development_dependency 'webmock'
38
+ # Rubocop - rubocop --auto-gen-config
39
+ spec.add_development_dependency 'rubocop'
40
+ # For debug binding.pry
41
+ spec.add_development_dependency 'pry'
42
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sourcescrub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Encore Shao
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
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
+ - !ruby/object:Gem::Dependency
42
+ name: vcr
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Sourcescrub is a ruby wrapper based on Source Scrub API.
98
+ email:
99
+ - encore@ekohe.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".rubocop_todo.yml"
108
+ - ".travis.yml"
109
+ - CHANGELOG.md
110
+ - CODE_OF_CONDUCT.md
111
+ - Gemfile
112
+ - Gemfile.lock
113
+ - LICENSE.txt
114
+ - README.md
115
+ - Rakefile
116
+ - bin/console
117
+ - bin/setup
118
+ - lib/sourcescrub.rb
119
+ - lib/sourcescrub/account.rb
120
+ - lib/sourcescrub/apis/companies.rb
121
+ - lib/sourcescrub/client.rb
122
+ - lib/sourcescrub/models.rb
123
+ - lib/sourcescrub/models/company.rb
124
+ - lib/sourcescrub/models/concerns/entity.rb
125
+ - lib/sourcescrub/models/source.rb
126
+ - lib/sourcescrub/models/tag.rb
127
+ - lib/sourcescrub/utils/request.rb
128
+ - lib/sourcescrub/utils/response.rb
129
+ - lib/sourcescrub/utils/ss_model.rb
130
+ - lib/sourcescrub/version.rb
131
+ - sourcescrub.gemspec
132
+ homepage: https://github.com/ekohe/sourcescrub
133
+ licenses:
134
+ - MIT
135
+ metadata:
136
+ allowed_push_host: https://rubygems.org
137
+ homepage_uri: https://github.com/ekohe/sourcescrub
138
+ source_code_uri: https://github.com/ekohe/sourcescrub
139
+ changelog_uri: https://github.com/ekohe/sourcescrub/blob/master/CHANGELOG.md
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: 2.3.0
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubygems_version: 3.0.3
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Sourcescrub is a ruby wrapper based on Source Scrub API.
159
+ test_files: []