Class: Whoa::Request
- Inherits:
-
Object
- Object
- Whoa::Request
- Defined in:
- lib/whoa/request.rb
Class Method Summary collapse
- .auth_token ⇒ Object
- .build_payload ⇒ Object
- .build_xml_namespaces ⇒ Object
- .headers ⇒ Object
-
.method_missing(id, *args, &blk) ⇒ Object
For http verbs.
- .namespaces ⇒ Object
- .send_to_wo(verb, url, payload = nil) ⇒ Object
Class Method Details
.auth_token ⇒ Object
6 7 8 |
# File 'lib/whoa/request.rb', line 6 def auth_token @auth_token ||= Whoa::Authentication.new.auth_token end |
.build_payload ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/whoa/request.rb', line 35 def build_payload xml = Builder::XmlMarkup.new xml.entry(build_xml_namespaces) do yield xml xml.gwo :analyticsAccountId, Whoa.account_id end end |
.build_xml_namespaces ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/whoa/request.rb', line 27 def build_xml_namespaces returning Hash.new do |hash| namespaces.each_pair do |key, value| hash.merge!({"xmlns#{':'+key.to_s unless key == :base}" => value}) end end end |
.headers ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/whoa/request.rb', line 10 def headers @headers ||= { :content_type => "application/atom+xml", 'Authorization' => "GoogleLogin auth=#{auth_token}" } end |
.method_missing(id, *args, &blk) ⇒ Object
For http verbs
52 53 54 55 56 57 58 |
# File 'lib/whoa/request.rb', line 52 def method_missing(id, *args, &blk) if id.to_s =~ /^(get|post|put|delete)/ send_to_wo(id, *args, &blk) else super end end |
.namespaces ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/whoa/request.rb', line 18 def namespaces { :base => 'http://www.w3.org/2005/Atom', :gwo => 'http://schemas.google.com/analytics/websiteoptimizer/2009', :app => 'http://www.w3.org/2007/app', :gd => 'http://schemas.google.com/g/2005' } end |
.send_to_wo(verb, url, payload = nil) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/whoa/request.rb', line 44 def send_to_wo(verb, url, payload=nil) args = verb.to_s =~ /(post|put)/ ? [url, payload, headers] : [url, headers] RestClient.send(verb, *args) do |resp| yield resp end end |