attune 1.0.11 → 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +2 -0
- data/blacklist.md +8 -5
- data/lib/attune/client.rb +26 -1
- data/lib/attune/configurable.rb +9 -1
- data/lib/attune/default.rb +0 -25
- data/lib/attune/version.rb +1 -1
- data/spec/attune/client_spec.rb +0 -1
- data/spec/remote_spec.rb +31 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3864ecede09a3148c23d49737275d5c49486b6b0
|
4
|
+
data.tar.gz: 42197d4441dec9a6ba768c83323888f9c475429e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec73bb2719d24b224d44beae11f2bd66a3b78676e57ec311fa0419ac24de71d82ed0868db15e21d9b94b5c746b30a94a87a10b06f103a5e93d79ec16d7e4120a
|
7
|
+
data.tar.gz: 94e15e68ff09a9add6a480ccbc2a2b9e17fc4cedf30f5635a4f5d0cea59560529a6160c034b9934ad63007c0882110f95f3b7ddbfee71141443d32574f6621b5
|
data/.yardopts
CHANGED
data/blacklist.md
CHANGED
@@ -10,9 +10,10 @@ scope = Attune::Model::ScopeEntry.new
|
|
10
10
|
scope.name = 'page'
|
11
11
|
scope.value = 'sale'
|
12
12
|
params.scope = [scope]
|
13
|
-
params.active_from =
|
14
|
-
params.active_to =
|
15
|
-
client.entities.blacklist_save(params)
|
13
|
+
params.active_from = DateTime.now
|
14
|
+
params.active_to = DateTime.now + 7
|
15
|
+
response = client.entities.blacklist_save(params)
|
16
|
+
blacklist_id = response.id
|
16
17
|
```
|
17
18
|
|
18
19
|
## Retrieve a blacklist entry
|
@@ -26,7 +27,7 @@ blacklist = client.entities.blacklist_get(blacklist_id)
|
|
26
27
|
``` ruby
|
27
28
|
params = Attune::Model::BlacklistParams.new
|
28
29
|
params.disabled = true
|
29
|
-
client.entities.blacklist_update(params)
|
30
|
+
client.entities.blacklist_update(blacklist_id, params)
|
30
31
|
```
|
31
32
|
|
32
33
|
## Delete a blacklist entry
|
@@ -36,6 +37,8 @@ client.entities.blacklist_delete(blacklist_id)
|
|
36
37
|
```
|
37
38
|
|
38
39
|
## Get all blacklists for your account
|
40
|
+
|
39
41
|
``` ruby
|
40
|
-
|
42
|
+
response = client.entities.blacklist_get_all()
|
43
|
+
all_blacklists = response.blacklists
|
41
44
|
```
|
data/lib/attune/client.rb
CHANGED
@@ -100,10 +100,35 @@ module Attune
|
|
100
100
|
|
101
101
|
def adapter
|
102
102
|
raise DisabledException if disabled?
|
103
|
-
|
103
|
+
effective_middleware = middleware || default_middleware
|
104
|
+
Faraday.new(url: endpoint, builder: effective_middleware, request: {timeout: timeout}) do |connection|
|
104
105
|
connection.authorization :Bearer, auth_token unless !auth_token
|
105
106
|
end
|
106
107
|
end
|
108
|
+
|
109
|
+
def default_middleware
|
110
|
+
Faraday::Builder.new do |builder|
|
111
|
+
# Needed for encoding of BATCH GET requests
|
112
|
+
builder.use Attune::ParamFlattener
|
113
|
+
|
114
|
+
builder.use Attune::CallDropping
|
115
|
+
|
116
|
+
builder.request :url_encoded
|
117
|
+
|
118
|
+
# Allow one retry per request
|
119
|
+
builder.request :retry, 1
|
120
|
+
|
121
|
+
builder.use Attune::JsonLogger, logger if logging_enabled
|
122
|
+
|
123
|
+
# Gzip requests, Faraday handles responses automatically
|
124
|
+
builder.use Attune::Gzip
|
125
|
+
|
126
|
+
# Raise exceptions for HTTP 4xx/5xx
|
127
|
+
builder.response :raise_error
|
128
|
+
|
129
|
+
builder.adapter :attune_http_persistent
|
130
|
+
end
|
131
|
+
end
|
107
132
|
end
|
108
133
|
end
|
109
134
|
|
data/lib/attune/configurable.rb
CHANGED
@@ -6,7 +6,9 @@ module Attune
|
|
6
6
|
:middleware,
|
7
7
|
:disabled,
|
8
8
|
:exception_handler,
|
9
|
-
:timeout
|
9
|
+
:timeout,
|
10
|
+
:logger,
|
11
|
+
:logging_enabled
|
10
12
|
]
|
11
13
|
|
12
14
|
# The Authorization token
|
@@ -25,6 +27,12 @@ module Attune
|
|
25
27
|
# Time (in seconds) to wait for requests to finish
|
26
28
|
attr_accessor :timeout
|
27
29
|
|
30
|
+
# Logger to write request statistics to
|
31
|
+
attr_accessor :logger
|
32
|
+
|
33
|
+
# Turn request logging on
|
34
|
+
attr_accessor :logging_enabled
|
35
|
+
|
28
36
|
# How to deal with HTTP exceptions
|
29
37
|
# @param [:mock, :raise] handler Method used for handling exceptions.
|
30
38
|
# @raise [ArgumentError] if handler is not :mock or :raise
|
data/lib/attune/default.rb
CHANGED
@@ -14,33 +14,8 @@ module Attune
|
|
14
14
|
# user our version of NetHttpPersistent adapter
|
15
15
|
Faraday::Adapter.register_middleware(attune_http_persistent: NetHttpPersistent)
|
16
16
|
|
17
|
-
MIDDLEWARE = Faraday::Builder.new do |builder|
|
18
|
-
# Needed for encoding of BATCH GET requests
|
19
|
-
builder.use Attune::ParamFlattener
|
20
|
-
|
21
|
-
# Log all requests
|
22
|
-
builder.use Attune::CallDropping
|
23
|
-
|
24
|
-
builder.request :url_encoded
|
25
|
-
|
26
|
-
# Allow one retry per request
|
27
|
-
builder.request :retry, 1
|
28
|
-
|
29
|
-
# Log all requests
|
30
|
-
builder.use Attune::JsonLogger
|
31
|
-
|
32
|
-
# Gzip requests, Faraday handles responses automatically
|
33
|
-
builder.use Attune::Gzip
|
34
|
-
|
35
|
-
# Raise exceptions for HTTP 4xx/5xx
|
36
|
-
builder.response :raise_error
|
37
|
-
|
38
|
-
builder.adapter :attune_http_persistent
|
39
|
-
end
|
40
|
-
|
41
17
|
configure do |c|
|
42
18
|
c.endpoint = ENDPOINT
|
43
|
-
c.middleware = MIDDLEWARE
|
44
19
|
c.disabled = false
|
45
20
|
c.exception_handler = :raise
|
46
21
|
c.timeout = 1
|
data/lib/attune/version.rb
CHANGED
data/spec/attune/client_spec.rb
CHANGED
@@ -7,7 +7,6 @@ describe Attune::Client do
|
|
7
7
|
context "with defaults" do
|
8
8
|
let(:options){ {} }
|
9
9
|
specify { expect(subject.endpoint).to eq(Attune::Default::ENDPOINT) }
|
10
|
-
specify { expect(subject.middleware).to eq(Attune::Default::MIDDLEWARE) }
|
11
10
|
end
|
12
11
|
context "with custom endpoint" do
|
13
12
|
let(:endpoint){ 'http://example.com/' }
|
data/spec/remote_spec.rb
CHANGED
@@ -11,7 +11,7 @@ describe "remote requests" do
|
|
11
11
|
pending "REMOTE_ENDPOINT required for remote spec" unless endpoint
|
12
12
|
pending "AUTH_TOKEN required for remote spec" unless auth_token
|
13
13
|
end
|
14
|
-
let!(:client){ Attune::Client.new(endpoint: endpoint, auth_token: auth_token) }
|
14
|
+
let!(:client){ Attune::Client.new(endpoint: endpoint, auth_token: auth_token, timeout: 20) }
|
15
15
|
|
16
16
|
it "can request an auth_token given a client id and secret" do
|
17
17
|
pending "CLIENT_ID required for get_auth_token spec" unless client_id
|
@@ -66,4 +66,34 @@ describe "remote requests" do
|
|
66
66
|
ranking.sort.should == entities.map(&:to_s).sort
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
it 'should call blacklist api' do
|
71
|
+
# create
|
72
|
+
params = Attune::Model::BlacklistParams.new
|
73
|
+
params.ids = [1,2,3]
|
74
|
+
params.entity_type = 'products'
|
75
|
+
scope = Attune::Model::ScopeEntry.new
|
76
|
+
scope.name = 'page'
|
77
|
+
scope.value = 'sale'
|
78
|
+
params.scope = [scope]
|
79
|
+
params.active_from = DateTime.now
|
80
|
+
params.active_to = DateTime.now + 7
|
81
|
+
response = client.entities.blacklist_save(params)
|
82
|
+
blacklist_id = response.id
|
83
|
+
blacklist_id.should match(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)
|
84
|
+
# get
|
85
|
+
blacklist = client.entities.blacklist_get(blacklist_id)
|
86
|
+
blacklist.id.should == blacklist_id
|
87
|
+
# update
|
88
|
+
params = Attune::Model::BlacklistParams.new
|
89
|
+
params.disabled = true
|
90
|
+
client.entities.blacklist_update(blacklist_id, params)
|
91
|
+
blacklist = client.entities.blacklist_get(blacklist_id)
|
92
|
+
blacklist.disabled.should == true
|
93
|
+
# get all
|
94
|
+
all_blacklists = client.entities.blacklist_get_all()
|
95
|
+
all_blacklists.blacklists.should be_an Array
|
96
|
+
# delete
|
97
|
+
client.entities.blacklist_delete(blacklist_id)
|
98
|
+
end
|
69
99
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attune
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hawthorn
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-08-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|