castle-rb 4.0.0 → 5.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.
- checksums.yaml +4 -4
- data/README.md +61 -20
- data/lib/castle.rb +5 -4
- data/lib/castle/api.rb +16 -7
- data/lib/castle/api/connection.rb +24 -0
- data/lib/castle/api/request.rb +16 -11
- data/lib/castle/api/session.rb +20 -0
- data/lib/castle/client.rb +29 -8
- data/lib/castle/configuration.rb +45 -20
- data/lib/castle/context/default.rb +1 -1
- data/lib/castle/extractors/headers.rb +10 -10
- data/lib/castle/extractors/ip.rb +37 -17
- data/lib/castle/{header_filter.rb → headers_filter.rb} +7 -7
- data/lib/castle/headers_formatter.rb +22 -0
- data/lib/castle/version.rb +1 -1
- data/spec/lib/castle/api/connection_spec.rb +59 -0
- data/spec/lib/castle/api/request_spec.rb +75 -37
- data/spec/lib/castle/api/session_spec.rb +86 -0
- data/spec/lib/castle/api_spec.rb +4 -4
- data/spec/lib/castle/client_spec.rb +2 -2
- data/spec/lib/castle/commands/impersonate_spec.rb +2 -2
- data/spec/lib/castle/configuration_spec.rb +17 -16
- data/spec/lib/castle/context/default_spec.rb +3 -2
- data/spec/lib/castle/extractors/client_id_spec.rb +1 -1
- data/spec/lib/castle/extractors/headers_spec.rb +11 -12
- data/spec/lib/castle/extractors/ip_spec.rb +39 -6
- data/spec/lib/castle/{header_filter_spec.rb → headers_filter_spec.rb} +6 -6
- data/spec/lib/castle/{header_formatter_spec.rb → headers_formatter_spec.rb} +2 -2
- data/spec/spec_helper.rb +1 -2
- metadata +18 -15
- data/lib/castle/api/request/build.rb +0 -27
- data/lib/castle/header_formatter.rb +0 -12
- data/spec/lib/castle/api/request/build_spec.rb +0 -46
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Castle
|
4
|
-
module API
|
5
|
-
# generate api request
|
6
|
-
module Request
|
7
|
-
module Build
|
8
|
-
class << self
|
9
|
-
def call(command, headers, api_secret)
|
10
|
-
request = Net::HTTP.const_get(
|
11
|
-
command.method.to_s.capitalize
|
12
|
-
).new("/#{Castle.config.url_prefix}/#{command.path}", headers)
|
13
|
-
|
14
|
-
unless command.method == :get
|
15
|
-
request.body = ::Castle::Utils.replace_invalid_characters(
|
16
|
-
command.data
|
17
|
-
).to_json
|
18
|
-
end
|
19
|
-
|
20
|
-
request.basic_auth('', api_secret)
|
21
|
-
request
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Castle
|
4
|
-
# formats header name
|
5
|
-
class HeaderFormatter
|
6
|
-
# @param header [String]
|
7
|
-
# @return [String]
|
8
|
-
def call(header)
|
9
|
-
header.to_s.gsub(/^HTTP(?:_|-)/i, '').split(/_|-/).map(&:capitalize).join('-')
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe Castle::API::Request::Build do
|
4
|
-
subject(:call) { described_class.call(command, headers, api_secret) }
|
5
|
-
|
6
|
-
let(:headers) { { 'SAMPLE-HEADER' => '1' } }
|
7
|
-
let(:api_secret) { 'secret' }
|
8
|
-
|
9
|
-
describe 'call' do
|
10
|
-
context 'when get' do
|
11
|
-
let(:command) { Castle::Commands::Review.build(review_id) }
|
12
|
-
let(:review_id) { SecureRandom.uuid }
|
13
|
-
|
14
|
-
it { expect(call.body).to be_nil }
|
15
|
-
it { expect(call.method).to eql('GET') }
|
16
|
-
it { expect(call.path).to eql("/v1/#{command.path}") }
|
17
|
-
it { expect(call.to_hash).to have_key('authorization') }
|
18
|
-
it { expect(call.to_hash).to have_key('sample-header') }
|
19
|
-
it { expect(call.to_hash['sample-header']).to eql(['1']) }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'when post' do
|
23
|
-
let(:time) { Time.now.utc.iso8601(3) }
|
24
|
-
let(:command) do
|
25
|
-
Castle::Commands::Track.new({}).build(event: '$login.succeeded', name: "\xC4")
|
26
|
-
end
|
27
|
-
let(:expected_body) do
|
28
|
-
{
|
29
|
-
event: '$login.succeeded',
|
30
|
-
name: '�',
|
31
|
-
context: {},
|
32
|
-
sent_at: time
|
33
|
-
}
|
34
|
-
end
|
35
|
-
|
36
|
-
before { allow(Castle::Utils::Timestamp).to receive(:call).and_return(time) }
|
37
|
-
|
38
|
-
it { expect(call.body).to be_eql(expected_body.to_json) }
|
39
|
-
it { expect(call.method).to eql('POST') }
|
40
|
-
it { expect(call.path).to eql("/v1/#{command.path}") }
|
41
|
-
it { expect(call.to_hash).to have_key('authorization') }
|
42
|
-
it { expect(call.to_hash).to have_key('sample-header') }
|
43
|
-
it { expect(call.to_hash['sample-header']).to eql(['1']) }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|