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.
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.
-
#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, 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, region: nil, base_url: nil, adapter: Faraday.default_adapter, logger: nil) ⇒ Client
Returns a new instance of Client.
33 34 35 36 37 38 39 40 |
# File 'lib/boldsign/client.rb', line 33 def initialize(api_key: nil, region: nil, base_url: nil, adapter: Faraday.default_adapter, logger: nil) @api_key = api_key || ENV["BOLDSIGN_API_KEY"] raise ConfigurationError, "Missing BoldSign API key" if @api_key.nil? || @api_key.empty? @base_url = base_url || Boldsign::REGIONS[region&.to_sym] || DEFAULT_BASE_URL @adapter = adapter @logger = logger end |
Instance Attribute Details
#api_key ⇒ String (readonly)
Returns the API key in use.
22 23 24 |
# File 'lib/boldsign/client.rb', line 22 def api_key @api_key end |
#base_url ⇒ String (readonly)
Returns the resolved base URL (region or explicit override).
25 26 27 |
# File 'lib/boldsign/client.rb', line 25 def base_url @base_url end |
Instance Method Details
#brand ⇒ Resources::Brand
43 |
# File 'lib/boldsign/client.rb', line 43 def brand; @brand ||= Resources::Brand.new(self); end |
#contact_groups ⇒ Resources::ContactGroup
47 |
# File 'lib/boldsign/client.rb', line 47 def contact_groups; @contact_groups ||= Resources::ContactGroup.new(self); end |
#contacts ⇒ Resources::Contact
45 |
# File 'lib/boldsign/client.rb', line 45 def contacts; @contacts ||= Resources::Contact.new(self); end |
#custom_fields ⇒ Resources::CustomField
49 |
# File 'lib/boldsign/client.rb', line 49 def custom_fields; @custom_fields ||= Resources::CustomField.new(self); end |
#delete(path, params = {}) ⇒ Object
Issue a DELETE request.
100 101 102 |
# File 'lib/boldsign/client.rb', line 100 def delete(path, params = {}) request(:delete, path, params: params) end |
#documents ⇒ Resources::Document
51 |
# File 'lib/boldsign/client.rb', line 51 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).
110 111 112 113 114 115 116 |
# File 'lib/boldsign/client.rb', line 110 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.
70 71 72 |
# File 'lib/boldsign/client.rb', line 70 def get(path, params = {}) request(:get, path, params: params) end |
#identity_verification ⇒ Resources::IdentityVerification
53 |
# File 'lib/boldsign/client.rb', line 53 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.
93 94 95 |
# File 'lib/boldsign/client.rb', line 93 def patch(path, body: nil, params: {}) request(:patch, path, body: body, params: params) end |
#plan ⇒ Resources::Plan
55 |
# File 'lib/boldsign/client.rb', line 55 def plan; @plan ||= Resources::Plan.new(self); end |
#post(path, body: nil, params: {}, multipart: false) ⇒ Hash, ...
Issue a POST request.
83 84 85 |
# File 'lib/boldsign/client.rb', line 83 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.
88 89 90 |
# File 'lib/boldsign/client.rb', line 88 def put(path, body: nil, params: {}) request(:put, path, body: body, params: params) end |
#sender_identities ⇒ Resources::SenderIdentity
57 |
# File 'lib/boldsign/client.rb', line 57 def sender_identities; @sender_identities ||= Resources::SenderIdentity.new(self); end |
#teams ⇒ Resources::Team
59 |
# File 'lib/boldsign/client.rb', line 59 def teams; @teams ||= Resources::Team.new(self); end |
#templates ⇒ Resources::Template
61 |
# File 'lib/boldsign/client.rb', line 61 def templates; @templates ||= Resources::Template.new(self); end |
#users ⇒ Resources::User
63 |
# File 'lib/boldsign/client.rb', line 63 def users; @users ||= Resources::User.new(self); end |