Class: SmartyStreets::ClientBuilder
- Inherits:
-
Object
- Object
- SmartyStreets::ClientBuilder
- Defined in:
- lib/smartystreets_ruby_sdk/client_builder.rb
Overview
The ClientBuilder class helps you build a client object for one of the supported SmartyStreets APIs. You can use ClientBuilder’s methods to customize settings like maximum retries or timeout duration. These methods are chainable, so you can usually get set up with one line of code.
Constant Summary collapse
- INTERNATIONAL_STREET_API_URL =
'https://international-street.api.smartystreets.com/verify'.freeze
- US_AUTOCOMPLETE_API_URL =
'https://us-autocomplete.api.smartystreets.com/suggest'.freeze
- US_EXTRACT_API_URL =
'https://us-extract.api.smartystreets.com/'.freeze
- US_STREET_API_URL =
'https://us-street.api.smartystreets.com/street-address'.freeze
- US_ZIP_CODE_API_URL =
'https://us-zipcode.api.smartystreets.com/lookup'.freeze
Instance Method Summary collapse
- #build_international_street_api_client ⇒ Object
- #build_sender ⇒ Object
- #build_us_autocomplete_api_client ⇒ Object
- #build_us_extract_api_client ⇒ Object
- #build_us_street_api_client ⇒ Object
- #build_us_zipcode_api_client ⇒ Object
- #ensure_url_prefix_not_null(url) ⇒ Object
-
#initialize(signer) ⇒ ClientBuilder
constructor
A new instance of ClientBuilder.
-
#retry_at_most(max_retries) ⇒ Object
Sets the maximum number of times to retry sending the request to the API.
-
#with_base_url(base_url) ⇒ Object
This may be useful when using a local installation of the SmartyStreets APIs.
-
#with_max_timeout(max_timeout) ⇒ Object
The maximum time (in milliseconds) to wait for a connection, and also to wait for the response to be read.
-
#with_proxy(host, port, username, password) ⇒ Object
Assigns a proxy through which all requests will be sent.
-
#with_sender(sender) ⇒ Object
Default is a series of nested senders.
-
#with_serializer(serializer) ⇒ Object
Changes the Serializer from the default.
Constructor Details
#initialize(signer) ⇒ ClientBuilder
Returns a new instance of ClientBuilder.
27 28 29 30 31 32 33 34 35 |
# File 'lib/smartystreets_ruby_sdk/client_builder.rb', line 27 def initialize(signer) @signer = signer @serializer = NativeSerializer.new @http_sender = nil @max_retries = 5 @max_timeout = 10_000 @url_prefix = nil @proxy = nil end |
Instance Method Details
#build_international_street_api_client ⇒ Object
88 89 90 91 |
# File 'lib/smartystreets_ruby_sdk/client_builder.rb', line 88 def build_international_street_api_client ensure_url_prefix_not_null(INTERNATIONAL_STREET_API_URL) InternationalStreet::Client.new(build_sender, @serializer) end |
#build_sender ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/smartystreets_ruby_sdk/client_builder.rb', line 113 def build_sender return @http_sender unless @http_sender.nil? sender = NativeSender.new(@max_timeout, @proxy) sender = StatusCodeSender.new(sender) sender = SigningSender.new(@signer, sender) unless @signer.nil? sender = RetrySender.new(@max_retries, sender, SmartyStreets::Sleeper.new,SmartyStreets::Logger.new) if @max_retries > 0 URLPrefixSender.new(@url_prefix, sender) end |
#build_us_autocomplete_api_client ⇒ Object
93 94 95 96 |
# File 'lib/smartystreets_ruby_sdk/client_builder.rb', line 93 def build_us_autocomplete_api_client ensure_url_prefix_not_null(US_AUTOCOMPLETE_API_URL) USAutocomplete::Client.new(build_sender, @serializer) end |
#build_us_extract_api_client ⇒ Object
98 99 100 101 |
# File 'lib/smartystreets_ruby_sdk/client_builder.rb', line 98 def build_us_extract_api_client ensure_url_prefix_not_null(US_EXTRACT_API_URL) USExtract::Client.new(build_sender, @serializer) end |
#build_us_street_api_client ⇒ Object
103 104 105 106 |
# File 'lib/smartystreets_ruby_sdk/client_builder.rb', line 103 def build_us_street_api_client ensure_url_prefix_not_null(US_STREET_API_URL) USStreet::Client.new(build_sender, @serializer) end |
#build_us_zipcode_api_client ⇒ Object
108 109 110 111 |
# File 'lib/smartystreets_ruby_sdk/client_builder.rb', line 108 def build_us_zipcode_api_client ensure_url_prefix_not_null(US_ZIP_CODE_API_URL) USZipcode::Client.new(build_sender, @serializer) end |
#ensure_url_prefix_not_null(url) ⇒ Object
127 128 129 |
# File 'lib/smartystreets_ruby_sdk/client_builder.rb', line 127 def ensure_url_prefix_not_null(url) @url_prefix = url if @url_prefix.nil? end |
#retry_at_most(max_retries) ⇒ Object
Sets the maximum number of times to retry sending the request to the API. (Default is 5)
Returns self to accommodate method chaining.
40 41 42 43 |
# File 'lib/smartystreets_ruby_sdk/client_builder.rb', line 40 def retry_at_most(max_retries) @max_retries = max_retries self end |
#with_base_url(base_url) ⇒ Object
This may be useful when using a local installation of the SmartyStreets APIs. base_url is a string that defaults to the URL for the API corresponding to the Client object being built.
Returns self to accommodate method chaining.
74 75 76 77 |
# File 'lib/smartystreets_ruby_sdk/client_builder.rb', line 74 def with_base_url(base_url) @url_prefix = base_url self end |
#with_max_timeout(max_timeout) ⇒ Object
The maximum time (in milliseconds) to wait for a connection, and also to wait for the response to be read. (Default is 10000)
Returns self to accommodate method chaining.
49 50 51 52 |
# File 'lib/smartystreets_ruby_sdk/client_builder.rb', line 49 def with_max_timeout(max_timeout) @max_timeout = max_timeout self end |
#with_proxy(host, port, username, password) ⇒ Object
Assigns a proxy through which all requests will be sent. proxy is a Proxy object from this module.
Returns self to accommodate method chaining.
83 84 85 86 |
# File 'lib/smartystreets_ruby_sdk/client_builder.rb', line 83 def with_proxy(host, port, username, password) @proxy = SmartyStreets::Proxy.new(host, port, username, password) self end |
#with_sender(sender) ⇒ Object
Default is a series of nested senders. (See build_sender()
Returns self to accommodate method chaining.
57 58 59 60 |
# File 'lib/smartystreets_ruby_sdk/client_builder.rb', line 57 def with_sender(sender) @http_sender = sender self end |
#with_serializer(serializer) ⇒ Object
Changes the Serializer from the default.
Returns self to accommodate method chaining.
65 66 67 68 |
# File 'lib/smartystreets_ruby_sdk/client_builder.rb', line 65 def with_serializer(serializer) @serializer = serializer self end |