t_rex 0.1.2

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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTdmOGUxMWRlYTFhZmUxOGNjZWU0MTgyNmVhZDYwNTllNDkxNmIzOA==
5
+ data.tar.gz: !binary |-
6
+ ODdkZTUxYmFhZjU3YTkwMWFjNGEwY2Y5ZDVmZGExMmEwNWUzYzIwZQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OWFhMjA2YjQ5N2YwZmFjMWU5ZDhlZTdhYmE3MTQ5NGI5MDEyOGExYTQ4M2Q0
10
+ MmMyYTYwOGE1MTQ4NGQ2ZDFmOWFkMDI3MGI3Y2UzMmI5NDY5NTFiMGNjMWY1
11
+ MjU5MzljZjg3M2ViNmNkMzI1YzcwNDViY2YzYjRkZmFjZDZhNjI=
12
+ data.tar.gz: !binary |-
13
+ OTg4ZmQ3YTg1OWU2ODZlZjE5YjE5NGUyMGFmNTExNjQ3OWE5NjEwNmQxM2M4
14
+ MjE2ZWRhNzhhNDIzMzkyNDY4NTc0MTBmOTYwN2EyYWZmODlhNmM3OGI3NGRk
15
+ N2Q3ZmY0OTZmMjkyMmNmYjA5OWMxMWZhNzNjM2U2N2ZkMWQ4OTE=
@@ -0,0 +1,11 @@
1
+ .ruby-gemset
2
+ .ruby-version
3
+ .bundle
4
+ vendor/ruby
5
+ .rspec
6
+ .rvmrc
7
+ .rvm
8
+ /coverage
9
+ /pkg
10
+ /tmp
11
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ # source 'http://gems.idg.primedia.com'
3
+ gemspec
@@ -0,0 +1,133 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ t_rex (0.1.2)
5
+ activesupport
6
+ hashie (~> 2.0)
7
+ httparty (~> 0.11.0)
8
+ multi_json
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activesupport (4.0.0)
14
+ i18n (~> 0.6, >= 0.6.4)
15
+ minitest (~> 4.2)
16
+ multi_json (~> 1.3)
17
+ thread_safe (~> 0.1)
18
+ tzinfo (~> 0.3.37)
19
+ atomic (1.1.14)
20
+ awesome_print (1.2.0)
21
+ bogus (0.1.4)
22
+ dependor (>= 0.0.4)
23
+ cane (2.6.0)
24
+ parallel
25
+ celluloid (0.15.2)
26
+ timers (~> 1.1.0)
27
+ cheat (1.3.3)
28
+ pager (~> 1.0)
29
+ coderay (1.0.9)
30
+ colorize (0.6.0)
31
+ columnize (0.3.6)
32
+ debugger (1.6.2)
33
+ columnize (>= 0.3.1)
34
+ debugger-linecache (~> 1.2.0)
35
+ debugger-ruby_core_source (~> 1.2.3)
36
+ debugger-linecache (1.2.0)
37
+ debugger-ruby_core_source (1.2.3)
38
+ dependor (1.0.1)
39
+ diff-lcs (1.2.4)
40
+ factory_girl (4.2.0)
41
+ activesupport (>= 3.0.0)
42
+ faker (1.2.0)
43
+ i18n (~> 0.5)
44
+ ffi (1.9.0)
45
+ formatador (0.2.4)
46
+ guard (2.0.3)
47
+ formatador (>= 0.2.4)
48
+ listen (~> 2.0)
49
+ lumberjack (~> 1.0)
50
+ pry (>= 0.9.12)
51
+ thor (>= 0.18.1)
52
+ guard-rspec (3.1.0)
53
+ guard (>= 1.8)
54
+ rspec (~> 2.13)
55
+ hashie (2.1.2)
56
+ httparty (0.11.0)
57
+ multi_json (~> 1.0)
58
+ multi_xml (>= 0.5.2)
59
+ i18n (0.6.5)
60
+ letters (0.4.1)
61
+ activesupport
62
+ awesome_print
63
+ colorize
64
+ xml-simple
65
+ listen (2.0.3)
66
+ celluloid (>= 0.15.2)
67
+ rb-fsevent (>= 0.9.3)
68
+ rb-inotify (>= 0.9)
69
+ lumberjack (1.0.4)
70
+ method_source (0.8.2)
71
+ minitest (4.7.5)
72
+ multi_json (1.8.1)
73
+ multi_xml (0.5.5)
74
+ pager (1.0.1)
75
+ parallel (0.8.4)
76
+ pry (0.9.12.2)
77
+ coderay (~> 1.0.5)
78
+ method_source (~> 0.8)
79
+ slop (~> 3.4)
80
+ rack (1.5.2)
81
+ rack-protection (1.5.0)
82
+ rack
83
+ rack-test (0.6.2)
84
+ rack (>= 1.0)
85
+ rake (10.1.0)
86
+ rb-fsevent (0.9.3)
87
+ rb-inotify (0.9.2)
88
+ ffi (>= 0.5.0)
89
+ rspec (2.14.1)
90
+ rspec-core (~> 2.14.0)
91
+ rspec-expectations (~> 2.14.0)
92
+ rspec-mocks (~> 2.14.0)
93
+ rspec-core (2.14.5)
94
+ rspec-expectations (2.14.3)
95
+ diff-lcs (>= 1.1.3, < 2.0)
96
+ rspec-mocks (2.14.3)
97
+ simplecov (0.7.1)
98
+ multi_json (~> 1.0)
99
+ simplecov-html (~> 0.7.1)
100
+ simplecov-html (0.7.1)
101
+ sinatra (1.4.3)
102
+ rack (~> 1.4)
103
+ rack-protection (~> 1.4)
104
+ tilt (~> 1.3, >= 1.3.4)
105
+ slop (3.4.6)
106
+ thor (0.18.1)
107
+ thread_safe (0.1.3)
108
+ atomic
109
+ tilt (1.4.1)
110
+ timers (1.1.0)
111
+ tzinfo (0.3.38)
112
+ vcr (2.6.0)
113
+ xml-simple (1.1.2)
114
+
115
+ PLATFORMS
116
+ ruby
117
+
118
+ DEPENDENCIES
119
+ bogus
120
+ cane
121
+ cheat
122
+ debugger
123
+ factory_girl
124
+ faker
125
+ guard-rspec
126
+ letters
127
+ rack-test
128
+ rake
129
+ rspec
130
+ simplecov
131
+ sinatra
132
+ t_rex!
133
+ vcr
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
@@ -0,0 +1,174 @@
1
+ ![<Display Name>](http://mrbiggs.com/wp-content/illustrations/trex/t-rex_cover.jpg)
2
+
3
+ ## T Rex: Consume Metasaurus
4
+
5
+ The *t_rex* gem consumes the Metasaurus geographic lookup service. Roar!
6
+
7
+ ### Setup
8
+ ```
9
+ require 't_rex'
10
+ ```
11
+
12
+ ### Usage
13
+
14
+ To use the gem, create and transmit a `TRex::Request`. The general form is …
15
+
16
+ ```
17
+ request = TRex::Request.new(options, headers)
18
+ response = request.get
19
+ ```
20
+ … where `options` and `headers` are both hashes. Both arguments are optional.
21
+
22
+ You can also pass a block to `.get` to process the response.
23
+
24
+ ```
25
+ request = TRex::Request.new(options, headers)
26
+ request.get do |response|
27
+ # do something with the response
28
+ end
29
+
30
+ ```
31
+
32
+ trex also provides a convenience method to build and transmit the request at once.
33
+
34
+ ```
35
+ response = TRex::Request.get(options, headers)
36
+ ```
37
+
38
+ This form can also take a block.
39
+
40
+ ```
41
+ TRex::Request.get(options, headers) do |response|
42
+ # do something with the response
43
+ end
44
+ ```
45
+
46
+ Which form to use is a matter of style. The second form is provided for brevity. Both allow you to [add a geolocation header](#add_a_geolocation_header) to the request before it is sent, albeit with slightly different code.
47
+
48
+ The next sections describe each of the available requests.
49
+
50
+
51
+ ### Ping Metasaurus
52
+
53
+ The simplest request pings Metasaurus.
54
+
55
+
56
+ ```
57
+ request = TRex::Request.new
58
+ request.get
59
+
60
+ # produces
61
+ # {status: 0}
62
+ ```
63
+
64
+ ### Lookup via Zipcode
65
+
66
+ To receive information about a zipcode, send it as an argument in the options hash.
67
+
68
+ ```
69
+ response = TRex::Request.get({zip: 27605})
70
+
71
+ # produces
72
+ # {}
73
+ ```
74
+
75
+ If you pass a 5+4 zipcode as a string, the "+4" portion is stripped prior to calling Metasaurus.
76
+
77
+
78
+ ### Lookup via Latitude and Longitude
79
+
80
+ You can also perform a lookup with latitude and longitude.
81
+
82
+ ```
83
+ response = TRex::Request.get({lat: -35, lng: 79})
84
+
85
+ # produces
86
+ # {}
87
+ ```
88
+
89
+
90
+ ### Lookup via City and State
91
+
92
+ The most typical lookup uses city and state name. (The state name must be spelled out. Two-letter abbreviations produce incorrect results.)
93
+
94
+
95
+ ```
96
+ response = TRex::Request.get({city: 'Atlanta', state: 'Georgia'})
97
+
98
+ # produces
99
+ # {}
100
+ ```
101
+
102
+
103
+ ### Hitting Other Metasaurus Endpoints
104
+
105
+ By default, requests from T Rex hit the */geo* endpoint. However, you can hit other service endpoints, such as */nearby_neighborhoods*, if you specify the `:endpoint` option.
106
+
107
+
108
+ ```
109
+ request = TRex::Request.get({
110
+ endpoint: :nearby_neighborhood,
111
+ city: 'Atlanta',
112
+ state: 'Georgia'})
113
+
114
+ # produces
115
+ # {}
116
+ ```
117
+
118
+ Valid endpoints are `:colleges`, `:community`, `:geo`, `military_bases`, `nearby_neighborhoods`, `nearby_colleges`, `nearby_military_bases`.
119
+
120
+
121
+ ### Add a Geolocation Header
122
+
123
+ If you cannot provide a zipcode, latitude/longitude pair, or a city and state, you can approximate a location using the Geo IP information sent from the browser (if available).
124
+
125
+ There are three forms. In the first, you can set the location using a setter method.
126
+
127
+
128
+ ```
129
+ request = TRex::Request.new
130
+ request.location = 'city=Norcross,region=GA,country=US,' \
131
+ 'lat=33.9411,long=-84.2136,metro=909,msa=9009,' \
132
+ 'zip=30092,areacode=770'
133
+ response = request.get
134
+
135
+ # produces
136
+ # {}
137
+ ```
138
+
139
+ Or, in the second method, you can pass the location in the `headers` hash.
140
+
141
+ ```
142
+ headers = { 'X-Geo-Data' => 'city=Norcross,region=GA,country=US,…' }
143
+ request = TRex::Request.new({}, headers)
144
+ request.get
145
+
146
+ # produces
147
+ # {}
148
+ ```
149
+
150
+ And the third is similar to the second, but is terse.
151
+
152
+ ```
153
+ headers = { 'X-Geo-Data' => 'city=Norcross,region=GA,country=US,…' }
154
+ response = TRex::Request.get({}, headers)
155
+
156
+ # produces
157
+ # {}
158
+ ```
159
+
160
+ If you do not have a location string, you can set the location to Norcross, GA, with `set_default_location`.
161
+
162
+ ```
163
+ request = TRex::Request.new
164
+ request.set_default_location
165
+ response = request.get
166
+
167
+ # produces
168
+ # {}
169
+ ```
170
+
171
+ --
172
+ *Thanks for reading!* Here's a [cool factoid](http://ca.news.yahoo.com/blogs/geekquinox/fossil-dino-bite-shows-tyrannosaurus-rex-hunter-not-161904955.html) to reward your effort.
173
+
174
+
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,18 @@
1
+ require 'active_support'
2
+ # require 'letters/patch/core'
3
+ require_relative 't_rex/initialize'
4
+
5
+ module TRex
6
+ ACCEPTABLE_KEYS = [
7
+ :application,
8
+ :city,
9
+ :endpoint,
10
+ :geoname,
11
+ :lat,
12
+ :lng,
13
+ :neighborhood,
14
+ :rectype,
15
+ :state,
16
+ :zip,
17
+ ]
18
+ end
@@ -0,0 +1,4 @@
1
+ module TRex
2
+ TRexBadEndpointError = Class.new(StandardError)
3
+ TRexConfigurationError = Class.new(StandardError)
4
+ end
@@ -0,0 +1,4 @@
1
+ require_relative 'exceptions'
2
+ require_relative 'metasaurus'
3
+ require_relative 'request'
4
+ require_relative 'util/initialize'
@@ -0,0 +1,47 @@
1
+ require 'httparty'
2
+
3
+ module TRex
4
+ class Metasaurus
5
+ include HTTParty
6
+
7
+ attr_accessor :headers, :params
8
+
9
+ class << self
10
+ # Hooks for rspec testing to clear memoization
11
+ attr_accessor :metasaurus_path
12
+ end
13
+
14
+ def self.metasaurus_url
15
+ @metasaurus_path ||= TRex.configuration.metasaurus_url ||
16
+ raise(TRexConfigurationError, 'No URL defined for Metasaurus')
17
+ end
18
+
19
+ def initialize(params = {}, headers = {})
20
+ @params, @headers = params, headers
21
+ scrub_params
22
+ end
23
+
24
+ def debug
25
+ TRex.configuration.metasaurus_debug
26
+ end
27
+
28
+ def endpoint
29
+ @endpoint ||= (self.params.delete('endpoint') || 'geo')
30
+ end
31
+
32
+ def get
33
+ options = {query: params, headers: headers}
34
+ self.class.get url, options
35
+ end
36
+
37
+ def scrub_params
38
+ if params[:zip].to_s =~ /(\d{5})[-\w]?/
39
+ self.params[:zip] = $1
40
+ end
41
+ end
42
+
43
+ def url
44
+ "#{self.class.metasaurus_url}/#{endpoint}"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,75 @@
1
+ module TRex
2
+ class Request
3
+ ACCEPTABLE_ENDPOINTS = %w(
4
+ colleges
5
+ community
6
+ geo
7
+ military_bases
8
+ nearby_neighborhoods
9
+ nearby_colleges
10
+ nearby_military_bases )
11
+
12
+ DEFAULT_LOCATION = "city=Norcross,region=GA,country=US,lat=33.9411,long=-84.2136,metro=909,msa=9009,zip=30092,areacode=770"
13
+
14
+ attr_accessor :headers, :params, :request, :response
15
+ attr_reader :location
16
+
17
+ def self.get(params = {}, headers = {}, &block)
18
+ new(params, headers).get(&block)
19
+ end
20
+
21
+ def initialize(params = {}, headers = {})
22
+ @headers = TRex::ParamsHash.new headers
23
+ @params = TRex::ParamsHash.new params
24
+ @params[:endpoint] ||= 'geo'
25
+ @params[:endpoint] = @params[:endpoint].to_s
26
+ clean_params! if params_includes_endpoint
27
+ end
28
+
29
+ def execute(client, &block)
30
+ @response = client.get
31
+ @request = response.request
32
+ block ? yield(response) : response
33
+ end
34
+
35
+ def get(&block)
36
+ execute(client, &block)
37
+ end
38
+
39
+ def location=(geo_string)
40
+ set_default_location geo_string
41
+ end
42
+
43
+ def set_default_location(geo_string = DEFAULT_LOCATION)
44
+ @location = { 'X-Geo-Data' => geo_string }
45
+ end
46
+
47
+ private
48
+
49
+ def acceptable_strings
50
+ @acceptable ||= TRex::ACCEPTABLE_KEYS.map(&:to_s)
51
+ end
52
+
53
+ def params_includes_endpoint
54
+ ACCEPTABLE_ENDPOINTS.include?(params[:endpoint]) or raise(TRexBadEndpointError, 'Invalid endpoint')
55
+ end
56
+
57
+ def clean_params!
58
+ params.keys.any? {|k| params.delete k unless acceptable_strings.include? k}
59
+ sanitize_params!
60
+ end
61
+
62
+ def sanitize_params!
63
+ params.each { |k, v| v.gsub!(' ', '-') if v.respond_to? :gsub! }
64
+ end
65
+
66
+ def client
67
+ headers = (@location || {}).merge self.headers
68
+ Metasaurus.new params, headers
69
+ end
70
+
71
+ def growl
72
+ 'Rawwwrrrr!'
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,54 @@
1
+ #
2
+ # Refer to http://robots.thoughtbot.com/post/344833329/mygem-configure-block
3
+ # for explanation.
4
+ #
5
+ module TRex
6
+ class << self
7
+ attr_accessor :configuration
8
+ end
9
+
10
+ def self.configure
11
+ self.configuration ||= Config.new
12
+ yield configuration
13
+ configuration
14
+ end
15
+
16
+ class Config
17
+ attr_accessor :data
18
+
19
+ def initialize(data={})
20
+ @data = {}
21
+ update!(data)
22
+ end
23
+
24
+ def update!(data)
25
+ data.each do |key, value|
26
+ self[key.to_sym] = value
27
+ end
28
+ end
29
+
30
+ def [](key)
31
+ @data[key.to_sym]
32
+ end
33
+
34
+ def []=(key, value)
35
+ @data[key.to_sym] = value
36
+ end
37
+
38
+ def keys
39
+ @data.keys
40
+ end
41
+
42
+ def to_hash
43
+ @data
44
+ end
45
+
46
+ def method_missing(sym, *args)
47
+ if sym.to_s =~ /(.+)=$/
48
+ self[$1] = args.first
49
+ else
50
+ self[sym]
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'configure'
2
+ require_relative 'params_hash'
3
+ require_relative 'version'
@@ -0,0 +1,9 @@
1
+ require 'hashie'
2
+
3
+ module TRex
4
+ class ParamsHash < Hash
5
+ include Hashie::Extensions::IndifferentAccess
6
+ include Hashie::Extensions::MergeInitializer
7
+ include Hashie::Extensions::MethodAccess
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module TRex
2
+ VERSION = '0.1.2'
3
+ end
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+ source 'http://gems.idg.primedia.com'
3
+
4
+ gem 'debugger'
5
+ gem 'letters'
6
+ gem 't_rex', path: '../../../t_rex'
7
+ # gem 'trex'
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: ../../../trex
3
+ specs:
4
+ trex (0.0.1)
5
+ activesupport
6
+ hashie (~> 2.0)
7
+ httparty (~> 0.11.0)
8
+ oj (~> 1.4)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ remote: http://gemserver01.nor.primedia.com/
13
+ remote: http://gems01.lab.primedia.com/
14
+ specs:
15
+ activesupport (4.0.0)
16
+ i18n (~> 0.6, >= 0.6.4)
17
+ minitest (~> 4.2)
18
+ multi_json (~> 1.3)
19
+ thread_safe (~> 0.1)
20
+ tzinfo (~> 0.3.37)
21
+ atomic (1.1.10)
22
+ awesome_print (1.1.0)
23
+ colorize (0.5.8)
24
+ columnize (0.3.6)
25
+ debugger (1.6.1)
26
+ columnize (>= 0.3.1)
27
+ debugger-linecache (~> 1.2.0)
28
+ debugger-ruby_core_source (~> 1.2.3)
29
+ debugger-linecache (1.2.0)
30
+ debugger-ruby_core_source (1.2.3)
31
+ hashie (2.0.5)
32
+ httparty (0.11.0)
33
+ multi_json (~> 1.0)
34
+ multi_xml (>= 0.5.2)
35
+ i18n (0.6.4)
36
+ letters (0.4.1)
37
+ activesupport
38
+ awesome_print
39
+ colorize
40
+ xml-simple
41
+ minitest (4.7.5)
42
+ multi_json (1.7.7)
43
+ multi_xml (0.5.4)
44
+ oj (1.4.7)
45
+ thread_safe (0.1.2)
46
+ atomic
47
+ tzinfo (0.3.37)
48
+ xml-simple (1.1.2)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ debugger
55
+ letters
56
+ trex!
@@ -0,0 +1,25 @@
1
+ require 't_rex'
2
+ require 'debugger'
3
+
4
+ TRex.configure do |config|
5
+ config.metasaurus_url = 'http://172.21.17.51:8081'
6
+ end
7
+
8
+
9
+ begin
10
+ TRex::Request.new
11
+ rescue Exception => e
12
+ pp e
13
+ end
14
+
15
+ r = TRex::Request.new({zip: 27605})
16
+ pp r.execute
17
+
18
+ r = TRex::Request.new({city: 'Paris'})
19
+ pp r.execute
20
+
21
+ r = TRex::Request.new({city: 'Atlanta', state: 'Georgia'})
22
+ pp r.get
23
+
24
+ r = TRex::Request.new({lat: 35.796302, lng: -78.656568})
25
+ pp r.get
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'bogus/rspec'
4
+ require 'debugger'
5
+ require 'factory_girl'
6
+ require 'faker'
7
+ require 'letters'
8
+ require 'simplecov'
9
+
10
+ SimpleCov.start do
11
+ add_filter '/spec/'
12
+ add_filter '/patches/'
13
+ add_filter '/vendor/'
14
+ end
15
+
16
+ require 't_rex'
17
+
18
+ spec_dir = File.dirname __FILE__
19
+ Dir.glob("#{spec_dir}/support/**/*.rb").each {|f| require f}
20
+
21
+ RSpec.configure do |config|
22
+ config.include FactoryGirl::Syntax::Methods
23
+ end
24
+
25
+ Bogus.configure do |c|
26
+ c.search_modules << TRex
27
+ end
@@ -0,0 +1,3 @@
1
+ Bogus.fakes do
2
+ fake(:metasaurus, metasaurus_url: 'http://www.example.com')
3
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module TRex
4
+ describe Metasaurus do
5
+ describe 'Class Methods' do
6
+ before(:all) do
7
+ TRex.configure do |config|
8
+ config.metasaurus_url = 'abc'
9
+ end
10
+ end
11
+
12
+ describe '.metasaurus_url' do
13
+ it 'returns the url configured if set' do
14
+ expect(described_class.metasaurus_url).to eq('abc')
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ module TRex
4
+ describe Request do
5
+ describe 'Class Methods' do
6
+ before(:all) do
7
+ TRex.configure do |config|
8
+ config.metasaurus_url = 'abc'
9
+ end
10
+ end
11
+ end
12
+
13
+ describe 'Instance Methods' do
14
+ describe '#execute' do
15
+ let(:meta) { fake :metasaurus }
16
+ let(:response) { fake body: :body, request: :request }
17
+
18
+ before(:each) do
19
+ stub(meta).get(any_args) { response }
20
+ end
21
+
22
+ it 'yields to block if provided' do
23
+ expect(subject.execute(meta) {|r| r.body}).to eq(:body)
24
+ end
25
+
26
+ it 'returns response if no block' do
27
+ result = subject.execute(meta)
28
+ expect(result.body).to eq(:body)
29
+ end
30
+ end
31
+
32
+ describe '#initialize' do
33
+ it 'can set the endpoint' do
34
+ endpoint = 'colleges'
35
+ request = described_class.new endpoint: endpoint
36
+ expect(request.params.endpoint).to eq(endpoint)
37
+ end
38
+
39
+ it 'sets the default endpoint to `geo`' do
40
+ expect(subject.params.endpoint).to eq('geo')
41
+ end
42
+
43
+ %w(
44
+ colleges
45
+ community
46
+ geo
47
+ military_bases
48
+ nearby_neighborhoods
49
+ nearby_colleges
50
+ nearby_military_bases )
51
+ .each do |endpoint|
52
+ it "does not throw an exception for endpoint #{endpoint}" do
53
+ expect {described_class.new(endpoint: endpoint)}
54
+ .not_to raise_error
55
+ end
56
+ end
57
+
58
+ it 'removes invalid params' do
59
+ request = described_class.new({hello: :kitty})
60
+ expect(request.params).to_not include(:hello)
61
+ end
62
+
63
+ it 'replaces spaces with hyphens' do
64
+ request = described_class.new({state: 'New York', city: 'New York'})
65
+ expect(request.params.state).to eq('New-York')
66
+ expect(request.params.city).to eq('New-York')
67
+ end
68
+
69
+ it 'throws exception for a bad endpoint' do
70
+ expect {described_class.new(endpoint: :bad)}
71
+ .to raise_error(TRexBadEndpointError)
72
+ end
73
+
74
+ it 'does not throw exception for empty params' do
75
+ expect {described_class.new({})}
76
+ .not_to raise_error
77
+ end
78
+
79
+ it 'does not throw exception for nil param values' do
80
+ expect {described_class.new({application: nil})}
81
+ .not_to raise_error
82
+ end
83
+ end
84
+
85
+ describe '#location=' do
86
+ it 'sets the value of the geo header' do
87
+ value = :location
88
+ subject.location = value
89
+ expect(subject.location['X-Geo-Data']).to eq(value)
90
+ end
91
+ end
92
+
93
+ describe '#set_default_location' do
94
+ it 'sets the value of the geo header to the default if none given' do
95
+ subject.set_default_location
96
+ expect(subject.location['X-Geo-Data']).to include('Norcross')
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe TRex do
4
+ describe 'Class Methods' do
5
+ before(:all) do
6
+ TRex.configure do |config|
7
+ config.metasaurus_url = 'abc'
8
+ config.metasaurus_debug = true
9
+ end
10
+ end
11
+
12
+ describe '.configure' do
13
+ it 'sets any configuration option' do
14
+ config = described_class.configuration
15
+ expect(config.metasaurus_url).to eq('abc')
16
+ expect(config.metasaurus_debug).to eq(true)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'date'
3
+ require './lib/t_rex/util/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.add_dependency 'activesupport'
7
+ gem.add_dependency 'hashie', '~> 2.0'
8
+ gem.add_dependency 'httparty', '~> 0.11.0'
9
+ gem.add_dependency 'multi_json'
10
+
11
+ gem.add_development_dependency 'bogus'
12
+ gem.add_development_dependency 'cane'
13
+ gem.add_development_dependency 'cheat'
14
+ gem.add_development_dependency 'debugger'
15
+ gem.add_development_dependency 'factory_girl'
16
+ gem.add_development_dependency 'faker'
17
+ gem.add_development_dependency 'guard-rspec'
18
+ gem.add_development_dependency 'letters'
19
+ gem.add_development_dependency 'rack-test'
20
+ gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency 'rspec'
22
+ gem.add_development_dependency 'simplecov'
23
+ gem.add_development_dependency 'sinatra'
24
+ gem.add_development_dependency 'vcr'
25
+
26
+ gem.authors = ['Martin Streicher']
27
+ gem.date = Date.today.to_s
28
+ gem.description = 'Gem to make connections to and queries against Metasaurus'
29
+ gem.email = ['mstreicher@rentpath.com']
30
+ gem.files = `git ls-files`.split($/)
31
+ gem.homepage = 'http://github.com/primedia/trex'
32
+ gem.name = 't_rex'
33
+ gem.platform = Gem::Platform::RUBY
34
+ gem.require_paths = ['lib']
35
+ gem.required_ruby_version = '>= 1.8.7'
36
+ gem.summary = 'Provide standardized access to Metasaurus'
37
+ gem.version = TRex::VERSION
38
+ end
metadata ADDED
@@ -0,0 +1,355 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: t_rex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Martin Streicher
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
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: hashie
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.11.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.11.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: multi_json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: bogus
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: cane
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
+ - !ruby/object:Gem::Dependency
98
+ name: cheat
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: debugger
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: factory_girl
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: faker
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: letters
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rack-test
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ! '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: rake
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ! '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ! '>='
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: rspec
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ! '>='
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ! '>='
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: simplecov
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ! '>='
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: sinatra
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ! '>='
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ! '>='
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: vcr
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ! '>='
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ! '>='
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
265
+ description: Gem to make connections to and queries against Metasaurus
266
+ email:
267
+ - mstreicher@rentpath.com
268
+ executables: []
269
+ extensions: []
270
+ extra_rdoc_files: []
271
+ files:
272
+ - .gitignore
273
+ - .ruby-version
274
+ - Gemfile
275
+ - Gemfile.lock
276
+ - Guardfile
277
+ - README.md
278
+ - Rakefile
279
+ - lib/t_rex.rb
280
+ - lib/t_rex/exceptions.rb
281
+ - lib/t_rex/initialize.rb
282
+ - lib/t_rex/metasaurus.rb
283
+ - lib/t_rex/request.rb
284
+ - lib/t_rex/util/configure.rb
285
+ - lib/t_rex/util/initialize.rb
286
+ - lib/t_rex/util/params_hash.rb
287
+ - lib/t_rex/util/version.rb
288
+ - spec/dummy/Gemfile
289
+ - spec/dummy/Gemfile.lock
290
+ - spec/dummy/test.rb
291
+ - spec/spec_helper.rb
292
+ - spec/support/fakes.rb
293
+ - spec/unit/metasaurus_spec.rb
294
+ - spec/unit/request_spec.rb
295
+ - spec/unit/trex_spec.rb
296
+ - t_rex.gemspec
297
+ - vendor/cache/activesupport-4.0.0.gem
298
+ - vendor/cache/bogus-0.1.4.gem
299
+ - vendor/cache/cane-2.6.0.gem
300
+ - vendor/cache/cheat-1.3.3.gem
301
+ - vendor/cache/coderay-1.0.9.gem
302
+ - vendor/cache/columnize-0.3.6.gem
303
+ - vendor/cache/debugger-linecache-1.2.0.gem
304
+ - vendor/cache/debugger-ruby_core_source-1.2.3.gem
305
+ - vendor/cache/diff-lcs-1.2.4.gem
306
+ - vendor/cache/factory_girl-4.2.0.gem
307
+ - vendor/cache/faker-1.2.0.gem
308
+ - vendor/cache/ffi-1.9.0.gem
309
+ - vendor/cache/formatador-0.2.4.gem
310
+ - vendor/cache/hashie-2.0.5.gem
311
+ - vendor/cache/httparty-0.11.0.gem
312
+ - vendor/cache/letters-0.4.1.gem
313
+ - vendor/cache/lumberjack-1.0.4.gem
314
+ - vendor/cache/method_source-0.8.2.gem
315
+ - vendor/cache/minitest-4.7.5.gem
316
+ - vendor/cache/multi_xml-0.5.5.gem
317
+ - vendor/cache/pager-1.0.1.gem
318
+ - vendor/cache/pry-0.9.12.2.gem
319
+ - vendor/cache/rack-1.5.2.gem
320
+ - vendor/cache/rack-protection-1.5.0.gem
321
+ - vendor/cache/rack-test-0.6.2.gem
322
+ - vendor/cache/rake-10.1.0.gem
323
+ - vendor/cache/rb-fsevent-0.9.3.gem
324
+ - vendor/cache/rspec-2.14.1.gem
325
+ - vendor/cache/simplecov-0.7.1.gem
326
+ - vendor/cache/simplecov-html-0.7.1.gem
327
+ - vendor/cache/sinatra-1.4.3.gem
328
+ - vendor/cache/slop-3.4.6.gem
329
+ - vendor/cache/thor-0.18.1.gem
330
+ - vendor/cache/tilt-1.4.1.gem
331
+ - vendor/cache/xml-simple-1.1.2.gem
332
+ homepage: http://github.com/primedia/trex
333
+ licenses: []
334
+ metadata: {}
335
+ post_install_message:
336
+ rdoc_options: []
337
+ require_paths:
338
+ - lib
339
+ required_ruby_version: !ruby/object:Gem::Requirement
340
+ requirements:
341
+ - - ! '>='
342
+ - !ruby/object:Gem::Version
343
+ version: 1.8.7
344
+ required_rubygems_version: !ruby/object:Gem::Requirement
345
+ requirements:
346
+ - - ! '>='
347
+ - !ruby/object:Gem::Version
348
+ version: '0'
349
+ requirements: []
350
+ rubyforge_project:
351
+ rubygems_version: 2.4.1
352
+ signing_key:
353
+ specification_version: 4
354
+ summary: Provide standardized access to Metasaurus
355
+ test_files: []