Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

- name: Check gem can be required
run: |
ruby -e "require './lib/bundleup'; puts '✓ Gem requires successfully'"
bundle exec ruby -e "require './lib/bundleup'; puts '✓ Gem requires successfully'"

lint:
runs-on: ubuntu-latest
Expand Down
2 changes: 0 additions & 2 deletions lib/bundleup/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ def resource_name
end

def request(method, path, body = nil)
url = "#{BASE_URL}#{path}"

response = connection.public_send(method) do |req|
req.url path
req.headers['Content-Type'] = 'application/json'
Expand Down
16 changes: 11 additions & 5 deletions lib/bundleup/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Client
# @raise [ArgumentError] if api_key is nil or empty
def initialize(api_key)
raise ArgumentError, 'API key is required to initialize BundleUp SDK.' if api_key.nil? || api_key.to_s.empty?

@api_key = api_key
end

Expand Down Expand Up @@ -42,8 +42,11 @@ def webhooks
# @return [Bundleup::Proxy] Proxy instance
# @raise [ArgumentError] if connection_id is nil or empty
def proxy(connection_id)
raise ArgumentError, 'Connection ID is required to create a Proxy instance.' if connection_id.nil? || connection_id.to_s.empty?

if connection_id.nil? || connection_id.to_s.empty?
raise ArgumentError,
'Connection ID is required to create a Proxy instance.'
end

Bundleup::Proxy.new(@api_key, connection_id)
end

Expand All @@ -53,8 +56,11 @@ def proxy(connection_id)
# @return [Hash] Hash with :chat, :git, and :pm Unify instances
# @raise [ArgumentError] if connection_id is nil or empty
def unify(connection_id)
raise ArgumentError, 'Connection ID is required to create a Unify instance.' if connection_id.nil? || connection_id.to_s.empty?

if connection_id.nil? || connection_id.to_s.empty?
raise ArgumentError,
'Connection ID is required to create a Unify instance.'
end

{
chat: Bundleup::Unify::Chat.new(@api_key, connection_id),
git: Bundleup::Unify::Git.new(@api_key, connection_id),
Expand Down
2 changes: 1 addition & 1 deletion lib/bundleup/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def request(method, path, body = nil)
req.headers['Content-Type'] = 'application/json'
req.headers['Authorization'] = "Bearer #{api_key}"
req.headers['BU-Connection-Id'] = connection_id

if body && %i[post patch put].include?(method)
req.body = body.to_json
elsif body && method == :get
Expand Down
2 changes: 1 addition & 1 deletion lib/bundleup/unify/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def request(method, path, params = {}, include_raw: false)
req.headers['Authorization'] = "Bearer #{api_key}"
req.headers['BU-Connection-Id'] = connection_id
req.headers['BU-Include-Raw'] = include_raw.to_s

if params && %i[post patch put].include?(method)
req.body = params.to_json
elsif params && method == :get
Expand Down
32 changes: 16 additions & 16 deletions spec/bundleup/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def resource_name
describe '#list' do
it 'makes a GET request to the resource path' do
stub = stub_request(:get, 'https://api.bundleup.io/v1/test_resources')
.with(headers: { 'Authorization' => 'Bearer test_api_key' })
.to_return(status: 200, body: '{"data": []}', headers: { 'Content-Type' => 'application/json' })
.with(headers: { 'Authorization' => 'Bearer test_api_key' })
.to_return(status: 200, body: '{"data": []}', headers: { 'Content-Type' => 'application/json' })

instance.list

Expand All @@ -36,11 +36,11 @@ def resource_name
describe '#create' do
it 'makes a POST request with data' do
stub = stub_request(:post, 'https://api.bundleup.io/v1/test_resources')
.with(
headers: { 'Authorization' => 'Bearer test_api_key', 'Content-Type' => 'application/json' },
body: '{"name":"Test"}'
)
.to_return(status: 201, body: '{"id":"123"}', headers: { 'Content-Type' => 'application/json' })
.with(
headers: { 'Authorization' => 'Bearer test_api_key', 'Content-Type' => 'application/json' },
body: '{"name":"Test"}'
)
.to_return(status: 201, body: '{"id":"123"}', headers: { 'Content-Type' => 'application/json' })

instance.create(name: 'Test')

Expand All @@ -51,8 +51,8 @@ def resource_name
describe '#retrieve' do
it 'makes a GET request with the resource ID' do
stub = stub_request(:get, 'https://api.bundleup.io/v1/test_resources/123')
.with(headers: { 'Authorization' => 'Bearer test_api_key' })
.to_return(status: 200, body: '{"id":"123"}', headers: { 'Content-Type' => 'application/json' })
.with(headers: { 'Authorization' => 'Bearer test_api_key' })
.to_return(status: 200, body: '{"id":"123"}', headers: { 'Content-Type' => 'application/json' })

instance.retrieve('123')

Expand All @@ -63,11 +63,11 @@ def resource_name
describe '#update' do
it 'makes a PATCH request with data' do
stub = stub_request(:patch, 'https://api.bundleup.io/v1/test_resources/123')
.with(
headers: { 'Authorization' => 'Bearer test_api_key', 'Content-Type' => 'application/json' },
body: '{"name":"Updated"}'
)
.to_return(status: 200, body: '{"id":"123"}', headers: { 'Content-Type' => 'application/json' })
.with(
headers: { 'Authorization' => 'Bearer test_api_key', 'Content-Type' => 'application/json' },
body: '{"name":"Updated"}'
)
.to_return(status: 200, body: '{"id":"123"}', headers: { 'Content-Type' => 'application/json' })

instance.update('123', name: 'Updated')

Expand All @@ -78,8 +78,8 @@ def resource_name
describe '#delete' do
it 'makes a DELETE request' do
stub = stub_request(:delete, 'https://api.bundleup.io/v1/test_resources/123')
.with(headers: { 'Authorization' => 'Bearer test_api_key' })
.to_return(status: 204, body: '', headers: {})
.with(headers: { 'Authorization' => 'Bearer test_api_key' })
.to_return(status: 204, body: '', headers: {})

instance.delete('123')

Expand Down
16 changes: 12 additions & 4 deletions spec/bundleup/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
end

it 'raises an error when API key is nil' do
expect { described_class.new(nil) }.to raise_error(ArgumentError, 'API key is required to initialize BundleUp SDK.')
expect do
described_class.new(nil)
end.to raise_error(ArgumentError, 'API key is required to initialize BundleUp SDK.')
end

it 'raises an error when API key is empty' do
expect { described_class.new('') }.to raise_error(ArgumentError, 'API key is required to initialize BundleUp SDK.')
expect do
described_class.new('')
end.to raise_error(ArgumentError, 'API key is required to initialize BundleUp SDK.')
end
end

Expand Down Expand Up @@ -64,7 +68,9 @@
end

it 'raises an error when connection_id is nil' do
expect { client.proxy(nil) }.to raise_error(ArgumentError, 'Connection ID is required to create a Proxy instance.')
expect do
client.proxy(nil)
end.to raise_error(ArgumentError, 'Connection ID is required to create a Proxy instance.')
end

it 'raises an error when connection_id is empty' do
Expand All @@ -88,7 +94,9 @@
end

it 'raises an error when connection_id is nil' do
expect { client.unify(nil) }.to raise_error(ArgumentError, 'Connection ID is required to create a Unify instance.')
expect do
client.unify(nil)
end.to raise_error(ArgumentError, 'Connection ID is required to create a Unify instance.')
end

it 'raises an error when connection_id is empty' do
Expand Down
74 changes: 37 additions & 37 deletions spec/bundleup/proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
describe '#get' do
it 'makes a GET request with proper headers' do
stub = stub_request(:get, 'https://proxy.bundleup.io/api/users')
.with(headers: {
'Authorization' => 'Bearer test_api_key',
'BU-Connection-Id' => 'conn_123'
})
.to_return(status: 200, body: '{"users":[]}', headers: { 'Content-Type' => 'application/json' })
.with(headers: {
'Authorization' => 'Bearer test_api_key',
'BU-Connection-Id' => 'conn_123'
})
.to_return(status: 200, body: '{"users":[]}', headers: { 'Content-Type' => 'application/json' })

instance.get('/api/users')

Expand All @@ -30,15 +30,15 @@
describe '#post' do
it 'makes a POST request with body' do
stub = stub_request(:post, 'https://proxy.bundleup.io/api/users')
.with(
headers: {
'Authorization' => 'Bearer test_api_key',
'BU-Connection-Id' => 'conn_123',
'Content-Type' => 'application/json'
},
body: '{"name":"Test"}'
)
.to_return(status: 201, body: '{"id":"123"}', headers: { 'Content-Type' => 'application/json' })
.with(
headers: {
'Authorization' => 'Bearer test_api_key',
'BU-Connection-Id' => 'conn_123',
'Content-Type' => 'application/json'
},
body: '{"name":"Test"}'
)
.to_return(status: 201, body: '{"id":"123"}', headers: { 'Content-Type' => 'application/json' })

instance.post('/api/users', name: 'Test')

Expand All @@ -49,15 +49,15 @@
describe '#put' do
it 'makes a PUT request' do
stub = stub_request(:put, 'https://proxy.bundleup.io/api/users/123')
.with(
headers: {
'Authorization' => 'Bearer test_api_key',
'BU-Connection-Id' => 'conn_123',
'Content-Type' => 'application/json'
},
body: '{"name":"Updated"}'
)
.to_return(status: 200, body: '{"id":"123"}', headers: { 'Content-Type' => 'application/json' })
.with(
headers: {
'Authorization' => 'Bearer test_api_key',
'BU-Connection-Id' => 'conn_123',
'Content-Type' => 'application/json'
},
body: '{"name":"Updated"}'
)
.to_return(status: 200, body: '{"id":"123"}', headers: { 'Content-Type' => 'application/json' })

instance.put('/api/users/123', name: 'Updated')

Expand All @@ -68,15 +68,15 @@
describe '#patch' do
it 'makes a PATCH request' do
stub = stub_request(:patch, 'https://proxy.bundleup.io/api/users/123')
.with(
headers: {
'Authorization' => 'Bearer test_api_key',
'BU-Connection-Id' => 'conn_123',
'Content-Type' => 'application/json'
},
body: '{"email":"test@example.com"}'
)
.to_return(status: 200, body: '{"id":"123"}', headers: { 'Content-Type' => 'application/json' })
.with(
headers: {
'Authorization' => 'Bearer test_api_key',
'BU-Connection-Id' => 'conn_123',
'Content-Type' => 'application/json'
},
body: '{"email":"test@example.com"}'
)
.to_return(status: 200, body: '{"id":"123"}', headers: { 'Content-Type' => 'application/json' })

instance.patch('/api/users/123', email: 'test@example.com')

Expand All @@ -87,11 +87,11 @@
describe '#delete' do
it 'makes a DELETE request' do
stub = stub_request(:delete, 'https://proxy.bundleup.io/api/users/123')
.with(headers: {
'Authorization' => 'Bearer test_api_key',
'BU-Connection-Id' => 'conn_123'
})
.to_return(status: 204, body: '', headers: {})
.with(headers: {
'Authorization' => 'Bearer test_api_key',
'BU-Connection-Id' => 'conn_123'
})
.to_return(status: 204, body: '', headers: {})

instance.delete('/api/users/123')

Expand Down
Loading