mygasfeed 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e7c7a4d2b39c6a40877903f33ef998828ae5a10
4
+ data.tar.gz: 43c5b35f9126d73c4d4c6c0e98641ad0f22f65ae
5
+ SHA512:
6
+ metadata.gz: b1cd6e01c95e4278e076e63fb04393abd1489a54bfffe03c11091e6cc2951e1ea9fee9933e8cb6ad860406550dfe44a7885d920229f04dbd51536545573d2937
7
+ data.tar.gz: fa5a0b75c835a9b1bbbd2029d2b1febb0e58c604f0e1f5e77c31d929ed6c0afd94a3ac215f3ac764f3bfd9cb1861e4f13ab03915fb8a7420e8f39f3c4442ab39
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mygasfeed.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Mason Wiley
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.
@@ -0,0 +1,80 @@
1
+ # Mygasfeed
2
+
3
+ Ruby API client for [www.mygasfeed.org](http://www.mygasfeed.com/)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'mygasfeed'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mygasfeed
20
+
21
+ ## Obtaining an API Key
22
+
23
+ You need to get an API key from [here](http://www.mygasfeed.com/keys/submit).
24
+
25
+ You can use it by setting an environment variable from the command line
26
+
27
+ export MYGASFEED_API_KEY=your_api_key
28
+
29
+ Use it when running `rails s`
30
+
31
+ MYGASFEED_API_KEY=your_api_key rails s
32
+
33
+ Or store it in a `.env` file and either use [Foreman](https://github.com/ddollar/foreman) or the [dotenv](https://github.com/bkeepers/dotenv) gem.
34
+
35
+ MYGASFEED_API_KEY=your_api_key
36
+
37
+ ## Usage
38
+
39
+ ### Get nearby stations
40
+ **Params:** latitude, longitude, distance, fuel_type, sort_by
41
+
42
+ Mygasfeed.get_stations 39.7400, -121.8356, 50, "reg", "distance"
43
+
44
+ ### Get price history for a station
45
+ **Params:** station_id
46
+
47
+ Mygasfeed.get_history 33862
48
+
49
+ ### Get details for a station
50
+ **Params:** station_id
51
+
52
+ Mygasfeed.get_details 33862
53
+
54
+ ### Get a list of all gas station brands
55
+ **Params:** none
56
+
57
+ Mygasfeed.get_brands
58
+
59
+ ### Update a gas price
60
+ **Params:** price, fuel_type, station_id
61
+
62
+ Mygasfeed 4.15, "reg", 33862
63
+
64
+ ### Get an address by latitude and longitude
65
+ **Params:** latitude, longitude
66
+
67
+ Mygasfeed.get_adddress 39.7400, -121.8356
68
+
69
+ ### Get stations close by another station
70
+ **Params:** station_id, limit
71
+
72
+ Mygasfeed.get_close_by 33862, 50
73
+
74
+ ## Contributing
75
+
76
+ 1. Fork it ( https://github.com/mwiley/mygasfeed/fork )
77
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
78
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
79
+ 4. Push to the branch (`git push origin my-new-feature`)
80
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mygasfeed"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ require "mygasfeed/version"
2
+ require "mygasfeed/request"
3
+ Dir[File.dirname(__FILE__) + "/mygasfeed/dsl/*.rb"].each { |f| require f }
4
+ Dir[File.dirname(__FILE__) + "/mygasfeed/resources/*.rb"].each { |f| require f }
5
+
6
+ module Mygasfeed
7
+
8
+ API_URL = 'http://api.mygasfeed.com'
9
+ API_KEY = ENV["MYGASFEED_API_KEY"]
10
+
11
+ #API_URL = 'http://devapi.mygasfeed.com/'
12
+ #API_KEY = 'rfej9napna'
13
+
14
+ end
@@ -0,0 +1,13 @@
1
+ module Mygasfeed
2
+
3
+ class << self
4
+
5
+ # Providing the latitude & longitude of the current location, you will retrieve the full address.
6
+ def get_address latitude, longitude
7
+ response = request('/locations/geoaddress/', [latitude, longitude])
8
+ Location.build response['location']
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ module Mygasfeed
2
+
3
+ class << self
4
+
5
+ # Retrieves a list of all gas station brands.
6
+ def get_brands
7
+ response = request "/stations/brands/"
8
+ response['stations'].map { |brand| Brand.build brand }
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,14 @@
1
+ module Mygasfeed
2
+
3
+ class << self
4
+
5
+ # Retrieve a list of other gas stations that are close by to a
6
+ # particular station by just suppling the station id.
7
+ def get_close_by station_id, limit
8
+ response = request '/locations/otherclosebystations/', [station_id, limit]
9
+ response['stations'].map { |station| Station.build station }
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,14 @@
1
+ module Mygasfeed
2
+
3
+ class << self
4
+
5
+ # Retrieves gas station details by providing the station id.
6
+ # The station id can be retrieved when making a request for a list of stations.
7
+ def get_details station_id
8
+ response = request '/stations/details/', [station_id]
9
+ Station.build response['details']
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,13 @@
1
+ module Mygasfeed
2
+
3
+ class << self
4
+
5
+ # Retrieves a list of gas price histroy for a particular gas station by id.
6
+ def get_history station_id
7
+ response = request '/locations/pricehistory/', [station_id]
8
+ response['histroy'].map { |price| PreviousPrice.build price }
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,17 @@
1
+ module Mygasfeed
2
+
3
+ class << self
4
+
5
+ # Retrieves nearby gas stations according to a user's geo location.
6
+ # `Distance` - a number of miles under 50.
7
+ # `fuel_type` - reg, mid, pre, or diesel
8
+ # `sort_by` - distance or price
9
+ def get_stations latitude, longitude, distance, fuel_type, sort_by
10
+ params = [latitude, longitude, distance, fuel_type, sort_by]
11
+ response = request "/stations/radius/", params
12
+ response['stations'].map { |station| Station.build station }
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,15 @@
1
+ module Mygasfeed
2
+
3
+ class << self
4
+
5
+ # Updates gas prices for a particular station.
6
+ # `price` - Actual gas price. Format (3.64)
7
+ # `fuel_type` - reg, mid, pre, or diesel
8
+ def update_price price, fuel_type, station_id
9
+ response = post '/locations/price/', body: {price: price, fueltype: fuel_type, stationid: station_id}
10
+ Station.build response['details']
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,25 @@
1
+ require 'httparty'
2
+ require 'addressable/uri'
3
+
4
+ module Mygasfeed
5
+
6
+ class << self
7
+
8
+ def request path, params=[]
9
+ response = HTTParty.get _build_url(path, params)
10
+ JSON.parse response.body
11
+ end
12
+
13
+ def post path, params={}
14
+ response = HTTParty.post _build_url(path), params
15
+ JSON.parse response.body
16
+ end
17
+
18
+ def _build_url path, params=[]
19
+ uri = API_URL + path
20
+ params.each { |param| uri = uri + param.to_s + '/' }
21
+ uri = uri + API_KEY + ".json"
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ module Mygasfeed
2
+
3
+ class BaseStruct < Struct
4
+ class << self
5
+
6
+ protected
7
+
8
+ def get_i str
9
+ return nil if str.nil?
10
+ str.to_i
11
+ end
12
+
13
+ def get_f str
14
+ return nil if str.nil?
15
+ str.to_f
16
+ end
17
+
18
+ def get_bool str
19
+ str == '1'
20
+ end
21
+
22
+ def get_str str
23
+ str.to_s.strip
24
+ end
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,10 @@
1
+ module Mygasfeed
2
+ Brand = BaseStruct.new :name, :id do
3
+
4
+ def self.build raw
5
+ new get_str(raw["name"]),
6
+ get_i(raw["id"])
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ module Mygasfeed
2
+ Location = BaseStruct.new :country_short, :lat, :lng, :country_long,
3
+ :region_short, :region_long, :city_long,
4
+ :city_short, :address, :result do
5
+
6
+ def self.build raw
7
+ new get_str(raw["country_short"]),
8
+ get_f(raw["lat"]),
9
+ get_f(raw["lng"]),
10
+ get_str(raw["country_long"]),
11
+ get_str(raw["region_short"]),
12
+ get_str(raw["region_long"]),
13
+ get_str(raw["city_long"]),
14
+ get_str(raw["city_short"]),
15
+ get_str(raw["address"]),
16
+ get_str(raw["result"])
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ module Mygasfeed
2
+ PreviousPrice = BaseStruct.new :type, :price, :date, :via do
3
+
4
+ def self.build raw
5
+ new get_str(raw["type"]),
6
+ get_f(raw["price"]),
7
+ get_str(raw["date"]),
8
+ get_str(raw["via"])
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ module Mygasfeed
2
+ Station = BaseStruct.new :country, :reg_price, :mid_price, :pre_price, :diesel_price, :address,
3
+ :diesel, :id, :lat, :lng, :station, :region, :city,
4
+ :reg_date, :mid_date, :pre_date, :diesel_date, :distance do
5
+
6
+ def self.build raw
7
+ new get_str(raw["country"]),
8
+ get_f(raw["reg_price"]),
9
+ get_f(raw["mid_price"]),
10
+ get_f(raw["pre_price"]),
11
+ get_f(raw["diesel_price"]),
12
+ get_str(raw["address"]),
13
+ get_bool(raw["diesel"]),
14
+ get_i(raw["id"]),
15
+ get_f(raw["lat"]),
16
+ get_f(raw["lng"]),
17
+ get_str(raw["station"]),
18
+ get_str(raw["region"]),
19
+ get_str(raw["city"]),
20
+ get_str(raw["reg_date"]),
21
+ get_str(raw["mid_date"]),
22
+ get_str(raw["pre_date"]),
23
+ get_str(raw["diesel_date"]),
24
+ get_str(raw["distance"])
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Mygasfeed
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mygasfeed/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mygasfeed"
8
+ spec.version = Mygasfeed::VERSION
9
+ spec.authors = ["Mason Wiley"]
10
+ spec.email = ["masonwiley92@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby API client for www.mygasfeed.org}
13
+ spec.description = %q{Provides a Ruby gem wrapper for MyGasFeed API.}
14
+ spec.homepage = "https://github.com/mwiley/mygasfeed"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'httparty'
23
+ spec.add_dependency 'addressable'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.8"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "rspec-its"
29
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mygasfeed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mason Wiley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
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: addressable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
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.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
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: '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: rspec-its
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: Provides a Ruby gem wrapper for MyGasFeed API.
98
+ email:
99
+ - masonwiley92@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/mygasfeed.rb
114
+ - lib/mygasfeed/dsl/get_address.rb
115
+ - lib/mygasfeed/dsl/get_brands.rb
116
+ - lib/mygasfeed/dsl/get_close_by.rb
117
+ - lib/mygasfeed/dsl/get_details.rb
118
+ - lib/mygasfeed/dsl/get_history.rb
119
+ - lib/mygasfeed/dsl/get_stations.rb
120
+ - lib/mygasfeed/dsl/update_price.rb
121
+ - lib/mygasfeed/request.rb
122
+ - lib/mygasfeed/resources/base_struct.rb
123
+ - lib/mygasfeed/resources/brand.rb
124
+ - lib/mygasfeed/resources/location.rb
125
+ - lib/mygasfeed/resources/previous_price.rb
126
+ - lib/mygasfeed/resources/station.rb
127
+ - lib/mygasfeed/version.rb
128
+ - mygasfeed.gemspec
129
+ homepage: https://github.com/mwiley/mygasfeed
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.2.2
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Ruby API client for www.mygasfeed.org
153
+ test_files: []