Module: Shark

Extended by:
SingleForwardable
Defined in:
lib/shark.rb,
lib/shark/base.rb,
lib/shark/asset.rb,
lib/shark/error.rb,
lib/shark/group.rb,
lib/shark/rails.rb,
lib/shark/survey.rb,
lib/shark/account.rb,
lib/shark/consent.rb,
lib/shark/contact.rb,
lib/shark/package.rb,
lib/shark/version.rb,
lib/shark/activity.rb,
lib/shark/contract.rb,
lib/shark/membership.rb,
lib/shark/permission.rb,
lib/shark/contact_log.rb,
lib/shark/form_service.rb,
lib/shark/notification.rb,
lib/shark/configuration.rb,
lib/shark/rspec/helpers.rb,
lib/shark/mailing_service.rb,
lib/shark/client/connection.rb,
lib/shark/form_service/base.rb,
lib/shark/middleware/status.rb,
lib/shark/concerns/connected.rb,
lib/shark/survey_participant.rb,
lib/shark/form_service/v2/base.rb,
lib/shark/form_service/v2/form.rb,
lib/shark/mailing_service/base.rb,
lib/shark/mailing_service/mail.rb,
lib/shark/double_opt_in/request.rb,
lib/shark/mailing_service/mailer.rb,
lib/shark/rspec/helpers/fixtures.rb,
lib/shark/rspec/helpers/response.rb,
lib/shark/double_opt_in/execution.rb,
lib/shark/rspec/fake_asset_service.rb,
lib/shark/rspec/fake_double_opt_in.rb,
lib/shark/concerns/normalized_email.rb,
lib/shark/form_service/form/element.rb,
lib/shark/rspec/fake_survey_service.rb,
lib/shark/form_service/v2/form_input.rb,
lib/shark/middleware/compose_request.rb,
lib/shark/rspec/fake_contact_service.rb,
lib/shark/rspec/fake_mailing_service.rb,
lib/shark/rspec/helpers/cache_helper.rb,
lib/shark/form_service/form/container.rb,
lib/shark/form_service/form/structure.rb,
lib/shark/form_service/form/text_area.rb,
lib/shark/form_service/form/text_field.rb,
lib/shark/form_service/v2/form_version.rb,
lib/shark/form_service/form/rating_star.rb,
lib/shark/mailing_service/configuration.rb,
lib/shark/form_service/form/rating_scale.rb,
lib/shark/rspec/fake_notification_service.rb,
lib/shark/rspec/fake_asset_service/request.rb,
lib/shark/rspec/fake_double_opt_in/request.rb,
lib/shark/form_service/form/multiple_choice.rb,
lib/shark/mailing_service/renderers/context.rb,
lib/shark/rspec/fake_survey_service/request.rb,
lib/shark/rspec/helpers/form_service_helper.rb,
lib/shark/rspec/fake_asset_service/public_id.rb,
lib/shark/rspec/fake_contact_service/request.rb,
lib/shark/rspec/fake_mailing_service/request.rb,
lib/shark/rspec/fake_asset_service/object_cache.rb,
lib/shark/rspec/fake_double_opt_in/object_cache.rb,
lib/shark/mailing_service/renderers/erb_renderer.rb,
lib/shark/rspec/fake_survey_service/object_cache.rb,
lib/shark/rspec/fake_contact_service/object_cache.rb,
lib/shark/rspec/fake_notification_service/request.rb

Defined Under Namespace

Modules: AssetService, Client, Connected, ContactService, DoubleOptIn, FormService, MailingService, Middleware, NormalizedEmail, NotificationService, RSpec, SurveyService Classes: AccessDenied, Account, ActionNotSupportedError, Activity, ApiError, Asset, Base, ClientError, Configuration, ConnectionError, Consent, Contact, ContactLog, Contract, Error, Group, Membership, NotAuthorized, Notification, Package, Permission, Railtie, ResourceConflict, ResourceNotFound, ServerError, Survey, SurveyParticipant, UnexpectedStatus, UnprocessableEntity

Constant Summary collapse

VERSION =
'3.1.1'

Class Method Summary collapse

Class Method Details

.auth_tokenObject



63
64
65
# File 'lib/shark.rb', line 63

def self.auth_token
  Thread.current['shark-auth-token']
end

.auth_token=(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



68
69
70
# File 'lib/shark.rb', line 68

def self.auth_token=(value)
  Thread.current['shark-auth-token'] = value
end

.configure {|self.configuration| ... } ⇒ Object

Yields:

  • (self.configuration)


25
26
27
28
# File 'lib/shark.rb', line 25

def self.configure
  self.configuration ||= Configuration.new
  yield self.configuration
end

.with_auth_token(token) ⇒ Object

Within the given block, add the authorization header token to all api requests.

Parameters:

  • token (String)

    The token for the authorization header

  • block (Block)

    The block where authorization token will be set for



52
53
54
55
56
57
58
59
60
# File 'lib/shark.rb', line 52

def self.with_auth_token(token)
  raise ArgumentError, 'Parameter :token must be kind of String.' unless token.is_a?(String)

  self.auth_token = token

  yield
ensure
  self.auth_token = nil
end

.with_service_token(token) ⇒ Object

Within the given block, add the service token authorization header to all api requests.

Parameters:

  • token (String)

    The service token for the authorization header

  • block (Block)

    The block where service token authorization will be set for



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/shark.rb', line 35

def self.with_service_token(token)
  if token.is_a?(String)
    auth_token = "Bearer #{token}"
  elsif token.respond_to?(:jwt)
    auth_token = "Bearer #{token.jwt}"
  else
    raise ArgumentError, 'Parameter :token must be kind of String.'
  end

  with_auth_token(auth_token)
end