swiftype 0.0.5 → 1.0.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.
- data/.gitignore +5 -0
- data/.travis.yml +6 -0
- data/Gemfile +1 -1
- data/README.md +202 -283
- data/lib/data/ca-bundle.crt +3554 -0
- data/lib/swiftype.rb +7 -31
- data/lib/swiftype/client.rb +439 -11
- data/lib/swiftype/configuration.rb +29 -4
- data/lib/swiftype/exceptions.rb +2 -0
- data/lib/swiftype/ext/backport-uri.rb +33 -0
- data/lib/swiftype/request.rb +88 -20
- data/lib/swiftype/result_set.rb +43 -6
- data/lib/swiftype/sso.rb +20 -0
- data/lib/swiftype/version.rb +1 -1
- data/spec/client_spec.rb +576 -0
- data/spec/configuration_spec.rb +36 -0
- data/spec/deprecated_spec.rb +20 -0
- data/spec/fixtures/vcr/analytics_autoselects.yml +55 -0
- data/spec/fixtures/vcr/analytics_autoselects_with_document_type.yml +55 -0
- data/spec/fixtures/vcr/analytics_autoselects_with_document_type_and_time_range.yml +55 -0
- data/spec/fixtures/vcr/analytics_autoselects_with_time_range.yml +55 -0
- data/spec/fixtures/vcr/analytics_clicks.yml +55 -0
- data/spec/fixtures/vcr/analytics_clicks_with_document_type.yml +55 -0
- data/spec/fixtures/vcr/analytics_clicks_with_document_type_and_time_range.yml +55 -0
- data/spec/fixtures/vcr/analytics_clicks_with_time_range.yml +55 -0
- data/spec/fixtures/vcr/analytics_searches.yml +55 -0
- data/spec/fixtures/vcr/analytics_searches_with_document_type_and_time_range.yml +55 -0
- data/spec/fixtures/vcr/analytics_searches_with_time_range.yml +55 -0
- data/spec/fixtures/vcr/analytics_searchs_with_document_type.yml +55 -0
- data/spec/fixtures/vcr/analytics_top_no_result_queries.yml +55 -0
- data/spec/fixtures/vcr/analytics_top_no_result_queries_paginated.yml +55 -0
- data/spec/fixtures/vcr/analytics_top_queries.yml +55 -0
- data/spec/fixtures/vcr/analytics_top_queries_paginated.yml +55 -0
- data/spec/fixtures/vcr/analytics_top_queries_too_large.yml +51 -0
- data/spec/fixtures/vcr/bulk_create_documents.yml +49 -0
- data/spec/fixtures/vcr/bulk_create_or_update_documents_failure.yml +45 -0
- data/spec/fixtures/vcr/bulk_create_or_update_documents_success.yml +49 -0
- data/spec/fixtures/vcr/bulk_destroy_documents.yml +45 -0
- data/spec/fixtures/vcr/crawl_url.yml +45 -0
- data/spec/fixtures/vcr/create_document.yml +48 -0
- data/spec/fixtures/vcr/create_document_type.yml +45 -0
- data/spec/fixtures/vcr/create_domain.yml +45 -0
- data/spec/fixtures/vcr/create_engine.yml +45 -0
- data/spec/fixtures/vcr/create_or_update_document_create.yml +47 -0
- data/spec/fixtures/vcr/create_or_update_document_update.yml +47 -0
- data/spec/fixtures/vcr/create_user.yml +45 -0
- data/spec/fixtures/vcr/destroy_document.yml +41 -0
- data/spec/fixtures/vcr/destroy_document_type.yml +41 -0
- data/spec/fixtures/vcr/destroy_domain.yml +41 -0
- data/spec/fixtures/vcr/destroy_engine.yml +41 -0
- data/spec/fixtures/vcr/destroy_non_existent_document_type.yml +43 -0
- data/spec/fixtures/vcr/document_type_search.yml +60 -0
- data/spec/fixtures/vcr/document_type_search_pagination.yml +45 -0
- data/spec/fixtures/vcr/document_type_suggest.yml +50 -0
- data/spec/fixtures/vcr/document_type_suggest_pagination.yml +45 -0
- data/spec/fixtures/vcr/engine_search.yml +64 -0
- data/spec/fixtures/vcr/engine_search_facets.yml +162 -0
- data/spec/fixtures/vcr/engine_search_pagination.yml +45 -0
- data/spec/fixtures/vcr/engine_suggest.yml +52 -0
- data/spec/fixtures/vcr/engine_suggest_pagination.yml +45 -0
- data/spec/fixtures/vcr/find_document.yml +47 -0
- data/spec/fixtures/vcr/find_document_type.yml +45 -0
- data/spec/fixtures/vcr/find_domain.yml +45 -0
- data/spec/fixtures/vcr/find_domain_failure.yml +43 -0
- data/spec/fixtures/vcr/find_engine.yml +45 -0
- data/spec/fixtures/vcr/list_document_type.yml +45 -0
- data/spec/fixtures/vcr/list_documents.yml +68 -0
- data/spec/fixtures/vcr/list_documents_with_pagination.yml +68 -0
- data/spec/fixtures/vcr/list_domains.yml +45 -0
- data/spec/fixtures/vcr/list_engines.yml +46 -0
- data/spec/fixtures/vcr/list_users.yml +45 -0
- data/spec/fixtures/vcr/list_users_with_pagination.yml +45 -0
- data/spec/fixtures/vcr/log_clickthrough_failure.yml +43 -0
- data/spec/fixtures/vcr/log_clickthrough_success.yml +45 -0
- data/spec/fixtures/vcr/recrawl_domain_failure.yml +44 -0
- data/spec/fixtures/vcr/recrawl_domain_success.yml +45 -0
- data/spec/fixtures/vcr/show_user.yml +45 -0
- data/spec/fixtures/vcr/update_document.yml +47 -0
- data/spec/fixtures/vcr/update_document_unknown_field_failure.yml +45 -0
- data/spec/fixtures/vcr/update_documents_failure_non_existent_document.yml +45 -0
- data/spec/fixtures/vcr/update_documents_success.yml +45 -0
- data/spec/fixtures/vcr/users_client_secret_incorrect.yml +42 -0
- data/spec/fixtures/vcr/users_no_api_key.yml +42 -0
- data/spec/fixtures/vcr/users_no_client_id_or_secret.yml +43 -0
- data/spec/platform_spec.rb +95 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/ssl_spec.rb +34 -0
- data/spec/sso_spec.rb +24 -0
- data/swiftype.gemspec +10 -11
- metadata +183 -52
- data/lib/swiftype/base_model.rb +0 -89
- data/lib/swiftype/connection.rb +0 -47
- data/lib/swiftype/document.rb +0 -17
- data/lib/swiftype/document_type.rb +0 -69
- data/lib/swiftype/easy.rb +0 -77
- data/lib/swiftype/engine.rb +0 -33
- data/lib/swiftype/search.rb +0 -23
data/lib/swiftype/document.rb
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
module Swiftype
|
|
2
|
-
class Document < BaseModel
|
|
3
|
-
parents Engine, DocumentType
|
|
4
|
-
|
|
5
|
-
def engine
|
|
6
|
-
Engine.find engine_id
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def document_type
|
|
10
|
-
DocumentType.find document_type_id
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def update_fields!(hash)
|
|
14
|
-
update_with! put("#{raw_path_to_model}/update_fields.json", {:fields => hash})
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
module Swiftype
|
|
2
|
-
class DocumentType < BaseModel
|
|
3
|
-
parents Engine
|
|
4
|
-
include Swiftype::Search
|
|
5
|
-
|
|
6
|
-
def build_document(params={})
|
|
7
|
-
Document.new({
|
|
8
|
-
:document_type_id => id || slug,
|
|
9
|
-
:engine_id => engine_id
|
|
10
|
-
}.merge(params))
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def create_document(params={})
|
|
14
|
-
doc = build_document(params)
|
|
15
|
-
doc.create!
|
|
16
|
-
doc
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def create_documents(documents=[])
|
|
20
|
-
post("engines/#{engine_id}/document_types/#{slug}/documents/bulk_create.json", {:documents => documents})
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def update_documents(documents=[])
|
|
24
|
-
put("engines/#{engine_id}/document_types/#{slug}/documents/bulk_update.json", {:documents => documents})
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def update_document(document={})
|
|
28
|
-
document_id = document[:external_id]
|
|
29
|
-
put("engines/#{engine_id}/document_types/#{slug}/documents/#{document_id}/update_fields", {:fields => document[:fields]})
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def destroy_document(document_id)
|
|
33
|
-
!!delete("engines/#{engine_id}/document_types/#{slug}/documents/#{document_id}")
|
|
34
|
-
rescue NonExistentRecord
|
|
35
|
-
false
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def destroy_documents(document_ids=[])
|
|
39
|
-
post("engines/#{engine_id}/document_types/#{slug}/documents/bulk_destroy.json", {:documents => document_ids})
|
|
40
|
-
rescue NonExistentRecord
|
|
41
|
-
false
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def document(id)
|
|
45
|
-
Document.new get("engines/#{engine_id}/document_types/#{slug}/documents/#{id}.json")
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def engine
|
|
49
|
-
Engine.find(engine_id)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def documents
|
|
53
|
-
get("engines/#{engine_id}/document_types/#{slug}/documents.json").map { |d| Document.new(d) }
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def suggest(query, options={})
|
|
57
|
-
search_params = { :q => query }.merge(parse_suggest_options(options))
|
|
58
|
-
response = post("engines/#{engine_id}/document_types/#{slug}/suggest.json", search_params)
|
|
59
|
-
results = {}
|
|
60
|
-
response['records'].each { |document_type, records| results[document_type] = records.map { |d| Swiftype::Document.new(d) }}
|
|
61
|
-
results
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def search(query, options={})
|
|
65
|
-
search_params = { :q => query }.merge(parse_search_options(options))
|
|
66
|
-
ResultSet.new(post("engines/#{engine_id}/document_types/#{slug}/search.json", search_params))
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
data/lib/swiftype/easy.rb
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
require 'swiftype/document'
|
|
2
|
-
|
|
3
|
-
module Swiftype
|
|
4
|
-
class Easy
|
|
5
|
-
include Swiftype::Connection
|
|
6
|
-
include Swiftype::Search
|
|
7
|
-
|
|
8
|
-
def initialize(options={})
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
module Engine
|
|
12
|
-
def engines
|
|
13
|
-
get("engines.json")
|
|
14
|
-
end
|
|
15
|
-
def create_engine(engine={})
|
|
16
|
-
post("engines.json", :engine => engine)
|
|
17
|
-
end
|
|
18
|
-
def destroy_engine(engine_id)
|
|
19
|
-
delete("engines/#{engine_id}")
|
|
20
|
-
end
|
|
21
|
-
def suggest(engine_id, query, options={})
|
|
22
|
-
search_params = { :q => query }.merge(parse_suggest_options(options))
|
|
23
|
-
ResultSet.new(post("engines/#{engine_id}/suggest.json", search_params))
|
|
24
|
-
end
|
|
25
|
-
def search(engine_id, query, options={})
|
|
26
|
-
search_params = { :q => query }.merge(parse_search_options(options))
|
|
27
|
-
ResultSet.new(post("engines/#{engine_id}/search.json", search_params))
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
module DocumentType
|
|
32
|
-
def document_types(engine_id)
|
|
33
|
-
get("engines/#{engine_id}/document_types.json")
|
|
34
|
-
end
|
|
35
|
-
def create_document_type(engine_id, document_type={})
|
|
36
|
-
post("engines/#{engine_id}/document_types.json", :document_type => document_type)
|
|
37
|
-
end
|
|
38
|
-
def destroy_document_type(engine_id, document_type_id)
|
|
39
|
-
delete("engines/#{engine_id}/document_types/#{document_type_id}")
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
module Document
|
|
44
|
-
def documents(engine_id, document_type_id)
|
|
45
|
-
get("engines/#{engine_id}/document_types/#{document_type_id}/documents.json")
|
|
46
|
-
end
|
|
47
|
-
def create_document(engine_id, document_type_id, document={})
|
|
48
|
-
post("engines/#{engine_id}/document_types/#{document_type_id}/documents.json", :document => document)
|
|
49
|
-
end
|
|
50
|
-
def create_documents(engine_id, document_type_id, documents=[])
|
|
51
|
-
post("engines/#{engine_id}/document_types/#{document_type_id}/documents/bulk_create.json", :documents => documents)
|
|
52
|
-
end
|
|
53
|
-
def destroy_document(engine_id, document_type_id, document_id)
|
|
54
|
-
delete("engines/#{engine_id}/document_types/#{document_type_id}/documents/#{document_id}")
|
|
55
|
-
end
|
|
56
|
-
def destroy_documents(engine_id, document_type_id, document_ids=[])
|
|
57
|
-
post("engines/#{engine_id}/document_types/#{document_type_id}/documents/bulk_destroy.json", :documents => document_ids)
|
|
58
|
-
end
|
|
59
|
-
def create_or_update_document(engine_id, document_type_id, document={})
|
|
60
|
-
post("engines/#{engine_id}/document_types/#{document_type_id}/documents/create_or_update.json", :document => document)
|
|
61
|
-
end
|
|
62
|
-
def create_or_update_documents(engine_id, document_type_id, documents=[])
|
|
63
|
-
post("engines/#{engine_id}/document_types/#{document_type_id}/documents/bulk_create_or_update.json", :documents => documents)
|
|
64
|
-
end
|
|
65
|
-
def update_document(engine_id, document_type_id, document_id, fields)
|
|
66
|
-
put("engines/#{engine_id}/document_types/#{document_type_id}/documents/#{document_id}/update_fields.json", { :fields => fields })
|
|
67
|
-
end
|
|
68
|
-
def update_documents(engine_id, document_type_id, documents={})
|
|
69
|
-
put("engines/#{engine_id}/document_types/#{document_type_id}/documents/bulk_update.json", { :documents => documents })
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
include Swiftype::Easy::Engine
|
|
74
|
-
include Swiftype::Easy::DocumentType
|
|
75
|
-
include Swiftype::Easy::Document
|
|
76
|
-
end
|
|
77
|
-
end
|
data/lib/swiftype/engine.rb
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
module Swiftype
|
|
2
|
-
class Engine < BaseModel
|
|
3
|
-
def self.find(id)
|
|
4
|
-
new Swiftype::Client.new.get("engines/#{id}.json")
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def build_document_type(params={})
|
|
8
|
-
DocumentType.new({
|
|
9
|
-
:engine_id => id
|
|
10
|
-
}.merge(params))
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def create_document_type(params={})
|
|
14
|
-
doc = build_document_type(params)
|
|
15
|
-
doc.create!
|
|
16
|
-
doc
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def destroy_document_type(document_type_name)
|
|
20
|
-
!!delete("engines/#{slug}/document_types/#{document_type_name}")
|
|
21
|
-
rescue NonExistentRecord
|
|
22
|
-
false
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def document_type(id)
|
|
26
|
-
DocumentType.new get("engines/#{slug}/document_types/#{id}.json")
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def document_types
|
|
30
|
-
get("engines/#{slug}/document_types.json").map { |dt| DocumentType.new(dt) }
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
data/lib/swiftype/search.rb
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
module Swiftype
|
|
2
|
-
module Search
|
|
3
|
-
VALID_SUGGEST_OPTIONS = [:fetch_fields, :search_fields, :filters, :document_types, :functional_boosts, :page, :per_page]
|
|
4
|
-
VALID_SEARCH_OPTIONS = [:fetch_fields, :search_fields, :filters, :document_types, :functional_boosts, :page, :per_page, :sort_field, :sort_direction, :facets]
|
|
5
|
-
|
|
6
|
-
def parse_search_options(options)
|
|
7
|
-
parse_options(options, VALID_SEARCH_OPTIONS)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def parse_suggest_options(options)
|
|
11
|
-
parse_options(options, VALID_SUGGEST_OPTIONS)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def parse_options(options, valid_options)
|
|
15
|
-
parsed_options = {}
|
|
16
|
-
valid_options.each do |option_name|
|
|
17
|
-
next unless options[option_name]
|
|
18
|
-
parsed_options[option_name] = options[option_name]
|
|
19
|
-
end
|
|
20
|
-
parsed_options
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|