Class: Phabulous::Conduit::Client
- Inherits:
-
Object
- Object
- Phabulous::Conduit::Client
- Includes:
- HTTParty
- Defined in:
- lib/phabulous/conduit/client.rb
Constant Summary collapse
- Error =
Class.new(RuntimeError)
Instance Attribute Summary collapse
-
#cert ⇒ Object
Returns the value of attribute cert.
-
#host ⇒ Object
Returns the value of attribute host.
-
#session ⇒ Object
Returns the value of attribute session.
-
#token ⇒ Object
Returns the value of attribute token.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(_host = Phabulous.configuration.host, _user = Phabulous.configuration.user, _cert = Phabulous.configuration.cert) ⇒ Client
constructor
A new instance of Client.
- #ping ⇒ Object
- #request(method, data = {}) ⇒ Object
Constructor Details
#initialize(_host = Phabulous.configuration.host, _user = Phabulous.configuration.user, _cert = Phabulous.configuration.cert) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 |
# File 'lib/phabulous/conduit/client.rb', line 13 def initialize(_host = Phabulous.configuration.host, _user = Phabulous.configuration.user, _cert = Phabulous.configuration.cert) self.host = _host self.user = _user self.cert = _cert self.session = nil end |
Instance Attribute Details
#cert ⇒ Object
Returns the value of attribute cert.
11 12 13 |
# File 'lib/phabulous/conduit/client.rb', line 11 def cert @cert end |
#host ⇒ Object
Returns the value of attribute host.
11 12 13 |
# File 'lib/phabulous/conduit/client.rb', line 11 def host @host end |
#session ⇒ Object
Returns the value of attribute session.
11 12 13 |
# File 'lib/phabulous/conduit/client.rb', line 11 def session @session end |
#token ⇒ Object
Returns the value of attribute token.
11 12 13 |
# File 'lib/phabulous/conduit/client.rb', line 11 def token @token end |
#user ⇒ Object
Returns the value of attribute user.
11 12 13 |
# File 'lib/phabulous/conduit/client.rb', line 11 def user @user end |
Instance Method Details
#connect ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/phabulous/conduit/client.rb', line 25 def connect self.token = Time.now.to_i if result = request('conduit.connect', connection_payload) self.session = Conduit::Session.new(result['connectionID'], result['sessionKey']) end self.session end |
#ping ⇒ Object
21 22 23 |
# File 'lib/phabulous/conduit/client.rb', line 21 def ping request('conduit.ping') end |
#request(method, data = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/phabulous/conduit/client.rb', line 35 def request(method, data = {}) post_body = post_body(data) response = self.class.post("#{self.host}/api/#{method}", body: post_body, :headers => { 'Content-Type' => 'application/json' } ) if response.parsed_response['result'] response.parsed_response['result'] else raise Error, "Conduit error: #{response.parsed_response['error_info']}" end end |