Permalink
Browse files

working on a new version...

  • Loading branch information...
ppadron committed Aug 17, 2011
1 parent f57826f commit a2fd2d5816d4116e2130fb8718aee4d03a29399e
Showing with 75 additions and 23 deletions.
  1. +38 −23 lib/konstati.rb
  2. +15 −0 lib/konstati/account.rb
  3. +22 −0 lib/konstati/test.rb
View
@@ -1,39 +1,54 @@
-require "active_resource"
+require 'restclient'
+require 'json'
+require 'konstati/account'
+require 'konstati/test'
module Konstati
- VERSION = "0.1.0"
-
- class Base < ActiveResource::Base
+ def self.endpoint
+ @endpoint ||= "http://api.konstati.co/v1"
+ end
- self.format = :json
- self.site = "http://api.konstati.co/"
- self.headers['User-Agent'] = "Konstati Ruby Client v0.1"
+ def self.endpoint=(val)
+ @endpoint = val
+ end
- def self.authenticate(options)
- self.user = options[:username]
- self.password = options[:password]
+ def self.username
+ @username
end
- def self.element_path(id, prefix_options = {}, query_options = nil)
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
- "#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
+ def self.username=(val)
+ @username = val
end
- def self.collection_path(prefix_options = {}, query_options = nil)
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
- "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
+ def self.apikey=(val)
+ @apikey = val
end
- end
- module Tests
+ def self.apikey
+ @apikey
+ end
- class Spamassassin < Base
- self.site = "http://api.konstati.co/"
- self.collection_name = "tests/spamassassin"
- self.element_name = "tests/spamassassin"
+ def self.resource(path)
+ RestClient::Resource.new(@endpoint + path, @username, @apikey)
end
- end
+ def self.request(method, path, params = {})
+
+ begin
+ response = RestClient::Request.execute(
+ :method => method,
+ :url => endpoint + path,
+ :payload => params,
+ :user => @username,
+ :password => @apikey
+ )
+ rescue Exception => e
+ puts e
+ return false
+ end
+
+ JSON.parse(response)
+ end
end
View
@@ -0,0 +1,15 @@
+require 'json'
+
+module Konstati
+ class Account
+
+ def self.initialize
+ puts 'bola'
+ end
+
+ def self.info
+ Konstati.request("get", "/account")
+ # RestClient::Resource.new(Konstati::Config.endpoint + '/account', Konstati::Config.username, Konstati::Config.apikey).get
+ end
+ end
+end
View
@@ -0,0 +1,22 @@
+module Konstati
+
+ class Test
+
+ def self.create(params)
+ Konstati.request(:post, '/tests', params)
+ end
+
+ def self.find(params = {})
+ Konstati.request(:get, '/tests', params)
+ end
+
+ def self.delete(id)
+ Konstati.request(:delete, '/tests/' + id)
+ end
+
+ def self.get(id)
+ Konstati.request(:get, '/tests/' + id)
+ end
+
+ end
+end

0 comments on commit a2fd2d5

Please sign in to comment.