constructorio 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4370d4a0766294312355664d6de9d6db03a7c3cf
4
- data.tar.gz: 79c87e8b69acac8e9caa795ec0d661a25284022a
3
+ metadata.gz: fe604fd3ac7fe08978e0e68596eb3af0c2bd4a8f
4
+ data.tar.gz: 3526b15c3f1483066d1dac2347896677934cb8b2
5
5
  SHA512:
6
- metadata.gz: ab32e550be7ffc9e127f25e4993e2385a45829b45436de01bb243f59bf13462cfacbeb12ffc24866107ceffe748593f105d4bd359f3da57e7ed4169fd99f7604
7
- data.tar.gz: 8028246abb04c80e835e1f1c30c3d887ed134f7ac66a06f73218c132f52a9d421b4ef457edf309a459bdf8ea70fb96784ac379b09b1d32ea08ecf9916c60937e
6
+ metadata.gz: ed8737caf068e6702d17e00312e3d241aba25aabc815fec4340e5846593c52b39b7505e6b39a4c74a4ea6b703529d8fe63c7b8f2e134fbf7ff4abaf681c4c8b7
7
+ data.tar.gz: f16564a17ae4a5b5ebd458bf7bb84aca329d14fd0ae6e44706abcc7e142a6b96fa6fabd85b01e26735a650c0fdc7a9a01a9ac03ba995c9621a24bcc61cea7f24
@@ -2,6 +2,17 @@ require 'json'
2
2
 
3
3
  module ConstructorIO
4
4
  class Client
5
+
6
+ attr_accessor :local_configuration
7
+
8
+ def initialize(config = nil)
9
+ @local_configuration = config || ConstructorIO::Configuration.new(
10
+ api_token: ConstructorIO.configuration.api_token,
11
+ api_url: ConstructorIO.configuration.api_url || "https://ac.cnstrc.com/",
12
+ autocomplete_key: ConstructorIO.configuration.autocomplete_key
13
+ )
14
+ end
15
+
5
16
  def add(params)
6
17
  call_api("item", "post", params)
7
18
  end
@@ -33,9 +44,9 @@ module ConstructorIO
33
44
  private
34
45
 
35
46
  def call_api(path, method, params = {})
36
- api_token = ConstructorIO.configuration.api_token
37
- api_url = ConstructorIO.configuration.api_url || "https://ac.cnstrc.com/"
38
- autocomplete_key = ConstructorIO.configuration.autocomplete_key
47
+ api_token = self.local_configuration.api_token
48
+ api_url = self.local_configuration.api_url
49
+ autocomplete_key = self.local_configuration.autocomplete_key
39
50
  @http_client ||= Faraday.new(url: api_url)
40
51
  @http_client.basic_auth(api_token, '')
41
52
 
@@ -1,5 +1,12 @@
1
1
  module ConstructorIO
2
2
  class Configuration
3
3
  attr_accessor :api_token, :autocomplete_key, :api_url
4
+
5
+ def initialize(opts = {})
6
+ self.api_token = opts[:api_token]
7
+ self.api_url = opts[:api_url]
8
+ self.autocomplete_key = opts[:autocomplete_key]
9
+ end
4
10
  end
11
+
5
12
  end
@@ -1,3 +1,3 @@
1
1
  module ConstructorIO
2
- VERSION = "2.0.4"
2
+ VERSION = "2.0.5"
3
3
  end
@@ -10,6 +10,6 @@ class ConfigurationTest < MiniTest::Test
10
10
  end
11
11
 
12
12
  def test_configure_api_url
13
- assert_equal ConstructorIO.configuration.api_url, "http://dev.ac.cnstrc.com"
13
+ assert_equal ConstructorIO.configuration.api_url, "https://devac.cnstrc.com"
14
14
  end
15
15
  end
@@ -25,6 +25,23 @@ class ConstructorIOTest < MiniTest::Test
25
25
  c.add( { item_name: "power drill" } )
26
26
  end
27
27
 
28
+ def test_add_record_sends_request_with_local_config
29
+ c = ConstructorIO::Client.new(ConstructorIO::Configuration.new(
30
+ api_token: "this-api-token",
31
+ autocomplete_key: "this-autocomplete-key",
32
+ api_url: "https://devac.cnstrc.com")
33
+ )
34
+ c.expects(:send_request).with(
35
+ "item",
36
+ "post",
37
+ instance_of(Faraday::Connection),
38
+ { item_name: "power drill" },
39
+ "this-autocomplete-key"
40
+ )
41
+
42
+ c.add( { item_name: "power drill" } )
43
+ end
44
+
28
45
  def test_remove_record_calls_delete
29
46
  c = ConstructorIO::Client.new
30
47
  c.expects(:call_api).with(
@@ -4,6 +4,7 @@ require 'vcr'
4
4
  VCR.configure do |config|
5
5
  config.cassette_library_dir = "test/fixtures/vcr_cassettes"
6
6
  config.hook_into :webmock
7
+ config.default_cassette_options = { :record => :none }
7
8
  end
8
9
 
9
10
  class ConstructorIOVCRTest < MiniTest::Test
@@ -7,24 +7,39 @@ require 'vcr'
7
7
  VCR.configure do |config|
8
8
  config.cassette_library_dir = "test/fixtures/vcr_cassettes"
9
9
  config.hook_into :webmock
10
+ config.default_cassette_options = { :record => :none }
10
11
  end
11
12
 
12
13
  class ConstructorIOVCRTestErrors < MiniTest::Test
13
- def test_add_item_error
14
- ConstructorIO.configure do |config|
15
- config.api_token = "Bad token"
16
- config.autocomplete_key = ENV['CONSTRUCTORIO_AUTOCOMPLETE_KEY'] || "example_autocomplete_key"
17
- config.api_url = "http://dev.ac.cnstrc.com"
14
+ def test_add_item_bad_token_error
15
+ c = ConstructorIO::Client.new(ConstructorIO::Configuration.new(
16
+ api_token: "Bad token",
17
+ autocomplete_key: ENV['CONSTRUCTORIO_AUTOCOMPLETE_KEY'] || "example_autocomplete_key",
18
+ api_url: "https://devac.cnstrc.com")
19
+ )
20
+
21
+ VCR.use_cassette("add_item_error") do
22
+ response = c.add(
23
+ { item_name: "power_drill", autocomplete_section: "standard" }
24
+ )
25
+ assert_equal 401, response.status
26
+ assert_match(/Invalid auth_token. If you've forgotten your token, you can generate a new one in the admin dashboard/, response.body)
18
27
  end
28
+ end
19
29
 
20
- c = ConstructorIO::Client.new
30
+ def test_add_item_bad_key_error
31
+ c = ConstructorIO::Client.new(ConstructorIO::Configuration.new(
32
+ api_token: ENV['CONSTRUCTORIO_API_TOKEN'] || "example_api_token",
33
+ autocomplete_key: "bad_autocomplete_key",
34
+ api_url: "https://devac.cnstrc.com")
35
+ )
21
36
 
22
37
  VCR.use_cassette("add_item_error") do
23
38
  response = c.add(
24
39
  { item_name: "power_drill", autocomplete_section: "standard" }
25
40
  )
26
41
  assert_equal 401, response.status
27
- assert_match /Invalid auth_token. If you've forgotten your token, you can generate a new one in the admin dashboard/, response.body
42
+ assert_match(/You have supplied an invalid autocomplete key. Look up your valid autocomplete key in your admin dashboard/, response.body)
28
43
  end
29
44
  end
30
45
  end
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: post
5
- uri: http://IC9WGYro9O8o5orJW7p2:@dev.ac.cnstrc.com/v1/item?autocomplete_key=Du08voCN2t3IKdUhSepw
5
+ uri: https://example_api_token:@devac.cnstrc.com/v1/item?autocomplete_key=example_autocomplete_key
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"item_name":"power_drill","autocomplete_section":"standard"}'
@@ -20,30 +20,32 @@ http_interactions:
20
20
  code: 204
21
21
  message: NO CONTENT
22
22
  headers:
23
- Server:
24
- - nginx/1.4.6 (Ubuntu)
25
- Content-Type:
26
- - text/html; charset=utf-8
27
- Content-Length:
28
- - '0'
29
- Set-Cookie:
30
- - session=eyJwd19oYXNoIjp7IiBiIjoiSkRKaEpEQTRKRkpQY1RkNGJGSnlOeTlzWXpaVFYzWkNjbFYyUkM1YVZqQXlZMjlUVVM5b05DNVZhRlJUVG5Bek5XSlZVVFZ0UXpobWNrd3kifX0.CLlrcA.PcmF6orlyXrxZhE4eQQPN6Q4hn4;
31
- HttpOnly; Path=/
32
23
  Accept-Ranges:
33
24
  - bytes
34
- Date:
35
- - Sat, 22 Aug 2015 02:09:52 GMT
36
- X-Varnish:
37
- - '1173375154'
38
25
  Age:
39
26
  - '0'
27
+ Content-Length:
28
+ - '0'
29
+ Content-Type:
30
+ - text/html; charset=utf-8
31
+ Date:
32
+ - Fri, 16 Oct 2015 16:31:30 GMT
33
+ Server:
34
+ - nginx/1.4.6 (Ubuntu)
35
+ Set-Cookie:
36
+ - session=eyJwd19oYXNoIjp7IiBiIjoiSkRKaEpEQTRKRkpQY1RkNGJGSnlOeTlzWXpaVFYzWkNjbFYyUkM1YVZqQXlZMjlUVVM5b05DNVZhRlJUVG5Bek5XSlZVVFZ0UXpobWNrd3kifX0.CQK34g.J6XoEQJTyZV5ngAmVgSsYthAz0c;
37
+ HttpOnly; Path=/
38
+ Strict-Transport-Security:
39
+ - max-age=31536000
40
40
  Via:
41
41
  - 1.1 varnish
42
+ X-Varnish:
43
+ - '1717338774'
42
44
  Connection:
43
45
  - keep-alive
44
46
  body:
45
47
  encoding: UTF-8
46
48
  string: ''
47
49
  http_version:
48
- recorded_at: Sat, 22 Aug 2015 02:09:52 GMT
50
+ recorded_at: Fri, 16 Oct 2015 16:31:27 GMT
49
51
  recorded_with: VCR 2.9.3
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: post
5
- uri: http://Bad%20token:@dev.ac.cnstrc.com/v1/item?autocomplete_key=Du08voCN2t3IKdUhSepw
5
+ uri: https://Bad%20token:@devac.cnstrc.com/v1/item?autocomplete_key=example_autocomplete_key
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"item_name":"power_drill","autocomplete_section":"standard"}'
@@ -20,30 +20,80 @@ http_interactions:
20
20
  code: 401
21
21
  message: UNAUTHORIZED
22
22
  headers:
23
- Server:
24
- - nginx/1.4.6 (Ubuntu)
23
+ Accept-Ranges:
24
+ - bytes
25
+ Age:
26
+ - '0'
25
27
  Content-Type:
26
28
  - application/json
29
+ Date:
30
+ - Fri, 16 Oct 2015 16:38:59 GMT
31
+ Server:
32
+ - nginx/1.4.6 (Ubuntu)
33
+ Strict-Transport-Security:
34
+ - max-age=31536000
35
+ Via:
36
+ - 1.1 varnish
37
+ X-Varnish:
38
+ - '1717338970'
27
39
  Content-Length:
28
40
  - '120'
41
+ Connection:
42
+ - keep-alive
43
+ body:
44
+ encoding: UTF-8
45
+ string: |-
46
+ {
47
+ "message": "Invalid auth_token. If you've forgotten your token, you can generate a new one in the admin dashboard"
48
+ }
49
+ http_version:
50
+ recorded_at: Fri, 16 Oct 2015 16:38:57 GMT
51
+ - request:
52
+ method: post
53
+ uri: https://example_api_token:@devac.cnstrc.com/v1/item?autocomplete_key=bad_autocomplete_key
54
+ body:
55
+ encoding: UTF-8
56
+ string: '{"item_name":"power_drill","autocomplete_section":"standard"}'
57
+ headers:
58
+ User-Agent:
59
+ - Faraday v0.9.1
60
+ Content-Type:
61
+ - application/json
62
+ Accept-Encoding:
63
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
64
+ Accept:
65
+ - "*/*"
66
+ response:
67
+ status:
68
+ code: 401
69
+ message: UNAUTHORIZED
70
+ headers:
29
71
  Accept-Ranges:
30
72
  - bytes
31
- Date:
32
- - Sat, 22 Aug 2015 02:50:30 GMT
33
- X-Varnish:
34
- - '1173375167'
35
73
  Age:
36
74
  - '0'
75
+ Content-Type:
76
+ - application/json
77
+ Date:
78
+ - Fri, 16 Oct 2015 16:40:14 GMT
79
+ Server:
80
+ - nginx/1.4.6 (Ubuntu)
81
+ Strict-Transport-Security:
82
+ - max-age=31536000
37
83
  Via:
38
84
  - 1.1 varnish
85
+ X-Varnish:
86
+ - '1717338996'
87
+ Content-Length:
88
+ - '126'
39
89
  Connection:
40
90
  - keep-alive
41
91
  body:
42
92
  encoding: UTF-8
43
93
  string: |-
44
94
  {
45
- "message": "Invalid auth_token. If you've forgotten your token, you can generate a new one in the admin dashboard"
95
+ "message": "You have supplied an invalid autocomplete key. Look up your valid autocomplete key in your admin dashboard."
46
96
  }
47
97
  http_version:
48
- recorded_at: Sat, 22 Aug 2015 02:50:31 GMT
98
+ recorded_at: Fri, 16 Oct 2015 16:40:11 GMT
49
99
  recorded_with: VCR 2.9.3
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: delete
5
- uri: http://IC9WGYro9O8o5orJW7p2:@dev.ac.cnstrc.com/v1/item?autocomplete_key=Du08voCN2t3IKdUhSepw
5
+ uri: https://example_api_token:@devac.cnstrc.com/v1/item?autocomplete_key=example_autocomplete_key
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"item_name":"power_drill","autocomplete_section":"standard","suggested_score":10}'
@@ -20,30 +20,32 @@ http_interactions:
20
20
  code: 204
21
21
  message: NO CONTENT
22
22
  headers:
23
- Server:
24
- - nginx/1.4.6 (Ubuntu)
25
- Content-Type:
26
- - text/html; charset=utf-8
27
- Content-Length:
28
- - '0'
29
- Set-Cookie:
30
- - session=eyJwd19oYXNoIjp7IiBiIjoiSkRKaEpEQTRKRkpQY1RkNGJGSnlOeTlzWXpaVFYzWkNjbFYyUkM1YVZqQXlZMjlUVVM5b05DNVZhRlJUVG5Bek5XSlZVVFZ0UXpobWNrd3kifX0.CLlsOQ.-AKI1lmN4lNo6I5A2d1mKjswwik;
31
- HttpOnly; Path=/
32
23
  Accept-Ranges:
33
24
  - bytes
34
- Date:
35
- - Sat, 22 Aug 2015 02:13:13 GMT
36
- X-Varnish:
37
- - '1173375164'
38
25
  Age:
39
26
  - '0'
27
+ Content-Length:
28
+ - '0'
29
+ Content-Type:
30
+ - text/html; charset=utf-8
31
+ Date:
32
+ - Fri, 16 Oct 2015 16:32:45 GMT
33
+ Server:
34
+ - nginx/1.4.6 (Ubuntu)
35
+ Set-Cookie:
36
+ - session=eyJwd19oYXNoIjp7IiBiIjoiSkRKaEpEQTRKRkpQY1RkNGJGSnlOeTlzWXpaVFYzWkNjbFYyUkM1YVZqQXlZMjlUVVM5b05DNVZhRlJUVG5Bek5XSlZVVFZ0UXpobWNrd3kifX0.CQK4LQ.pCfOTI1WpHfQS43FrXjaoC69dE4;
37
+ HttpOnly; Path=/
38
+ Strict-Transport-Security:
39
+ - max-age=31536000
40
40
  Via:
41
41
  - 1.1 varnish
42
+ X-Varnish:
43
+ - '1717338812'
42
44
  Connection:
43
45
  - keep-alive
44
46
  body:
45
47
  encoding: UTF-8
46
48
  string: ''
47
49
  http_version:
48
- recorded_at: Sat, 22 Aug 2015 02:13:14 GMT
50
+ recorded_at: Fri, 16 Oct 2015 16:32:42 GMT
49
51
  recorded_with: VCR 2.9.3
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: delete
5
- uri: http://IC9WGYro9O8o5orJW7p2:@dev.ac.cnstrc.com/v1/item?autocomplete_key=Du08voCN2t3IKdUhSepw
5
+ uri: https://example_api_token:@devac.cnstrc.com/v1/item?autocomplete_key=example_autocomplete_key
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"item_name":"power_drill","autocomplete_section":"standard"}'
@@ -20,30 +20,32 @@ http_interactions:
20
20
  code: 204
21
21
  message: NO CONTENT
22
22
  headers:
23
- Server:
24
- - nginx/1.4.6 (Ubuntu)
25
- Content-Type:
26
- - text/html; charset=utf-8
27
- Content-Length:
28
- - '0'
29
- Set-Cookie:
30
- - session=eyJwd19oYXNoIjp7IiBiIjoiSkRKaEpEQTRKRkpQY1RkNGJGSnlOeTlzWXpaVFYzWkNjbFYyUkM1YVZqQXlZMjlUVVM5b05DNVZhRlJUVG5Bek5XSlZVVFZ0UXpobWNrd3kifX0.CLlr-g.sNGaLdVDC52vovPDfy1tOxSuNfc;
31
- HttpOnly; Path=/
32
23
  Accept-Ranges:
33
24
  - bytes
34
- Date:
35
- - Sat, 22 Aug 2015 02:12:10 GMT
36
- X-Varnish:
37
- - '1173375163'
38
25
  Age:
39
26
  - '0'
27
+ Content-Length:
28
+ - '0'
29
+ Content-Type:
30
+ - text/html; charset=utf-8
31
+ Date:
32
+ - Fri, 16 Oct 2015 16:32:33 GMT
33
+ Server:
34
+ - nginx/1.4.6 (Ubuntu)
35
+ Set-Cookie:
36
+ - session=eyJwd19oYXNoIjp7IiBiIjoiSkRKaEpEQTRKRkpQY1RkNGJGSnlOeTlzWXpaVFYzWkNjbFYyUkM1YVZqQXlZMjlUVVM5b05DNVZhRlJUVG5Bek5XSlZVVFZ0UXpobWNrd3kifX0.CQK4IQ.H03aEqDi2KY5OCpQiI02AdxSZ00;
37
+ HttpOnly; Path=/
38
+ Strict-Transport-Security:
39
+ - max-age=31536000
40
40
  Via:
41
41
  - 1.1 varnish
42
+ X-Varnish:
43
+ - '1717338807'
42
44
  Connection:
43
45
  - keep-alive
44
46
  body:
45
47
  encoding: UTF-8
46
48
  string: ''
47
49
  http_version:
48
- recorded_at: Sat, 22 Aug 2015 02:12:10 GMT
50
+ recorded_at: Fri, 16 Oct 2015 16:32:30 GMT
49
51
  recorded_with: VCR 2.9.3
data/test/test_helper.rb CHANGED
@@ -6,5 +6,5 @@ require_relative '../lib/constructorio'
6
6
  ConstructorIO.configure do |config|
7
7
  config.api_token = ENV['CONSTRUCTORIO_API_TOKEN'] || "example_api_token"
8
8
  config.autocomplete_key = ENV['CONSTRUCTORIO_AUTOCOMPLETE_KEY'] || "example_autocomplete_key"
9
- config.api_url = "http://dev.ac.cnstrc.com"
9
+ config.api_url = "https://devac.cnstrc.com"
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constructorio
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan McCormick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-14 00:00:00.000000000 Z
11
+ date: 2015-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday