Class: Craigslist::API::Configuration
- Inherits:
-
Object
- Object
- Craigslist::API::Configuration
- Defined in:
- lib/craigslist/api/configuration.rb
Overview
Immutable configuration for a Client.
Instances are frozen on construction. Nothing mutates configuration at request time, which keeps a single client safe to share across threads. Multi-account setups build one client per account rather than swapping credentials on a global.
Constant Summary collapse
- DEFAULT_BULK_HOST =
Host serving the RSS bulk posting interface (posting creation).
"https://post.craigslist.org"- DEFAULT_BAPI_HOST =
Host serving the JSON Bulkpost API (everything after creation).
"https://bapi.craigslist.org"- DEFAULT_REFERENCE_HOST =
Host serving public areas/categories reference data. No auth required.
"https://reference.craigslist.org"- DEFAULT_SCOPES =
Top-level OAuth scopes. Scopes are hierarchical, so requesting
bulkpost.postingalso grantsbulkpost.posting.deleteand friends. %w[ bulkpost.posting bulkpost.account.billing bulkpost.account.message bulkpost.account.stats ].freeze
- DEFAULT_TIMEOUT =
Bulk submissions can carry base64 image payloads, so the default read timeout is generous.
120- DEFAULT_OPEN_TIMEOUT =
Connection establishment timeout, in seconds.
15
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#bapi_host ⇒ Object
readonly
Returns the value of attribute bapi_host.
-
#bulk_host ⇒ Object
readonly
Returns the value of attribute bulk_host.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#open_timeout ⇒ Object
readonly
Returns the value of attribute open_timeout.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#reference_host ⇒ Object
readonly
Returns the value of attribute reference_host.
-
#scopes ⇒ Object
readonly
Returns the value of attribute scopes.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
-
#basic_authorization ⇒ String
HTTP Basic credential for the token endpoint.
-
#client_id ⇒ String
The OAuth2
client_id, which Craigslist defines as the account email and account id joined by a semicolon. -
#initialize(email:, password:, account_id:, scopes: DEFAULT_SCOPES, bulk_host: DEFAULT_BULK_HOST, bapi_host: DEFAULT_BAPI_HOST, reference_host: DEFAULT_REFERENCE_HOST, timeout: DEFAULT_TIMEOUT, open_timeout: DEFAULT_OPEN_TIMEOUT, user_agent: "craigslist-api-ruby/#{VERSION}", logger: nil, adapter: Faraday.default_adapter) ⇒ Configuration
constructor
A new instance of Configuration.
-
#inspect ⇒ String
(also: #to_s)
Redacts the password so credentials never leak into logs or exception output through a stray
inspect. -
#post_url ⇒ String
The URL RSS submissions are posted to.
-
#validate_url ⇒ String
The URL RSS submissions are validated against.
Constructor Details
#initialize(email:, password:, account_id:, scopes: DEFAULT_SCOPES, bulk_host: DEFAULT_BULK_HOST, bapi_host: DEFAULT_BAPI_HOST, reference_host: DEFAULT_REFERENCE_HOST, timeout: DEFAULT_TIMEOUT, open_timeout: DEFAULT_OPEN_TIMEOUT, user_agent: "craigslist-api-ruby/#{VERSION}", logger: nil, adapter: Faraday.default_adapter) ⇒ Configuration
Returns a new instance of Configuration.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/craigslist/api/configuration.rb', line 54 def initialize( email:, password:, account_id:, scopes: DEFAULT_SCOPES, bulk_host: DEFAULT_BULK_HOST, bapi_host: DEFAULT_BAPI_HOST, reference_host: DEFAULT_REFERENCE_HOST, timeout: DEFAULT_TIMEOUT, open_timeout: DEFAULT_OPEN_TIMEOUT, user_agent: "craigslist-api-ruby/#{VERSION}", logger: nil, adapter: Faraday.default_adapter ) @email = presence!(email, :email) @password = presence!(password, :password) @account_id = presence!(account_id, :account_id).to_s @scopes = Array(scopes).map(&:to_s).freeze @bulk_host = bulk_host @bapi_host = bapi_host @reference_host = reference_host @timeout = timeout @open_timeout = open_timeout @user_agent = user_agent @logger = logger @adapter = adapter freeze end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
37 38 39 |
# File 'lib/craigslist/api/configuration.rb', line 37 def account_id @account_id end |
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
37 38 39 |
# File 'lib/craigslist/api/configuration.rb', line 37 def adapter @adapter end |
#bapi_host ⇒ Object (readonly)
Returns the value of attribute bapi_host.
37 38 39 |
# File 'lib/craigslist/api/configuration.rb', line 37 def bapi_host @bapi_host end |
#bulk_host ⇒ Object (readonly)
Returns the value of attribute bulk_host.
37 38 39 |
# File 'lib/craigslist/api/configuration.rb', line 37 def bulk_host @bulk_host end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
37 38 39 |
# File 'lib/craigslist/api/configuration.rb', line 37 def email @email end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
37 38 39 |
# File 'lib/craigslist/api/configuration.rb', line 37 def logger @logger end |
#open_timeout ⇒ Object (readonly)
Returns the value of attribute open_timeout.
37 38 39 |
# File 'lib/craigslist/api/configuration.rb', line 37 def open_timeout @open_timeout end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
37 38 39 |
# File 'lib/craigslist/api/configuration.rb', line 37 def password @password end |
#reference_host ⇒ Object (readonly)
Returns the value of attribute reference_host.
37 38 39 |
# File 'lib/craigslist/api/configuration.rb', line 37 def reference_host @reference_host end |
#scopes ⇒ Object (readonly)
Returns the value of attribute scopes.
37 38 39 |
# File 'lib/craigslist/api/configuration.rb', line 37 def scopes @scopes end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
37 38 39 |
# File 'lib/craigslist/api/configuration.rb', line 37 def timeout @timeout end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
37 38 39 |
# File 'lib/craigslist/api/configuration.rb', line 37 def user_agent @user_agent end |
Instance Method Details
#basic_authorization ⇒ String
HTTP Basic credential for the token endpoint.
Encoded with Array#pack rather than the base64 gem, which stopped
being a default gem in Ruby 3.4 and would otherwise add a dependency.
98 99 100 |
# File 'lib/craigslist/api/configuration.rb', line 98 def "Basic #{["#{client_id}:#{password}"].pack("m0")}" end |
#client_id ⇒ String
The OAuth2 client_id, which Craigslist defines as the account email
and account id joined by a semicolon.
88 89 90 |
# File 'lib/craigslist/api/configuration.rb', line 88 def client_id "#{email};#{account_id}" end |
#inspect ⇒ String Also known as: to_s
Redacts the password so credentials never leak into logs or exception
output through a stray inspect.
116 117 118 |
# File 'lib/craigslist/api/configuration.rb', line 116 def inspect "#<#{self.class.name} email=#{email.inspect} account_id=#{account_id.inspect} password=[FILTERED]>" end |
#post_url ⇒ String
Returns the URL RSS submissions are posted to.
108 109 110 |
# File 'lib/craigslist/api/configuration.rb', line 108 def post_url "#{bulk_host}/bulk-rss/post" end |
#validate_url ⇒ String
Returns the URL RSS submissions are validated against.
103 104 105 |
# File 'lib/craigslist/api/configuration.rb', line 103 def validate_url "#{bulk_host}/bulk-rss/validate" end |