module Eventick
Constants
- BASE_PATH
- BASE_URL
- MAJOR
- MINOR
- PATCH
- VERSION
Public Class Methods
api_path(resource)
click to toggle source
# File lib/eventick.rb, line 60 def self.api_path(resource) BASE_PATH + resource end
auth()
click to toggle source
# File lib/eventick.rb, line 68 def self.auth @auth end
auth_token()
click to toggle source
# File lib/eventick.rb, line 64 def self.auth_token @auth.token if @auth end
config(&block)
click to toggle source
# File lib/eventick.rb, line 20 def self.config(&block) @auth = Eventick::Auth.new &block end
get(resource, params={})
click to toggle source
# File lib/eventick.rb, line 24 def self.get(resource, params={}) path = api_path resource path = with_params path, params method = Net::HTTP::Get.new(path) request(method) end
put(resource, params={})
click to toggle source
# File lib/eventick.rb, line 32 def self.put(resource, params={}) path = api_path resource method = Net::HTTP::Put.new(path) method.set_form_data(params) method.content_type = 'application/json' if params.is_a? String request(method, params) end
request(method, params={})
click to toggle source
# File lib/eventick.rb, line 41 def self.request(method, params={}) uri = URI("https://#{ BASE_URL }") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if auth && auth.authenticated? method.basic_auth auth_token, "" end response = http.start do |http| http.request method end return { } unless response.is_a? Net::HTTPSuccess # return response.body unless block_given? # yield JSON.parse(response.body) JSON.parse(response.body) unless response.body.nil? end
Private Class Methods
with_params(url, params )
click to toggle source
# File lib/eventick.rb, line 73 def self.with_params(url, params ) escape_pair = Proc.new {|k,v| CGI.escape(k.to_s)+'='+CGI.escape(v.to_s) } to_query = "?" + params.map(&escape_pair).join("&") unless params.empty? "#{ url }#{ to_query }" end