Class: Transports::HttpClient
- Inherits:
-
Object
- Object
- Transports::HttpClient
- Defined in:
- lib/mote_sms/transports/http_client.rb
Overview
Small abstraction on top of Net::HTTP to handle things like public key pinning et all.
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#proxy_address ⇒ Object
readonly
Returns the value of attribute proxy_address.
-
#proxy_port ⇒ Object
readonly
Returns the value of attribute proxy_port.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Class Method Summary collapse
Instance Method Summary collapse
- #https? ⇒ Boolean
-
#initialize(endpoint, ssl: self.class.ssl_options, proxy_address: nil, proxy_port: nil, user_agent: self.class.default_user_agent) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #request(request) ⇒ Object
Constructor Details
#initialize(endpoint, ssl: self.class.ssl_options, proxy_address: nil, proxy_port: nil, user_agent: self.class.default_user_agent) ⇒ HttpClient
Returns a new instance of HttpClient.
36 37 38 39 40 41 42 43 |
# File 'lib/mote_sms/transports/http_client.rb', line 36 def initialize(endpoint, ssl: self.class., proxy_address: nil, proxy_port: nil, user_agent: self.class.default_user_agent) @endpoint = URI.parse(endpoint) @proxy_address = proxy_address @proxy_port = proxy_port @user_agent = user_agent @ssl = ssl || self.class. end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
34 35 36 |
# File 'lib/mote_sms/transports/http_client.rb', line 34 def endpoint @endpoint end |
#proxy_address ⇒ Object (readonly)
Returns the value of attribute proxy_address.
34 35 36 |
# File 'lib/mote_sms/transports/http_client.rb', line 34 def proxy_address @proxy_address end |
#proxy_port ⇒ Object (readonly)
Returns the value of attribute proxy_port.
34 35 36 |
# File 'lib/mote_sms/transports/http_client.rb', line 34 def proxy_port @proxy_port end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
34 35 36 |
# File 'lib/mote_sms/transports/http_client.rb', line 34 def ssl @ssl end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
34 35 36 |
# File 'lib/mote_sms/transports/http_client.rb', line 34 def user_agent @user_agent end |
Class Method Details
.default_user_agent ⇒ Object
30 31 32 |
# File 'lib/mote_sms/transports/http_client.rb', line 30 def self.default_user_agent "Ruby/mote_sms #{MoteSMS::VERSION}" end |
.ssl_options ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mote_sms/transports/http_client.rb', line 14 def self. @ssl_options ||= lambda do |http| http.verify_mode = OpenSSL::SSL::VERIFY_PEER http.verify_depth = 9 http.cert_store = OpenSSL::X509::Store.new http.cert_store.set_default_paths Dir["#{CERTS_PATH}/*.crt"].each do |c| begin http.cert_store.add_cert OpenSSL::X509::Certificate.new(File.read(c)) rescue OpenSSL::X509::StoreError => error nil end end end end |
Instance Method Details
#https? ⇒ Boolean
45 46 47 |
# File 'lib/mote_sms/transports/http_client.rb', line 45 def https? endpoint.scheme == 'https' end |
#request(request) ⇒ Object
49 50 51 52 |
# File 'lib/mote_sms/transports/http_client.rb', line 49 def request(request) request['User-Agent'] = user_agent build_http_client.request(request) end |