tsp_scraper 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -4
- data/lib/tsp_scraper/client.rb +8 -0
- data/lib/tsp_scraper/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9435a25a43cea911351f675903a19e0fc567e16c
|
4
|
+
data.tar.gz: d536b629de412bee275c24f8ca76b8b0b48a669c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30dd0e765735a8c6e49be308ee6bdca8757269b70bea54752317cd59f0d6244381b7630d0b17bee8e64cc96cc0016ef2c1bfdf3ac47f13b665b13a178605acfe
|
7
|
+
data.tar.gz: cefdbced940927ed4078e3204c427e7e61575d32a361afec32a64c2aa81aaeec99d8040dbba2ea8a7e413c3696ffefe456ce2cc23fcf70b81231be6eb01c0568
|
data/README.md
CHANGED
@@ -12,12 +12,13 @@ gem install tsp_scraper
|
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
15
|
-
The `scrape`
|
15
|
+
The `scrape` methods accept `Date` objects as parameters and return TSP price data as an array of hashes:
|
16
16
|
|
17
17
|
```ruby
|
18
18
|
require 'tsp_scraper'
|
19
19
|
TSPScraper::Client.scrape() # Get trailing one month's prices
|
20
|
-
TSPScraper::Client.scrape(
|
20
|
+
TSPScraper::Client.scrape(date) # Get prices for a specific date
|
21
|
+
TSPScraper::Client.scrape(start_date, end_date) # Get January prices
|
21
22
|
```
|
22
23
|
|
23
24
|
The returned array of hashes has the format:
|
@@ -51,10 +52,12 @@ The returned array of hashes has the format:
|
|
51
52
|
]
|
52
53
|
```
|
53
54
|
|
54
|
-
You can get the raw CSV data as returned by the TSP website by using `TSPScraper::Client.scrape_raw()
|
55
|
+
You can get the raw CSV data as returned by the TSP website by using `TSPScraper::Client.scrape_raw()`, which accepts the same parameters as the `scrape` method.
|
56
|
+
|
57
|
+
### HTTParty Options
|
55
58
|
|
56
59
|
The `scrape` and `scrape_raw` methods also accept an options hash for the HTTP request. The options hash should contain [HTTParty](https://github.com/jnunemaker/httparty) options.
|
57
60
|
|
58
61
|
```ruby
|
59
|
-
TSPScraper::Client.scrape(
|
62
|
+
TSPScraper::Client.scrape(start_date, end_date, verify: false) # Don't verify SSL certificate
|
60
63
|
```
|
data/lib/tsp_scraper/client.rb
CHANGED
@@ -6,6 +6,10 @@ module TSPScraper
|
|
6
6
|
disable_rails_query_string_format
|
7
7
|
base_uri "https://www.tsp.gov/InvestmentFunds/FundPerformance"
|
8
8
|
|
9
|
+
def self.scrape_raw(date = Date.today, options = {})
|
10
|
+
self.scrape_raw(date, date, options)
|
11
|
+
end
|
12
|
+
|
9
13
|
def self.scrape_raw(start_date = Date.today.prev_month, end_date = Date.today, options = {})
|
10
14
|
funds = ["Linc", "L2010", "L2020", "L2030", "L2040", "L2050", "G", "F", "C", "S", "I"]
|
11
15
|
default_options = {
|
@@ -23,6 +27,10 @@ module TSPScraper
|
|
23
27
|
response.body.strip
|
24
28
|
end
|
25
29
|
|
30
|
+
def self.scrape(date = Date.today, options = {})
|
31
|
+
self.scrape(date, date, options)
|
32
|
+
end
|
33
|
+
|
26
34
|
def self.scrape(start_date = Date.today.prev_month, end_date = Date.today, options = {})
|
27
35
|
raw = self.scrape_raw(start_date, end_date, options = {})
|
28
36
|
TSPScraper::Converter.raw_csv_to_hash(raw)
|
data/lib/tsp_scraper/version.rb
CHANGED