sec_edgar_ruby 0.1.1 → 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: e0b5a4e4ec058dc727c6b18bc7693f648cbf425a5ec130340bca25d03d2c14e2
4
- data.tar.gz: 4b20aa4496d85625dc7194f63390525e8689bf65c8621fbf442b9cf49919dc66
3
+ metadata.gz: c9bb05fa37127b8e9c21af85244ada60b40e2ea6f036a98e13374a5a1a11eb67
4
+ data.tar.gz: 14fa10c980fcb19b429b4c42cf7c4a3b1e2cd53220bdf8d14e23ff361f6cd9a6
5
5
  SHA512:
6
- metadata.gz: dca2272de71d15421010d9f1e970221b3d4b01eb8d89d959236f02fee8eb121df5ce3ccd9eec87db207ed8c5febe94ca5e135ce57ea30e0a75924fab6469f91a
7
- data.tar.gz: 6f97e6427e909b4181377f6bcae59dc5629ce6f1fd979a5ed3b4090fd33dc14ae9f56062d99a95423a0f3b1f58e4d8fe752451c39b909b9cd087196b1dc0d1ef
6
+ metadata.gz: cec0c903191272ac79836f656f9563c92105072960bdc5013b4fc81dacc96fa0eef8847a7876ed2cf33e46af1b016c190c68e19bffde5864125fd5ab6e040ba5
7
+ data.tar.gz: 5bf3d916dbbcb775c1295c9197555f7375def795591a92b14befad258ebb74f277d34e74df92d5fe531b1d9fd9d21e6552b7e48a7d65f70405ddff2ca3f4a7b4
data/CHANGELOG.md CHANGED
@@ -7,3 +7,9 @@
7
7
  ## [0.1.1] - 2022-07-20
8
8
 
9
9
  - Update some small issues.
10
+
11
+ ## [0.1.2] - 2022-07-20
12
+
13
+ - Update user agent.
14
+ - Handle some responses.
15
+ - Retry 3 times for some cases.
data/README.md CHANGED
@@ -31,3 +31,11 @@ The gem is available as open source under the terms of the [MIT License](https:/
31
31
  ## Code of Conduct
32
32
 
33
33
  Everyone interacting in the SecEdgarRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nnhansg/sec-edgar-ruby/blob/master/CODE_OF_CONDUCT.md).
34
+
35
+ ## Notes
36
+
37
+ ### Fair Access
38
+
39
+ To ensure that everyone has equitable access to SEC EDGAR content, please use efficient scripting, downloading only what you need and please moderate requests to minimize server load. Current guidelines limit each user to a total of no more than 10 requests per second, regardless of the number of machines used to submit requests.
40
+
41
+ To ensure that SEC.gov remains available to all users, we reserve the right to block IP addresses that submit excessive requests. The SEC does not allow "unclassified" bots or automated tools to crawl the site. Any request that has been identified as part of an unclassified bot or an automated tool outside of the acceptable policy will be managed to ensure fair access for all users. See the Developer FAQ on how to comply with SEC's Web Site Privacy and Security Policy.
@@ -9,24 +9,54 @@ module SecEdgarRuby
9
9
  "https://data.sec.gov/submissions/CIK#{cik}.json"
10
10
  end
11
11
 
12
- # @options: { cik: 'xxx' }
12
+ # @options: { cik: 'xxx', user_agent: 'Name (email)', attempts: 0 }
13
13
  def self.find(options = {})
14
14
  result = {}
15
+ options[:user_agent] ||= "#{SecEdgarRuby.name}/#{SecEdgarRuby::VERSION}"
16
+ options[:attempts] = options[:attempts].to_i
15
17
  return result if options.blank? || options[:cik].blank?
16
18
 
17
19
  url = cik_api_url(options[:cik])
18
20
  return result if url.blank?
19
21
 
22
+ puts "GET: #{url}"
23
+
20
24
  response = Faraday.get(url) do |request|
21
25
  request.headers['Accept'] = '*/*'
22
26
  request.headers['Content-Type'] = 'application/json'
23
- request.headers['User-Agent'] = "#{SecEdgarRuby.name}/#{SecEdgarRuby::VERSION}"
27
+ request.headers['User-Agent'] = options[:user_agent]
28
+ end
29
+
30
+ content_type = response.headers['content-type']
31
+ puts "Headers: #{response.headers}"
32
+
33
+ case content_type
34
+ when 'application/json'
35
+ result = JSON.parse(response.body)
36
+ when 'application/xml'
37
+ result = Hash.from_xml(response.body).as_json
38
+ when 'text/html'
39
+ options[:attempts] = options[:attempts].to_i + 1
40
+ return find(options) if options[:attempts].to_i > 2
41
+
42
+ result = {
43
+ error: {
44
+ message: 'Your Request reached to limit or is rejected.',
45
+ details: response.body
46
+ }
47
+ }
48
+ else
49
+ options[:attempts] = options[:attempts].to_i + 1
50
+ return find(options) if options[:attempts].to_i > 2
51
+
52
+ result = {
53
+ error: {
54
+ message: 'Your Request is unknown or rejected.',
55
+ details: response.body
56
+ }
57
+ }
24
58
  end
25
59
 
26
- result = JSON.parse(response.body)
27
- Util.deep_snake_case_keys(result)
28
- rescue JSON::ParserError => e
29
- result = Hash.from_xml(response.body).as_json
30
60
  Util.deep_snake_case_keys(result)
31
61
  end
32
62
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SecEdgarRuby
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sec_edgar_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nhan Nguyen
@@ -86,8 +86,8 @@ files:
86
86
  - lib/sec_edgar_ruby/submission.rb
87
87
  - lib/sec_edgar_ruby/util.rb
88
88
  - lib/sec_edgar_ruby/version.rb
89
+ - pkg/sec_edgar_ruby-0.1.1.gem
89
90
  - sec_edgar_ruby.gemspec
90
- - sig/sec_edgar_ruby.rbs
91
91
  - spec/sec_edgar_ruby_spec.rb
92
92
  - spec/spec_helper.rb
93
93
  homepage: http://www.nhansg.com
@@ -1,4 +0,0 @@
1
- module SecEdgarRuby
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end