Class: WriteItInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/writeit-rails/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/writeit-rails/writeitinstance.rb', line 5

def api_key
  @api_key
end

#base_urlObject

Returns the value of attribute base_url.



3
4
5
# File 'lib/writeit-rails/writeitinstance.rb', line 3

def base_url
  @base_url
end

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/writeit-rails/writeitinstance.rb', line 7

def errors
  @errors
end

#per_pageObject

Returns the value of attribute per_page.



6
7
8
# File 'lib/writeit-rails/writeitinstance.rb', line 6

def per_page
  @per_page
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/writeit-rails/writeitinstance.rb', line 2

def url
  @url
end

#usernameObject

Returns the value of attribute username.



4
5
6
# File 'lib/writeit-rails/writeitinstance.rb', line 4

def username
  @username
end

Instance Method Details

#validateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/writeit-rails/writeitinstance.rb', line 13

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