mw-dictionary-api 0.1.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 +7 -0
- data/lib/mw-dictionary-api.rb +48 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: faa87b348033f93042b4ff332fe6d7cb9d37ced66a5d25f00adcc6841324a61b
|
4
|
+
data.tar.gz: e983f19f8337d6222cb179cdab5c526c0b97f89af1ab80af13bdb73dd1071809
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f397fbf8b4a234778b4d16d349058fe047f7a4e1eab14b0cec50995a257e102916080bc5403f917b636b72eb430a1511683aa4f832eee08b8da0d0d9852fbc0
|
7
|
+
data.tar.gz: c8940d13226e93f8bcc79f33801cdd19dac1edd00207fc22305b01b00a49b69e788a33930b705171be3e707e0d8f88ff561d2f376d64a67fb3ebc8a2e34b73d4
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# mw-dictionary-api.rb
|
2
|
+
# Julian I. Kamil / @juliankamil
|
3
|
+
# 2019/05/12
|
4
|
+
|
5
|
+
require 'rest-client'
|
6
|
+
require 'json'
|
7
|
+
require 'colorize'
|
8
|
+
|
9
|
+
module MwDictionary
|
10
|
+
API_SERVICES = {
|
11
|
+
elementary: 'references/sd2/json/{word}?key={api_key}',
|
12
|
+
intermediate: 'references/sd2/json/{word}?key={api_key}'
|
13
|
+
}
|
14
|
+
|
15
|
+
class Api
|
16
|
+
attr_accessor :api_key, :dictionary
|
17
|
+
|
18
|
+
@api_domain = 'www.dictionaryapi.com'
|
19
|
+
@api_version = 'api/v3'
|
20
|
+
|
21
|
+
class << self
|
22
|
+
attr_accessor :api_domain, :api_version
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(api_key, dictionary = :elementary)
|
26
|
+
@api_key = api_key
|
27
|
+
@dictionary = dictionary
|
28
|
+
end
|
29
|
+
|
30
|
+
def lookup(word)
|
31
|
+
lookup_url = lookup_url(word)
|
32
|
+
|
33
|
+
response = RestClient::Request.new(
|
34
|
+
:method => :get,
|
35
|
+
:url => lookup_url,
|
36
|
+
:headers => { :accept => :json, :content_type => :json }
|
37
|
+
).execute
|
38
|
+
|
39
|
+
results = JSON.parse(response.to_str)
|
40
|
+
end
|
41
|
+
|
42
|
+
def lookup_url(word)
|
43
|
+
"https://#{self.class.api_domain}/#{self.class.api_version}/#{API_SERVICES[@dictionary]}".
|
44
|
+
gsub!('{api_key}', "#{@api_key}").
|
45
|
+
gsub!('{word}', "#{word}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mw-dictionary-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Julian I. Kamil
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby binding for the Merriam-Webster Dictionaries REST APIs
|
14
|
+
email: julian.kamil@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/mw-dictionary-api.rb
|
20
|
+
homepage: http://rubygems.org/gems/mw-dictionary-api
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.7.6
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Merriam-Webster Dictionaries REST APIs
|
44
|
+
test_files: []
|