Class: CloudConnect::Client
- Inherits:
-
Object
- Object
- CloudConnect::Client
- Includes:
- Channels, Fields, Messages, Trackings, Units, Users
- Defined in:
- lib/cloud_connect/client.rb
Instance Attribute Summary (collapse)
-
- (Object) account
readonly
Returns the value of attribute account.
-
- (Object) cookie
Returns the value of attribute cookie.
-
- (Object) env
readonly
Returns the value of attribute env.
-
- (Object) password
readonly
Returns the value of attribute password.
-
- (Object) username
readonly
Returns the value of attribute username.
Instance Method Summary (collapse)
-
- (String) api_url
Provides the URL for accessing the API.
-
- (Faraday::Connection) connection
Raw HTTP connection, either Faraday::Connection.
-
- (Client) initialize(options = {})
constructor
A new instance of Client.
- - (Object) login
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
- (Client) initialize(options = {})
A new instance of Client
6 7 8 9 10 11 |
# 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" end |
Instance Attribute Details
- (Object) account (readonly)
Returns the value of attribute account
3 4 5 |
# File 'lib/cloud_connect/client.rb', line 3 def account @account end |
- (Object) cookie
Returns the value of attribute cookie
3 4 5 |
# File 'lib/cloud_connect/client.rb', line 3 def @cookie end |
- (Object) env (readonly)
Returns the value of attribute env
3 4 5 |
# File 'lib/cloud_connect/client.rb', line 3 def env @env end |
- (Object) password (readonly)
Returns the value of attribute password
3 4 5 |
# File 'lib/cloud_connect/client.rb', line 3 def password @password end |
- (Object) username (readonly)
Returns the value of attribute username
3 4 5 |
# File 'lib/cloud_connect/client.rb', line 3 def username @username end |
Instance Method Details
- (String) api_url
Provides the URL for accessing the API
33 34 35 36 37 38 39 |
# File 'lib/cloud_connect/client.rb', line 33 def api_url if env == "preprod" "http://srv/api/v2" else "http://#{env}.g8teway.com/api/v2" end end |
- (Faraday::Connection) connection
Raw HTTP connection, either Faraday::Connection
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cloud_connect/client.rb', line 16 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 |
- (Object) login
42 43 44 |
# File 'lib/cloud_connect/client.rb', line 42 def login req = connection.post('sessions', {:login => username, :password => password, :client => account}) end |