-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves duplicate code to superclasses, cleaned up other duplication.
- Loading branch information
Showing
14 changed files
with
226 additions
and
368 deletions.
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 @@ | ||
module Neography | ||
class Rest | ||
class AutoIndexes | ||
include Neography::Rest::Helpers | ||
|
||
def initialize(connection) | ||
@connection = connection | ||
end | ||
|
||
def get(key, value) | ||
index = @connection.get(key_value_path(:key => key, :value => value)) || [] | ||
return nil if index.empty? | ||
index | ||
end | ||
|
||
def find(key, value) | ||
@connection.get(key_value_path(:key => key, :value => value)) || [] | ||
end | ||
|
||
def query(query_expression) | ||
@connection.get(query_index_path(:query => query_expression)) || [] | ||
end | ||
|
||
def status | ||
@connection.get(index_status_path) | ||
end | ||
|
||
def status=(value) | ||
options = { | ||
:body => value.to_json, | ||
:headers => json_content_type | ||
} | ||
@connection.put(index_status_path, options) | ||
end | ||
|
||
def properties | ||
@connection.get(index_properties_path) | ||
end | ||
|
||
def add_property(property) | ||
options = { | ||
:body => property, | ||
:headers => json_content_type | ||
} | ||
@connection.post(index_properties_path, options) | ||
end | ||
|
||
def remove_property(property) | ||
@connection.delete(index_property_path(:property => property)) | ||
end | ||
|
||
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,76 @@ | ||
module Neography | ||
class Rest | ||
class Indexes | ||
include Neography::Rest::Helpers | ||
|
||
def initialize(connection, index_type) | ||
@connection = connection | ||
@index_type = index_type | ||
end | ||
|
||
def list | ||
@connection.get(all_path) | ||
end | ||
|
||
def create(name, type, provider) | ||
options = { | ||
:body => ( | ||
{ :name => name, | ||
:config => { | ||
:type => type, | ||
:provider => provider | ||
} | ||
} | ||
).to_json, | ||
:headers => json_content_type | ||
} | ||
@connection.post(all_path, options) | ||
end | ||
|
||
def create_auto(type, provider) | ||
create("#{@index_type}_auto_index", type, provider) | ||
end | ||
|
||
def add(index, key, value, id) | ||
options = { | ||
:body => ( | ||
{ :uri => @connection.configuration + "/#{@index_type}/#{get_id(id)}", | ||
:key => key, | ||
:value => value | ||
} | ||
).to_json, | ||
:headers => json_content_type | ||
} | ||
|
||
@connection.post(base_path(:index => index), options) | ||
end | ||
|
||
def get(index, key, value) | ||
index = @connection.get(key_value_path(:index => index, :key => key, :value => value)) || [] | ||
return nil if index.empty? | ||
index | ||
end | ||
|
||
def find_by_key_value(index, key, value) | ||
@connection.get(key_value_path(:index => index, :key => key, :value => value)) || [] | ||
end | ||
|
||
def find_by_query(index, query) | ||
@connection.get(query_path(:index => index, :query => query)) || [] | ||
end | ||
|
||
def remove(index, id) | ||
@connection.delete(id_path(:index => index, :id => get_id(id))) | ||
end | ||
|
||
def remove_by_key(index, id, key) | ||
@connection.delete(key_path(:index => index, :id => get_id(id), :key => key)) | ||
end | ||
|
||
def remove_by_value(index, id, key, value) | ||
@connection.delete(value_path(:index => index, :id => get_id(id), :key => key, :value => value)) | ||
end | ||
|
||
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 |
---|---|---|
@@ -1,61 +1,14 @@ | ||
module Neography | ||
class Rest | ||
class NodeAutoIndexes | ||
class NodeAutoIndexes < AutoIndexes | ||
include Neography::Rest::Paths | ||
include Neography::Rest::Helpers | ||
|
||
add_path :key_value, "/index/auto/node/:key/:value" | ||
add_path :query_index, "/index/auto/node/?query=:query" | ||
add_path :index_status, "/index/auto/node/status" | ||
add_path :index_properties, "/index/auto/node/properties" | ||
add_path :index_property, "/index/auto/node/properties/:property" | ||
|
||
def initialize(connection) | ||
@connection = connection | ||
end | ||
|
||
def get(key, value) | ||
index = @connection.get(key_value_path(:key => key, :value => value)) || [] | ||
return nil if index.empty? | ||
index | ||
end | ||
|
||
def find(key, value) | ||
@connection.get(key_value_path(:key => key, :value => value)) || [] | ||
end | ||
|
||
def query(query_expression) | ||
@connection.get(query_index_path(:query => query_expression)) || [] | ||
end | ||
|
||
def status | ||
@connection.get(index_status_path) | ||
end | ||
|
||
def status=(value) | ||
options = { | ||
:body => value.to_json, | ||
:headers => json_content_type | ||
} | ||
@connection.put(index_status_path, options) | ||
end | ||
|
||
def properties | ||
@connection.get(index_properties_path) | ||
end | ||
|
||
def add_property(property) | ||
options = { | ||
:body => property, | ||
:headers => json_content_type | ||
} | ||
@connection.post(index_properties_path, options) | ||
end | ||
|
||
def remove_property(property) | ||
@connection.delete(index_property_path(:property => property)) | ||
end | ||
|
||
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
Oops, something went wrong.