Class: SmartCampus::ApiV1::Base
- Inherits:
-
Object
- Object
- SmartCampus::ApiV1::Base
- Includes:
- HTTParty
- Defined in:
- lib/smart_campus/api_v1/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #hashie(response) ⇒ Object
-
#initialize(params, options = {}) ⇒ Base
constructor
A new instance of Base.
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, = {}) base_uri = [:host] || SmartCampus.api_url #self.class.base_uri(base_uri+":8000") self.class.base_uri(base_uri) puts app_key = [:key] || SmartCampus.app_key app_secret = [:secret] || SmartCampus.app_secret puts ts = [: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
#params ⇒ Object
Returns the value of attribute params.
9 10 11 |
# File 'lib/smart_campus/api_v1/base.rb', line 9 def params @params end |
#token ⇒ Object
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 |