usda_market 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e43cacbe726eb18d6f96046c1478ce5ff2d11780
4
+ data.tar.gz: 2531bb2d167c43ee94905dbcf2d5ba71d84b04dc
5
+ SHA512:
6
+ metadata.gz: 8ee3b3427e1c2a7f6efc2bb03ce9b589c0449f109574c2bb80430c86e5bc14694d135f02102f9830959cb9b57436cf970139e8bcbdd41aa8f1e29aec5de81184
7
+ data.tar.gz: f20ca6c4e378c488f11f98bff4edc08fd02c011f23728b0b0ac7d215f0678fb04ca1c738f31ef134be35a03de69be0dc6181b248cf36d5e47458939a268ed4b4
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ usda-market
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p247
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in usda_market.gemspec
4
+ gemspec
5
+ gem 'minitest', '~> 4.0'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrew Medeiros
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,59 @@
1
+ # Usda Market
2
+
3
+ Usda Market is a ruby gem for using the USDA's farmers market directory api. For more information on this api see their documentation [here](http://search.ams.usda.gov/farmersmarkets/v1/svcdesc.html)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'usda_market'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install usda_market
18
+
19
+ ## Usage
20
+
21
+ ## Initializer
22
+ Takes option arguments. The current only and required option is zip
23
+ ```ruby
24
+ api = UsdaMarket::Api.new(zip: 33558)
25
+ ```
26
+
27
+ ## Missing argument error
28
+ ```ruby
29
+ api = UsdaMarket::Api.new() => ArugmentError 'Missing argument zip'
30
+ ```
31
+
32
+ ## Return names
33
+ Returns the markets id and name in an array of hashes
34
+ ```ruby
35
+ api = UsdaMarket::Api.new(zip: 33558)
36
+ results = api.return_names
37
+ results => [{"id"=>"20049", "marketname"=>"2.8 Cheyennes Country Thangs "}]
38
+ ```
39
+
40
+ ## Return all
41
+ Return all the farmers market information as an array of hashes. ID, Market name, Address, Google Link, Products and Schedule
42
+ ```ruby
43
+ api = UsdaMarket::Api.new(zip: 33558)
44
+ results = api.return_all
45
+ results => [{"id"=>"20049", "marketname"=>"2.8 Cheyennes Country Thangs ", "Address"=>"19319 Holly Lane, Lutz, Florida, 33548", "GoogleLink"=>"http://maps.google.com/?q=28.1619%2C%20-82.4747%20(%22Cheyennes+Country+Thangs+%22)", "Products"=>"", "Schedule"=>" "}]
46
+ ```
47
+
48
+ ## Author
49
+ Andrew Medeiros, amedeiros0920@gmail.com, @_AndrewMedeiros
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. bundle install
56
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 5. rake test
58
+ 6. Push to the branch (`git push origin my-new-feature`)
59
+ 7. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |task|
5
+ task.libs << 'test'
6
+ end
7
+
8
+ task :default => [:test]
@@ -0,0 +1,33 @@
1
+ require 'usda_market/version'
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ module UsdaMarket
6
+ class Api
7
+ attr_accessor :options
8
+
9
+ def initialize(options={})
10
+ @options = options
11
+ raise ArgumentError, 'Missing argument zip' if @options[:zip].nil?
12
+ end
13
+
14
+ # Returns an array of hashes. Each hash has an id and market name key
15
+ def return_names
16
+ url = URI.parse"http://search.ams.usda.gov/farmersmarkets/v1/data.svc/zipSearch?zip=#{@options[:zip]}"
17
+ JSON.parse(Net::HTTP.get(url)).delete('results')
18
+ end
19
+
20
+ # Returns an array of hashes. Each hash has an id, market name, address, time, products and google link
21
+ def return_all
22
+ market_details = return_names.collect do |value|
23
+ url = URI.parse "http://search.ams.usda.gov/farmersmarkets/v1/data.svc/mktDetail?id=#{value['id']}"
24
+ result = JSON.parse(Net::HTTP.get(url) )
25
+ value = value.merge(result.delete('marketdetails'))
26
+ value
27
+ end
28
+ market_details
29
+ end
30
+ end
31
+ end
32
+
33
+
@@ -0,0 +1,3 @@
1
+ module UsdaMarket
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'test/unit'
2
+ require 'usda_market'
3
+ require 'shoulda'
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+ class TestUsdaMarket < Test::Unit::TestCase
4
+ ZIP = 33558
5
+
6
+ context UsdaMarket::Api do
7
+ context '.initialize' do
8
+ should 'raise an exception for a missing zip' do
9
+ exception = assert_raise ArgumentError do
10
+ UsdaMarket::Api.new()
11
+ end
12
+ assert_equal 'Missing argument zip', exception.message
13
+ end
14
+
15
+ should 'set the options' do
16
+ api = UsdaMarket::Api.new(zip: ZIP)
17
+ assert_not_nil api.options
18
+ end
19
+ end
20
+
21
+ context '.return_names' do
22
+ setup { @api = UsdaMarket::Api.new(zip: ZIP) }
23
+ should 'return a hash of farmers market names and ids' do
24
+ results = @api.return_names
25
+ assert_includes results.first.keys, 'id'
26
+ assert_includes results.first.keys, 'marketname'
27
+ end
28
+ end
29
+
30
+ context '.return_all' do
31
+ setup { @api = UsdaMarket::Api.new(zip: ZIP) }
32
+ should 'return a hash for farmers market names, google map url, products and times' do
33
+ results = @api.return_all
34
+ assert_includes results.first.keys, 'id'
35
+ assert_includes results.first.keys, 'marketname'
36
+
37
+ assert_includes results.first.keys, 'Address'
38
+ assert_includes results.first.keys, 'GoogleLink'
39
+ assert_includes results.first.keys, 'Products'
40
+ assert_includes results.first.keys, 'Schedule'
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'usda_market/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'usda_market'
8
+ spec.version = UsdaMarket::VERSION
9
+ spec.authors = ['Andrew Medeiros']
10
+ spec.email = %w(amedeiros0920@gmail.com)
11
+ spec.summary = %q{USDA Market is a small library for interacting with the USDA's farmers market api.}
12
+ spec.homepage = ''
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = %w(lib)
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.3.5'
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'shoulda'
23
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: usda_market
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Medeiros
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-18 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.3.5
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: shoulda
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
+ description:
56
+ email:
57
+ - amedeiros0920@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .ruby-gemset
64
+ - .ruby-version
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/usda_market.rb
70
+ - lib/usda_market/version.rb
71
+ - test/test_helper.rb
72
+ - test/test_usda_market.rb
73
+ - usda_market.gemspec
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.0.3
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: USDA Market is a small library for interacting with the USDA's farmers market
98
+ api.
99
+ test_files:
100
+ - test/test_helper.rb
101
+ - test/test_usda_market.rb