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
5 changes: 1 addition & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ require "rspec/core/rake_task"
require "standard/rake"

RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = [
"spec/**/*_spec.rb",
"lib/seam/*_spec.rb"
]
t.pattern = "spec/**/*_spec.rb"
end

task default: %i[lint test]
Expand Down
4 changes: 2 additions & 2 deletions lib/seam.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def self.new(**args)
Seam::Http.new(**args)
end

def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: false)
def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: true)
Seam::Http.from_api_key(api_key, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt)
end

def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: false)
def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: true)
Seam::Http.from_personal_access_token(personal_access_token, workspace_id, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt)
end

Expand Down
4 changes: 4 additions & 0 deletions lib/seam/deep_hash_accessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def [](key)
instance_variable_get(:"@#{key}")
end

def to_h
@data
end

private

def create_accessor_methods
Expand Down
23 changes: 16 additions & 7 deletions lib/seam/helpers/action_attempt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ module Seam
module Helpers
module ActionAttempt
def self.decide_and_wait(action_attempt, client, wait_for_action_attempt)
if wait_for_action_attempt == true
return wait_until_finished(action_attempt, client)
elsif wait_for_action_attempt.is_a?(Hash)
return wait_until_finished(action_attempt, client, timeout: wait_for_action_attempt[:timeout],
polling_interval: wait_for_action_attempt[:polling_interval])
end
return wait_until_finished(action_attempt, client) if wait_for_action_attempt == true

action_attempt
options = wait_options(wait_for_action_attempt)
return action_attempt if options.nil?

wait_until_finished(action_attempt, client, timeout: options[:timeout],
polling_interval: options[:polling_interval])
end

# The client wraps its defaults in a DeepHashAccessor, so the hash form of
# this option reaches here as an accessor when it comes from the client
# and as a plain Hash when it comes from the method call.
def self.wait_options(wait_for_action_attempt)
case wait_for_action_attempt
when Hash then wait_for_action_attempt
when Seam::DeepHashAccessor then wait_for_action_attempt.to_h
end
end

def self.wait_until_finished(action_attempt, client, timeout: nil, polling_interval: nil)
Expand Down
4 changes: 2 additions & 2 deletions lib/seam/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ def self.new(**args)
Http::SingleWorkspace.new(**args)
end

def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: false)
def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: true)
Http::SingleWorkspace.from_api_key(api_key, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt)
end

def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: false)
def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: true)
Http::SingleWorkspace.from_personal_access_token(personal_access_token, workspace_id, endpoint: endpoint,
wait_for_action_attempt: wait_for_action_attempt)
end
Expand Down
21 changes: 13 additions & 8 deletions lib/seam/http_single_workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ class SingleWorkspace

def initialize(client: nil, api_key: nil, personal_access_token: nil, workspace_id: nil, endpoint: nil,
wait_for_action_attempt: true, faraday_options: {}, faraday_retry_options: {})
options = Http::Options.parse_options(api_key: api_key, personal_access_token: personal_access_token,
workspace_id: workspace_id, endpoint: endpoint)
@endpoint = options[:endpoint]
@auth_headers = options[:auth_headers]
@defaults = Seam::DeepHashAccessor.new({"wait_for_action_attempt" => wait_for_action_attempt})
@client = client || Http::Request.create_faraday_client(@endpoint, @auth_headers, faraday_options,
faraday_retry_options)

# A client carries its own endpoint and authorization, so the auth
# options are only parsed when one has to be built.
@client = client || begin
options = Http::Options.parse_options(api_key: api_key, personal_access_token: personal_access_token,
workspace_id: workspace_id, endpoint: endpoint)
@endpoint = options[:endpoint]
@auth_headers = options[:auth_headers]

Http::Request.create_faraday_client(@endpoint, @auth_headers, faraday_options, faraday_retry_options)
end

initialize_routes(client: @client, defaults: @defaults)
end
Expand All @@ -37,12 +42,12 @@ def create_paginator(request, params = {})
Paginator.new(request, params)
end

def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: false, faraday_options: {}, faraday_retry_options: {})
def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: true, faraday_options: {}, faraday_retry_options: {})
new(api_key: api_key, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt,
faraday_options: faraday_options, faraday_retry_options: faraday_retry_options)
end

def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: false, faraday_options: {}, faraday_retry_options: {})
def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: true, faraday_options: {}, faraday_retry_options: {})
new(personal_access_token: personal_access_token, workspace_id: workspace_id, endpoint: endpoint,
wait_for_action_attempt: wait_for_action_attempt, faraday_options: faraday_options, faraday_retry_options: faraday_retry_options)
end
Expand Down
178 changes: 0 additions & 178 deletions spec/clients/access_codes_spec.rb

This file was deleted.

22 changes: 0 additions & 22 deletions spec/clients/action_attempts_spec.rb

This file was deleted.

73 changes: 0 additions & 73 deletions spec/clients/connect_webviews_spec.rb

This file was deleted.

Loading
Loading