similarweb_rapidapi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5aff259cb85d5d4f076b938d313f57d842287e81e03c16bfca1fa881cad679bc
4
+ data.tar.gz: 00023662f13271721f9131fc110fe06a61850a83a16e5a92bfd07a25ad9f551e
5
+ SHA512:
6
+ metadata.gz: 3dba9ea3ccb9756916dd70df4404be28d94134f7d94b47a645f26b8c517c4bb30edf98ea9f348ad3f9b68aa8c0887d4c7ecf5c0f9f9ae81c895b406fed6a68a2
7
+ data.tar.gz: 393b4e7a3d09b279824c027f07ba6e05ef80b5bfdf69733aa99dbc55cd481bbb08a6a7fd5e31c0cd1bb51126d44e9b61a48e8b1193f25705d04f37a4df88b2ae
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at hello@letsscrape.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in similarweb_rapidapi.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem 'dry-types'
13
+ gem 'dry-struct'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 LetsScrape
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.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # SimilarwebRapidapi
2
+
3
+ Welcome to SimilarWeb RapidApi, a gem for easy integration and handling with our SimilarWeb API which is published on RapidAPI.
4
+
5
+ This gem simplifies the process of integrating SimilarWeb's data into your Ruby applications, abstracting the direct API interaction through a set of user-friendly methods. We aim to let developers focus on what truly matters - creating innovative applications that make the most of the rich data provided by SimilarWeb.
6
+
7
+ Put your Ruby code in the file `lib/similarweb_rapidapi`. To experiment with that code, run `bin/console` for an interactive prompt.
8
+
9
+ Read more on [main project page](https://letsscrape.com/scrapers/similarweb-api/)
10
+ See on [RapidAPI](https://rapidapi.com/letsscrape/api/similarweb-working-api)
11
+
12
+ ### How to get RAPID API key
13
+ 1. **Register** you account on RapidAPI https://rapidapi.com/auth/sign-up
14
+ 2. Go to https://bit.ly/3z3DInS and **Subscribe to test**
15
+ 3. After subscribing, please revisit https://bit.ly/3z3DInS to obtain your **X-RapidAPI-Key**.
16
+ 4. You will find **X-RapidAPI-Key** on the right side in the Code Snippets.
17
+
18
+ ## Installation
19
+
20
+ To install this gem onto your system, run:
21
+
22
+ ```bash
23
+ gem install similarweb_rapidapi
24
+ ```
25
+
26
+ To add this gem to your application's Gemfile:
27
+
28
+ ```ruby
29
+ gem 'similarweb_rapidapi'
30
+ ```
31
+
32
+ And then execute:
33
+
34
+ ```bash
35
+ bundle
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ To start using this gem, you will first need to set up your API key:
41
+
42
+ ```ruby
43
+ require 'similarweb_rapidapi'
44
+
45
+ SimilarwebRapidapi.configure do |config|
46
+ config.api_key = 'YOUR_SIMILAR_WEB_API_KEY'
47
+ end
48
+ ```
49
+
50
+ Then, you can use the API methods like so:
51
+
52
+ ```ruby
53
+ result = SimilarwebRapidapi.get_website_overview('example.com')
54
+ puts result
55
+ ```
56
+
57
+ More methods and usage examples will be available in our [Wiki](LINK_TO_YOUR_WIKI).
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
62
+
63
+ ## Contact
64
+
65
+ If you have any questions or need further guidance, please don't hesitate to contact us at [LetsScrape Support](hello@letsscrape.com)
data/Rakefile ADDED
@@ -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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimilarwebRapidapi
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,185 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "similarweb_rapidapi/version"
4
+ require_relative "similarweb_rapidapi/logger_mock"
5
+ require_relative "similarweb_rapidapi/task_status"
6
+
7
+ require 'uri'
8
+ require 'net/http'
9
+ require 'json'
10
+ require 'ostruct'
11
+
12
+ module SimilarwebRapidapi
13
+ class Error < StandardError; end
14
+
15
+ class ApiClient
16
+
17
+ def initialize(rapidapi_key, logger = nil)
18
+ <<~DESC
19
+ To get rapid_api_key you just have to register here https://bit.ly/3Mz1U9n
20
+ :param rapidapi_host: X-RapidAPI-Host header & Base URL
21
+ :param rapidapi_key: X-RapidAPI-Key header
22
+ DESC
23
+
24
+ @rapidapi_host = 'similarweb-working-api.p.rapidapi.com'
25
+ @logger = logger.nil? ? SimilarwebRapidapi::LoggerMock.new : logger
26
+ @headers = {
27
+ 'X-RapidAPI-Key': rapidapi_key,
28
+ 'X-RapidAPI-Host': @rapidapi_host
29
+ }
30
+ end
31
+
32
+ def get_request(path)
33
+
34
+ url = URI.join("https://#{@rapidapi_host}", path).to_s
35
+
36
+ uri = URI.parse(url)
37
+ http = Net::HTTP.new(uri.host, uri.port)
38
+ http.use_ssl = true
39
+
40
+ session_timeout = 45.0
41
+ is_ok = false
42
+
43
+ while true
44
+ request = Net::HTTP::Get.new(uri.request_uri)
45
+
46
+ request['X-RapidAPI-Key'] = @headers[:'X-RapidAPI-Key']
47
+ request['X-RapidAPI-Host'] = @headers[:'X-RapidAPI-Host']
48
+
49
+ response = http.request(request)
50
+ json_response = JSON.parse(response.body, object_class: OpenStruct)
51
+
52
+ if response.code == "200"
53
+ is_ok = true
54
+ end
55
+
56
+ break if is_ok
57
+
58
+ sleep(0.3)
59
+ end
60
+
61
+ json_response
62
+ end
63
+
64
+ def wait
65
+ sleep(1)
66
+ end
67
+
68
+ def get_basic_data_from_domain(domain)
69
+ path = "/similarweb/getdata?domain=#{domain}"
70
+ response = get_request(path)
71
+ response
72
+ end
73
+
74
+ def get_additional_data_form_domain(domain)
75
+ path = "/similarweb/GetAdditionalDomainData?domain=#{domain}"
76
+ response = get_request(path)
77
+ response
78
+ end
79
+
80
+ def get_complete_data_for_domain(domain, callback_url = "")
81
+ <<~DESC
82
+ Instead of using get_complete_data_task and then downloading get task result
83
+ use this method. It'll do everything for you.
84
+ DESC
85
+ user_task = get_complete_data_task(domain, callback_url)
86
+ task_result = nil
87
+
88
+ while true
89
+ wait
90
+ task_result = get_task_result(user_task.data.task_id)
91
+
92
+ if task_result.is_finished
93
+ if !@logger.nil?
94
+ @logger.info("Task=#{user_task.data.task_id} domain=#{domain} has been completed.")
95
+ end
96
+ break
97
+ end
98
+
99
+ if !@logger.nil?
100
+ @logger.info("Waiting for the task=#{user_task.data.task_id} domain=#{domain} to be completed.")
101
+ end
102
+ end
103
+
104
+ task_result
105
+ end
106
+
107
+ def get_complete_data_for_domains(domains, callback_url = "", callback_success = nil, callback_error = nil)
108
+ result = []
109
+ max_tries = 3
110
+
111
+ domains.each do |domain|
112
+ last_exception = nil
113
+ max_tries.times do |i|
114
+ begin
115
+ r = get_complete_data_for_domain(domain, callback_url)
116
+ last_exception = nil
117
+ result.append(r)
118
+ if !callback_success.nil?
119
+ callback_success.call(r)
120
+ end
121
+ break
122
+ rescue => ex
123
+ last_exception = ex
124
+ end
125
+ end
126
+
127
+ if !last_exception.nil?
128
+ error_message = "Cannot get data for domain=#{domain}. Try again or contact us hello@letsscrape.com"
129
+ if !@logger.nil?
130
+ @logger.error(error_message, last_exception)
131
+ end
132
+ if !callback_error.nil?
133
+ callback_error.call(last_exception)
134
+ end
135
+ end
136
+ end
137
+
138
+ result
139
+ end
140
+
141
+
142
+ def get_my_tasks(task_status)
143
+ <<~DESC
144
+ Returns the list of you all tasks.
145
+ DESC
146
+ ts = task_status == TaskStatus::ALL ? "" : task_status.to_s
147
+ path = "/similarweb/GetMyTasks?task_status=#{ts}"
148
+ response = get_request(path)
149
+ response
150
+ end
151
+
152
+ def cancel_task(task_id)
153
+ <<~DESC
154
+ Cancels created task.
155
+ DESC
156
+ path = "/similarweb/CancelTask?task_id=#{task_id}"
157
+ response = get_request(path)
158
+ response
159
+ end
160
+
161
+ def get_task_result(task_id)
162
+ <<~DESC
163
+ After calling get_complete_data_task just use this method to get the result.
164
+ DESC
165
+ path = "/similarweb/GetTaskResult?task_id=#{task_id}"
166
+ response = get_request(path)
167
+ response
168
+ end
169
+
170
+ def get_complete_data_task(domain, callback_url = "")
171
+ <<~DESC
172
+ Creates task in the system. The task takes a while to complete, so you can check its
173
+ status by calling get_task_result or set a callback_url where the result will be sent.
174
+ About callbacks you can read more here https://rapidapi.com/letsscrape/api/similarweb-working-api/tutorials/use-callbacks-when-using-async-endpoints!
175
+ :param domain: domain
176
+ :param callback_url: url where to send response (domain data)
177
+ DESC
178
+ path = "/similarweb/GetCompleteDataAsync?domain=#{domain}&callback_url=#{callback_url}"
179
+ response = get_request(path)
180
+ response
181
+ end
182
+
183
+
184
+ end
185
+ end
@@ -0,0 +1,4 @@
1
+ module SimilarwebRapidapi
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/similarweb_rapidapi/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "similarweb_rapidapi"
7
+ spec.version = SimilarwebRapidapi::VERSION
8
+ spec.authors = ["letsscrape"]
9
+ spec.email = ["hello@letsscrape.com"]
10
+
11
+ spec.summary = "Gem provides simple methods for communicating with the SimilarWeb API"
12
+ spec.description = "Integrating with the SimilarWeb API becomes fast and convenient, enabling Ruby programmers to easily consume valuable website traffic statistics, rankings, competitive analysis, and much more."
13
+ spec.homepage = "https://rapidapi.com/letsscrape/api/similarweb-working-api?src=ruby"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/letsscrape/ruby_similarweb_rapidapi"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ # spec.add_dependency "example-gem", "~> 1.0"
33
+ spec.add_dependency "dry-types"
34
+ spec.add_dependency "dry-struct"
35
+ # For more information and examples about making a new gem, check out our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: similarweb_rapidapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - letsscrape
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-types
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: dry-struct
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
+ description: Integrating with the SimilarWeb API becomes fast and convenient, enabling
42
+ Ruby programmers to easily consume valuable website traffic statistics, rankings,
43
+ competitive analysis, and much more.
44
+ email:
45
+ - hello@letsscrape.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".rspec"
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - lib/similarweb_rapidapi.rb
57
+ - lib/similarweb_rapidapi/version.rb
58
+ - sig/similarweb_rapidapi.rbs
59
+ - similarweb_rapidapi.gemspec
60
+ homepage: https://rapidapi.com/letsscrape/api/similarweb-working-api?src=ruby
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ homepage_uri: https://rapidapi.com/letsscrape/api/similarweb-working-api?src=ruby
65
+ source_code_uri: https://github.com/letsscrape/ruby_similarweb_rapidapi
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.6.0
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.4.10
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Gem provides simple methods for communicating with the SimilarWeb API
85
+ test_files: []