snowreports 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
+ SHA1:
3
+ metadata.gz: 278606379eb08260bcd0b038d9c25e8269b81974
4
+ data.tar.gz: e809a81d2ab4e10ce130f626f97f3d204f323bcb
5
+ SHA512:
6
+ metadata.gz: 4ac97b64a4cfdab6e68bbc7d87cead42e0111d7a58da37e26be3a444000a50a0c0ab8fe1d4362cad8718eedd003dd366477562b457f79e22d2ce131fd7ba833b
7
+ data.tar.gz: 9638574d7ea61c9f59395a94fdfc21e2796e3d4ae7966f191074c82ddc3466eae2675940aefec339c8c5b062f419f53346e174429cd1fa7d192667a3f1cfd8ee
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in snowreports.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Patrick Davey
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,39 @@
1
+ # Snowreports
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/snowreports`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'snowreports'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install snowreports
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/snowreports.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "snowreports"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,20 @@
1
+ require_relative "snowreports/version"
2
+ require_relative "snowreports/builder"
3
+ require_relative "snowreports/endpoint"
4
+ require_relative "snowreports/fetcher"
5
+
6
+ module Snowreports
7
+ def self.fetch(ski_field)
8
+ endpoint = Endpoint.all.fetch(ski_field)
9
+ response = Fetcher.fetch(path: endpoint.path)
10
+ Builder.build(xml: response.body, field_id: endpoint.id)
11
+ end
12
+
13
+ def self.all
14
+ Endpoint.all.each_with_object([]) do |(_field_name, endpoint), acc|
15
+ response = Fetcher.fetch(path: endpoint.path)
16
+ acc << Builder.build(xml: response.body, field_id: endpoint.id)
17
+ acc
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,36 @@
1
+ require_relative './snowreport'
2
+ require 'nokogiri'
3
+
4
+ module Snowreports
5
+ class Builder
6
+ def self.build(xml:, field_id:)
7
+ parsed = Nokogiri.parse(xml)
8
+ last_updated_date = parsed.xpath("//skiareas/skiarea/date").text
9
+ last_updated_time = parsed.xpath("//skiareas/skiarea/time").text.sub(/:\d+$/,"")
10
+ weather_detail = parsed.xpath("//skiareas/skiarea/weather/detail").text
11
+ road_node = parsed.xpath('//facilitytype/name[contains(text(), "Road")]').first.parent
12
+ road_status = road_node.xpath(".//status/label").text
13
+ road_brief = road_node.xpath(".//brief").text
14
+ snowreports_field_id = parsed.xpath("//skiarea/id").text
15
+ snowreports_field_name = parsed.xpath("//skiarea/name").text
16
+ information = parsed.xpath("//information").text
17
+ snow_min = parsed.xpath("//snow/mindepth").text
18
+ snow_base = parsed.xpath("//snow/base").text
19
+ mountain_status = parsed.xpath("//skiarea/status/label").text
20
+
21
+ Snowreport.new(updated_date: last_updated_date,
22
+ updated_time: last_updated_time,
23
+ road_status: road_status,
24
+ road_brief: road_brief,
25
+ name: snowreports_field_name,
26
+ id: snowreports_field_id,
27
+ weather_detail: weather_detail,
28
+ snow_min: snow_min,
29
+ snow_base: snow_base,
30
+ information: information,
31
+ field_id: field_id,
32
+ mountain_status: mountain_status,
33
+ )
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,32 @@
1
+ module Snowreports
2
+ class Endpoint
3
+ SnowpoolWrapper = Struct.new(:id, :path)
4
+
5
+ def self.all
6
+ @all ||= {
7
+ turoa: SnowpoolWrapper.new(24, "/nz/mt-ruapehu-and-manganui/turoa/turoa-snow-report"),
8
+ whakapapa: SnowpoolWrapper.new(21, "/nz/mt-ruapehu-and-manganui/whakapapa/whakapapa-snow-report"),
9
+ cardrona: SnowpoolWrapper.new(15, "/nz/queenstown-and-wanaka/cardrona/cardrona-snow-report"),
10
+ treble_cone: SnowpoolWrapper.new(7, "/nz/queenstown-and-wanaka/treble-cone/treble-cone-snow-report"),
11
+ remarkables: SnowpoolWrapper.new(6, "/nz/queenstown-and-wanaka/the-remarkables/remarkables-snow-report"),
12
+ coronet_peak: SnowpoolWrapper.new(14, "/nz/queenstown-and-wanaka/coronet-peak/coronet-peak-snow-report"),
13
+ snow_farm: SnowpoolWrapper.new(18, "/nz/queenstown-and-wanaka/snow-farm/snow-farm-snow-report"),
14
+ manganui: SnowpoolWrapper.new(24, "/nz/mt-ruapehu-and-manganui/maunganui-ski-area/manganui-snow-report"),
15
+ rainbow: SnowpoolWrapper.new(20, "/nz/nelson-lakes/rainbow-ski-area/rainbow-snow-report"),
16
+ mt_hutt: SnowpoolWrapper.new(8, "/nz/canterbury/mt-hutt/mt-hutt-snow-report"),
17
+ mt_cheeseman: SnowpoolWrapper.new(3, "/nz/canterbury/mt-cheeseman/mt-cheeseman-snow-report"),
18
+ hanmer_springs: SnowpoolWrapper.new(9, "/nz/canterbury/hanmer-springs/hanmer-springs-snow-report"),
19
+ broken_river: SnowpoolWrapper.new(4, "/nz/canterbury/broken-river/broken-river-snow-report"),
20
+ my_lyford: SnowpoolWrapper.new(16, "/nz/canterbury/mt-lyford/mt-lyford-snow-report"),
21
+ craigieburn: SnowpoolWrapper.new(10, "/nz/canterbury/craigieburn/craigieburn-snow-report"),
22
+ porters: SnowpoolWrapper.new(1, "/nz/canterbury/porters/porters-snow-report"),
23
+ mt_olympus: SnowpoolWrapper.new(5, "/nz/canterbury/mt-olympus/mt-olympus-snow-report"),
24
+ temple_basin: SnowpoolWrapper.new(2, "/nz/canterbury/temple-basin/temple-basin-snow-report"),
25
+ ohau: SnowpoolWrapper.new(12, "/nz/mackenzie/ohau-snow-fields/ohau-snow-report"),
26
+ mt_dobson: SnowpoolWrapper.new(13, "/nz/mackenzie/mt-dobson/mt-dobson-snow-report"),
27
+ roundhill: SnowpoolWrapper.new(17, "/nz/mackenzie/roundhill/roundhill-snow-report"),
28
+ fox_peak: SnowpoolWrapper.new(11, "/nz/mackenzie/fox-peak/fox-peak-snow-report"),
29
+ }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,28 @@
1
+ require 'faraday'
2
+
3
+ module Snowreports
4
+ class Fetcher
5
+ BASE_PATH = "https://www.snowhq.com/"
6
+
7
+ class << self
8
+ attr_accessor :user, :pass
9
+ end
10
+
11
+ def self.fetch(path:)
12
+ conn.get(path + "/xml")
13
+ end
14
+
15
+ def self.conn
16
+ @conn ||= begin
17
+ conn = Faraday.new(url: BASE_PATH)
18
+ snow_user = user || ENV["SNOW_USER"]
19
+ snow_pass = pass || ENV["SNOW_PASS"]
20
+
21
+ raise "You must supply a username and password for API access" unless snow_user && snow_pass
22
+
23
+ conn.basic_auth(snow_user, snow_pass)
24
+ conn
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ module Snowreports
2
+ class RequiredKeywordStruct < Struct
3
+ def initialize(**kwargs)
4
+ super(*members.map{|k| kwargs.fetch(k) })
5
+ end
6
+ end
7
+
8
+ Snowreport = RequiredKeywordStruct.new(
9
+ :mountain_status,
10
+ :updated_date,
11
+ :updated_time,
12
+ :road_status,
13
+ :road_brief,
14
+ :name,
15
+ :id,
16
+ :weather_detail,
17
+ :snow_base,
18
+ :snow_min,
19
+ :information,
20
+ :field_id
21
+ )
22
+ end
@@ -0,0 +1,3 @@
1
+ module Snowreports
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "snowreports/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "snowreports"
8
+ spec.version = Snowreports::VERSION
9
+ spec.authors = ["Patrick Davey"]
10
+ spec.email = ["patrick.davey@gmail.com"]
11
+
12
+ spec.summary = %q{Fetches and parses reports from snowreports.co.nz}
13
+ spec.description = %q{Fetches are parses reports from snowreports.co.nz}
14
+ spec.homepage = "https://github.com/snowpool/snowreports"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "faraday", "~> 0.12.1"
25
+ spec.add_runtime_dependency "nokogiri", "~> 1.8"
26
+
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.15"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ spec.add_development_dependency "pry", "~> 0.10.1"
32
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: snowreports
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Patrick Davey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.10.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.10.1
97
+ description: Fetches are parses reports from snowreports.co.nz
98
+ email:
99
+ - patrick.davey@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/snowreports.rb
114
+ - lib/snowreports/builder.rb
115
+ - lib/snowreports/endpoint.rb
116
+ - lib/snowreports/fetcher.rb
117
+ - lib/snowreports/snowreport.rb
118
+ - lib/snowreports/version.rb
119
+ - snowreports.gemspec
120
+ homepage: https://github.com/snowpool/snowreports
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.6.12
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Fetches and parses reports from snowreports.co.nz
144
+ test_files: []
145
+ has_rdoc: