-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for Dictionaries #10
Open
Richard-Degenne
wants to merge
10
commits into
andhapp:master
Choose a base branch
from
PerfectMemory:dictionaries
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8b8ebf5
Added source_id to entities
43e736a
Added Dictionary model
cdc5c96
Revamped API calls
cd13418
Added dictionary creation
9da60ac
Added Dictionary deletion
fe018b0
Added DictionaryEntry
ca0f5c8
Added dictionary entry creation
958e262
Added dictionary entry deletion
07dcd06
Added dictionary entry retrieval
1a50173
Removed custom accept-encoding headers
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'json' | ||
|
||
module TextRazor | ||
|
||
class ApiResponse | ||
|
||
BadRequest = Class.new(StandardError) | ||
Unauthorised = Class.new(StandardError) | ||
RequestEntityTooLong = Class.new(StandardError) | ||
|
||
attr_reader :raw_response, :time | ||
|
||
def initialize(http_response) | ||
code = http_response.code | ||
body = http_response.body | ||
|
||
raise BadRequest.new(body) if bad_request?(code) | ||
raise Unauthorised.new(body) if unauthorised?(code) | ||
raise RequestEntityTooLong.new(body) if request_entity_too_long?(code) | ||
|
||
json_body = ::JSON::parse(body, symbolize_names: true) | ||
|
||
@time = json_body[:time].to_f | ||
@ok = json_body[:ok] | ||
@raw_response = json_body[:response] | ||
end | ||
|
||
def ok? | ||
@ok | ||
end | ||
|
||
#TODO: Not in a successful response | ||
#def error | ||
#end | ||
|
||
#def message | ||
#end | ||
|
||
private | ||
|
||
def bad_request?(code) | ||
code == 400 | ||
end | ||
|
||
def unauthorised?(code) | ||
code == 401 | ||
end | ||
|
||
def request_entity_too_long?(code) | ||
code == 413 | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module TextRazor | ||
|
||
class Dictionary | ||
|
||
include Util | ||
|
||
attr_reader :id, :match_type, :case_insensitive, :language | ||
|
||
def initialize(params = {}) | ||
initialize_params params | ||
end | ||
|
||
def to_h | ||
{ | ||
"matchType" => match_type, | ||
"caseInsensitive" => case_insensitive, | ||
"language" => language | ||
}.reject { |_, v| v.nil? } | ||
end | ||
|
||
def valid? | ||
!id.nil? && !id.empty? | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module TextRazor | ||
|
||
class DictionaryEntry | ||
|
||
include Util | ||
|
||
attr_reader :id, :text, :data | ||
|
||
def initialize(params = {}) | ||
initialize_params params | ||
end | ||
|
||
def to_h | ||
{ | ||
"id" => id, | ||
"text" => text, | ||
"data" => data | ||
}.reject { |_, v| v.nil? || v.empty? } | ||
end | ||
|
||
def valid? | ||
!text.nil? && !text.empty? | ||
end | ||
|
||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to
ApiRequest
,Response
class was meant to take care of this responsibility. Any particular reason to do this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Response
class is heavily oriented towards parsing responses to analysis requests.The more general
ApiResponse
can handle any kind of response from TextRazor. (Side note:Response
inherits fromApiResponse
)