Module: Claire::Client
- Defined in:
- lib/claire_client.rb,
lib/claire_client.rb,
lib/claire_client/item.rb,
lib/claire_client/list.rb,
lib/claire_client/video.rb,
lib/claire_client/stream.rb,
lib/claire_client/category.rb,
lib/claire_client/listable.rb
Defined Under Namespace
Modules: Item, Listable Classes: Category, List, Stream, Video
Constant Summary collapse
- @@hostname =
"localhost:3000"
- @@api_key =
"33c80d2e38e6b1753982500721f76eccaee0d111"
- @@format =
'xml'
Class Method Summary collapse
-
.assemble_url(url = "", params = {}) ⇒ Object
assembles an URL from an string of params.
-
.config(args = {}) ⇒ Object
receives all parameters necessary for request-making.
-
.get(url = '') ⇒ Object
gets an URL.
Class Method Details
.assemble_url(url = "", params = {}) ⇒ Object
assembles an URL from an string of params.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/claire_client.rb', line 43 def self.assemble_url url="", params={} url = "http://#{@@hostname}/#{url}" url += ".#{@@format.downcase}" if @@format uri = URI.parse url (uri.query ||= "") << "api_key=#{@@api_key}" params.each do |k,v| uri.query << "&#{k}=#{v}" end puts uri uri end |
.config(args = {}) ⇒ Object
receives all parameters necessary for request-making.
36 37 38 39 40 |
# File 'lib/claire_client.rb', line 36 def self.config args={} args.each do |k,v| class_variable_set "@@#{k}", v end end |
.get(url = '') ⇒ Object
gets an URL. Assembles it first.
57 58 59 60 61 62 63 |
# File 'lib/claire_client.rb', line 57 def self.get url='' url = assemble_url(url) request = Net::HTTP.get_response url return request.body if request.is_a? Net::HTTPSuccess rescue Exception => e raise end |