Skip to content
Closed
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
5 changes: 0 additions & 5 deletions lib/seam.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require_relative "seam/lts_version"
require_relative "seam/http"
require_relative "seam/http_multi_workspace"
require_relative "seam/webhook"
Expand All @@ -19,8 +18,4 @@ def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: true, tim
def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: true, timeout: nil)
Seam::Http.from_personal_access_token(personal_access_token, workspace_id, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt, timeout: timeout)
end

def self.lts_version
Seam::LTS_VERSION
end
end
9 changes: 0 additions & 9 deletions lib/seam/http_multi_workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require_relative "request"
require_relative "parse_options"
require_relative "lts_version"
require_relative "version"
require_relative "auth"
require_relative "resources/index"
Expand All @@ -24,14 +23,6 @@ def initialize(personal_access_token:, endpoint: nil, wait_for_action_attempt: t
faraday_retry_options, timeout: timeout)
end

def self.lts_version
Seam::LTS_VERSION
end

def lts_version
Seam::LTS_VERSION
end

def workspaces
@workspaces ||= WorkspacesProxy.new(Seam::Clients::Workspaces.new(client: @client, defaults: @defaults))
end
Expand Down
4 changes: 0 additions & 4 deletions lib/seam/http_single_workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ def initialize(client: nil, api_key: nil, personal_access_token: nil, workspace_
initialize_routes(client: @client, defaults: @defaults)
end

def lts_version
Seam::LTS_VERSION
end

def create_paginator(request, params = {})
Paginator.new(request, params)
end
Expand Down
5 changes: 0 additions & 5 deletions lib/seam/lts_version.rb

This file was deleted.

29 changes: 24 additions & 5 deletions lib/seam/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require "faraday"
require "faraday/retry"
require_relative "defaults"
require_relative "lts_version"
require_relative "version"
require_relative "paginator"

Expand All @@ -21,6 +20,12 @@ def self.create_faraday_client(endpoint, auth_headers, faraday_options = {}, far
}

options = deep_merge(default_options, faraday_options)
options.delete("headers")
options[:headers] = merge_headers(
faraday_options[:headers] || faraday_options["headers"] || {},
auth_headers,
default_headers
)

default_faraday_retry_options = {
max: 2,
Expand All @@ -40,11 +45,9 @@ def self.create_faraday_client(endpoint, auth_headers, faraday_options = {}, far

def self.default_headers
{
"User-Agent" => "seam-ruby/#{Seam::VERSION}",
"Content-Type" => "application/json",
:"seam-sdk-name" => "seamapi/ruby",
:"seam-sdk-version" => Seam::VERSION,
:"seam-lts-version" => Seam::LTS_VERSION
:"seam-sdk-version" => Seam::VERSION
}
end

Expand Down Expand Up @@ -107,7 +110,23 @@ def self.deep_merge(hash1, hash2)
result
end

private_class_method :deep_merge
def self.merge_headers(*headers_list)
result = {}
header_keys = {}

headers_list.each do |headers|
headers.each do |key, value|
normalized_key = key.to_s.downcase
result.delete(header_keys[normalized_key]) if header_keys.key?(normalized_key)
header_keys[normalized_key] = key
result[key] = value
end
end

result
end

private_class_method :deep_merge, :merge_headers
end
end
end
1 change: 0 additions & 1 deletion spec/module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
end

it "has a LTS version number" do
expect(Seam::LTS_VERSION).not_to be nil
end
end
9 changes: 0 additions & 9 deletions spec/seam_client/defaults_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,4 @@
expect(seam.defaults.wait_for_action_attempt).to be false
end
end

describe "#lts_version" do
it "is exposed on the instance and the module" do
seam = Seam.new(api_key: "seam_some_api_key")

expect(seam.lts_version).to eq(Seam::LTS_VERSION)
expect(Seam.lts_version).to eq(Seam::LTS_VERSION)
end
end
end
20 changes: 20 additions & 0 deletions spec/seam_client/faraday_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@
expect(seam.client.headers["seam-sdk-name"]).to eq("seamapi/ruby")
end

it "does not let faraday_options override auth or SDK headers" do
seam = described_class.new(
api_key: seed["seam_apikey1_token"],
endpoint: endpoint,
faraday_options: {
headers: {
"Authorization" => "Bearer caller_token",
"Content-Type" => "text/plain",
"Seam-Sdk-Name" => "caller-sdk",
:"seam-sdk-version" => "0.0.0"
}
}
)

expect(seam.client.headers["Authorization"]).to eq("Bearer #{seed["seam_apikey1_token"]}")
expect(seam.client.headers["Content-Type"]).to eq("application/json")
expect(seam.client.headers["seam-sdk-name"]).to eq("seamapi/ruby")
expect(seam.client.headers["seam-sdk-version"]).to eq(Seam::VERSION)
end

it "still authorizes requests against the server" do
seam = described_class.new(
api_key: seed["seam_apikey1_token"],
Expand Down
41 changes: 33 additions & 8 deletions spec/seam_client/headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"Authorization" => "Bearer seam_some_api_key",
"Content-Type" => "application/json",
"seam-sdk-name" => "seamapi/ruby",
"seam-sdk-version" => Seam::VERSION,
"seam-lts-version" => Seam::LTS_VERSION,
"User-Agent" => "seam-ruby/#{Seam::VERSION}"
"seam-sdk-version" => Seam::VERSION
}
)
.to_return(
Expand All @@ -31,6 +29,38 @@
expect(stub).to have_been_requested
end

it "sends the SDK and auth headers over caller-provided duplicates" do
stub = stub_request(:post, "#{Seam::DEFAULT_ENDPOINT}/devices/get")
.with(
headers: {
"Authorization" => "Bearer seam_some_api_key",
"Content-Type" => "application/json",
"seam-sdk-name" => "seamapi/ruby",
"seam-sdk-version" => Seam::VERSION
}
)
.to_return(
status: 200,
body: {device: {device_id: device_id}}.to_json,
headers: {"Content-Type" => "application/json"}
)

seam = Seam.new(
api_key: "seam_some_api_key",
faraday_options: {
headers: {
"Authorization" => "Bearer caller_token",
"Content-Type" => "text/plain",
"Seam-Sdk-Name" => "caller-sdk",
:"seam-sdk-version" => "0.0.0"
}
}
)
seam.devices.get(device_id: device_id)

expect(stub).to have_been_requested
end

it "sends the workspace header with a personal access token" do
stub = stub_request(:post, "#{Seam::DEFAULT_ENDPOINT}/devices/get")
.with(
Expand All @@ -50,9 +80,4 @@

expect(stub).to have_been_requested
end

it "exposes the LTS version on the module and the client" do
expect(Seam.lts_version).to eq(Seam::LTS_VERSION)
expect(Seam.new(api_key: "seam_some_api_key").lts_version).to eq(Seam::LTS_VERSION)
end
end