Class: DMS::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/dms/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_token = nil, api_access_key = nil) ⇒ API

Returns a new instance of API.



11
12
13
14
# File 'lib/dms/api.rb', line 11

def initialize(api_token = nil, api_access_key = nil)
  @api_token      = api_token.to_s
  @api_access_key = api_access_key.to_s
end

Instance Attribute Details

#api_access_keyObject

Returns the value of attribute api_access_key.



9
10
11
# File 'lib/dms/api.rb', line 9

def api_access_key
  @api_access_key
end

#api_tokenObject

Returns the value of attribute api_token.



8
9
10
# File 'lib/dms/api.rb', line 8

def api_token
  @api_token
end

Instance Method Details

#format_extensionObject



16
17
18
# File 'lib/dms/api.rb', line 16

def format_extension
  ".#{self.class.format.to_s}"
end

#generate_timestampObject



20
21
22
# File 'lib/dms/api.rb', line 20

def generate_timestamp
  Time.now.to_i.to_s
end

#get(slug) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dms/api.rb', line 28

def get(slug)
  response = perform_request(slug)
  if response.code == 200
    DMS::Node.new(response)
  elsif response.code == 401
    raise AuthenticationError.new(response.body)
  elsif response.code == 404
    raise ResourceNotFound.new(response.body)
  else
    raise UnknownError.new(response.body)
  end
end

#slug_to_path(slug) ⇒ Object



24
25
26
# File 'lib/dms/api.rb', line 24

def slug_to_path(slug)
  File.join("/", slug.to_s) + format_extension
end