swiftype 0.0.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/.gitignore +5 -0
  2. data/.travis.yml +6 -0
  3. data/Gemfile +1 -1
  4. data/README.md +202 -283
  5. data/lib/data/ca-bundle.crt +3554 -0
  6. data/lib/swiftype.rb +7 -31
  7. data/lib/swiftype/client.rb +439 -11
  8. data/lib/swiftype/configuration.rb +29 -4
  9. data/lib/swiftype/exceptions.rb +2 -0
  10. data/lib/swiftype/ext/backport-uri.rb +33 -0
  11. data/lib/swiftype/request.rb +88 -20
  12. data/lib/swiftype/result_set.rb +43 -6
  13. data/lib/swiftype/sso.rb +20 -0
  14. data/lib/swiftype/version.rb +1 -1
  15. data/spec/client_spec.rb +576 -0
  16. data/spec/configuration_spec.rb +36 -0
  17. data/spec/deprecated_spec.rb +20 -0
  18. data/spec/fixtures/vcr/analytics_autoselects.yml +55 -0
  19. data/spec/fixtures/vcr/analytics_autoselects_with_document_type.yml +55 -0
  20. data/spec/fixtures/vcr/analytics_autoselects_with_document_type_and_time_range.yml +55 -0
  21. data/spec/fixtures/vcr/analytics_autoselects_with_time_range.yml +55 -0
  22. data/spec/fixtures/vcr/analytics_clicks.yml +55 -0
  23. data/spec/fixtures/vcr/analytics_clicks_with_document_type.yml +55 -0
  24. data/spec/fixtures/vcr/analytics_clicks_with_document_type_and_time_range.yml +55 -0
  25. data/spec/fixtures/vcr/analytics_clicks_with_time_range.yml +55 -0
  26. data/spec/fixtures/vcr/analytics_searches.yml +55 -0
  27. data/spec/fixtures/vcr/analytics_searches_with_document_type_and_time_range.yml +55 -0
  28. data/spec/fixtures/vcr/analytics_searches_with_time_range.yml +55 -0
  29. data/spec/fixtures/vcr/analytics_searchs_with_document_type.yml +55 -0
  30. data/spec/fixtures/vcr/analytics_top_no_result_queries.yml +55 -0
  31. data/spec/fixtures/vcr/analytics_top_no_result_queries_paginated.yml +55 -0
  32. data/spec/fixtures/vcr/analytics_top_queries.yml +55 -0
  33. data/spec/fixtures/vcr/analytics_top_queries_paginated.yml +55 -0
  34. data/spec/fixtures/vcr/analytics_top_queries_too_large.yml +51 -0
  35. data/spec/fixtures/vcr/bulk_create_documents.yml +49 -0
  36. data/spec/fixtures/vcr/bulk_create_or_update_documents_failure.yml +45 -0
  37. data/spec/fixtures/vcr/bulk_create_or_update_documents_success.yml +49 -0
  38. data/spec/fixtures/vcr/bulk_destroy_documents.yml +45 -0
  39. data/spec/fixtures/vcr/crawl_url.yml +45 -0
  40. data/spec/fixtures/vcr/create_document.yml +48 -0
  41. data/spec/fixtures/vcr/create_document_type.yml +45 -0
  42. data/spec/fixtures/vcr/create_domain.yml +45 -0
  43. data/spec/fixtures/vcr/create_engine.yml +45 -0
  44. data/spec/fixtures/vcr/create_or_update_document_create.yml +47 -0
  45. data/spec/fixtures/vcr/create_or_update_document_update.yml +47 -0
  46. data/spec/fixtures/vcr/create_user.yml +45 -0
  47. data/spec/fixtures/vcr/destroy_document.yml +41 -0
  48. data/spec/fixtures/vcr/destroy_document_type.yml +41 -0
  49. data/spec/fixtures/vcr/destroy_domain.yml +41 -0
  50. data/spec/fixtures/vcr/destroy_engine.yml +41 -0
  51. data/spec/fixtures/vcr/destroy_non_existent_document_type.yml +43 -0
  52. data/spec/fixtures/vcr/document_type_search.yml +60 -0
  53. data/spec/fixtures/vcr/document_type_search_pagination.yml +45 -0
  54. data/spec/fixtures/vcr/document_type_suggest.yml +50 -0
  55. data/spec/fixtures/vcr/document_type_suggest_pagination.yml +45 -0
  56. data/spec/fixtures/vcr/engine_search.yml +64 -0
  57. data/spec/fixtures/vcr/engine_search_facets.yml +162 -0
  58. data/spec/fixtures/vcr/engine_search_pagination.yml +45 -0
  59. data/spec/fixtures/vcr/engine_suggest.yml +52 -0
  60. data/spec/fixtures/vcr/engine_suggest_pagination.yml +45 -0
  61. data/spec/fixtures/vcr/find_document.yml +47 -0
  62. data/spec/fixtures/vcr/find_document_type.yml +45 -0
  63. data/spec/fixtures/vcr/find_domain.yml +45 -0
  64. data/spec/fixtures/vcr/find_domain_failure.yml +43 -0
  65. data/spec/fixtures/vcr/find_engine.yml +45 -0
  66. data/spec/fixtures/vcr/list_document_type.yml +45 -0
  67. data/spec/fixtures/vcr/list_documents.yml +68 -0
  68. data/spec/fixtures/vcr/list_documents_with_pagination.yml +68 -0
  69. data/spec/fixtures/vcr/list_domains.yml +45 -0
  70. data/spec/fixtures/vcr/list_engines.yml +46 -0
  71. data/spec/fixtures/vcr/list_users.yml +45 -0
  72. data/spec/fixtures/vcr/list_users_with_pagination.yml +45 -0
  73. data/spec/fixtures/vcr/log_clickthrough_failure.yml +43 -0
  74. data/spec/fixtures/vcr/log_clickthrough_success.yml +45 -0
  75. data/spec/fixtures/vcr/recrawl_domain_failure.yml +44 -0
  76. data/spec/fixtures/vcr/recrawl_domain_success.yml +45 -0
  77. data/spec/fixtures/vcr/show_user.yml +45 -0
  78. data/spec/fixtures/vcr/update_document.yml +47 -0
  79. data/spec/fixtures/vcr/update_document_unknown_field_failure.yml +45 -0
  80. data/spec/fixtures/vcr/update_documents_failure_non_existent_document.yml +45 -0
  81. data/spec/fixtures/vcr/update_documents_success.yml +45 -0
  82. data/spec/fixtures/vcr/users_client_secret_incorrect.yml +42 -0
  83. data/spec/fixtures/vcr/users_no_api_key.yml +42 -0
  84. data/spec/fixtures/vcr/users_no_client_id_or_secret.yml +43 -0
  85. data/spec/platform_spec.rb +95 -0
  86. data/spec/spec_helper.rb +26 -0
  87. data/spec/ssl_spec.rb +34 -0
  88. data/spec/sso_spec.rb +24 -0
  89. data/swiftype.gemspec +10 -11
  90. metadata +183 -52
  91. data/lib/swiftype/base_model.rb +0 -89
  92. data/lib/swiftype/connection.rb +0 -47
  93. data/lib/swiftype/document.rb +0 -17
  94. data/lib/swiftype/document_type.rb +0 -69
  95. data/lib/swiftype/easy.rb +0 -77
  96. data/lib/swiftype/engine.rb +0 -33
  97. data/lib/swiftype/search.rb +0 -23
@@ -0,0 +1,45 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: http://hello:@localhost:3000/api/v1/engines/swiftype-api-example/document_types/videos/documents/FtX8nswnUKU/update_fields.json
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"fields":{"not_a_field":"not a field"}}'
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Swiftype-Ruby/1.0.0
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 400
19
+ message: Bad Request
20
+ headers:
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ X-Ua-Compatible:
24
+ - IE=Edge
25
+ Cache-Control:
26
+ - no-cache
27
+ Set-Cookie:
28
+ - _session_id=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJTAyNzA5MzQyMWU1YjAxMzQ4NDVkNGMxNDIxZWUyZmFhBjsAVEkiGXdhcmRlbi51c2VyLnVzZXIua2V5BjsAVFsISSIJVXNlcgY7AEZbBlU6Gk1vcGVkOjpCU09OOjpPYmplY3RJZCIRUDg5%2By7ZYCnHAAABSSIiJDJhJDEwJE1rNmZOdHA1cC9ZNVIuQU5sZFB2UWUGOwBU--2f8beaf078c885a87f8fe33dc37fff06995d1993;
29
+ path=/; HttpOnly
30
+ X-Request-Id:
31
+ - 0ee335dac175f232bf27d29dc65cc45a
32
+ X-Runtime:
33
+ - '0.034146'
34
+ Connection:
35
+ - close
36
+ Server:
37
+ - thin 1.5.0 codename Knife
38
+ body:
39
+ encoding: US-ASCII
40
+ string: ! '{"error":"Error updating field(s). Attempt to set() nonexistent key. Known
41
+ keys are: url, thumbnail_url, channel_id, title, caption, category_name, category_id,
42
+ published_at, duration, view_count, like_count"}'
43
+ http_version:
44
+ recorded_at: Thu, 12 Sep 2013 22:40:58 GMT
45
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,45 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: http://hello:@localhost:3000/api/v1/engines/swiftype-api-example/document_types/videos/documents/bulk_update.json
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"documents":[{"external_id":"not_there","fields":[{"name":"title","value":"hi","type":"string"}]}]}'
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Swiftype-Ruby/1.0.0
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ X-Ua-Compatible:
24
+ - IE=Edge
25
+ Etag:
26
+ - ! '"f9e544f77b7eac7add281ef28ca5559f"'
27
+ Cache-Control:
28
+ - max-age=0, private, must-revalidate
29
+ Set-Cookie:
30
+ - _session_id=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJTkzYTQ3NTIwNGRmMWY3MTkyMDVmNGZiZTM3ZWU1ZDQyBjsAVEkiGXdhcmRlbi51c2VyLnVzZXIua2V5BjsAVFsISSIJVXNlcgY7AEZbBlU6Gk1vcGVkOjpCU09OOjpPYmplY3RJZCIRUDg5%2By7ZYCnHAAABSSIiJDJhJDEwJE1rNmZOdHA1cC9ZNVIuQU5sZFB2UWUGOwBU--8efc561386be1984b12246d0ab067933720a0179;
31
+ path=/; HttpOnly
32
+ X-Request-Id:
33
+ - a9fd5dc44eb51d4a7d37fd53b165ba3a
34
+ X-Runtime:
35
+ - '0.150458'
36
+ Connection:
37
+ - close
38
+ Server:
39
+ - thin 1.5.0 codename Knife
40
+ body:
41
+ encoding: US-ASCII
42
+ string: ! '[false]'
43
+ http_version:
44
+ recorded_at: Thu, 12 Sep 2013 22:46:53 GMT
45
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,45 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: http://hello:@localhost:3000/api/v1/engines/swiftype-api-example/document_types/videos/documents/bulk_update.json
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"documents":[{"external_id":"INscMGmhmX4","fields":{"title":"hi"}},{"external_id":"XfY9Dsg_DZk","fields":{"title":"bye"}}]}'
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Swiftype-Ruby/1.0.0
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ X-Ua-Compatible:
24
+ - IE=Edge
25
+ Etag:
26
+ - ! '"bb009c6dcb5c622766ad5aa1ea1562d9"'
27
+ Cache-Control:
28
+ - max-age=0, private, must-revalidate
29
+ Set-Cookie:
30
+ - _session_id=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWM1YzRmN2EwYjg5NzU5YjU3MDE4ZTg0OWUyMzc0ZWU3BjsAVEkiGXdhcmRlbi51c2VyLnVzZXIua2V5BjsAVFsISSIJVXNlcgY7AEZbBlU6Gk1vcGVkOjpCU09OOjpPYmplY3RJZCIRUDg5%2By7ZYCnHAAABSSIiJDJhJDEwJE1rNmZOdHA1cC9ZNVIuQU5sZFB2UWUGOwBU--f928b9637411dd24c049b64c4bb0ca7455bb0508;
31
+ path=/; HttpOnly
32
+ X-Request-Id:
33
+ - 904d7bc728da1bbcb64649cbfb310078
34
+ X-Runtime:
35
+ - '0.062213'
36
+ Connection:
37
+ - close
38
+ Server:
39
+ - thin 1.5.0 codename Knife
40
+ body:
41
+ encoding: US-ASCII
42
+ string: ! '[true,true]'
43
+ http_version:
44
+ recorded_at: Thu, 12 Sep 2013 22:57:05 GMT
45
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:3000/api/v1/users.json?client_id=0d94f7cf2bd1e65a7e1f9f929d1bcb2b248af69b8112d24484e87014125538f8&client_secret=wrong
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Swiftype-Ruby/1.0.0
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 401
19
+ message: Unauthorized
20
+ headers:
21
+ Www-Authenticate:
22
+ - Basic realm="Swiftype"
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ X-Ua-Compatible:
26
+ - IE=Edge
27
+ Cache-Control:
28
+ - no-cache
29
+ X-Request-Id:
30
+ - 3605ea2e9f85f5b74652d7bade07e97a
31
+ X-Runtime:
32
+ - '0.013547'
33
+ Connection:
34
+ - close
35
+ Server:
36
+ - thin 1.5.0 codename Knife
37
+ body:
38
+ encoding: US-ASCII
39
+ string: ! '{"error":"You need to sign in or sign up before continuing."}'
40
+ http_version:
41
+ recorded_at: Fri, 13 Sep 2013 00:53:23 GMT
42
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:3000/api/v1/users.json?client_id=0d94f7cf2bd1e65a7e1f9f929d1bcb2b248af69b8112d24484e87014125538f8&client_secret=f600fb0b16b516cbb9b9f0eeb60f3b35f685b5ec4a94694ae57b5bbb8860f240
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Swiftype-Ruby/1.0.0
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 401
19
+ message: Unauthorized
20
+ headers:
21
+ Www-Authenticate:
22
+ - Basic realm="Swiftype"
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ X-Ua-Compatible:
26
+ - IE=Edge
27
+ Cache-Control:
28
+ - no-cache
29
+ X-Request-Id:
30
+ - 29b283e021cb39b78c9b6ef0c06ec041
31
+ X-Runtime:
32
+ - '0.015617'
33
+ Connection:
34
+ - close
35
+ Server:
36
+ - thin 1.5.0 codename Knife
37
+ body:
38
+ encoding: US-ASCII
39
+ string: ! '{"error":"You need to sign in or sign up before continuing."}'
40
+ http_version:
41
+ recorded_at: Fri, 13 Sep 2013 00:53:23 GMT
42
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://hello:@localhost:3000/api/v1/users.json?client_id&client_secret
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Swiftype-Ruby/1.0.0
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 400
19
+ message: Bad Request
20
+ headers:
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ X-Ua-Compatible:
24
+ - IE=Edge
25
+ Cache-Control:
26
+ - no-cache
27
+ Set-Cookie:
28
+ - _session_id=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJTllNTAzNzFlZDcwYWFhOWQ4MGRiOGYzMTkxMDUzODgzBjsAVEkiGXdhcmRlbi51c2VyLnVzZXIua2V5BjsAVFsISSIJVXNlcgY7AEZbBlU6Gk1vcGVkOjpCU09OOjpPYmplY3RJZCIRUDg5%2By7ZYCnHAAABSSIiJDJhJDEwJE1rNmZOdHA1cC9ZNVIuQU5sZFB2UWUGOwBU--3a3ffdd780afdce5468176fe6593400bdc28ab0e;
29
+ path=/; HttpOnly
30
+ X-Request-Id:
31
+ - afbbf899940811879d2af25a041fa397
32
+ X-Runtime:
33
+ - '0.026651'
34
+ Connection:
35
+ - close
36
+ Server:
37
+ - thin 1.5.0 codename Knife
38
+ body:
39
+ encoding: US-ASCII
40
+ string: ! '{"error":"Missing required parameter: client_id"}'
41
+ http_version:
42
+ recorded_at: Fri, 13 Sep 2013 00:53:23 GMT
43
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'platform user API' do
4
+ let(:client) { Swiftype::Client.new }
5
+
6
+ context 'authentication' do
7
+ it 'succeeds with api_key and correct client_id and client_secret' do
8
+ Swiftype.api_key = 'hello'
9
+ Swiftype.platform_client_id = '0d94f7cf2bd1e65a7e1f9f929d1bcb2b248af69b8112d24484e87014125538f8'
10
+ Swiftype.platform_client_secret = 'f600fb0b16b516cbb9b9f0eeb60f3b35f685b5ec4a94694ae57b5bbb8860f240'
11
+
12
+ VCR.use_cassette('list_users') do
13
+ expect do
14
+ client.users
15
+ end.to_not raise_error
16
+ end
17
+ end
18
+
19
+ it 'fails without api_key' do
20
+ Swiftype.platform_client_id = '0d94f7cf2bd1e65a7e1f9f929d1bcb2b248af69b8112d24484e87014125538f8'
21
+ Swiftype.platform_client_secret = 'f600fb0b16b516cbb9b9f0eeb60f3b35f685b5ec4a94694ae57b5bbb8860f240'
22
+
23
+ VCR.use_cassette('users_no_api_key') do
24
+ expect do
25
+ client.users
26
+ end.to raise_error
27
+ end
28
+ end
29
+
30
+ it 'fails with missing client_id and client_secret' do
31
+ Swiftype.api_key = 'hello'
32
+
33
+ VCR.use_cassette('users_no_client_id_or_secret') do
34
+ expect do
35
+ client.users
36
+ end.to raise_error
37
+ end
38
+ end
39
+
40
+ it 'fails with incorrect client_secret' do
41
+ Swiftype.platform_client_id = '0d94f7cf2bd1e65a7e1f9f929d1bcb2b248af69b8112d24484e87014125538f8'
42
+ Swiftype.platform_client_secret = 'wrong'
43
+
44
+ VCR.use_cassette('users_client_secret_incorrect') do
45
+ expect do
46
+ client.users
47
+ end.to raise_error
48
+ end
49
+ end
50
+ end
51
+
52
+ context 'with proper authentication' do
53
+ before :each do
54
+ Swiftype.api_key = 'hello'
55
+ Swiftype.platform_client_id = '0d94f7cf2bd1e65a7e1f9f929d1bcb2b248af69b8112d24484e87014125538f8'
56
+ Swiftype.platform_client_secret = 'f600fb0b16b516cbb9b9f0eeb60f3b35f685b5ec4a94694ae57b5bbb8860f240'
57
+ end
58
+
59
+ context 'creating a user' do
60
+ it 'returns a Hash with user info' do
61
+ VCR.use_cassette('create_user') do
62
+ user = client.create_user
63
+ user.should have_key('id')
64
+ user.should have_key('access_token')
65
+ end
66
+ end
67
+ end
68
+
69
+ context 'listing users' do
70
+ it 'returns the first page of users' do
71
+ VCR.use_cassette('list_users') do
72
+ users = client.users
73
+ users.length.should == 3
74
+ end
75
+ end
76
+
77
+ it 'returns an empty list of users once you page past the end' do
78
+ VCR.use_cassette('list_users_with_pagination') do
79
+ users = client.users(:page => 2)
80
+ users.length.should == 0
81
+ end
82
+ end
83
+ end
84
+
85
+ context 'showing a user' do
86
+ it 'returns a Hash with user info' do
87
+ VCR.use_cassette('show_user') do
88
+ user = client.user('5230b8c82ed960ba2000001d')
89
+ user['id'].should == '5230b8c82ed960ba2000001d'
90
+ user['access_token'].should == '0381294b7ef41db44fba20aad86a52d294b9fae67a26e85139d323eb78106706'
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,26 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ require 'vcr'
4
+ require 'awesome_print'
5
+ require 'swiftype'
6
+
7
+ RSpec.configure do |config|
8
+ # Run specs in random order to surface order dependencies. If you find an
9
+ # order dependency and want to debug it, you can fix the order by providing
10
+ # the seed, which is printed after each run.
11
+ # --seed 1234
12
+ config.order = "random"
13
+
14
+ VCR.configure do |c|
15
+ c.cassette_library_dir = 'spec/fixtures/vcr'
16
+ c.hook_into :webmock
17
+ end
18
+
19
+ config.before :each do
20
+ Swiftype.endpoint = "http://localhost:3000/api/v1/"
21
+ end
22
+
23
+ config.after :each do
24
+ Swiftype.reset
25
+ end
26
+ end
data/spec/ssl_spec.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ # These tests use real network connections to test the SSL
4
+ # support. Since a real API key is not used, the success condition is
5
+ # that the connection was made and the approriate error message is
6
+ # returned from the API
7
+ describe 'SSL support' do
8
+ let(:client) { Swiftype::Client.new }
9
+
10
+ context 'when the endpoint is configured to use SSL' do
11
+ it 'connects successfully' do
12
+ Swiftype.endpoint = 'https://api.swiftype.com/api/v1/'
13
+
14
+ VCR.turned_off do
15
+ WebMock.allow_net_connect!
16
+ expect do
17
+ client.search('swiftype-api-example', 'test')
18
+ end.to raise_error(Swiftype::InvalidCredentials)
19
+ end
20
+ end
21
+ end
22
+
23
+ context 'when the endpoint is configured not to use SSL' do
24
+ it 'connects successfully' do
25
+ Swiftype.endpoint = 'http://api.swiftype.com/api/v1/'
26
+ VCR.turned_off do
27
+ WebMock.allow_net_connect!
28
+ expect do
29
+ client.search('swiftype-api-example', 'test')
30
+ end.to raise_error(Swiftype::InvalidCredentials)
31
+ end
32
+ end
33
+ end
34
+ end
data/spec/sso_spec.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Swiftype::SSO do
4
+ let(:user_id) { '5064a7de2ed960e715000276' }
5
+ let(:timestamp) { 1379382520 }
6
+ before :each do
7
+ Swiftype.platform_client_id = '3e4fd842fc99aecb4dc50e5b88a186c1e206ddd516cdd336da3622c4afd7e2e9'
8
+ Swiftype.platform_client_secret = '4441879b5e2a9c3271f5b1a4bc223b715f091e5ed20fe75d1352e1290c7a6dfb'
9
+
10
+ Time.any_instance.stub(:to_i).and_return(timestamp)
11
+ end
12
+
13
+ context '.token' do
14
+ it 'generates an SSO token' do
15
+ Swiftype::SSO.token(user_id, timestamp).should == '81033d182ad51f231cc9cda9fb24f2298a411437'
16
+ end
17
+ end
18
+
19
+ context '.url' do
20
+ it 'generates an SSO URL' do
21
+ Swiftype::SSO.url(user_id).should == 'https://swiftype.com/sso?user_id=5064a7de2ed960e715000276&client_id=3e4fd842fc99aecb4dc50e5b88a186c1e206ddd516cdd336da3622c4afd7e2e9&timestamp=1379382520&token=81033d182ad51f231cc9cda9fb24f2298a411437'
22
+ end
23
+ end
24
+ end