Class: BoundioV2::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/boundioV2/resource.rb

Direct Known Subclasses

AudioFile, Call, TelStatus

Defined Under Namespace

Classes: Unauthorized

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Resource

Returns a new instance of Resource.



39
40
41
# File 'lib/boundioV2/resource.rb', line 39

def initialize(args = {})
  args.each {|k,v| send("#{k}=", v) }
end

Class Method Details

.api_versionObject



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

def api_version
  "vd2"
end

.create(args) ⇒ Object



4
5
6
7
8
# File 'lib/boundioV2/resource.rb', line 4

def create(args)
  o = new(args)
  o.save
  o
end

.exceptionsObject



34
35
36
# File 'lib/boundioV2/resource.rb', line 34

def exceptions
  { 1 => Unauthorized }
end

.request(method, path, params) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/boundioV2/resource.rb', line 21

def request(method, path, params)
  params = params.merge(:key => api_key, :auth => user_key)
  res = RestClient.send method,
    File.join("https://boundio.jp/api/", api_version, user_serial_id, path), 
    method == :get ? { :params => params } : params
  res = JSON.parse(res)
  res = res.first if res.is_a?(Array)
  unless res["success"] == "true"
    raise exceptions[res["error"].to_i] || BoundioV2::Exception.new("Error Code #{res["error"]}")
  end
  res
end