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.
@@ -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