Class: WriteItInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/models/writeitinstance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



5
6
7
# File 'lib/models/writeitinstance.rb', line 5

def api_key
  @api_key
end

#base_urlObject

Returns the value of attribute base_url.



3
4
5
# File 'lib/models/writeitinstance.rb', line 3

def base_url
  @base_url
end

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/models/writeitinstance.rb', line 6

def errors
  @errors
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/models/writeitinstance.rb', line 2

def url
  @url
end

#usernameObject

Returns the value of attribute username.



4
5
6
# File 'lib/models/writeitinstance.rb', line 4

def username
  @username
end

Instance Method Details

#validateObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/models/writeitinstance.rb', line 9

def validate
	authorization = 'ApiKey %{username}:%{api_key}' % {
        :username => self.username,
        :api_key => self.api_key,
    }

	url = self.base_url + "/api/v1" + self.url
	request = RestClient::Request.new(
        :method => :get,
        :url => url,
        :headers => {
            :accept => :json,
            :authorization => authorization,
            }
        )

	#RestClient::ResourceNotFound
	begin
		request.execute
 rescue Exception => e
 	@errors = [e.message]

 	return false
 end	
	return true
end