Module: BimsApiClient

Includes:
HTTParty
Defined in:
lib/configuration.rb,
lib/bims_api_client.rb,
lib/bims_api_client/version.rb

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

VERSION =
'0.0.1'

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



10
11
12
# File 'lib/bims_api_client.rb', line 10

def configuration
  @configuration
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



21
22
23
# File 'lib/bims_api_client.rb', line 21

def self.configure
  yield(configuration)
end

.resetObject



17
18
19
# File 'lib/bims_api_client.rb', line 17

def self.reset
  @configuration = Configuration.new
end

Instance Method Details

#initObject



27
28
29
30
31
32
33
34
35
# File 'lib/bims_api_client.rb', line 27

def init
  success = false
  begin
    success = setup_redis(@configuration.redis_url) && set_api_base_uri(@configuration.instance_url)
  rescue => e #debug the error
    puts e.to_s
  end
  return success
end

#login(username = (@configuration.username), password = (@configuration.password)) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/bims_api_client.rb', line 64

def (username = (@configuration.username), password = (@configuration.password))
  success = false
  begin
    return false if not_initialized?
    response_object = (username, password)
    if response_object[@configuration.status_key] == @configuration.status_value_ok
      @redis.set('bims_sid', response_object[@configuration.data_key][@configuration.data_session_key][@configuration.data_session_id_key].to_s)
      success = true
    end
  rescue => e
    puts e.to_s #debug the error
  end
  return success
end

#logoutObject



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/bims_api_client.rb', line 79

def logout
  begin
    return false if not_initialized?
    sid = @redis.get('bims_sid')
    @redis.set('bims_sid', nil)
    response_object = _logout(sid)
    response_object[@configuration.status_key] == @configuration.status_value_ok ? true : false
  rescue => e
    puts e.to_s #debug the error
  end
end

#not_initialized?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/bims_api_client.rb', line 37

def not_initialized?
  !@configuration.instance_url && !@configuration.instance_name
end

#session_active?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/bims_api_client.rb', line 60

def session_active?
  (@redis.get('bims_sid') && !@redis.get('bims_sid').empty?) ? true : false
end

#set_api_base_uri(uri) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/bims_api_client.rb', line 45

def set_api_base_uri(uri)
  success = false
  begin
    base_uri uri
    success = true
  rescue => e
    puts e.to_s #debug the error
  end
  return success
end

#set_error_object(data = nil) ⇒ Object



56
57
58
# File 'lib/bims_api_client.rb', line 56

def set_error_object(data = nil)
  {status: 'error', code: -1, data: data}
end

#setup_redis(redis_url) ⇒ Object



41
42
43
# File 'lib/bims_api_client.rb', line 41

def setup_redis(redis_url)
  @redis = Redis.new(url: redis_url)
end