Class: Ohmage::Client

Inherits:
Object
  • Object
show all
Includes:
API
Defined in:
lib/ohmage/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from API::Audit

#audit_read

Methods included from API::Survey

#survey_response_delete, #survey_response_read, #survey_response_update, #survey_upload

Methods included from API::Media

#image_read, #media_read

Methods included from API::Document

#document_contents, #document_create, #document_delete, #document_read, #document_update

Methods included from API::Campaign

#campaign_create, #campaign_delete, #campaign_read, #campaign_search, #campaign_update

Methods included from API::Clazz

#class_create, #class_delete, #class_read, #class_search, #class_update

Methods included from API::User

#user_create, #user_delete, #user_info_read, #user_password, #user_read, #user_search, #user_setup, #user_update

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Client

rubocop:disable MethodLength

Yields:

  • (_self)

Yield Parameters:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ohmage/client.rb', line 8

def initialize(options = {}) # rubocop:disable MethodLength
  self.server_url = ENV['OHMAGE_SERVER_URL']
  self.user = ENV['OHMAGE_USER']
  self.password = ENV['OHMAGE_PASSWORD']
  self.client_string = 'ruby-ohmage'
  self.path = 'app/'
  self.port = 443
  self.server_debug = false
  options.each do |k, v|
    instance_variable_set("@#{k}", v)
  end
  yield(self) if block_given?
  server_config_read
  self
end

Instance Attribute Details

#client_stringObject

Returns the value of attribute client_string.



7
8
9
# File 'lib/ohmage/client.rb', line 7

def client_string
  @client_string
end

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/ohmage/client.rb', line 7

def password
  @password
end

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/ohmage/client.rb', line 7

def path
  @path
end

#portObject

Returns the value of attribute port.



7
8
9
# File 'lib/ohmage/client.rb', line 7

def port
  @port
end

#server_configObject

Returns the value of attribute server_config.



7
8
9
# File 'lib/ohmage/client.rb', line 7

def server_config
  @server_config
end

#server_debugObject

Returns the value of attribute server_debug.



7
8
9
# File 'lib/ohmage/client.rb', line 7

def server_debug
  @server_debug
end

#server_urlObject

Returns the value of attribute server_url.



7
8
9
# File 'lib/ohmage/client.rb', line 7

def server_url
  @server_url
end

#tokenObject

Returns the value of attribute token.



7
8
9
# File 'lib/ohmage/client.rb', line 7

def token
  @token
end

#userObject

Returns the value of attribute user.



7
8
9
# File 'lib/ohmage/client.rb', line 7

def user
  @user
end

Instance Method Details

#auth_tokenObject Also known as: auth

ohmage user/auth_token call



39
40
41
42
43
44
45
46
47
# File 'lib/ohmage/client.rb', line 39

def auth_token
  params = {}
  params['user'] = user
  params['password'] = password
  request = Ohmage::Request.new(self, :post, 'user/auth_token', params)
  resp = request.perform
  self.token = resp[:token]
  resp[:token]
end

#inspectString

Masking password from inspected client. Lovingly lifted from github.com/octokit/octokit.rb, The full text of the license for this work (MIT) can be found at opensource.org/licenses/mit

Returns:

  • (String)


55
56
57
58
# File 'lib/ohmage/client.rb', line 55

def inspect
  inspected = super
  inspected.gsub! @password, '*******' if @password
end

#server_config_readObject

ohmage config/read call



28
29
30
31
32
# File 'lib/ohmage/client.rb', line 28

def server_config_read
  request = Ohmage::Request.new(self, :get, 'config/read', {})
  resp = request.perform
  self.server_config = resp[:data]
end