dark_sky_weather 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +63 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/dark_sky_weather.gemspec +30 -0
- data/lib/dark_sky_weather.rb +79 -0
- data/lib/dark_sky_weather/version.rb +3 -0
- metadata +95 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 9a017c00389b15d031dd37a9f58ef6b507145385
         | 
| 4 | 
            +
              data.tar.gz: 0d946fe8a3a514db40a09aa849a7b82cc907f304
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 597569739af307894f1fa1954d5df211935dc7b0c59cc2cf837f9e1aba55541ca445c623b9f6b554170226fb1cd4c726129830dfc7d4c6335837a0fa9a253fbd
         | 
| 7 | 
            +
              data.tar.gz: c0c3c04ace42e66cd2f1895c97dd2a81e3850f6681cd124be6ffe75ed906ad1bfed037376120ce2eddd834b6040266e4a43cd4069001f75d3b28873c1950a1c4
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,63 @@ | |
| 1 | 
            +
            # DarkSkyWeather
         | 
| 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/dark_sky_weather`. 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 'dark_sky_weather'
         | 
| 13 | 
            +
            ```
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            And then execute:
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                $ bundle
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            Or install it yourself as:
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                $ gem install dark_sky_weather
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            ## Usage
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            First, make sure you have an API_KEY in the .env file then call!
         | 
| 26 | 
            +
            To fetch currant conditions:
         | 
| 27 | 
            +
            ```ruby
         | 
| 28 | 
            +
            object_name = DarkSkyWeather::CurrentWeather.currently('#{ENV['WEATHER_API_URL']}', LATITUDE, LONGITUDE)
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            Cool methods to call on you new object:
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            object_name.to_date => "Thursday, 09 Apr 2015  7:25 PM"
         | 
| 33 | 
            +
            .summary
         | 
| 34 | 
            +
            .icon
         | 
| 35 | 
            +
            .precipProbability
         | 
| 36 | 
            +
            .temperature (rounded down)
         | 
| 37 | 
            +
            .apparentTemperature
         | 
| 38 | 
            +
            .humidity
         | 
| 39 | 
            +
            ```
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            To get an entire weeks worth of weather
         | 
| 42 | 
            +
            ```ruby
         | 
| 43 | 
            +
            object_name = DarkSkyWeather::CurrentWeather.daily('#{ENV['WEATHER_API_URL']}', LATITUDE, LONGITUDE)
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            All the above methods will work here plus:
         | 
| 46 | 
            +
            .precip => 50%
         | 
| 47 | 
            +
            .abbreviated_week_day => 'Sun', 'Mon', 'Tues', 'Wed', 'Thur', Fri, or Sun
         | 
| 48 | 
            +
            ```
         | 
| 49 | 
            +
             | 
| 50 | 
            +
             | 
| 51 | 
            +
            ## Development
         | 
| 52 | 
            +
             | 
| 53 | 
            +
            After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
         | 
| 56 | 
            +
             | 
| 57 | 
            +
            ## Contributing
         | 
| 58 | 
            +
             | 
| 59 | 
            +
            1. Fork it ( https://github.com/[my-github-username]/dark_sky_weather/fork )
         | 
| 60 | 
            +
            2. Create your feature branch (`git checkout -b my-new-feature`)
         | 
| 61 | 
            +
            3. Commit your changes (`git commit -am 'Add some feature'`)
         | 
| 62 | 
            +
            4. Push to the branch (`git push origin my-new-feature`)
         | 
| 63 | 
            +
            5. Create a new Pull Request
         | 
    
        data/Rakefile
    ADDED
    
    
    
        data/bin/console
    ADDED
    
    | @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "bundler/setup"
         | 
| 4 | 
            +
            require "dark_sky_weather"
         | 
| 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
         | 
    
        data/bin/setup
    ADDED
    
    
| @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require 'dark_sky_weather/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "dark_sky_weather"
         | 
| 8 | 
            +
              spec.version       = DarkSkyWeather::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["Troy Leach"]
         | 
| 10 | 
            +
              spec.email         = ["troyleach29@gmail.com"]
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              if spec.respond_to?(:metadata)
         | 
| 13 | 
            +
                # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              spec.summary       = %q{forecast.io API wrapper in Ruby.}
         | 
| 17 | 
            +
              spec.description   = %q{forecast.io API wrapper in Ruby.}
         | 
| 18 | 
            +
              spec.homepage      = "https://github.com/troyleach/dark_sky_weather"
         | 
| 19 | 
            +
              spec.license       = "MIT"
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              spec.files         = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         | 
| 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.8"
         | 
| 27 | 
            +
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              spec.add_dependency "unirest"
         | 
| 30 | 
            +
            end
         | 
| @@ -0,0 +1,79 @@ | |
| 1 | 
            +
            require "dark_sky_weather/version"
         | 
| 2 | 
            +
            require "unirest"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module DarkSkyWeather
         | 
| 5 | 
            +
              
         | 
| 6 | 
            +
              class CurrentWeather
         | 
| 7 | 
            +
                attr_reader :time, :summary, :icon, :precipProbability, :temperature, :apparentTemperature, :humidity, :temperatureMin, :temperatureMax, :precipType
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def initialize(args)
         | 
| 10 | 
            +
                  @time                = args["time"]
         | 
| 11 | 
            +
                  @summary             = args["summary"]
         | 
| 12 | 
            +
                  @icon                = args["icon"]
         | 
| 13 | 
            +
                  @precipProbability   = args["precipProbability"]
         | 
| 14 | 
            +
                  @temperature         = args["temperature"]
         | 
| 15 | 
            +
                  @apparentTemperature = args["apparentTemperature"]
         | 
| 16 | 
            +
                  @humidity            = args["humidity"]
         | 
| 17 | 
            +
                  @temperatureMin      = args["temperatureMin"]
         | 
| 18 | 
            +
                  @temperatureMax      = args["temperatureMax"]
         | 
| 19 | 
            +
                  @precipType          = args["precipType"]
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def self.currently(api_key, latitude, longitude)
         | 
| 23 | 
            +
                  latitude  = latitude.to_f
         | 
| 24 | 
            +
                  longitude = longitude.to_f
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  current_weather = Unirest.get("https://api.forecast.io/forecast/#{api_key}/#{latitude},#{longitude}").body["currently"]
         | 
| 27 | 
            +
                  return CurrentWeather.new(current_weather)
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def self.daily(api_key, latitude, longitude)
         | 
| 31 | 
            +
                  latitude  = latitude.to_f
         | 
| 32 | 
            +
                  longitude = longitude.to_f
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  weeks_weather_array = Unirest.get("https://api.forecast.io/forecast/#{api_key}/#{latitude},#{longitude}").body["daily"]["data"]
         | 
| 35 | 
            +
                  weeks_forecast = []
         | 
| 36 | 
            +
                  weeks_weather_array.each do |daily_weather|
         | 
| 37 | 
            +
                    weeks_forecast << CurrentWeather.new(daily_weather)
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
                  weeks_forecast
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                def to_date
         | 
| 43 | 
            +
                  format_seconds.strftime("%A, %d %b %Y %l:%M %p")
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                def abbreviated_week_day
         | 
| 47 | 
            +
                  if format_seconds.strftime("%A").downcase == "thursday" || "tuesday"
         | 
| 48 | 
            +
                    format_seconds.strftime("%A").slice(0, 4)
         | 
| 49 | 
            +
                  else
         | 
| 50 | 
            +
                    format_seconds.strftime("%A").slice(0, 3)
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                def temp
         | 
| 55 | 
            +
                  @temperature.round || @temperatureMin.round || @temperatureMax.round
         | 
| 56 | 
            +
                end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                def humidity
         | 
| 59 | 
            +
                  "#{find_percent(@humidity)}%"
         | 
| 60 | 
            +
                end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                def precip
         | 
| 63 | 
            +
                  "#{find_percent(@precipProbability)}%"
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                
         | 
| 67 | 
            +
                private
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                def format_seconds
         | 
| 70 | 
            +
                  Time.at(@time)
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                def find_percent(number)
         | 
| 74 | 
            +
                  (number * 100).to_i
         | 
| 75 | 
            +
                end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
              end
         | 
| 78 | 
            +
            end
         | 
| 79 | 
            +
             | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,95 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: dark_sky_weather
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Troy Leach
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: exe
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2015-04-10 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.8'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '1.8'
         | 
| 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: unirest
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :runtime
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">="
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 55 | 
            +
            description: forecast.io API wrapper in Ruby.
         | 
| 56 | 
            +
            email:
         | 
| 57 | 
            +
            - troyleach29@gmail.com
         | 
| 58 | 
            +
            executables: []
         | 
| 59 | 
            +
            extensions: []
         | 
| 60 | 
            +
            extra_rdoc_files: []
         | 
| 61 | 
            +
            files:
         | 
| 62 | 
            +
            - ".gitignore"
         | 
| 63 | 
            +
            - Gemfile
         | 
| 64 | 
            +
            - README.md
         | 
| 65 | 
            +
            - Rakefile
         | 
| 66 | 
            +
            - bin/console
         | 
| 67 | 
            +
            - bin/setup
         | 
| 68 | 
            +
            - dark_sky_weather.gemspec
         | 
| 69 | 
            +
            - lib/dark_sky_weather.rb
         | 
| 70 | 
            +
            - lib/dark_sky_weather/version.rb
         | 
| 71 | 
            +
            homepage: https://github.com/troyleach/dark_sky_weather
         | 
| 72 | 
            +
            licenses:
         | 
| 73 | 
            +
            - MIT
         | 
| 74 | 
            +
            metadata: {}
         | 
| 75 | 
            +
            post_install_message: 
         | 
| 76 | 
            +
            rdoc_options: []
         | 
| 77 | 
            +
            require_paths:
         | 
| 78 | 
            +
            - lib
         | 
| 79 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 80 | 
            +
              requirements:
         | 
| 81 | 
            +
              - - ">="
         | 
| 82 | 
            +
                - !ruby/object:Gem::Version
         | 
| 83 | 
            +
                  version: '0'
         | 
| 84 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 85 | 
            +
              requirements:
         | 
| 86 | 
            +
              - - ">="
         | 
| 87 | 
            +
                - !ruby/object:Gem::Version
         | 
| 88 | 
            +
                  version: '0'
         | 
| 89 | 
            +
            requirements: []
         | 
| 90 | 
            +
            rubyforge_project: 
         | 
| 91 | 
            +
            rubygems_version: 2.2.2
         | 
| 92 | 
            +
            signing_key: 
         | 
| 93 | 
            +
            specification_version: 4
         | 
| 94 | 
            +
            summary: forecast.io API wrapper in Ruby.
         | 
| 95 | 
            +
            test_files: []
         |