Skip to content

Commit

Permalink
Merge pull request #18 from lyrasis/add-user-agent
Browse files Browse the repository at this point in the history
add user agent
  • Loading branch information
mark-cooper authored Dec 29, 2023
2 parents 5a1b0c4 + 9184e96 commit 6fab50c
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 49 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ jobs:
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: 2.7

- name: Lint
run: |
bundle exec standardrb
- name: Run tests
run: |
bundle exec rake
bundle exec rspec
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.2
15 changes: 5 additions & 10 deletions archivesspace-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "aruba"
spec.add_development_dependency "awesome_print", "~> 1.8.0"
spec.add_development_dependency "bundler"
spec.add_development_dependency "capybara_discoball"
spec.add_development_dependency "cucumber"
spec.add_development_dependency "json_spec"
spec.add_development_dependency "aruba", "~> 2.0"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "3.6.0"
spec.add_development_dependency "rubocop"
spec.add_development_dependency "standard"
spec.add_development_dependency "vcr", "3.0.3"
spec.add_development_dependency "webmock", "3.0.1"
spec.add_development_dependency "rubocop", "1.56"
spec.add_development_dependency "standard", "1.31.0"
spec.add_development_dependency "vcr", "6.2.0"
spec.add_development_dependency "webmock", "3.19.1"

spec.add_dependency "dry-cli", "~> 0.7"
spec.add_dependency "httparty", "~> 0.14"
Expand Down
2 changes: 2 additions & 0 deletions lib/archivesspace/client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Client
attr_accessor :token
attr_reader :config

NAME = "ArchivesSpaceClient"

def initialize(config = Configuration.new)
raise "Invalid configuration object" unless config.is_a? ArchivesSpace::Configuration

Expand Down
2 changes: 1 addition & 1 deletion lib/archivesspace/client/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initialize(settings = {})
settings.each do |property, value|
next unless defaults.key?(property)

instance_variable_set("@#{property}", value)
instance_variable_set(:"@#{property}", value)
self.class.send(:attr_accessor, property)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/archivesspace/client/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def initialize(config, method = "GET", path = "", options = {})
@options = options
@options[:headers] =
options[:headers] ? default_headers(@method).merge(options[:headers]) : default_headers(@method)
@options[:headers]["User-Agent"] = "#{Client::NAME}/#{Client::VERSION}"
@options[:verify] = config.verify_ssl
@options[:timeout] = config.timeout
@options[:query] = {} unless options.key? :query
Expand Down
2 changes: 1 addition & 1 deletion lib/archivesspace/client/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module ArchivesSpace
class Client
VERSION = "0.2.0"
VERSION = "0.3.0"
end
end
18 changes: 8 additions & 10 deletions spec/archivesspace/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

describe ArchivesSpace::Client do
let(:client) { ArchivesSpace::Client.new }
let(:login) { -> { client.login } }

describe "Configuration" do
it "will use the default configuration if none is provided" do
client = ArchivesSpace::Client.new
expect(client.config.base_uri).to eq DEFAULT_BASE_URI
end

Expand All @@ -24,42 +22,43 @@

describe "Repository scoping" do
it "will set the repository with an integer id" do
client = ArchivesSpace::Client.new
client.repository 2
expect(client.config.base_repo).to eq "repositories/2"
end

it "will set the repository with a string id cast to integer" do
client = ArchivesSpace::Client.new
client.repository "2"
expect(client.config.base_repo).to eq "repositories/2"
end

it "will fail if the id cannot be cast to integer" do
client = ArchivesSpace::Client.new
expect { client.repository("xyz") }.to raise_error(
ArchivesSpace::RepositoryIdError
)
end

it "will use the global repo if repository is passed nil" do
client = ArchivesSpace::Client.new
client.repository 2
client.repository nil
expect(client.config.base_repo).to eq ""
end

it "will use the global repo when the method is called" do
client = ArchivesSpace::Client.new
client.repository 2
client.use_global_repository
expect(client.config.base_repo).to eq ""
end
end

describe "Requests" do
it "will have an identifiable user agent" do
request = ArchivesSpace::Request.new(client.config)
expect(request.options[:headers]["User-Agent"]).to eq "#{ArchivesSpace::Client::NAME}/#{ArchivesSpace::Client::VERSION}"
end
end

describe "Pagination" do
it "will have a method for defined paginated record types" do
client = ArchivesSpace::Client.new
ArchivesSpace::Pagination::ENDPOINTS.each do |e|
next if e.match?("/")

Expand All @@ -68,7 +67,6 @@
end

it "will have a method for defined paginated record types with multipart path" do
client = ArchivesSpace::Client.new
expect(client.respond_to?(:people)).to be true
end
end
Expand All @@ -80,7 +78,7 @@

it "can retrieve the backend version info" do
VCR.use_cassette("backend_version") do
login.call
client.login
response = client.get "version"
expect(response.status_code).to eq(200)
expect(response.body).to match(/ArchivesSpace \(.*\)/)
Expand Down
2 changes: 1 addition & 1 deletion spec/archivesspace/templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

it "can change the path when template envvar is set" do
expect(ArchivesSpace::Template.templates_path).to match(
/#{File.join('lib', 'archivesspace', 'client', 'templates')}/
/#{File.join("lib", "archivesspace", "client", "templates")}/
)
ENV["ARCHIVESSPACE_CLIENT_TEMPLATES_PATH"] = "/path/to/nowhere"
expect(ArchivesSpace::Template.templates_path).to eq "/path/to/nowhere"
Expand Down
59 changes: 35 additions & 24 deletions spec/fixtures/cassettes/backend_version.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6fab50c

Please sign in to comment.