Class: NameDotComApi::Connection
- Inherits:
-
Object
- Object
- NameDotComApi::Connection
- Defined in:
- lib/name_dot_com_api/connection.rb
Constant Summary collapse
- HTTP_FORMAT_HEADER_NAMES =
{ :get => 'Accept', :post => 'Content-Type' }
- JSON_MIME_TYPE =
'text/json; charset=utf-8'
Instance Attribute Summary collapse
-
#api_token ⇒ Object
Returns the value of attribute api_token.
-
#cookies ⇒ Object
Returns the value of attribute cookies.
-
#session_token ⇒ Object
Returns the value of attribute session_token.
-
#test_mode ⇒ Object
Returns the value of attribute test_mode.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#url ⇒ Object
Returns the value of attribute url.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #get(path, params = {}) ⇒ Object
-
#http ⇒ Object
Creates new Net::HTTP instance for communication with remote service and resources.
-
#initialize(test_mode = false) ⇒ Connection
constructor
A new instance of Connection.
- #logged_in? ⇒ Boolean
- #logger ⇒ Object
- #post(path, params = {}) ⇒ Object
Constructor Details
#initialize(test_mode = false) ⇒ Connection
Returns a new instance of Connection.
29 30 31 32 33 |
# File 'lib/name_dot_com_api/connection.rb', line 29 def initialize(test_mode = false) @headers ||= {} @cookies ||= {} @test_mode = test_mode end |
Instance Attribute Details
#api_token ⇒ Object
Returns the value of attribute api_token.
35 36 37 |
# File 'lib/name_dot_com_api/connection.rb', line 35 def api_token @api_token end |
#cookies ⇒ Object
Returns the value of attribute cookies.
36 37 38 |
# File 'lib/name_dot_com_api/connection.rb', line 36 def @cookies end |
#session_token ⇒ Object
Returns the value of attribute session_token.
35 36 37 |
# File 'lib/name_dot_com_api/connection.rb', line 35 def session_token @session_token end |
#test_mode ⇒ Object
Returns the value of attribute test_mode.
36 37 38 |
# File 'lib/name_dot_com_api/connection.rb', line 36 def test_mode @test_mode end |
#timeout ⇒ Object
Returns the value of attribute timeout.
36 37 38 |
# File 'lib/name_dot_com_api/connection.rb', line 36 def timeout @timeout end |
#url ⇒ Object
Returns the value of attribute url.
36 37 38 |
# File 'lib/name_dot_com_api/connection.rb', line 36 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
35 36 37 |
# File 'lib/name_dot_com_api/connection.rb', line 35 def username @username end |
Instance Method Details
#get(path, params = {}) ⇒ Object
55 |
# File 'lib/name_dot_com_api/connection.rb', line 55 def get(path, params = {}); request(:get, path, params); end |
#http ⇒ Object
Creates new Net::HTTP instance for communication with remote service and resources.
46 47 48 49 50 51 52 53 |
# File 'lib/name_dot_com_api/connection.rb', line 46 def http http = Net::HTTP.new(url.host, url.port) http.use_ssl = url.is_a?(URI::HTTPS) http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl? http.read_timeout = timeout || 60 # Net::HTTP default 60 seconds http.set_debug_output $stderr if test_mode http end |
#logged_in? ⇒ Boolean
38 |
# File 'lib/name_dot_com_api/connection.rb', line 38 def logged_in?; !!session_token; end |
#logger ⇒ Object
58 59 60 |
# File 'lib/name_dot_com_api/connection.rb', line 58 def logger defined?(ActiveRecord) ? ActiveRecord::Base.logger : nil end |
#post(path, params = {}) ⇒ Object
56 |
# File 'lib/name_dot_com_api/connection.rb', line 56 def post(path, params = {}); request(:post, path, params); end |