Class: CloudConnect::Client

Inherits:
Object
  • Object
show all
Includes:
Channels, Fields, Messages, Trackings, Units, Users
Defined in:
lib/cloud_connect/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Trackings

#trackings

Methods included from Fields

#fields

Methods included from Messages

#messages, #send_message

Methods included from Channels

#channels

Methods included from Users

#user, #users

Methods included from Units

#find_units, #unit, #units

Constructor Details

#initialize(options = {}) ⇒ Client



6
7
8
9
10
11
# File 'lib/cloud_connect/client.rb', line 6

def initialize(options={})
  @username = options[:username] || CloudConnect.username
  @password = options[:password] || CloudConnect.password
  @account  = options[:account]  || CloudConnect.
  @env      = options[:env]      || CloudConnect.env      || "prod"
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account



3
4
5
# File 'lib/cloud_connect/client.rb', line 3

def 
  @account
end

Returns the value of attribute cookie



3
4
5
# File 'lib/cloud_connect/client.rb', line 3

def cookie
  @cookie
end

#envObject (readonly)

Returns the value of attribute env



3
4
5
# File 'lib/cloud_connect/client.rb', line 3

def env
  @env
end

#passwordObject (readonly)

Returns the value of attribute password



3
4
5
# File 'lib/cloud_connect/client.rb', line 3

def password
  @password
end

#usernameObject (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

#api_urlString

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

#connectionFaraday::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

#loginObject



42
43
44
# File 'lib/cloud_connect/client.rb', line 42

def 
  req = connection.post('sessions', {:login => username, :password => password, :client => })
end