horizon_event 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +9 -0
- data/horizon_event.gemspec +27 -0
- data/lib/horizon_event.rb +7 -0
- data/lib/horizon_event/delimited.rb +37 -0
- data/lib/horizon_event/key_value_pairing.rb +39 -0
- data/lib/horizon_event/request.rb +43 -0
- data/lib/horizon_event/version.rb +3 -0
- data/test/sample_key_value_pairing.txt +33 -0
- data/test/sample_response.txt +1 -0
- data/test/test_helper.rb +11 -0
- data/test/unit/horizon_event/delimited_test.rb +36 -0
- data/test/unit/horizon_event/key_value_pairing_test.rb +36 -0
- data/test/unit/horizon_event/request_test.rb +21 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3e5386a633858bf4feb463e272259efb7f950a5c
|
4
|
+
data.tar.gz: 8d9e1c879d5d350cbea26f784c351ed1f13ee377
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 27f3e04819baf016b76a2d10f8322ec563cc690073bb2f25be471c1fc85178fdf2e2ac4ba226f5e585c71492a1f558ea8ccf19fba001b81961c01c7ccb5985e0
|
7
|
+
data.tar.gz: 6e2edb3188abf88aa9292e8bee317bfc284db5b72069dcf098bf6c9e95b3421cd82ca76ebce5faf99f8fc4209050bc47d652235ad4fa01651ab6c7a0c515f6c9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ryan T. Hosford
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# HorizonEvent
|
2
|
+
|
3
|
+
Requests a years worth of sunrise/sunset times for cities in the US.
|
4
|
+
See [USNO](http://aa.usno.navy.mil/data/docs/RS_OneYear.php)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'horizon_event'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install horizon_event
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require "horizon_event"
|
24
|
+
HorizonEvent::Delimited(delimiter: ",", city: "Birmingham", state: "AL").call
|
25
|
+
#=> returns a CSV string representing sunrise/sunset times for a whole year
|
26
|
+
|
27
|
+
HorizonEvent::KeyValuePairing.new(city: "Birmingham", state: "AL").call
|
28
|
+
#=> returns a Hash of all the year's sunrise/sunset times
|
29
|
+
|
30
|
+
HorizonEvent::Request.new(city: "Birmingham", state: "AL").call
|
31
|
+
#=> returns the raw response from USNO (United States Naval Observatory)
|
32
|
+
```
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'horizon_event/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "horizon_event"
|
8
|
+
spec.version = HorizonEvent::VERSION
|
9
|
+
spec.authors = ["Ryan T. Hosford"]
|
10
|
+
spec.email = ["tad.hosford@gmail.com"]
|
11
|
+
spec.description = %q{ This gem will get sunrise/sunset information from one of USNO's web services }
|
12
|
+
spec.summary = %q{ Please use this gem wisely, as I have no idea what kind of traffic the web service can handle }
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "pay_dirt"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
spec.add_development_dependency "coveralls"
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'pay_dirt'
|
2
|
+
|
3
|
+
module HorizonEvent
|
4
|
+
class Delimited < PayDirt::Base
|
5
|
+
def initialize(options = {})
|
6
|
+
options = {
|
7
|
+
delimiter: ",",
|
8
|
+
request_class: HorizonEvent::Request,
|
9
|
+
key_value_pairing_class: HorizonEvent::KeyValuePairing
|
10
|
+
}.merge(options)
|
11
|
+
# sets instance variables from key value pairs,
|
12
|
+
# will fail if any keys given before options aren't in options
|
13
|
+
load_options(:state, :city, :delimiter, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
return result(true, csv)
|
18
|
+
end
|
19
|
+
|
20
|
+
def csv
|
21
|
+
csv_string = CSV.generate(col_sep: @delimiter) do |csv|
|
22
|
+
csv << [ "day" , "sunrise" , "sunset", "cap"]
|
23
|
+
i=0
|
24
|
+
|
25
|
+
hash = @key_value_pairing_class.new(city: @city, state: @state, request_class: @request_class).call.data
|
26
|
+
hash.each do |k,v|
|
27
|
+
v.each do |monthday, events|
|
28
|
+
i+=1
|
29
|
+
if !!events[:sunrise] || !!events[:sunset]
|
30
|
+
csv << [i, events[:sunrise].to_i, events[:sunset].to_i, "2400"]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'pay_dirt'
|
2
|
+
|
3
|
+
module HorizonEvent
|
4
|
+
class KeyValuePairing < PayDirt::Base
|
5
|
+
def initialize(options = {})
|
6
|
+
options = {
|
7
|
+
request_class: HorizonEvent::Request
|
8
|
+
}.merge(options)
|
9
|
+
|
10
|
+
# sets instance variables from key value pairs,
|
11
|
+
# will fail if any keys given before options aren't in options
|
12
|
+
load_options(:request_class, :city, :state, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
return result(true, key_value_pairing)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def key_value_pairing
|
21
|
+
rows = @request_class.new(city: @city, state: @state).call.data.split("\n")
|
22
|
+
rows = rows.select { |row| "0".upto("3").to_a.include?(row[0]) }
|
23
|
+
|
24
|
+
options = {} and 1.upto(12) { |i| options.merge!({ i.to_s => {} }) }
|
25
|
+
|
26
|
+
rows.each do |row|
|
27
|
+
x1, x2, step, day = 4, 12, 11, row[0..1].to_i.to_s
|
28
|
+
options.each do |k,v|
|
29
|
+
rise_and_set = row[x1..x2].split(" ")
|
30
|
+
options[k][day] = { sunrise: rise_and_set[0], sunset: rise_and_set[1] }
|
31
|
+
|
32
|
+
x1, x2 = (x1 + step), (x2 + step)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
return options
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'pay_dirt'
|
2
|
+
require 'pry'
|
3
|
+
require 'net/http'
|
4
|
+
require 'csv'
|
5
|
+
|
6
|
+
module HorizonEvent
|
7
|
+
class Request < PayDirt::Base
|
8
|
+
def initialize(options = {})
|
9
|
+
options = {
|
10
|
+
http_headers: {
|
11
|
+
"Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
12
|
+
"Accept-Language" => "en-US,en;q=0.5",
|
13
|
+
"Accept-Encoding" => "gzip, deflate",
|
14
|
+
"Referer" => "http://aa.usno.navy.mil/data/docs/RS_OneYear.php"
|
15
|
+
},
|
16
|
+
year: Time.now.year.to_s,
|
17
|
+
city: "Birmingham",
|
18
|
+
state: "AL",
|
19
|
+
type: "0",
|
20
|
+
ffx: "1",
|
21
|
+
zzz: "END",
|
22
|
+
host: "aa.usno.navy.mil",
|
23
|
+
url: "http://aa.usno.navy.mil/cgi-bin/aa_rstablew.pl"
|
24
|
+
}.merge(options)
|
25
|
+
|
26
|
+
load_options(:http_headers, :ffx, :year, :type, :state, :city, :zzz, :host, :url, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def call
|
30
|
+
return result(true, request_response.body)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def request_response
|
35
|
+
response = Net::HTTP.start(@host) do |http|
|
36
|
+
request = Net::HTTP::Post.new(URI.parse(@url).path)
|
37
|
+
@http_headers.map { |k, v| request[k] = v }
|
38
|
+
request.body = "FFX=1&xxy=#{@year}&type=0&st=#{@state}&place=#{@city}&ZZZ=END"
|
39
|
+
http.request request
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
{"1"=>
|
2
|
+
{"1"=>{:sunrise=>"0652", :sunset=>"1651"},
|
3
|
+
"2"=>{:sunrise=>"0652", :sunset=>"1651"},
|
4
|
+
"3"=>{:sunrise=>"0652", :sunset=>"1652"},
|
5
|
+
"4"=>{:sunrise=>"0652", :sunset=>"1653"},
|
6
|
+
"5"=>{:sunrise=>"0652", :sunset=>"1654"},
|
7
|
+
"6"=>{:sunrise=>"0652", :sunset=>"1655"},
|
8
|
+
"7"=>{:sunrise=>"0652", :sunset=>"1655"},
|
9
|
+
"8"=>{:sunrise=>"0652", :sunset=>"1656"},
|
10
|
+
"9"=>{:sunrise=>"0652", :sunset=>"1657"},
|
11
|
+
"10"=>{:sunrise=>"0652", :sunset=>"1658"},
|
12
|
+
"11"=>{:sunrise=>"0652", :sunset=>"1659"},
|
13
|
+
"12"=>{:sunrise=>"0652", :sunset=>"1700"},
|
14
|
+
"13"=>{:sunrise=>"0652", :sunset=>"1701"},
|
15
|
+
"14"=>{:sunrise=>"0652", :sunset=>"1702"},
|
16
|
+
"15"=>{:sunrise=>"0651", :sunset=>"1703"},
|
17
|
+
"16"=>{:sunrise=>"0651", :sunset=>"1703"},
|
18
|
+
"17"=>{:sunrise=>"0651", :sunset=>"1704"},
|
19
|
+
"18"=>{:sunrise=>"0651", :sunset=>"1705"},
|
20
|
+
"19"=>{:sunrise=>"0650", :sunset=>"1706"},
|
21
|
+
"20"=>{:sunrise=>"0650", :sunset=>"1707"},
|
22
|
+
"21"=>{:sunrise=>"0649", :sunset=>"1708"},
|
23
|
+
"22"=>{:sunrise=>"0649", :sunset=>"1709"},
|
24
|
+
"23"=>{:sunrise=>"0649", :sunset=>"1710"},
|
25
|
+
"24"=>{:sunrise=>"0648", :sunset=>"1711"},
|
26
|
+
"25"=>{:sunrise=>"0648", :sunset=>"1712"},
|
27
|
+
"26"=>{:sunrise=>"0647", :sunset=>"1713"},
|
28
|
+
"27"=>{:sunrise=>"0646", :sunset=>"1714"},
|
29
|
+
"28"=>{:sunrise=>"0646", :sunset=>"1715"},
|
30
|
+
"29"=>{:sunrise=>"0645", :sunset=>"1716"},
|
31
|
+
"30"=>{:sunrise=>"0645", :sunset=>"1717"},
|
32
|
+
"31"=>{:sunrise=>"0644", :sunset=>"1718"}}
|
33
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n<title>Sun or Moon Rise/Set Table for One Year</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n</head>\n<body>\n<pre>\n o , o , BIRMINGHAM, ALABAMA Astronomical Applications Dept.\nLocation: W086 49, N33 32 Rise and Set for the Sun for 2013 U. S. Naval Observatory \n Washington, DC 20392-5420 \n Central Standard Time \n \n \n Jan. Feb. Mar. Apr. May June July Aug. Sept. Oct. Nov. Dec. \nDay Rise Set Rise Set Rise Set Rise Set Rise Set Rise Set Rise Set Rise Set Rise Set Rise Set Rise Set Rise Set\n h m h m h m h m h m h m h m h m h m h m h m h m h m h m h m h m h m h m h m h m h m h m h m h m\n01 0652 1651 0643 1719 0615 1744 0535 1808 0459 1830 0438 1852 0441 1901 0500 1847 0521 1812 0542 1731 0606 1655 0634 1639\n02 0652 1651 0643 1720 0614 1745 0533 1809 0458 1831 0438 1853 0441 1901 0501 1846 0522 1811 0542 1730 0607 1654 0634 1639\n03 0652 1652 0642 1721 0613 1746 0532 1809 0457 1832 0438 1853 0442 1901 0501 1845 0523 1810 0543 1729 0608 1653 0635 1639\n04 0652 1653 0641 1722 0612 1747 0531 1810 0456 1833 0437 1854 0442 1901 0502 1844 0523 1808 0544 1727 0609 1652 0636 1639\n05 0652 1654 0640 1723 0610 1747 0529 1811 0455 1833 0437 1855 0443 1901 0503 1843 0524 1807 0545 1726 0610 1651 0637 1639\n06 0652 1655 0639 1724 0609 1748 0528 1812 0454 1834 0437 1855 0443 1901 0503 1842 0525 1806 0545 1725 0611 1651 0638 1639\n07 0652 1655 0639 1725 0608 1749 0527 1812 0453 1835 0437 1856 0444 1900 0504 1841 0525 1804 0546 1723 0612 1650 0639 1639\n08 0652 1656 0638 1726 0606 1750 0525 1813 0452 1836 0437 1856 0444 1900 0505 1840 0526 1803 0547 1722 0613 1649 0639 1639\n09 0652 1657 0637 1727 0605 1751 0524 1814 0451 1836 0437 1856 0445 1900 0505 1839 0527 1802 0548 1721 0614 1648 0640 1639\n10 0652 1658 0636 1727 0604 1751 0523 1815 0450 1837 0437 1857 0445 1900 0506 1838 0527 1800 0548 1719 0614 1648 0641 1640\n11 0652 1659 0635 1728 0603 1752 0522 1815 0450 1838 0437 1857 0446 1859 0507 1837 0528 1759 0549 1718 0615 1647 0642 1640\n12 0652 1700 0634 1729 0601 1753 0520 1816 0449 1839 0437 1858 0447 1859 0508 1836 0529 1757 0550 1717 0616 1646 0642 1640\n13 0652 1701 0633 1730 0600 1754 0519 1817 0448 1839 0437 1858 0447 1859 0508 1835 0529 1756 0551 1716 0617 1646 0643 1640\n14 0652 1702 0632 1731 0559 1755 0518 1818 0447 1840 0437 1859 0448 1858 0509 1834 0530 1755 0551 1714 0618 1645 0644 1641\n15 0651 1703 0631 1732 0557 1755 0517 1818 0447 1841 0437 1859 0448 1858 0510 1833 0531 1753 0552 1713 0619 1644 0644 1641\n16 0651 1703 0630 1733 0556 1756 0515 1819 0446 1842 0437 1859 0449 1857 0510 1832 0531 1752 0553 1712 0620 1644 0645 1641\n17 0651 1704 0629 1734 0555 1757 0514 1820 0445 1842 0437 1859 0450 1857 0511 1831 0532 1751 0554 1711 0621 1643 0645 1642\n18 0651 1705 0628 1735 0553 1758 0513 1821 0445 1843 0437 1900 0450 1856 0512 1830 0533 1749 0555 1710 0622 1643 0646 1642\n19 0650 1706 0627 1736 0552 1758 0512 1821 0444 1844 0437 1900 0451 1856 0513 1828 0533 1748 0555 1708 0623 1642 0647 1642\n20 0650 1707 0626 1737 0551 1759 0511 1822 0443 1845 0438 1900 0452 1855 0513 1827 0534 1746 0556 1707 0624 1642 0647 1643\n21 0649 1708 0625 1737 0549 1800 0509 1823 0443 1845 0438 1900 0452 1855 0514 1826 0535 1745 0557 1706 0625 1642 0648 1643\n22 0649 1709 0624 1738 0548 1801 0508 1824 0442 1846 0438 1901 0453 1854 0515 1825 0536 1744 0558 1705 0626 1641 0648 1644\n23 0649 1710 0622 1739 0547 1801 0507 1824 0442 1847 0438 1901 0454 1854 0515 1824 0536 1742 0559 1704 0626 1641 0649 1644\n24 0648 1711 0621 1740 0545 1802 0506 1825 0441 1847 0439 1901 0454 1853 0516 1822 0537 1741 0559 1703 0627 1640 0649 1645\n25 0648 1712 0620 1741 0544 1803 0505 1826 0441 1848 0439 1901 0455 1852 0517 1821 0538 1739 0600 1702 0628 1640 0649 1646\n26 0647 1713 0619 1742 0543 1804 0504 1827 0440 1849 0439 1901 0456 1851 0517 1820 0538 1738 0601 1701 0629 1640 0650 1646\n27 0646 1714 0618 1743 0541 1804 0503 1827 0440 1849 0439 1901 0456 1851 0518 1819 0539 1737 0602 1700 0630 1640 0650 1647\n28 0646 1715 0616 1743 0540 1805 0502 1828 0440 1850 0440 1901 0457 1850 0519 1817 0540 1735 0603 1659 0631 1639 0651 1648\n29 0645 1716 0539 1806 0501 1829 0439 1851 0440 1901 0458 1849 0519 1816 0540 1734 0604 1658 0632 1639 0651 1648\n30 0645 1717 0537 1806 0500 1830 0439 1851 0441 1901 0458 1848 0520 1815 0541 1733 0605 1657 0633 1639 0651 1649\n31 0644 1718 0536 1807 0438 1852 0459 1848 0521 1814 0605 1656 0651 1650\n\n Add one hour for daylight time, if and when in use.\n\n</pre>\n<p><a href=\"javascript:history.go(-1)\">Back to form</a></p>\n</body>\n</html>\n
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
require "minitest/autorun"
|
5
|
+
|
6
|
+
# The gem
|
7
|
+
$: << File.dirname(__FILE__) + "/../lib"
|
8
|
+
$: << File.dirname(__FILE__)
|
9
|
+
require "horizon_event/request"
|
10
|
+
require "horizon_event/key_value_pairing"
|
11
|
+
require "horizon_event/delimited"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe HorizonEvent::Delimited do
|
4
|
+
before do
|
5
|
+
@subject = HorizonEvent::Delimited
|
6
|
+
@params = {
|
7
|
+
key_value_pairing_class: @kv_class = MiniTest::Mock.new,
|
8
|
+
request_class: @req_class = MiniTest::Mock.new,
|
9
|
+
city: "Birmingham",
|
10
|
+
state: "AL",
|
11
|
+
}
|
12
|
+
expected_hash = instance_eval(`cat test/sample_key_value_pairing.txt`)
|
13
|
+
@kv_class.expect(:new, @kv_instance = MiniTest::Mock.new, [{ request_class: @req_class, state: @params[:state], city: @params[:city] }])
|
14
|
+
@kv_instance.expect(:call, @result = MiniTest::Mock.new)
|
15
|
+
@result.expect(:data, expected_hash)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "as a class" do
|
19
|
+
it "initializes properly" do
|
20
|
+
@subject.new(@params).must_respond_to :call
|
21
|
+
end
|
22
|
+
|
23
|
+
it "errors when initialized without required dependencies" do
|
24
|
+
-> { @subject.new(@params.reject { |k| k.to_s == 'city' }) }.must_raise RuntimeError
|
25
|
+
-> { @subject.new(@params.reject { |k| k.to_s == 'state' }) }.must_raise RuntimeError
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "as an instance" do
|
30
|
+
it "executes successfully" do
|
31
|
+
result = @subject.new(@params).call
|
32
|
+
result.successful?.must_equal true
|
33
|
+
result.must_be_kind_of PayDirt::Result
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe HorizonEvent::KeyValuePairing do
|
4
|
+
before do
|
5
|
+
@subject = HorizonEvent::KeyValuePairing
|
6
|
+
@params = {
|
7
|
+
request_class: @req_class = MiniTest::Mock.new,
|
8
|
+
city: "Birmingham",
|
9
|
+
state: "AL",
|
10
|
+
}
|
11
|
+
|
12
|
+
expected_string = `cat test/sample_response.txt`
|
13
|
+
@req_class.expect(:new, @req_instance = MiniTest::Mock.new, [{state: @params[:state], city: @params[:city] }])
|
14
|
+
@req_instance.expect(:call, @result = MiniTest::Mock.new)
|
15
|
+
@result.expect(:data, expected_string)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "as a class" do
|
19
|
+
it "initializes properly" do
|
20
|
+
@subject.new(@params).must_respond_to :call
|
21
|
+
end
|
22
|
+
|
23
|
+
it "errors when initialized without required dependencies" do
|
24
|
+
-> { @subject.new(@params.reject { |k| k.to_s == 'city' }) }.must_raise RuntimeError
|
25
|
+
-> { @subject.new(@params.reject { |k| k.to_s == 'state' }) }.must_raise RuntimeError
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "as an instance" do
|
30
|
+
it "executes successfully" do
|
31
|
+
result = @subject.new(@params).call
|
32
|
+
result.successful?.must_equal true
|
33
|
+
result.must_be_kind_of PayDirt::Result
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe HorizonEvent::Request do
|
4
|
+
before do
|
5
|
+
@subject = HorizonEvent::Request
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "as a class" do
|
9
|
+
it "initializes properly" do
|
10
|
+
@subject.new.must_respond_to :call
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "as an instance" do
|
15
|
+
it "executes successfully" do
|
16
|
+
result = @subject.new.call
|
17
|
+
result.successful?.must_equal true
|
18
|
+
result.must_be_kind_of PayDirt::Result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: horizon_event
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan T. Hosford
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pay_dirt
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
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: minitest
|
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: pry
|
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: coveralls
|
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: ' This gem will get sunrise/sunset information from one of USNO''s web
|
98
|
+
services '
|
99
|
+
email:
|
100
|
+
- tad.hosford@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- horizon_event.gemspec
|
111
|
+
- lib/horizon_event.rb
|
112
|
+
- lib/horizon_event/delimited.rb
|
113
|
+
- lib/horizon_event/key_value_pairing.rb
|
114
|
+
- lib/horizon_event/request.rb
|
115
|
+
- lib/horizon_event/version.rb
|
116
|
+
- test/sample_key_value_pairing.txt
|
117
|
+
- test/sample_response.txt
|
118
|
+
- test/test_helper.rb
|
119
|
+
- test/unit/horizon_event/delimited_test.rb
|
120
|
+
- test/unit/horizon_event/key_value_pairing_test.rb
|
121
|
+
- test/unit/horizon_event/request_test.rb
|
122
|
+
homepage: ''
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.0.3
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Please use this gem wisely, as I have no idea what kind of traffic the web
|
146
|
+
service can handle
|
147
|
+
test_files:
|
148
|
+
- test/sample_key_value_pairing.txt
|
149
|
+
- test/sample_response.txt
|
150
|
+
- test/test_helper.rb
|
151
|
+
- test/unit/horizon_event/delimited_test.rb
|
152
|
+
- test/unit/horizon_event/key_value_pairing_test.rb
|
153
|
+
- test/unit/horizon_event/request_test.rb
|