infosimples-data 1.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE +21 -0
- data/README.md +112 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/infosimples-data.gemspec +29 -0
- data/lib/infosimples/data.rb +20 -0
- data/lib/infosimples/data/client.rb +105 -0
- data/lib/infosimples/data/code.rb +31 -0
- data/lib/infosimples/data/errors.rb +16 -0
- data/lib/infosimples/data/http.rb +76 -0
- data/lib/infosimples/data/symmetric_encryption.rb +25 -0
- data/lib/infosimples/data/version.rb +6 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cafc3657b7756d7c8d0fe8eb9d22e86960807fe7386c0c260eae0c1d57fd0264
|
4
|
+
data.tar.gz: e122aa869af811bd1c253c1bde7765fcd5d04978ef0fedc269151e6ab888dc68
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 641f9b9336802a6c6372ade60cfa698d89bf7615625a595da84108f83e467327ce0f0c8aeb645f16734a36a96b64e8bde14e97dc5969832bdac06aa790139d2b
|
7
|
+
data.tar.gz: f0bc464099cfe36c24c41aa9bd1a408b05f0d3770a0d390bd2e03e586fec6766922a8904a9720a5e1d8c33a1e4b58373f794725919806b75eca40e805b6c7858
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
infosimples-data (1.9.4)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.8.0)
|
12
|
+
rspec-core (~> 3.8.0)
|
13
|
+
rspec-expectations (~> 3.8.0)
|
14
|
+
rspec-mocks (~> 3.8.0)
|
15
|
+
rspec-core (3.8.0)
|
16
|
+
rspec-support (~> 3.8.0)
|
17
|
+
rspec-expectations (3.8.1)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.8.0)
|
20
|
+
rspec-mocks (3.8.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-support (3.8.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.16)
|
30
|
+
infosimples-data!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.6
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Infosimples
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# Infosimples::Data
|
2
|
+
|
3
|
+
Ruby API for Infosimples::Data (https://infosimples.com/).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'infosimples-data'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install infosimples-data
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
1. **Create a client**
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'infosimples/data'
|
27
|
+
client = Infosimples::Data::Client.new('my_token')
|
28
|
+
```
|
29
|
+
|
30
|
+
2. **Automate a service**
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
response = client.automate('correios/cep', cep: '01311915')
|
34
|
+
response['code'] # 200
|
35
|
+
response['code_message'] # "A consulta foi realizada com sucesso e retornou um resultado."
|
36
|
+
response['data'] # Information about the postal code
|
37
|
+
response['receipt']['sites_urls'] # Links for the original HTMLs.
|
38
|
+
|
39
|
+
client.download_sites_urls(response) # Array with HTML bodies for `sites_urls`.
|
40
|
+
```
|
41
|
+
|
42
|
+
> Check the full response in our documentation:
|
43
|
+
> https://data.infosimples.com/docs
|
44
|
+
|
45
|
+
3. **Billing**
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
billing = client.billing # Array of Hashes with:
|
49
|
+
billing.first['name'] # - Name of the Token
|
50
|
+
billing.first['quantity'] # - Number of automation requests the token has made
|
51
|
+
billing.first['credits'] # - How many credits the token has used
|
52
|
+
```
|
53
|
+
|
54
|
+
4. **Pricing**
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
pricing = client.pricing # Array of Hashes with:
|
58
|
+
pricing.first['service'] # - Name of the service that can be automated
|
59
|
+
pricing.first['credits'] # - How many credits this service uses
|
60
|
+
```
|
61
|
+
|
62
|
+
5. **Response codes**
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
# Check a response code:
|
66
|
+
response['code'] == Infosimples::Data::CODE[:single_result]
|
67
|
+
|
68
|
+
# List of codes
|
69
|
+
{
|
70
|
+
# success
|
71
|
+
single_result: 200,
|
72
|
+
multiple_results: 201,
|
73
|
+
|
74
|
+
# error
|
75
|
+
unexpected_error: 600,
|
76
|
+
unauthorized: 601,
|
77
|
+
invalid_service: 602,
|
78
|
+
forbidden: 603,
|
79
|
+
invalid_request: 604,
|
80
|
+
timeout: 605,
|
81
|
+
empty_parameters: 606,
|
82
|
+
invalid_parameters: 607,
|
83
|
+
refused_parameters: 608,
|
84
|
+
attempts_exceeded: 609,
|
85
|
+
failed_captcha: 610,
|
86
|
+
incomplete_data: 611,
|
87
|
+
inexistent: 612,
|
88
|
+
blocked_request: 613,
|
89
|
+
try_again: 614,
|
90
|
+
source_unavailable: 615,
|
91
|
+
source_error: 616,
|
92
|
+
service_overloaded: 617,
|
93
|
+
rate_limit_exceeded: 618,
|
94
|
+
converted_parameters: 619,
|
95
|
+
permanent_error: 620,
|
96
|
+
receipt_error: 621,
|
97
|
+
}
|
98
|
+
```
|
99
|
+
|
100
|
+
## Development
|
101
|
+
|
102
|
+
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.
|
103
|
+
|
104
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
105
|
+
|
106
|
+
## Contributing
|
107
|
+
|
108
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/infosimples/infosimples-data.
|
109
|
+
|
110
|
+
## License
|
111
|
+
|
112
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "infosimples/data"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "infosimples/data/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "infosimples-data"
|
8
|
+
spec.version = Infosimples::Data::VERSION
|
9
|
+
spec.authors = ["Infosimples"]
|
10
|
+
spec.email = ["team@infosimples.com.br"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby API for Infosimples::Data (https://infosimples.com/)}
|
13
|
+
spec.description = %q{Infosimples::Data allows you to automate web site navigation.}
|
14
|
+
spec.homepage = "https://github.com/infosimples/infosimples-data"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'openssl/cipher'
|
3
|
+
require 'digest/sha2'
|
4
|
+
require 'base64'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module Infosimples
|
8
|
+
module Data
|
9
|
+
def self.new(token, args = {})
|
10
|
+
Infosimples::Data::Client.new(token, args)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'infosimples/data/client'
|
16
|
+
require 'infosimples/data/code'
|
17
|
+
require 'infosimples/data/errors'
|
18
|
+
require 'infosimples/data/http'
|
19
|
+
require 'infosimples/data/symmetric_encryption'
|
20
|
+
require 'infosimples/data/version'
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module Infosimples::Data
|
2
|
+
# Infosimples::Data::Client is a client for the Infosimples Data API.
|
3
|
+
class Client
|
4
|
+
BASE_URL = 'https://data.infosimples.com/api/v1/:service.json'
|
5
|
+
ENCRYPTABLE_ARGS = ['pkcs12_cert', 'pkcs12_pass', 'pass'].map {
|
6
|
+
|arg| [arg, true]
|
7
|
+
}.to_h
|
8
|
+
|
9
|
+
attr_accessor :token, :timeout, :max_age
|
10
|
+
|
11
|
+
# Create a Infosimples::Data API client.
|
12
|
+
#
|
13
|
+
# @param [String] token Your access token.
|
14
|
+
# @param [Hash] options Options hash.
|
15
|
+
# @option options [Integer] :timeout (120) Seconds before giving up of an
|
16
|
+
# automation being completed.
|
17
|
+
# @option options [Integer] :max_age (86400) Duration in seconds for a
|
18
|
+
# cached automation to be
|
19
|
+
# allowed.
|
20
|
+
#
|
21
|
+
# @return [Infosimples::Data::Client] A Client instance.
|
22
|
+
def initialize(token, options = {})
|
23
|
+
self.token = token
|
24
|
+
self.timeout = options[:timeout] || 120 # 120 seconds
|
25
|
+
self.max_age = options[:max_age] || 86400 # 24 hours in seconds
|
26
|
+
end
|
27
|
+
|
28
|
+
# Automate a service.
|
29
|
+
#
|
30
|
+
# @param [String] service Service you want to automate.
|
31
|
+
# @param [Hash] args Arguments to be used in the service automation.
|
32
|
+
#
|
33
|
+
# @return [Hash] Response according to https://data.infosimples.com/docs.
|
34
|
+
def automate(service, args = {})
|
35
|
+
args.keys.each do |key|
|
36
|
+
if ENCRYPTABLE_ARGS[key.to_s]
|
37
|
+
args[key] = encrypt(args[key])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
request(service, :multipart, args)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Get billing statistics from your account.
|
44
|
+
#
|
45
|
+
# @return [Array] Billing statistics per token.
|
46
|
+
def billing
|
47
|
+
request('billing', :get)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Get prices for each service.
|
51
|
+
#
|
52
|
+
# @return [Array] Service with price.
|
53
|
+
def pricing
|
54
|
+
request('pricing', :get)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Download sites_urls from response.
|
58
|
+
#
|
59
|
+
# @param [Hash] response Response returned by #automate.
|
60
|
+
#
|
61
|
+
# @return [Array] HTML bodies from sites_urls.
|
62
|
+
def download_sites_urls(response)
|
63
|
+
return [] if !response.is_a?(Hash) ||
|
64
|
+
(sites_urls = response.dig('receipt', 'sites_urls')).nil?
|
65
|
+
sites_urls.map do |url|
|
66
|
+
Infosimples::Data::HTTP.request(url: url, http_timeout: 30)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
# Apply symmetric encryption to data.
|
73
|
+
#
|
74
|
+
# @param [String] data The original data that will be encrypted.
|
75
|
+
#
|
76
|
+
# @return [String] encrypted data.
|
77
|
+
def encrypt(data)
|
78
|
+
@crypt ||= Infosimples::Data::SymmetricEncryption.new(token)
|
79
|
+
@crypt.encrypt(data)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Perform an HTTP request to the Infosimples Data API.
|
83
|
+
#
|
84
|
+
# @param [String] service API method name.
|
85
|
+
# @param [Symbol] method HTTP method (:get, :post, :multipart).
|
86
|
+
# @param [Hash] payload Data to be sent through the HTTP request.
|
87
|
+
#
|
88
|
+
# @return [Hash] Parsed JSON from the API response.
|
89
|
+
#
|
90
|
+
def request(service, method = :get, payload = {})
|
91
|
+
res = Infosimples::Data::HTTP.request(
|
92
|
+
url: BASE_URL.gsub(':service', service),
|
93
|
+
http_timeout: timeout,
|
94
|
+
method: method,
|
95
|
+
payload: payload.merge(
|
96
|
+
token: token,
|
97
|
+
timeout: timeout,
|
98
|
+
max_age: max_age,
|
99
|
+
header: 1
|
100
|
+
)
|
101
|
+
)
|
102
|
+
JSON.parse(res)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Infosimples::Data
|
2
|
+
CODE = {
|
3
|
+
# success
|
4
|
+
single_result: 200,
|
5
|
+
multiple_results: 201,
|
6
|
+
|
7
|
+
# error
|
8
|
+
unexpected_error: 600,
|
9
|
+
unauthorized: 601,
|
10
|
+
invalid_service: 602,
|
11
|
+
forbidden: 603,
|
12
|
+
invalid_request: 604,
|
13
|
+
timeout: 605,
|
14
|
+
empty_parameters: 606,
|
15
|
+
invalid_parameters: 607,
|
16
|
+
refused_parameters: 608,
|
17
|
+
attempts_exceeded: 609,
|
18
|
+
failed_captcha: 610,
|
19
|
+
incomplete_data: 611,
|
20
|
+
inexistent: 612,
|
21
|
+
blocked_request: 613,
|
22
|
+
try_again: 614,
|
23
|
+
source_unavailable: 615,
|
24
|
+
source_error: 616,
|
25
|
+
service_overloaded: 617,
|
26
|
+
rate_limit_exceeded: 618,
|
27
|
+
converted_parameters: 619,
|
28
|
+
permanent_error: 620,
|
29
|
+
receipt_error: 621,
|
30
|
+
}
|
31
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Infosimples::Data
|
2
|
+
|
3
|
+
# This is our base Error class. Rescue `Infosimples::Data::Error` if you want
|
4
|
+
# to catch any known exception related to this gem.
|
5
|
+
class Error < Exception
|
6
|
+
end
|
7
|
+
|
8
|
+
class ArgumentError < Error
|
9
|
+
end
|
10
|
+
|
11
|
+
class Timeout < Error
|
12
|
+
def initialize
|
13
|
+
super('The request was not processed in the expected time')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Infosimples::Data
|
2
|
+
# Infosimples::Data::HTTP exposes common HTTP routines that can be used by the
|
3
|
+
# Infosimples::Data API client.
|
4
|
+
#
|
5
|
+
class HTTP
|
6
|
+
# Perform an HTTP request with support for multipart requests.
|
7
|
+
#
|
8
|
+
# @param [Hash] options Options hash.
|
9
|
+
# @param options [String] url URL to be requested.
|
10
|
+
# @param options [Symbol] method HTTP method (:get, :post, :multipart).
|
11
|
+
# @param options [Hash] payload Data to be sent through the HTTP request.
|
12
|
+
# @param options [Integer] http_timeout HTTP open/read timeout in seconds.
|
13
|
+
#
|
14
|
+
# @return [String] Response body of the HTTP request.
|
15
|
+
#
|
16
|
+
def self.request(options = {})
|
17
|
+
uri = URI(options[:url])
|
18
|
+
method = options[:method] || :get
|
19
|
+
payload = options[:payload] || {}
|
20
|
+
timeout = options[:http_timeout]
|
21
|
+
headers = { 'User-Agent' => Infosimples::Data::USER_AGENT }
|
22
|
+
|
23
|
+
case method
|
24
|
+
when :get
|
25
|
+
uri.query = URI.encode_www_form(payload)
|
26
|
+
req = Net::HTTP::Get.new(uri.request_uri, headers)
|
27
|
+
|
28
|
+
when :post
|
29
|
+
req = Net::HTTP::Post.new(uri.request_uri, headers)
|
30
|
+
req.set_form_data(payload)
|
31
|
+
|
32
|
+
when :multipart
|
33
|
+
req = Net::HTTP::Post.new(uri.request_uri, headers)
|
34
|
+
boundary, body = prepare_multipart_data(payload)
|
35
|
+
req.content_type = "multipart/form-data; boundary=#{boundary}"
|
36
|
+
req.body = body
|
37
|
+
|
38
|
+
else
|
39
|
+
fail Infosimples::Data::ArgumentError, "Illegal HTTP method (#{method})"
|
40
|
+
end
|
41
|
+
|
42
|
+
http = Net::HTTP.new(uri.hostname, uri.port)
|
43
|
+
http.use_ssl = true if (uri.scheme == 'https')
|
44
|
+
http.open_timeout = timeout
|
45
|
+
http.read_timeout = timeout + 10
|
46
|
+
http.max_retries = 0 # default is max_retries = 1
|
47
|
+
res = http.request(req)
|
48
|
+
res.body
|
49
|
+
|
50
|
+
rescue Net::OpenTimeout, Net::ReadTimeout
|
51
|
+
raise Infosimples::Data::Timeout
|
52
|
+
end
|
53
|
+
|
54
|
+
# Prepare the multipart data to be sent via a :multipart request.
|
55
|
+
#
|
56
|
+
# @param [Hash] payload Data to be prepared via a multipart post.
|
57
|
+
#
|
58
|
+
# @return [String, String] Boundary and body for the multipart post.
|
59
|
+
#
|
60
|
+
def self.prepare_multipart_data(payload)
|
61
|
+
boundary = 'randomstr' + rand(1_000_000).to_s # a random unique string
|
62
|
+
|
63
|
+
content = []
|
64
|
+
payload.each do |param, value|
|
65
|
+
content << '--' + boundary
|
66
|
+
content << "Content-Disposition: form-data; name=\"#{param}\""
|
67
|
+
content << ''
|
68
|
+
content << value
|
69
|
+
end
|
70
|
+
content << '--' + boundary + '--'
|
71
|
+
content << ''
|
72
|
+
|
73
|
+
[boundary, content.join("\r\n")]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Infosimples::Data
|
2
|
+
class SymmetricEncryption
|
3
|
+
attr_accessor :key
|
4
|
+
def initialize(key)
|
5
|
+
fail("INVALID KEY SIZE: #{key}") if key.size < 32
|
6
|
+
self.key = key[0,32]
|
7
|
+
end
|
8
|
+
|
9
|
+
def encrypt(data, to_base64=true)
|
10
|
+
aes = OpenSSL::Cipher.new('AES-256-CBC')
|
11
|
+
aes.encrypt
|
12
|
+
aes.key = Digest::SHA256.digest(key)
|
13
|
+
encrypted_data = aes.update(data) + aes.final
|
14
|
+
to_base64 ? Base64.encode64(encrypted_data) : encrypted_data
|
15
|
+
end
|
16
|
+
|
17
|
+
def decrypt(data, from_base64=true)
|
18
|
+
data = Base64.decode64(data) if from_base64
|
19
|
+
aes = OpenSSL::Cipher.new('AES-256-CBC')
|
20
|
+
aes.decrypt
|
21
|
+
aes.key = Digest::SHA256.digest(key)
|
22
|
+
aes.update(data) + aes.final
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: infosimples-data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.9.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Infosimples
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Infosimples::Data allows you to automate web site navigation.
|
56
|
+
email:
|
57
|
+
- team@infosimples.com.br
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- infosimples-data.gemspec
|
74
|
+
- lib/infosimples/data.rb
|
75
|
+
- lib/infosimples/data/client.rb
|
76
|
+
- lib/infosimples/data/code.rb
|
77
|
+
- lib/infosimples/data/errors.rb
|
78
|
+
- lib/infosimples/data/http.rb
|
79
|
+
- lib/infosimples/data/symmetric_encryption.rb
|
80
|
+
- lib/infosimples/data/version.rb
|
81
|
+
homepage: https://github.com/infosimples/infosimples-data
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.7.7
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Ruby API for Infosimples::Data (https://infosimples.com/)
|
105
|
+
test_files: []
|