Class: IpTracker::Client
- Inherits:
-
Object
- Object
- IpTracker::Client
- Includes:
- Connection, Request
- Defined in:
- lib/ip_tracker/client.rb,
lib/ip_tracker/client/errors.rb,
lib/ip_tracker/client/request.rb,
lib/ip_tracker/client/connection.rb,
lib/ip_tracker/client/authentication.rb
Defined Under Namespace
Modules: Authentication, Connection, Request Classes: HostTakenError, TargetError
Instance Attribute Summary collapse
-
#host_token ⇒ Object
Returns the value of attribute host_token.
-
#http_adapter ⇒ Object
readonly
Returns the value of attribute http_adapter.
-
#target_url ⇒ Object
readonly
Returns the value of attribute target_url.
Instance Method Summary collapse
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #register(hostname) ⇒ Object
- #update(host_id, attr, value) ⇒ Object
Methods included from Request
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
11 12 13 14 |
# File 'lib/ip_tracker/client.rb', line 11 def initialize @target_url = IpTracker::DEFAULT_LOCAL_TARGET @http_adapter = :net_http end |
Instance Attribute Details
#host_token ⇒ Object
Returns the value of attribute host_token.
20 21 22 |
# File 'lib/ip_tracker/client.rb', line 20 def host_token @host_token end |
#http_adapter ⇒ Object (readonly)
Returns the value of attribute http_adapter.
9 10 11 |
# File 'lib/ip_tracker/client.rb', line 9 def http_adapter @http_adapter end |
#target_url ⇒ Object (readonly)
Returns the value of attribute target_url.
9 10 11 |
# File 'lib/ip_tracker/client.rb', line 9 def target_url @target_url end |
Instance Method Details
#register(hostname) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/ip_tracker/client.rb', line 22 def register hostname response = post(IpTracker::HOSTS_PATH, :body => { name: hostname } ) raise HostTakenError if response.code == 201 raise TargetError if response.code == 200 || response.id == nil @host_token = response.id end |
#update(host_id, attr, value) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/ip_tracker/client.rb', line 30 def update host_id, attr, value response = put(IpTracker::HOSTS_PATH + "/#{host_id}", :body => {attr.to_sym => value}) raise TargetError if response.code == 200 || response.send(attr) != value true end |