oxford_dictionary 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2bc4731fbb7b2901e23070998aaeb6fb8d61131
4
- data.tar.gz: c6332d8e683d8baac52a0e415508c08e08d7af08
3
+ metadata.gz: 0f3926d3f83c2ba8e1bdd3e8d495d8711477f61c
4
+ data.tar.gz: 0c8cb98e9868d75be5472937b73aa8dbb63f2d08
5
5
  SHA512:
6
- metadata.gz: 445ece08c1459cb3fdc1d47696f1b37b1472a32f259070ab37ceadb4f553d7e99980b215e0cf2de9034d725a0b957f2726de38540870bdce07d55bea551e8362
7
- data.tar.gz: 1016dac1ce6bafc64f200118e39224d2c8d0f07af89ded910999faed3b07876c1120205203f7f0c475d79bdf17c2e9b869b486b30010bff55fef193a33020d07
6
+ metadata.gz: e8834b1e8c46e0dcad3a487f6a8e0fbe9e2da18d3f1e55661ed47d4e65dec6f9fc60603e9afedcb5683fa76cb434d15d239e7c077e474ca1c3156d912d22599f
7
+ data.tar.gz: 183e9474dcddd60208adfbc78c60c3c0a6eb65c95f0ec82210538be288687f729dfcc7eb46cdf107f12c3b7849eacf72f7ffea2f2f60ac0c3ce24f7034d661c1
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ## OxfordDictionary master (unreleased)
2
+
3
+ ## OxfordDictionary 1.0.0 (2017-09-19)
4
+
5
+ - Remove httparty as a runtime dependency
6
+ [\#1](https://github.com/swcraig/oxford-dictionary/pull/1)
7
+
8
+
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  [![Build Status](https://travis-ci.org/swcraig/oxford-dictionary.svg?branch=master)](https://travis-ci.org/swcraig/oxford-dictionary)
2
2
  [![Test Coverage](https://codeclimate.com/github/swcraig/oxford-dictionary/badges/coverage.svg)](https://codeclimate.com/github/swcraig/oxford-dictionary/coverage)
3
3
  [![Code Climate](https://codeclimate.com/github/swcraig/oxford-dictionary/badges/gpa.svg)](https://codeclimate.com/github/swcraig/oxford-dictionary)
4
+ [![Gem Version](https://badge.fury.io/rb/oxford_dictionary.svg)](https://badge.fury.io/rb/oxford_dictionary)
4
5
  # OxfordDictionary
5
6
 
6
7
  Ruby wrapper to consume the [Oxford Dictionary API](https://developer.oxforddictionaries.com/documentation)
@@ -18,6 +19,11 @@ After registering for an API key, setup the client:
18
19
  client = OxfordDictionary.new(app_id: 'ID', app_key: 'SECRET')
19
20
 
20
21
  ### Usage Examples
22
+ Some documentation on the different endpoint function calls can be found [here](http://rubydoc.info/gems/oxford_dictionary/OxfordDictionary/Endpoints)
23
+
24
+ This wrapper follows the schema laid out by the API quite closely. The data
25
+ schema for the different API calls can be found [here](https://developer.oxforddictionaries.com/documentation).
26
+
21
27
  ###### Get the results for an entry
22
28
 
23
29
  entry = client.entry('vapid')
@@ -68,7 +74,7 @@ After registering for an API key, setup the client:
68
74
  search_results = client.search('condition', prefix: true)
69
75
 
70
76
  ###### A quick note on how to add filters to queries
71
- There isn't much argument checking at the moment. Some endpoints do not accept filter arguments, refer to the API documentation to check for endpoints that accept filters.
77
+ There isn't much argument checking at the moment. Some endpoints do not accept filter arguments, refer to the API documentation to check for endpoints that accept filters.
72
78
 
73
79
  # All endpoints accept the :lang filter. This specifies which dictionary to use
74
80
  # If no argument is supplied, default is 'en'
@@ -85,13 +91,13 @@ Argument names need to be in camelCase, not snake_case. However, the objects ret
85
91
 
86
92
  ## Development
87
93
 
88
- After checking out the repo, run `bin/setup` to install dependencies.
94
+ After checking out the repo, run `bin/setup` to install dependencies.
89
95
  Run `bin/console` for an interactive prompt that will allow you to experiment.
90
96
 
91
97
  ## Contributing
92
98
 
93
- Bug reports and pull requests are more than welcome!
94
- Please make tests for anything that is added.
99
+ Bug reports and pull requests are more than welcome!
100
+ Please make tests for anything that is added.
95
101
  `bundle exec rake` will run rspec/rubocop.
96
102
 
97
103
  #### Pull Requests
@@ -1,11 +1,5 @@
1
1
  require 'oxford_dictionary/client'
2
- require 'oxford_dictionary/error'
3
- require 'oxford_dictionary/request'
4
2
  require 'oxford_dictionary/version'
5
- require 'oxford_dictionary/endpoints/entry_endpoint'
6
- require 'oxford_dictionary/endpoints/inflection_endpoint'
7
- require 'oxford_dictionary/endpoints/search_endpoint'
8
- require 'oxford_dictionary/endpoints/wordlist_endpoint'
9
3
 
10
4
  # Adds some aliasing
11
5
  module OxfordDictionary
@@ -52,6 +52,8 @@ module OxfordDictionary
52
52
  entry_request(query, params)
53
53
  end
54
54
 
55
+ private
56
+
55
57
  def entry_request(query, params)
56
58
  EntryResponse.new(request(ENDPOINT, query, params)['results'][0])
57
59
  end
@@ -1,14 +1,13 @@
1
- require 'httparty'
2
1
  require 'json'
2
+ require 'net/http'
3
3
  require 'plissken'
4
4
  require 'oxford_dictionary/error'
5
5
 
6
6
  module OxfordDictionary
7
7
  # Handles all of the actual API calls
8
8
  module Request
9
- include HTTParty
10
-
11
9
  BASE = 'https://od-api.oxforddictionaries.com/api/v1'.freeze
10
+ HTTP_OK = '200'.freeze
12
11
  ACCEPT_TYPE = 'application/json'.freeze
13
12
  # May be used by the wordlist endpoint
14
13
  ADVANCED_FILTERS = [:exact, :exclude, :exclude_senses,
@@ -16,12 +15,21 @@ module OxfordDictionary
16
15
  :prefix, :word_length].freeze
17
16
 
18
17
  def request(endpoint, q, params)
19
- url = build_url(endpoint, q, params)
20
- resp = HTTParty.get(url, headers: request_headers)
21
- unless resp.code == 200
22
- raise(Error.new(resp.code), error_message(resp.body))
18
+ url = URI(build_url(endpoint, q, params))
19
+ response = Net::HTTP.start(url.host, url.port, use_ssl: true) do |http|
20
+ request = build_get_request(url)
21
+ http.request(request)
22
+ end
23
+ parse_body_or_raise(response)
24
+ end
25
+
26
+ private
27
+
28
+ def parse_body_or_raise(response)
29
+ unless response.code == HTTP_OK
30
+ raise(Error.new(response.code), error_message(response.body))
23
31
  end
24
- JSON.parse(resp.body).to_snake_keys
32
+ JSON.parse(response.body).to_snake_keys
25
33
  end
26
34
 
27
35
  def build_url(endpoint, q, params)
@@ -98,6 +106,7 @@ module OxfordDictionary
98
106
  query
99
107
  end
100
108
 
109
+ # Remove <p> and </p> in error message
101
110
  def error_message(response)
102
111
  response.lines.last.chomp[3..-5]
103
112
  end
@@ -107,8 +116,12 @@ module OxfordDictionary
107
116
  element.is_a?(Hash)
108
117
  end
109
118
 
110
- def request_headers
111
- { 'Accept' => ACCEPT_TYPE, 'app_id' => app_id, 'app_key' => app_key }
119
+ def build_get_request(url)
120
+ request = Net::HTTP::Get.new(url)
121
+ request['Accept'] = ACCEPT_TYPE
122
+ request['app_id'] = app_id
123
+ request['app_key'] = app_key
124
+ request
112
125
  end
113
126
  end
114
127
  end
@@ -1,3 +1,3 @@
1
1
  module OxfordDictionary
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = 'A wrapper for the Oxford Dictionary API'
13
13
  spec.description = 'https://developer.oxforddictionaries.com/documentation'
14
- spec.homepage = 'https://github.com'
14
+ spec.homepage = 'https://github.com/swcraig/oxford-dictionary'
15
15
  spec.license = 'MIT'
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
@@ -27,7 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'webmock', '~> 2.1.0'
28
28
  spec.add_development_dependency 'rubocop', '~> 0.45.0'
29
29
 
30
- spec.add_runtime_dependency 'httparty', '~> 0.14.0'
31
30
  spec.add_runtime_dependency 'virtus', '~> 1.0.5'
32
31
  spec.add_runtime_dependency 'plissken', '~> 0.1.0'
33
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxford_dictionary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - swcraig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-14 00:00:00.000000000 Z
11
+ date: 2017-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.45.0
83
- - !ruby/object:Gem::Dependency
84
- name: httparty
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 0.14.0
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 0.14.0
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: virtus
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -132,6 +118,7 @@ files:
132
118
  - ".gitignore"
133
119
  - ".rspec"
134
120
  - ".travis.yml"
121
+ - CHANGELOG.md
135
122
  - CODE_OF_CONDUCT.md
136
123
  - Gemfile
137
124
  - LICENSE.txt
@@ -155,7 +142,7 @@ files:
155
142
  - lib/oxford_dictionary/request.rb
156
143
  - lib/oxford_dictionary/version.rb
157
144
  - oxford_dictionary.gemspec
158
- homepage: https://github.com
145
+ homepage: https://github.com/swcraig/oxford-dictionary
159
146
  licenses:
160
147
  - MIT
161
148
  metadata: {}