grammarbot 0.1.0
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/.gitignore +9 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +8 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/grammarbot.gemspec +31 -0
- data/lib/grammarbot.rb +8 -0
- data/lib/grammarbot/client.rb +49 -0
- data/lib/grammarbot/version.rb +5 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 676a1d2e43b3f4516f37705451e072b0881d697df9dca7d04f61ccc802947719
|
4
|
+
data.tar.gz: 273931a8fbcf2adee0d2d7b828241594238463f5711b3752c16e06af3bcfd3d2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cfdd8edb477df11c001fd84593a56775b63578e7a03579582a6406ac818fa15a550d9e92748dd761cd788d5c28bc655853d59460ebf0de2a1a9659d7b34f49e2
|
7
|
+
data.tar.gz: ac1c13144d8910bb644f5cbff562bc9a84e20e7c85bcd772b0a13de4259fa59198f0b0c596851b23d38f51ec444c8fcec93c27189e7931c68c79e320065630df
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
grammarbot
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.5.3
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Timur Valeev
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Grammarbot
|
2
|
+
|
3
|
+
A Ruby API client for [GrammrBot API](https://www.grammarbot.io/quickstart)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'grammarbot'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install grammarbot
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
Client initialization, `api_key`, `language` and `base_uri` are optional and could be ommited, or defined later
|
23
|
+
|
24
|
+
gbot = Grammarbot::Client.new(api_key: 'grammarbot_default_key', language: 'en-US', base_uri: 'http://api.grammarbot.io')
|
25
|
+
|
26
|
+
gbot.api_key = 'new_api_key'
|
27
|
+
gbot.language = 'en-GB'
|
28
|
+
gbot.base_uri = 'http://pro.grammarbot.io'
|
29
|
+
|
30
|
+
Don't want to check the key into source control? Put the key on the GRAMMARBOT_API_KEY environment variable!
|
31
|
+
|
32
|
+
Simple example
|
33
|
+
|
34
|
+
result = gbot.check("I can't remember how to go their.")
|
35
|
+
|
36
|
+
result.language.code # => 'en-US'
|
37
|
+
result.matches.size # => 1
|
38
|
+
result.matches.first.message # => "Statistics suggests that 'there' (as in 'Is there an answer?') might be the correct word here, not 'their' (as in 'It’s not their fault.'). Please check."
|
39
|
+
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/GrammarBot-API/grammarbot-rb.
|
44
|
+
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
49
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'grammarbot'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
require 'pry'
|
11
|
+
Pry.start
|
data/bin/setup
ADDED
data/grammarbot.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'grammarbot/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'grammarbot'
|
9
|
+
spec.version = Grammarbot::VERSION
|
10
|
+
spec.authors = ['Timur Valeev']
|
11
|
+
spec.email = ['kibenimatik@yandex.ru']
|
12
|
+
|
13
|
+
spec.summary = 'Client library for GrammarBot API'
|
14
|
+
spec.description = <<~DESC
|
15
|
+
Gem wrapper for GrammarBot API for detecting grammar and spelling errors
|
16
|
+
DESC
|
17
|
+
spec.homepage = 'https://github.com/GrammarBot-API/grammarbot-rb'
|
18
|
+
spec.license = 'MIT'
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
21
|
+
f.match(%r{^(test|spec|features)/})
|
22
|
+
end
|
23
|
+
spec.bindir = 'exe'
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_dependency 'httparty'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
30
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
31
|
+
end
|
data/lib/grammarbot.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Grammarbot
|
4
|
+
class Client
|
5
|
+
include HTTParty
|
6
|
+
|
7
|
+
# Initializes API client
|
8
|
+
# @param api_key [String] GrammarBot API key, optional
|
9
|
+
# @param language [String] language in which to check, optional
|
10
|
+
# @param base_uri [String] GrammarBot API server url, optional
|
11
|
+
def initialize(api_key: nil, language: 'en-US', base_uri: 'http://api.grammarbot.io')
|
12
|
+
api_key ||= ENV['GRAMMARBOT_API_KEY'] || 'ruby-default'
|
13
|
+
self.class.base_uri base_uri
|
14
|
+
self.class.default_params api_key: api_key, language: language
|
15
|
+
end
|
16
|
+
|
17
|
+
# Submits text for grammar and spelling errors to GrammarBot
|
18
|
+
# @param text [String] text to submit
|
19
|
+
# @return [Object] GrammarBot response
|
20
|
+
def check(text)
|
21
|
+
request(:get, '/v2/check', query: { text: text })
|
22
|
+
end
|
23
|
+
|
24
|
+
# Change client api_key
|
25
|
+
# @param new_api_key [String] API key
|
26
|
+
def api_key=(new_api_key)
|
27
|
+
self.class.default_params[:api_key] = new_api_key
|
28
|
+
end
|
29
|
+
|
30
|
+
# Change language for text check
|
31
|
+
# @param lang [String] language code
|
32
|
+
def language=(lang)
|
33
|
+
self.class.default_params[:language] = lang
|
34
|
+
end
|
35
|
+
|
36
|
+
# Change client base_uri
|
37
|
+
# @param uri [String] API endpoint base uri
|
38
|
+
def base_uri=(uri)
|
39
|
+
self.class.base_uri(uri)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def request(http_method, path, query: {})
|
45
|
+
response = self.class.send(http_method, path, query: query)
|
46
|
+
JSON.parse response.body, object_class: OpenStruct
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grammarbot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Timur Valeev
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: 'Gem wrapper for GrammarBot API for detecting grammar and spelling errors
|
56
|
+
|
57
|
+
'
|
58
|
+
email:
|
59
|
+
- kibenimatik@yandex.ru
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".ruby-gemset"
|
66
|
+
- ".ruby-version"
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- grammarbot.gemspec
|
74
|
+
- lib/grammarbot.rb
|
75
|
+
- lib/grammarbot/client.rb
|
76
|
+
- lib/grammarbot/version.rb
|
77
|
+
homepage: https://github.com/GrammarBot-API/grammarbot-rb
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.7.8
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Client library for GrammarBot API
|
101
|
+
test_files: []
|