Class: SmartCampus::ApiV1::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/smart_campus/api_v1/base.rb

Direct Known Subclasses

Ap

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, options = {}) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/smart_campus/api_v1/base.rb', line 10

def initialize(params, options= {})
  base_uri = options[:host] || SmartCampus.api_url
  #self.class.base_uri(base_uri+":8000")
  self.class.base_uri(base_uri)
  puts  app_key = options[:key] || SmartCampus.app_key
  app_secret = options[:secret] || SmartCampus.app_secret
  puts ts = options[:ts] ||  Time.now.to_i
  puts token = SmartCampus::Sign.generate_str("#{app_key}#{ts}#{app_secret}")
  @params = {
      key: app_key,
      ts: ts,
      token: token
  }.merge(params)
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



9
10
11
# File 'lib/smart_campus/api_v1/base.rb', line 9

def params
  @params
end

#tokenObject

Returns the value of attribute token.



9
10
11
# File 'lib/smart_campus/api_v1/base.rb', line 9

def token
  @token
end

Instance Method Details

#hashie(response) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/smart_campus/api_v1/base.rb', line 25

def hashie(response)
  puts response.body
  json_body = MultiJson.load(response.body,:symbolize_keys => true)
  if json_body.is_a? Array
    Array.new(json_body.count){|i| Hashie::Mash.new(json_body[i])}
  else
    Hashie::Mash.new json_body
  end
end