Class: UboostClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/uboost-client/uboost_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = Hash.new) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
# File 'lib/uboost-client/uboost_client.rb', line 13

def initialize(options = Hash.new)
  @subdomain        = options[:subdomain]
  @api_credentials  = options[:api_credentials]
  @debug            = options[:debug] || false
end

Instance Attribute Details

#api_credentialsObject

Returns the value of attribute api_credentials.



11
12
13
# File 'lib/uboost-client/uboost_client.rb', line 11

def api_credentials
  @api_credentials
end

#subdomainObject

Returns the value of attribute subdomain.



11
12
13
# File 'lib/uboost-client/uboost_client.rb', line 11

def subdomain
  @subdomain
end

Instance Method Details

#accountObject



42
43
44
# File 'lib/uboost-client/uboost_client.rb', line 42

def 
  @account ||= UboostClient::Account.new(self)
end

#badgesObject



50
51
52
# File 'lib/uboost-client/uboost_client.rb', line 50

def badges
  @badges ||= UboostClient::Badges.new(self)
end

#connection(credentials = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/uboost-client/uboost_client.rb', line 19

def connection(credentials = nil)
  if credentials
    basic_auth_creds = "#{credentials[:username]}:#{credentials[:password]}"
  else
    basic_auth_creds = "#{@api_credentials[:username]}:#{@api_credentials[:password]}"
  end
  url = "https://#{basic_auth_creds}@#{@subdomain}.uboost.com"
  Faraday.new(url) do |faraday|
    faraday.request  :url_encoded               # form-encode POST params
    faraday.response :logger          if @debug # log requests to STDOUT
    faraday.adapter  Faraday.default_adapter    # make requests with Net::HTTP
  end
end

#connection_with_uboost_session(uboost_session_id) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/uboost-client/uboost_client.rb', line 33

def connection_with_uboost_session(uboost_session_id)
  url = "https://#{@subdomain}.uboost.com"
  Faraday.new(url, {:headers=>{'Cookie'=> uboost_session_id}}) do |faraday|
    faraday.request  :url_encoded             # form-encode POST params
    faraday.response :logger        if @debug # log requests to STDOUT
    faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
  end
end

#pointsObject



46
47
48
# File 'lib/uboost-client/uboost_client.rb', line 46

def points
  @points ||= UboostClient::Points.new(self)
end

#widgets(options = Hash.new) ⇒ Object



54
55
56
# File 'lib/uboost-client/uboost_client.rb', line 54

def widgets(options = Hash.new)
  @widgets = UboostClient::Widgets.new(self, options)
end