Class: CloudConnect::Client
- Inherits:
-
Object
- Object
- CloudConnect::Client
- Defined in:
- lib/cloud_connect/client.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#cookie ⇒ Object
Returns the value of attribute cookie.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#api_url ⇒ String
Provides the URL for accessing the API.
-
#connection ⇒ Faraday::Connection
Raw HTTP connection, either Faraday::Connection.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #login ⇒ Object
Methods included from Trackings
Methods included from Fields
Methods included from Messages
Methods included from Channels
Methods included from Users
Methods included from Units
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 11 12 |
# File 'lib/cloud_connect/client.rb', line 6 def initialize(={}) @username = [:username] || CloudConnect.username @password = [:password] || CloudConnect.password @account = [:account] || CloudConnect.account @env = [:env] || CloudConnect.env || "prod" @version = [:version] || "v2" end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
3 4 5 |
# File 'lib/cloud_connect/client.rb', line 3 def account @account end |
#cookie ⇒ Object
Returns the value of attribute cookie.
3 4 5 |
# File 'lib/cloud_connect/client.rb', line 3 def end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
3 4 5 |
# File 'lib/cloud_connect/client.rb', line 3 def env @env end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
3 4 5 |
# File 'lib/cloud_connect/client.rb', line 3 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
3 4 5 |
# File 'lib/cloud_connect/client.rb', line 3 def username @username end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
3 4 5 |
# File 'lib/cloud_connect/client.rb', line 3 def version @version end |
Instance Method Details
#api_url ⇒ String
Provides the URL for accessing the API
34 35 36 37 38 39 40 |
# File 'lib/cloud_connect/client.rb', line 34 def api_url if env == "preprod" "http://srv/api/v2" else "http://#{env}.g8teway.com/api/#{version}" end end |
#connection ⇒ Faraday::Connection
Raw HTTP connection, either Faraday::Connection
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cloud_connect/client.rb', line 17 def connection params = {} params[:access_token] = @access_token if @access_token @connection ||= Faraday::Connection.new(:url => api_url, :params => params, :headers => default_headers) do |builder| builder.use Faraday::Request::CookieAuth, self builder.adapter Faraday.default_adapter builder.use Faraday::Response::RaiseHttp5xx builder.use Faraday::Response::ParseJson builder.use Faraday::Response::RaiseHttp4xx builder.use Faraday::Response::Mashify #builder.response :yajl # Faraday::Request::Yajl end end |
#login ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/cloud_connect/client.rb', line 42 def login if version == "v1.5" req = connection.post('ws?login', "username=#{username}&password=#{password}&client=#{account}") else req = connection.post('sessions', {:login => username, :password => password, :client => account}) end end |