Class: Boldsign::Client
- Inherits:
-
Object
- Object
- Boldsign::Client
- Defined in:
- lib/boldsign/client.rb
Overview
HTTP client for the BoldSign REST API.
Holds API credentials and exposes one accessor per resource group (‘documents`, `templates`, `contacts`, …). Each accessor returns a memoized resource object whose methods wrap individual endpoints.
Low-level verb methods (#get, #post, #put, #patch, #delete, #download) are also available for hitting any endpoint directly.
Authenticates with either an API key (‘X-API-KEY`) or OAuth 2.0 (`Authorization: Bearer`). For OAuth, pass `client_id`/`client_secret` and the client fetches + caches a token via the client credentials grant; or pass a `access_token` you obtained yourself.
Constant Summary collapse
- DEFAULT_BASE_URL =
Default region (US).
"https://api.boldsign.com".freeze
- USER_AGENT =
User-Agent header value sent on every request.
"boldsign-ruby/#{Boldsign::VERSION}".freeze
Instance Attribute Summary collapse
-
#api_key ⇒ String?
readonly
The API key in use, when authenticating via API key.
-
#auth_mode ⇒ Symbol
readonly
The resolved auth mode (‘:api_key`, `:oauth`, or `:bearer`).
-
#base_url ⇒ String
readonly
The resolved base URL (region or explicit override).
Instance Method Summary collapse
- #brand ⇒ Resources::Brand
- #contact_groups ⇒ Resources::ContactGroup
- #contacts ⇒ Resources::Contact
- #custom_fields ⇒ Resources::CustomField
-
#delete(path, params = {}) ⇒ Object
Issue a DELETE request.
- #documents ⇒ Resources::Document
-
#download(path, params = {}) ⇒ String
Issue a GET request and return the raw response body without JSON parsing.
-
#get(path, params = {}) ⇒ Hash, ...
Issue a GET request.
- #identity_verification ⇒ Resources::IdentityVerification
-
#initialize(api_key: nil, client_id: nil, client_secret: nil, access_token: nil, scope: nil, token_url: nil, region: nil, base_url: nil, adapter: Faraday.default_adapter, logger: nil) ⇒ Client
constructor
A new instance of Client.
-
#patch(path, body: nil, params: {}) ⇒ Object
Issue a PATCH request.
- #plan ⇒ Resources::Plan
-
#post(path, body: nil, params: {}, multipart: false) ⇒ Hash, ...
Issue a POST request.
-
#put(path, body: nil, params: {}) ⇒ Object
Issue a PUT request.
- #sender_identities ⇒ Resources::SenderIdentity
- #teams ⇒ Resources::Team
- #templates ⇒ Resources::Template
- #users ⇒ Resources::User
Constructor Details
#initialize(api_key: nil, client_id: nil, client_secret: nil, access_token: nil, scope: nil, token_url: nil, region: nil, base_url: nil, adapter: Faraday.default_adapter, logger: nil) ⇒ Client
Returns a new instance of Client.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/boldsign/client.rb', line 53 def initialize(api_key: nil, client_id: nil, client_secret: nil, access_token: nil, scope: nil, token_url: nil, region: nil, base_url: nil, adapter: Faraday.default_adapter, logger: nil) @api_key = api_key || ENV["BOLDSIGN_API_KEY"] @static_access_token = access_token @base_url = base_url || Boldsign::REGIONS[region&.to_sym] || DEFAULT_BASE_URL @adapter = adapter @logger = logger if present?(client_id) && present?(client_secret) @auth_mode = :oauth @access_token = AccessToken.new( client_id: client_id, client_secret: client_secret, token_url: token_url || default_token_url(region), scope: scope || AccessToken::DEFAULT_SCOPE, adapter: adapter ) elsif present?(@static_access_token) @auth_mode = :bearer elsif present?(@api_key) @auth_mode = :api_key else raise ConfigurationError, "Missing BoldSign credentials: provide client_id/client_secret, access_token, or api_key" end end |
Instance Attribute Details
#api_key ⇒ String? (readonly)
Returns the API key in use, when authenticating via API key.
34 35 36 |
# File 'lib/boldsign/client.rb', line 34 def api_key @api_key end |
#auth_mode ⇒ Symbol (readonly)
Returns the resolved auth mode (‘:api_key`, `:oauth`, or `:bearer`).
37 38 39 |
# File 'lib/boldsign/client.rb', line 37 def auth_mode @auth_mode end |
#base_url ⇒ String (readonly)
Returns the resolved base URL (region or explicit override).
40 41 42 |
# File 'lib/boldsign/client.rb', line 40 def base_url @base_url end |
Instance Method Details
#brand ⇒ Resources::Brand
80 |
# File 'lib/boldsign/client.rb', line 80 def brand; @brand ||= Resources::Brand.new(self); end |
#contact_groups ⇒ Resources::ContactGroup
84 |
# File 'lib/boldsign/client.rb', line 84 def contact_groups; @contact_groups ||= Resources::ContactGroup.new(self); end |
#contacts ⇒ Resources::Contact
82 |
# File 'lib/boldsign/client.rb', line 82 def contacts; @contacts ||= Resources::Contact.new(self); end |
#custom_fields ⇒ Resources::CustomField
86 |
# File 'lib/boldsign/client.rb', line 86 def custom_fields; @custom_fields ||= Resources::CustomField.new(self); end |
#delete(path, params = {}) ⇒ Object
Issue a DELETE request.
137 138 139 |
# File 'lib/boldsign/client.rb', line 137 def delete(path, params = {}) request(:delete, path, params: params) end |
#documents ⇒ Resources::Document
88 |
# File 'lib/boldsign/client.rb', line 88 def documents; @documents ||= Resources::Document.new(self); end |
#download(path, params = {}) ⇒ String
Issue a GET request and return the raw response body without JSON parsing. Use for binary endpoints (downloads, audit logs, attachments).
147 148 149 150 151 152 153 |
# File 'lib/boldsign/client.rb', line 147 def download(path, params = {}) response = connection.get(path) do |req| req.params.update(params) if params && !params.empty? end handle_errors(response) response.body end |
#get(path, params = {}) ⇒ Hash, ...
Issue a GET request.
107 108 109 |
# File 'lib/boldsign/client.rb', line 107 def get(path, params = {}) request(:get, path, params: params) end |
#identity_verification ⇒ Resources::IdentityVerification
90 |
# File 'lib/boldsign/client.rb', line 90 def identity_verification; @identity_verification ||= Resources::IdentityVerification.new(self); end |
#patch(path, body: nil, params: {}) ⇒ Object
Issue a PATCH request. See #post for parameter semantics.
130 131 132 |
# File 'lib/boldsign/client.rb', line 130 def patch(path, body: nil, params: {}) request(:patch, path, body: body, params: params) end |
#plan ⇒ Resources::Plan
92 |
# File 'lib/boldsign/client.rb', line 92 def plan; @plan ||= Resources::Plan.new(self); end |
#post(path, body: nil, params: {}, multipart: false) ⇒ Hash, ...
Issue a POST request.
120 121 122 |
# File 'lib/boldsign/client.rb', line 120 def post(path, body: nil, params: {}, multipart: false) request(:post, path, body: body, params: params, multipart: multipart) end |
#put(path, body: nil, params: {}) ⇒ Object
Issue a PUT request. See #post for parameter semantics.
125 126 127 |
# File 'lib/boldsign/client.rb', line 125 def put(path, body: nil, params: {}) request(:put, path, body: body, params: params) end |
#sender_identities ⇒ Resources::SenderIdentity
94 |
# File 'lib/boldsign/client.rb', line 94 def sender_identities; @sender_identities ||= Resources::SenderIdentity.new(self); end |
#teams ⇒ Resources::Team
96 |
# File 'lib/boldsign/client.rb', line 96 def teams; @teams ||= Resources::Team.new(self); end |
#templates ⇒ Resources::Template
98 |
# File 'lib/boldsign/client.rb', line 98 def templates; @templates ||= Resources::Template.new(self); end |
#users ⇒ Resources::User
100 |
# File 'lib/boldsign/client.rb', line 100 def users; @users ||= Resources::User.new(self); end |