Class: Rubervu::Ubervu
- Inherits:
-
Object
- Object
- Rubervu::Ubervu
- Defined in:
- lib/rubervu/ubervu.rb
Overview
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(api_key, api_url = 'http://api.contextvoice.com') ⇒ Ubervu
constructor
Initializes the Ubervu Class.
-
#reactions ⇒ Object
Maps UbervuReaction.
-
#request(resource, function, params, method = 'get', post_data = nil, api_key = @api_key, api_url = @api_url) ⇒ Object
Processes the request.
-
#resources ⇒ Object
Maps UbervuResource.
Constructor Details
#initialize(api_key, api_url = 'http://api.contextvoice.com') ⇒ Ubervu
Initializes the Ubervu Class.
16 17 18 19 |
# File 'lib/rubervu/ubervu.rb', line 16 def initialize(api_key, api_url = 'http://api.contextvoice.com') @api_key = api_key @api_url = api_url end |
Instance Method Details
#reactions ⇒ Object
Maps UbervuReaction. See UbervuReaction for more information about methods
27 28 29 |
# File 'lib/rubervu/ubervu.rb', line 27 def reactions UbervuReaction.new(@api_key, @api_url) end |
#request(resource, function, params, method = 'get', post_data = nil, api_key = @api_key, api_url = @api_url) ⇒ Object
Processes the request. Creates the API call and returns a JSON parsed result.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rubervu/ubervu.rb', line 32 def request(resource, function, params, method = 'get', post_data = nil, api_key = @api_key, api_url = @api_url) rq = "#{api_url}/#{API_VER}/#{resource}/#{function}?apikey=#{CGI.escape api_key}&format=#{CGI.escape FORMAT}" if params and params.size > 0 params.each_pair do |key, value| rq += "&#{key}=#{CGI.escape value}" end end new_post_data = [] if post_data and post_data.size > 0 post_data.each_pair do |key, value| new_post_data.push("#{key}=#{CGI.escape value}") end end post_data = new_post_data.join('&') result = case method when 'get' get(rq) when 'post' post(rq, post_data) when 'put' put(rq, post_data) when 'delete' delete(rq) end case result when Net::HTTPSuccess JSON.parse(result.body) else result.error! end end |
#resources ⇒ Object
Maps UbervuResource. See UbervuResource for more information about methods.
22 23 24 |
# File 'lib/rubervu/ubervu.rb', line 22 def resources UbervuResource.new(@api_key, @api_url) end |