dinosaurus 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.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +31 -0
- data/Rakefile +8 -0
- data/dinosaurus.gemspec +22 -0
- data/lib/dinosaurus.rb +10 -0
- data/lib/dinosaurus/configuration.rb +28 -0
- data/lib/dinosaurus/logging.rb +26 -0
- data/lib/dinosaurus/railties.rb +7 -0
- data/lib/dinosaurus/thesaurus.rb +29 -0
- data/lib/dinosaurus/version.rb +3 -0
- data/spec/dinosaurus/thesaurus_spec.rb +27 -0
- data/spec/fixtures/vcr_cassettes/word.yml +47 -0
- data/spec/spec_helper.rb +23 -0
- metadata +97 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 David Tuite
|
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,31 @@
|
|
1
|
+
# Dinosaurus
|
2
|
+
|
3
|
+
Ruby wrapper for the [Big Huge Labs Thesaurus](http://words.bighugelabs.com/) API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dinosaurus'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dinosaurus
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
require "dnosaurus"
|
22
|
+
|
23
|
+
results = Dinosaurus.lookup('word')
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/dinosaurus.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/dinosaurus/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["David Tuite"]
|
6
|
+
gem.email = ["dtuite@gmail.com"]
|
7
|
+
gem.description = %q{Ruby wrapper for the Big Huge Thesaurus APIs.}
|
8
|
+
gem.summary = %q{Lookup synonyms, antonyms etc. using the Big Huge Thesaurus API.}
|
9
|
+
gem.homepage = "http://words.bighugelabs.com"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "dinosaurus"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Dinosaurus::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "rspec"
|
19
|
+
gem.add_development_dependency "vcr"
|
20
|
+
|
21
|
+
gem.add_dependency "httparty"
|
22
|
+
end
|
data/lib/dinosaurus.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Enable setting and getting of configuration options.
|
2
|
+
#
|
3
|
+
# Example:
|
4
|
+
#
|
5
|
+
# This can now be used under config/initializers/dinosaurus.rb
|
6
|
+
# Dinosaurus.configure do |config|
|
7
|
+
# config.api_key = 'dfskljkf'
|
8
|
+
# end
|
9
|
+
|
10
|
+
module Dinosaurus
|
11
|
+
class Configuration
|
12
|
+
DEFAULT_LOG_LEVEL = 'info'
|
13
|
+
|
14
|
+
attr_accessor :api_key, :log_level
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
self.log_level = DEFAULT_LOG_LEVEL
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.configuration
|
22
|
+
@configuration ||= Configuration.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.configure
|
26
|
+
yield configuration
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "logger"
|
2
|
+
|
3
|
+
module Logging
|
4
|
+
def logger
|
5
|
+
Logging.logger
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.logger
|
9
|
+
unless @logger
|
10
|
+
@logger = Logger.new(STDOUT)
|
11
|
+
@logger.level = Logging.infer_level
|
12
|
+
end
|
13
|
+
@logger
|
14
|
+
end
|
15
|
+
|
16
|
+
# infer a suitable Log level from the ENVIRONMENT variable
|
17
|
+
# Can pass in an environment value for testing purposes
|
18
|
+
def self.infer_level(level = nil)
|
19
|
+
level = level || Dinosaurus.configuration.log_level
|
20
|
+
case level
|
21
|
+
when 'debug' then Logger::DEBUG
|
22
|
+
when 'warn' then Logger::WARN
|
23
|
+
else Logger::INFO # default
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module Dinosaurus
|
5
|
+
class Thesaurus
|
6
|
+
include HTTParty
|
7
|
+
base_uri "words.bighugelabs.com"
|
8
|
+
format :json
|
9
|
+
|
10
|
+
|
11
|
+
def self.lookup(word)
|
12
|
+
res = get(url_for(word))
|
13
|
+
|
14
|
+
if res.code == 200
|
15
|
+
{ text: word, results: JSON.parse(res.body) }
|
16
|
+
else
|
17
|
+
warning = "DINOSAURUS_WARNING: #{res.code}. WORD: #{word}."
|
18
|
+
Logging.logger.warn(warning)
|
19
|
+
{ text: word }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def self.url_for(word)
|
26
|
+
"/api/2/" + Dinosaurus.configuration.api_key + '/' + word + '/json'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Dinosaurus::Thesaurus do
|
4
|
+
subject { Dinosaurus::Thesaurus }
|
5
|
+
|
6
|
+
it "should return results" do
|
7
|
+
VCR.use_cassette('word') do
|
8
|
+
results = subject.lookup('word')[:results]
|
9
|
+
results["noun"]["syn"].should include("news")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return the lookup word" do
|
14
|
+
VCR.use_cassette('word') do
|
15
|
+
subject.lookup('word')[:text].should == 'word'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should log errors" do
|
20
|
+
subject.stub(:get) { stub(code: 500) }
|
21
|
+
Logging.logger.should_receive(:warn)
|
22
|
+
|
23
|
+
VCR.use_cassette('word') do
|
24
|
+
subject.lookup('word')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://words.bighugelabs.com/api/2/<API_KEY>/word/json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Server:
|
16
|
+
- nginx/1.1.19
|
17
|
+
Date:
|
18
|
+
- Sun, 22 Jul 2012 17:29:10 GMT
|
19
|
+
Content-Type:
|
20
|
+
- text/javascript
|
21
|
+
Content-Length:
|
22
|
+
- '736'
|
23
|
+
Connection:
|
24
|
+
- keep-alive
|
25
|
+
X-Powered-By:
|
26
|
+
- PHP/5.3.10-1ubuntu3.2
|
27
|
+
Set-Cookie:
|
28
|
+
- PHPSESSID=k1cu7dsr9cdlrd6utgpr5efel2; path=/; domain=words.bighugelabs.com
|
29
|
+
Expires:
|
30
|
+
- Thu, 19 Nov 1981 08:52:00 GMT
|
31
|
+
Cache-Control:
|
32
|
+
- no-store, no-cache, must-revalidate, post-check=0, pre-check=0
|
33
|
+
Pragma:
|
34
|
+
- no-cache
|
35
|
+
body:
|
36
|
+
encoding: US-ASCII
|
37
|
+
string: ! '{"noun":{"syn":["news","intelligence","tidings","discussion","give-and-take","parole","word
|
38
|
+
of honor","Son","Word","Logos","password","watchword","countersign","Bible","Christian
|
39
|
+
Bible","Book","Good Book","Holy Scripture","Holy Writ","Scripture","Word of
|
40
|
+
God","arcanum","computer memory unit","hypostasis","hypostasis of Christ","info","information","language","language
|
41
|
+
unit","linguistic unit","oral communication","order","positive identification","promise","religious
|
42
|
+
text","religious writing","sacred text","sacred writing","secret","speech","speech
|
43
|
+
communication","spoken communication","spoken language","statement","voice
|
44
|
+
communication"]},"verb":{"syn":["give voice","formulate","phrase","articulate","evince","express","show"]}}'
|
45
|
+
http_version:
|
46
|
+
recorded_at: Sun, 22 Jul 2012 17:29:10 GMT
|
47
|
+
recorded_with: VCR 2.2.0
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Require application.
|
2
|
+
require "dinosaurus"
|
3
|
+
|
4
|
+
# Require testing dependencies.
|
5
|
+
require "vcr"
|
6
|
+
|
7
|
+
# An API Key must b supplied in order to regenerate VCR casettes.
|
8
|
+
# THis is a testing account API key.
|
9
|
+
API_KEY = 'c5aedd41d31e32f3597100dd5b0d0163'
|
10
|
+
|
11
|
+
VCR.configure do |c|
|
12
|
+
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
13
|
+
c.hook_into :webmock # or :fakeweb
|
14
|
+
c.ignore_hosts '127.0.0.1', 'localhost'
|
15
|
+
|
16
|
+
if API_KEY
|
17
|
+
c.filter_sensitive_data('<API_KEY>') { API_KEY }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Dinosaurus.configure do |c|
|
22
|
+
c.api_key = API_KEY
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dinosaurus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- David Tuite
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70239728703440 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70239728703440
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: vcr
|
27
|
+
requirement: &70239728702020 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70239728702020
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: httparty
|
38
|
+
requirement: &70239728699900 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70239728699900
|
47
|
+
description: Ruby wrapper for the Big Huge Thesaurus APIs.
|
48
|
+
email:
|
49
|
+
- dtuite@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- .rspec
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- dinosaurus.gemspec
|
61
|
+
- lib/dinosaurus.rb
|
62
|
+
- lib/dinosaurus/configuration.rb
|
63
|
+
- lib/dinosaurus/logging.rb
|
64
|
+
- lib/dinosaurus/railties.rb
|
65
|
+
- lib/dinosaurus/thesaurus.rb
|
66
|
+
- lib/dinosaurus/version.rb
|
67
|
+
- spec/dinosaurus/thesaurus_spec.rb
|
68
|
+
- spec/fixtures/vcr_cassettes/word.yml
|
69
|
+
- spec/spec_helper.rb
|
70
|
+
homepage: http://words.bighugelabs.com
|
71
|
+
licenses: []
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.8.16
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Lookup synonyms, antonyms etc. using the Big Huge Thesaurus API.
|
94
|
+
test_files:
|
95
|
+
- spec/dinosaurus/thesaurus_spec.rb
|
96
|
+
- spec/fixtures/vcr_cassettes/word.yml
|
97
|
+
- spec/spec_helper.rb
|